how to solve this kind of problem?
can anyone suggest approach to solve this problem? https://mirror.codeforces.com/gym/102157/problem/3
CF Edu Round 173 Solution Discussion