A solution to the 1st problem of the 39th Bundeswettbewerb Informatik (German Olympiad in Informatics)