Why i am getting NZEC runtime error

Problem link : https://www.codechef.com/problems/TRNSN
I have the following solution for this problem.

lens = int(input())
arrs = sorted([int(x) for x in input().split()])
cnt  = 0
for i in range(lens - 1):
    cnt += arrs[i] != arrs[i + 1]
print(cnt)

another one

lens = int(input())
arrs = sorted([int(x) for x in input().split()])
cnt  = 0
for i in range(1, lens):
    if arrs[i] != arrs[i - 1]:
        cnt += 1
print(cnt)

howerver looking at the submission i found this to be only AC solution in python 3

l=[]
while True:
    try:
        l+=list(map(int,input().split()))
    except:
        break
n=l[0]
del(l[0])
l.sort()
ans=0
for i in range(1,n):
    if l[i]!=l[i-1]:
        ans+=1
print(ans)

Can someone please tell me why my solution are getting NZEC and this solution does not.
Thanks in advance

The only thing I can think of is that the testcases are mis-formatted - perhaps with a stray line-break, or something; since this question is from an External Contest, this wouldn’t surprise me.

The (misformatted) test input:

4
1 2
1 4

would cause your submission to fail, but not the AC one you’ve posted.

1 Like