How to solve DLINE question of December lunchtime 2018?

Can somebody please help me out with the problem DLINE

https://discuss.codechef.com/questions/143000/dline-editorial