Problem p02761 (python)

Fixed submission:
import sys
N,M=list(map(int, input().split()))

s=[list(map(int, input().split())) for _ in range(M)]

a=["a" for _ in range(N)]

if len(s)==0 and N==1:
    print(0)
    sys.exit()
    
elif len(s)==0:
    print(10**(N-1))
    sys.exit()

for i in s:
    if i[1]==0 and i[0]==1 and N!=1:
        print(-1)
        sys.exit()
   
    if a[i[0]-1]=="a":
        a[i[0]-1]=str(i[1])
    
    elif a[i[0]-1]!="a" and a[i[0]-1]==str(i[1]):
        continue
        
    elif a[i[0]-1]!="a" and a[i[0]-1]!=str(i[1]):
        print(-1)
        sys.exit()

num=[int(i) if i!="a" else 0 for i in a ]
    
if N==1:
    print(int(num[-1]))
elif N==2:
    ans=10*int(num[0])+int(num[1])
    if ans//10==0:
        ans+=10
    print(ans)
elif N==3:
    ans=100*int(num[0])+10*int(num[1])+int(num[2])
    
    if ans//100==0:
        ans+=100
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N,M=list(map(int, input().split()))

s=[list(map(int, input().split())) for _ in range(M)]

a=["a" for _ in range(N+1)]

if len(s)==0 and N==1:
    print(0)
    sys.exit()
    
elif len(s)==0:
    print(10**(N-1))
    sys.exit()

for i in s:
    if i[1]==0 and i[0]==1 and N!=1:
        print(-1)
        sys.exit()
   
    if a[i[0]-1]=="a":
        a[i[0]-1]=str(i[1])
    
    elif a[i[0]-1]!="a" and a[i[0]-1]==str(i[1]):
        continue
        
    elif a[i[0]-1]!="a" and a[i[0]-1]!=str(i[1]):
        print(-1)
        sys.exit()

num=[int(i) if i!="a" else 0 for i in a ]
    
        
if N==1:
    print(int(num[2]))
elif N==2:
    ans=10*int(num[1])+int(num[2])
    if ans//10==0:
        ans+=10
    print(ans)
elif N==3:
    ans=100*int(num[0])+10*int(num[1])+int(num[2])
    
    if ans//100==0:
        ans+=100
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N,M=list(map(int, input().split()))

s=[list(map(int, input().split())) for _ in range(M)]

a=["a" for _ in range(N+1)]

if len(s)==0 and N==1:
    print(0)
    sys.exit()
    
elif len(s)==0:
    print(10**(N-1))
    sys.exit()

for i in s:
    if i[1]==0 and i[0]==1:
        print(-1)
        sys.exit()
    

    
    if a[i[0]-1]=="a":
        a[i[0]-1]=str(i[1])
    
    elif a[i[0]-1]!="a" and a[i[0]-1]==str(i[1]):
        continue
        
    elif a[i[0]-1]!="a" and a[i[0]-1]!=str(i[1]):
        print(-1)
        sys.exit()

num=[int(i) if i!="a" else 0 for i in a ]
    
        
if N==1:
    print(int(num[2]))
elif N==2:
    ans=10*int(num[1])+int(num[2])
    if ans//10==0:
        ans+=10
    print(ans)
elif N==3:
    ans=100*int(num[0])+10*int(num[1])+int(num[2])
    
    if ans//100==0:
        ans+=100
    print(ans)

Buggy submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(M)]

Num=0
A=[]
B=[]
C=[]
        
if N==3:
    if M==0:
        print(Num=100)
    
    else:
        for i in s:
            if i[0]==1:
                A.append(i[1])
            
            elif i[0]==2:
                B.append(i[1])
            
            elif i[0]==3:
                C.append(i[1])
    
        if len(A)==0:
            print(-1)
        elif min(A)==0:
            print(-1)
        else:
            Num+=min(A)*100
            if len(B)==0:
                pass
            elif len(B)!=0:
                Num+=min(B)*10
            if len(C)==0:
                pass
            elif len(C)!=0:
                Num+=min(C)
            print(Num)
        
elif N==2:
    if M==0:
        print(Num=10)
    
    else:    
        for i in s:
            if i[0]==1:
                B.append(i[1])
            
            elif i[0]==2:
                C.append(i[1])
        
        if len(B)==0:
            print(-1)
        elif min(B)==0:
            print(-1)
        else:
            Num+=min(B)*10
            if len(C)==0:
                pass
            elif len(C)!=0:
                Num+=min(C)
            print(Num)

elif N==1:
    if M==0:
        print(0)
    else;
        for i in s:
            if i[0]==1:
                C.append(i[1])
        
            if len(C)!=0:
                N+=min(C)
                print(Num)
            else:
                print(Num)

Buggy submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(M)]

Num=0
A=[]
B=[]
C=[]
for i in s:
    if i[0]==1:
        A.append(i[1])
            
    elif i[0]==2:
        B.append(i[1])
            
    elif i[0]==3:
        C.append(i[1])
        
if N==3:      
    if len(A)==0:
        print(-1)
    elif min(A)==0:
        print(-1)
    else:
        Num+=min(A)*100
        if len(B)==0:
            pass
        elif len(B)!=0:
            Num+=min(B)*10
        if len(C)==0:
            pass
        elif len(C)!=0:
            Num+=min(C)
        print(Num)
        
elif N==2:
    if min(B)==0:
        print(-1)
    elif len(B)==0:
        print(-1)
    else:
        Num+=min(B)*10
        if len(C)==0:
            pass
        elif len(C)!=0:
            Num+=min(C)
        print(Num)
elif N==1:
    if len(C)!=0:
        N+=min(C)
        print(Num)
    else:
        print(Num)

Buggy submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(M)]

Num=0

A=[]
B=[]
C=[]
for i in s:
    if i[0]==1:
        A.append(i[1])
            
    elif i[0]==2:
        B.append(i[1])
            
    elif i[0]==3:
        C.append(i[1])
        
if N==3:      
    if len(A)==0:
        print(-1)
    elif min(A)==0:
        print(-1)
    else:
        Num+=min(A)*100
        if len(B)==0:
            pass
        elif len(B)!=0:
            Num+=min(B)*10
        if len(C)==0:
            pass
        elif len(C)!=0:
            Num+=min(C)
        print(Num)
        
elif N==2:
    if min(B)==0:
        print(-1)
    elif len(B)==0:
        print(-1)
    else:
        Num+=min(B)*10
        if len(C)==0:
            pass
        elif len(C)!=0:
            Num+=min(C)
        print(Num)
elif N==1:
    N+=min(C)
    print(Num)