Solution for the second task of the second round of the 31st BwInf (national CS competition in Germany).