Help in a question

Hello codechef This is Aryan I am new to competitive programming! I was participating in Code-O-Fiesta in codechef right now(The contest is over now) I had a doubt in this problem:\n The Problem Link

I had solved it in one of the way I think is correct this is my solution My solution link

This solution works perfectly on the testcases and some random cases I made myself But it still shows wrong answer.

As the contest was over I looked into some of the solutions in my language but I was not able to understand them :frowning: Can anyone help me!! Thanks a lot!

@galencolin @ssrivastava990 @cubefreak777
please help me!!