Stuck in TOWIN

Its frustrating that I got stuck in the very first problem in my first day though I am not that of a beginner.So,I saw the editorial and followed the steps.Still getting wrong answer.
So help please!!!
https://www.codechef.com/viewsolution/37809793