Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
S = []
C = []
for m in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
cnt = -1
man = False
for n in range(1000):
    num = str(n)
    res = True
    if len(num) != N:
        res = False
        continue
    for m in range(M):
        if num[S[m]-1] != str(C[m]):
            res = False
    if res:
        cnt = int(num)
        man = True
        break
if man:
    print(cnt)
else:
    print(cnt)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
res = True
A = [0]*N
B = ''
S = []
C = []
for m in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
T = max(S)
cnt = -1
man = False
for n in range(1, 1000):
    num = str(n)
    res = True
    for m in range(M):
        if len(num) != N:
            res = False
            continue
        if num[S[m]-1] != str(C[m]):
            res = False
    if res:
        cnt = int(num)
        man = True
        break
if man:
    print(cnt)
else:
    print(cnt)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
res = True
A = [0]*N
B = ''
S = []
C = []
for m in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
T = max(S)
cnt = -1
man = False
for n in range(1, 1000):
    num = str(n)
    res = True
    for m in range(M):
        if len(num) != N:
            res = False
            continue
        if num[S[m]-1] != str(C[m]):
            res = False
    if res:
        cnt = int(num)
        man = True
if man:
    print(cnt)
else:
    print(cnt)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [0]*N
res = True
for m in range(M):
    s, c = map(int, input().split())
    if A[s-1] != 0:
        if A[s-1] != c:
            res = False
            break
    else:
        A[s-1] = c
if len(A) == 1:
    A = str(A[2])
elif len(A) == 2:
    A = str(A[1]) + str(A[2])
else:
    A = str(A[0]) + str(A[1]) + str(A[2])
if res:
    print(A)
else:
    print('-1')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [0]*N
res = True
for m in range(M):
    s, c = map(int, input().split())
    if A[s-1] != 0:
        if A[s-1] != c:
            res = False
            break
    else:
        A[s-1] = c
A = str(A[0]) + str(A[1]) + str(A[2])
if res:
    print(A)
else:
    print('-1')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = []
B = [0]*N
for m in range(M):
    s, c = map(int, input().split())
    A.append([s, c])
res = True
for a in A:
    if a[0] == 1:
        if B[0] != 0:
            if B[0] != a[1]:
                res = False
                break
        else:
            B[0] = a[1]
    elif a[0] == 2:
        if B[1] != 0:
            if B[1] != a[1]:
                res = False
                break
        else:
            B[1] = a[1]
    elif a[0] == 3:
        if B[2] != 0:
            if B[2] != a[1]:
                res = False
                break
        else:
            B[2] = a[1]
# for b in range(len(B)-2):
    # if B[b] == 0 and B[b+1] == 0 and B[b+2] == 0:
        # res = False
B = str(B[0]) + str(B[1]) + str(B[2])
if res:
    print(B)
else:
    print('-1')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = []
B = [0]*N
for m in range(M):
    s, c = map(int, input().split())
    A.append([s, c])
res = True
for a in A:
    if a[0] == 1:
        if B[0] != 0:
            if B[0] != a[1]:
                res = False
                break
        else:
            B[0] = a[1]
    elif a[0] == 2:
        if B[1] != 0:
            if B[1] != a[1]:
                res = False
                break
        else:
            B[1] = a[1]
    elif a[0] == 3:
        if B[2] != 0:
            if B[2] != a[1]:
                res = False
                break
        else:
            B[2] = a[1]
for b in range(len(B)-2):
    if B[b] == 0 and B[b+1] == 0 and B[b+2] == 0:
        res = False

B = str(B[0]) + str(B[1]) + str(B[2])
if res:
    print(B)
else:
    print('-1')