https://codeforces.com/contest/1385/problem/F

Please help me with this problem .I am unable to understand the code given in the editorial.

Maybe this could help https://codeforces.com/contest/1385/submission/87198725