Nzec error in python (MARBLES)

hii, i am new to codechef .when i was solving the problem in idle with custom inputs it is executing succefully but when i submit it i get NZEC error .
plzz help me ,
below is the link f my soln
https://www.codechef.com/viewsolution/30968266