Stucked in FloorI4



Problem Link:

I am not getting the concept to solve this question. i also tried to read the editorials and solutions but all in vain.Can anyone please explain me in detail how to solve this and what is the tricky thing that needs to be observed??