BSTOPS All test cases not being passed

I am not able to pass all the test cases with my code. I am not able to figure out the mistake in my code. Please help me out
Here is my code: https://www.codechef.com/viewsolution/33228345