Art of Problem Solving

2021 JMPSC Invitationals Problems/Problem 9