Can someone plz tell me how my code for CARVANS is incorrect

I’ve tried my code for sample I/O and it’s running correctly. But according to codechef it’s giving incorrect answer on submitting.
Here’s my code: https://www.codechef.com/viewsolution/25268991