why i am getting runtime error(NZEC)

this is my code…
http://www.codechef.com/viewsolution/3406448

The problem is with line 3 and line 4. You wrote:

 n=int(input())
 m=int(input())

This will not work, because n and m are space separated(not newline separated) and the first input() takes both of them as a whole string. This gives the error:

ValueError: invalid literal for int() with base 10: '3 3'

when tried with first two lines of the given test case on the problem page.

To get rid of this, try this instead of those lines:

n,m=map(int,input().split())

This will split the string “3 3” as “3” and “3” and convert them to int and finally assign them to n and m respectively.

2 Likes