Code works while running, but not when I submit it

The question is:
https://www.codechef.com/MARCH19B/problems/CHDIGER

The issue is that when I run the code with a custom input, CodeChef tells me I have the right answer, but when I submit the code, I get a message saying it is the wrong answer (second screenshot).
(I am not able to share another image because I am a new user here)

I’ve checked my answer with other submissions as well, and I get the same answer with my code.
Why is it so?

2 Likes