This problem comes from the 2022 Chilean National Olympiad. Before looking at the solution, give the…