Why am i getting wrong answer for this code?

The question is as follows:

and here’s my solution to it:
https://www.codechef.com/viewsolution/18994787

Thanks for the help!