Problem p02761 (python)

Fixed submission:
import sys
n,m=map(int,input().split())
ans=[0]*n
scash=[]
buf=0
for i in range(m):
    s,c=map(int,input().split())
    if s not in scash:
        ans[s-1]+=c
        scash.append(s)
    elif (s in scash) and c!=ans[s-1]:
        buf+=1
        scash.append(s)
if n==1 and ans[0]==0:
    print(0)
    sys.exit()
if buf==0 and ans[0]!=0:
    anstr=[str(num) for num in ans]
    print(''.join(anstr))
elif buf==0 and (1 not in scash):
    ans[0]+=1
    anstr=[str(num) for num in ans]
    print(''.join(anstr))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=[0]*n
buf=0
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]==0:
        ans[s-1]+=c
    elif ans[s-1]!=0 and c!=ans[s-1]:
        buf+=1
if buf==0 and ans[0]!=0:
    anstr=[str(num) for num in ans]
    print(''.join(ans))
elif buf==0 and ans[0]==0:
    print(-1)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
l=[]
cnt=0
for i in range(m):
    s,c=map(int, input().split())
    l.append([s,c])
    if s==1 and c==0: #最上位の位が0の時に対する処理
        cnt+=1
if m==1 and s==1 and c==0:
    print('-1')
elif m==1 and s!=n:
    print(10**(n-1)+c*(10**(n-s)))
elif m==1:
    print(c*(10**(n-s)))
else:
    buf=0
    for i in range(m-1):
        for j in range(i+1,m):
            if l[i][0]==l[j][0] and l[i][1]!=l[j][1]:
                buf+=1
    if buf!=0 or cnt!=0:
        print('-1')
    else:
        l.sort()
        ans=l[0][1]*(10**(n-l[0][0]))
        for i in range(1,m):
            if l[i-1][0]==l[i][0]:
                continue
            else:
                ans+=l[i][1]*(10**(n-l[i][0]))
        print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
l=[]
cnt=0
if m==1:
    s,c=map(int, input().split())
    if s==1 and c==0:
        print('-1')
    elif s!=n:
        print(10**(n-1)+c*(10**(n-s)))
    else:
        print(c*(10**(n-s))
else:
    for i in range(m):
        s,c=map(int, input().split())
        l.append([s,c])
        if s==1 and c==0: #最上位の位が0の時に対する処理
            cnt+=1
    buf=0
    for i in range(m-1):
        for j in range(i+1,m):
            if l[i][0]==l[j][0] and l[i][1]!=l[j][1]:
                buf+=1
    if buf!=0 or cnt!=0:
        print('-1')
    else:
        l.sort()
        ans=l[0][1]*(10**(n-l[0][0]))
        for i in range(1,m):
            if l[i-1][0]==l[i][0]:
                continue
            else:
                ans+=l[i][1]*(10**(n-l[i][0]))
        print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
l=[]
cnt=0
for i in range(m):
    s,c=map(int, input().split())
    l.append([s,c])
    if s==1 and c==0: #最上位の位が1の時に対する処理
        cnt+=1
buf=0
for i in range(m-1):
    for j in range(i+1,m):
        if l[i][0]==l[j][0] and l[i][1]!=l[j][1]:
            buf+=1
if buf!=0 or cnt!=0:
    print('-1')
else:
    l.sort()
    ans=l[0][1]*(10**(n-l[0][0]))
    for i in range(1,m):
        if l[i-1][0]==l[i][0]:
            continue
        else:
            ans+=l[i][1]*(10**(n-l[i][0]))
    print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
l=[]
cnt=0
for i in range(m):
    s,c=map(int, input().split())
    l.append([s,c])
    if s==1 and c==0: #最上位の位が1の時に対する処理
        cnt+=1
buf=0
for i in range(m-1):
    for j in range(i+1,m):
        if l[i][0]==l[j][0] and l[i][1]!=l[j][1]:
            buf+=1
if buf!=0 or cnt!=0:
    print('-1')
else:
    l.sort()
    ans=l[0][1]*(10**(3-l[0][0]))
    for i in range(1,m):
        if l[i-1][0]==l[i][0]:
            continue
        else:
            ans+=l[i][1]*(10**(3-l[i][0]))
    print(ans)