Source: https://www.math.univ-paris-diderot.fr/diffusion/_media/rallye_09_solution.pdf