Source: https://www.i-profs.fr/problemes/c2/conference_C1_2_Canivenc_dec09.pdf