WA in The Gray-Similar code

https://www.codechef.com/viewsolution/37020212