Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if m==0:
    if n==3:
        print(100)
    elif n==2:
        print(10)
    else :
        print(0)
elif (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
else:
    if (n==3 or n==2) and len(a[0]) == 0:
        a[0].append(1)
    if (n==3 or n==2) and a[0][0] == 0:
        print(-1)
    else:
        for i in range(n):
            if len(a[i]) == 1:
                ans += a[i][0] * (10**(n-1-i))
        print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if m==0:
    if n==3:
        print(100)
    elif n==2:
        print(10)
    else :
        print(0)
elif (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
else:
    if (n==3 or n==2) and len(a[0]) == 0:
        a[0][0]=1
    if (n==3 or n==2) and a[0][0] == 0:
        print(-1)
    else:
        for i in range(n):
            if len(a[i]) == 1:
                ans += a[i][0] * (10**(n-1-i))
        print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if m==0:
    if n==3:
        print(100)
    elif n==2:
        print(10)
    else :
        print(0)
elif (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif (n==3 or n==2) and len(a[0]) == 0:
    a[0][0]=1
    if (n==3 or n==2) and a[0][0] == 0:
        print(-1)
    else:
        for i in range(n):
            if len(a[i]) == 1:
                ans += a[i][0] * (10**(n-1-i))
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if m==0:
    if n==3:
        print(100)
    elif n==2:
        print(10)
    else :
        print(0)
elif (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif (n==3 or n==2) and a[0][0] == 0:
    print(-1)
else:
    if n==3 and len(a[0])==0 and a[1][0]==0:
        a[0].append(1)
    for i in range(n):
        if len(a[i]) == 1:
            ans += a[i][0] * (10**(n-1-i))
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif (n==3 or n==2) and a[0][0] == 0:
    print(-1)
else:
    if n==3 and len(a[0])==0 and a[1][0]==0:
        a[0].append(1)
    for i in range(n):
        if len(a[i]) == 1:
            ans += a[i][0] * (10**(n-1-i))
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif n==3 and n==2 and a[0][0] == 0:
    print(-1)
else:
    if n==3 and len(a[0])==0 and a[1][0]==0:
        a[0].append(1)
    for i in range(n):
        if len(a[i]) == 1:
            ans += a[i][0] * (10**(n-1-i))
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif a[0][0] == 0:
    print(-1)
else:
    if len(a[0])==0 and a[1][0]==0:
        a[0].append(1)
    for i in range(n):
        if len(a[i]) == 1:
            ans += a[i][0] * (10**(n-1-i))
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif a[0][0] == 0:
    print(-1)
else:
    if len(a[0])==0 and a[1][0]==0:
        a[0].append(1)
    for i in range(3):
        if len(a[i]) == 1:
            ans += a[i][0] * (10**(2-i))
    print(ans)