Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

if len(S) == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    else:
        print(100)
    exit()

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]] = C[i]

if N == 1:
    if ans[0] == 0:
        print(0)
        exit()

if ans[0] == -1:
    ans[0] = 1
elif ans[0] == 0:
    print(-1)
    exit()

ans = [a if a != -1 else 0 for a in ans]
print(''.join(list(map(str, ans))))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

z = zip(S, C)
z = sorted(z)
S, C = zip(*z)

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]] = C[i]

if ans[0] == 0:
    print(-1)
    exit()

while len(ans) > 0:
    if ans[0] == -1:
        ans = ans[1:]
    else:
        break

if ans == [-1]:
    print(-1)
    exit()

ans = [a if a != -1 else 0 for a in ans]
print(''.join(list(map(str, ans))))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

z = zip(S, C)
z = sorted(z)
S, C = zip(*z)

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]] = C[i]

if ans[0] == 0:
    print(-1)
    exit()

while len(ans) > 0:
    if ans[0] == -1:
        ans = ans[1:]
    else:
        break

if ans == [-1]:
    print(-1)
    exit()

ans = [a if a != -1 else 0 for a in ans]
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    """if s == 1 and c == 0:
        print(-1)
        exit()"""
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

z = zip(S, C)
z = sorted(z)
S, C = zip(*z)

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]-1] = C[i]

if ans[0] == 0:
    print(-1)
    exit()

if ans[0] == -1 and ans[1] == 0:
    print(-1)
    exit()

if ans[0] == -1 and ans[1] == -1 and ans[2] == -1:
    print(-1)
    exit()
if ans[0] == -1 and ans[1] == -1:
    print(ans[2])
    exit()
if ans[0] == -1:
    print(str(ans[1]) + str(max(0, ans[2])))
    exit()
print(str(ans[0]) + str(max(0, ans[1])) + str(max(0, ans[2])))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

z = zip(S, C)
z = sorted(z)
S, C = zip(*z)

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]-1] = C[i]

if ans[0] == 0:
    print(-1)
    exit()

if ans[0] == -1 and ans[1] == -1 and ans[2] == -1:
    print(-1)
    exit()
if ans[0] == -1 and ans[1] == -1:
    print(ans[2])
    exit()
if ans[0] == -1:
    print(str(ans[1]) + str(max(0, ans[2])))
    exit()
print(str(ans[0]) + str(max(0, ans[1])) + str(max(0, ans[2])))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        print(-1)
        exit()
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

z = zip(S, C)
z = sorted(z)
S, C = zip(*z)
for i in range(1, max(S)+1):
    if i != 1 and i not in S:
        print(0, end='')
    if i in S:
        print(C[S.index(i)], end='')