Part of 2021 Ukraine National Mathematical Olympiad
Source: Ukrainian Mathematical Olympiad 2021. Day 2, Problem 9.7