Part of 2017 Mediterranean Mathematics Olympiad
Source: Mediterranean Mathematics Olympiad 2017, Problem 4