How to solve this problem?
https://training.ia-toki.org/problemsets/88/problems/459/
Codeforces Round 1095 Solution Discussion