I am getting a WA in all except one test case in the problem CHRL4 (Chef and Way) when submitted to the grader

The link to the problem is: https://www.codechef.com/problems/CHRL4

The link to my solution is: https://www.codechef.com/viewsolution/22138303

Can someone help me figure out the problem in this code?

Thanks