Not able to get the logic

Hello…
I am doing this question from codeforces…
https://codeforces.com/problemset/problem/1312/C
Not able to come up with proper logic… and the editorial also …i am not able to understand properly.
Please give some idea… how to approach this question…

hello @ashishnnnnn please give me sometime to as i also have go through it first .
till then please tell me what you havenot understood in this question and editorial ?

I have understood the question… But not able to come up with a proper approch…

hey @ashishnnnnn please see this :