NZEC in STUPMACH

Problem code STUPMACH

When I am executing the code on python’s IDE it works perfectly fine, but when i submit or run on Codechef it says NZEC Error.
please help.
https://www.codechef.com/viewsolution/36152044

try to run it for this test case:

1
5
1 2 3 4 5

you will get the answer

what’s your approach?
i think it can be done in simple manner.

thanks, solves the problem!