WA in PSHOT

https://www.codechef.com/viewsolution/32703485
I tried a lot of testcases on my own, still can’t get it right. Any suggestions on the above code?