Https://www.codechef.com/viewsolution/39313854

https://www.codechef.com/viewsolution/39313854
can anyone explain the few testcases which is giving WA.
My solution is partially correct but could not figure out the edge case.