Help me in solving problem

problem:

my code:
https://www.codechef.com/viewsolution/1032374617

I am getting wrong answer. Help me to identify test case which is failing.