Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]

for i in range(1000):
    if len(str(i)) == N:
        for j in range(M):
            if str(i)[s[j]-1] != str(c[j]):
                break
        else:
            print(i)
            break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]
sc.sort()
if N==1:
    if 2 in s or 3 in s:
        ans=-1
    else:
        ans=sc[0][1]
if N==2:
    if 3 in s:
        ans=-1
    else:
        if sc[0][0]==1:
            for i in range(1,M):
                if sc[i][0]==2:
                    ans=sc[i][1]+sc[0][0]*10
            else:
                ans=sc[0][1]*10
if N==3:
    if sc[0][0]==1:
        for i in range(1,M):
            if sc[i][0]==2:
                for j in range(i,M):
                    if sc[j][0]==3:
                        ans=sc[0][1]*100+sc[i][1]*10+sc[j][1]
                else:
                    ans=sc[0][1]*100+sc[i][1]*10
        else:
            ans=sc[0][0]*100
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]
sc.sort()
sets=list(set(s))
setc=list(set(c))
if len(sets)!=len(setc):
    ans=-1
if len(setc)==1 and setc[0]==0:
    ans=0
elif sc[0][0]==1 and sc[0][1]==0:
    ans=-1
else:
    if len(sets)==3:
        ans=sc[0][1]*100+sc[1][1]*10+sc[2][1]
    elif len(sets)==2:
        if len(sc)==3:
            sc=[sc[0],sc[2]]
        if sc[0][0]==1:
            if sc[1][0]==2:
                if N==2:
                    ans=sc[0][1]*10+sc[1][1]
                if N==3:
                    ans=sc[0][1]*100+sc[1][1]*10
            if sc[1][0]==3:
                ans=sc[0][1]*100+sc[1][1]
        if sc[0][0]==2:
            ans=100+sc[0][0]*10+sc[0][1]
    elif len(sets)==1:
        if sc[0][0]==1:
            if N==1:
                ans=sc[0][1]
            if N==2:
                ans=sc[0][1]*10
            if N==3:
                ans=sc[0][1]*100
        if sc[0][0]==2:
            if N==1:
                ans=-1
            if N==2:
                ans=sc[0][1]*10
            if N==3:
                ans=100+sc[0][1]*10
        if sc[0][0]==3:
            if N==1:
                ans=-1
            if N==2:
                ans=-1
            if N==3:
                ans=sc[0][1]*100
if len(str(ans))==N:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]
sc.sort()
sets=list(set(s))
setc=list(set(c))
if len(sets)!=len(setc):
    ans=-1
if len(setc)==1 and setc[0]==0:
    ans=0
elif sc[0][0]==1 and sc[0][1]==0:
    ans=-1
else:
    if len(sets)==3:
        ans=sc[0][1]*100+sc[1][1]*10+sc[2][1]
    elif len(sets)==2:
        if len(sc)==3:
            sc=[sc[0],sc[2]]
        if sc[0][0]==1:
            if sc[1][0]==2:
                ans=sc[0][1]*100+sc[1][1]*10
            if sc[1][0]==3:
                ans=sc[0][1]*100+sc[1][1]
        if sc[0][0]==2:
            ans=100+sc[0][0]*10+sc[0][1]
    elif len(sets)==1:
        if sc[0][0]==1:
            if N==1:
                ans=sc[0][1]
            if N==2:
                ans=sc[0][1]*10
            if N==3:
                ans=sc[0][1]*100
        if sc[0][0]==2:
            if N==1:
                ans=-1
            if N==2:
                ans=sc[0][1]*10
            if N==3:
                ans=100+sc[0][1]*10
        if sc[0][0]==3:
            if N==1:
                ans=-1
            if N==2:
                ans=-1
            if N==3:
                ans=sc[0][1]*100
if len(str(ans))==N:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]
sc.sort()
sets=list(set(s))
setc=list(set(c))
if len(sets)!=len(setc):
    ans=-1
if len(setc)==1 and setc[0]==0:
    ans=0
elif sc[0][0]==1 and sc[0][1]==0:
    ans=-1
else:
    if len(sets)==3:
        ans=sc[0][1]*100+sc[1][1]*10+sc[2][1]
    elif len(sets)==2:
        if len(sc)==3:
            sc=[sc[0],sc[2]]
        if sc[0][0]==1:
            if sc[1][0]==2:
                ans=sc[0][1]*100+sc[1][1]*10
            if sc[1][0]==3:
                ans=sc[0][1]*100+sc[1][1]
        if sc[0][0]==2:
            ans=100+sc[0][0]*10+sc[0][1]
    elif len(sets)==1:
        if sc[0][0]==1:
            ans=sc[0][1]*100
        if sc[0][0]==2:
            ans=100+sc[0][1]*10
        if sc[0][0]==3:
            ans=100+sc[0][1]
if len(str(ans))==N:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]
sc.sort()
sets=list(set(s))
setc=list(set(c))
if len(sets)!=len(setc):
    print(-1)
if sets==0 and setc==0:
    print(0)
if sc[0][0]==1 and sc[0][1]==0:
    print(-1)
else:
    if len(sets)==3:
        print(sc[0][1]*100+sc[1][1]*10+sc[2][1])
    elif len(sets)==2:
        if len(sc)==3:
            sc=[sc[0],sc[2]]
        if sc[0][0]==1:
            if sc[1][0]==2:
                print(sc[0][1]*100+sc[1][1]*10)
            if sc[1][0]==3:
                print(sc[0][1]*100+sc[1][1])
        if sc[0][0]==2:
            print(100+sc[0][0]*10+sc[0][1])
    elif len(sets)==1:
        if sc[0][0]==1:
            print(sc[0][1]*100)
        if sc[0][0]==2:
            print(100+sc[0][1]*10)
        if sc[0][0]==3:
            print(100+sc[0][1])