Buggy python submission (verdict: Runtime Error):


def solve(N,M,S,C) -> int:
    if(N == 1): return min(C)
    dic = {key:[] for key in range(1,N+1)}
    ans = 10**5
    for s,c in zip(S,C):
        if(s in dic.keys()):
            dic[s].append(c)
        else:
            dic[s]=[c]
    if(N != 1):
        if(0 in dic[1]):
            dic[1].remove(0)
        for i in range(2,N+1):
            if(dic[i] == []):
                dic[i].append(0)
    if(dic[1]==[]):
        return -1
    else:
        ans = ""
        for values in dic.values():
            tmp = min(values)
            ans+= str(tmp)
        return int(ans)
    


def main():
    N,M = map(int,input().split())
    S = []
    C = []
    for _ in range(M):
        s,c = map(int,input().split())
        S.append(s)
        C.append(c)
    # solve()
    print(solve(N,M,S,C))
if __name__ == "__main__":
    main()


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

for _ in range(M):
    s,c=map(int,input().split())
    SC.append([s,c])

ans=-1
for i in range(10**N):
    if(len(str(i)) == N):
        for j in range(M):
            s=SC[j][0] - 1
            c=SC[j][1]
            tmp=list(str(i))
            if(tmp[s] != str(c) ):
                break
        else:
            if(ans == -1):
                ans=i
            else:
                ans=min(ans,i)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
N,M=map(int,input().split())
SC={}
for i in range(1,N + 1):
    SC[i]=[]
for _ in range(M):
    s,c=map(int,input().split())
    SC[s].append(c*10**(N - s))

ans=[]
for h in SC[1]:
    tmp=h
    if(N == 1):
        ans.append(tmp)
    else:
        for t in SC[2]:
            if(N == 2 and tmp != 0):
                ans.append(tmp + t)
            else:
                for j in SC[3]:
                    if(len(str(tmp))!= 0):
                        ans.append(tmp + t + j)
        else:
            for j in SC[3]:
                if(len(str(tmp)) != 0):
                    ans.append(tmp + j)

if(ans == []):
    print(-1)
elif(len(str(min(ans))) == N):
    print(min(ans))
else:
    print(-1)

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

for _ in range(M):
    s,c=map(int,input().split())
    SC.append([s,c])

ans=-1
for i in range(10**N):
    if(len(str(i)) == N):
        for j in range(M):
            s=SC[j][0] - 1
            c=SC[j][1]
            tmp=list(str(i))
            if(tmp[s] != str(c) ):
                break
        else:
            if(ans == -1):
                ans=i
            else:
                ans=min(ans,i)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
N,M=map(int,input().split())
SC=dict()
for n in range(1,N+1):
    SC[n]=[]

for _ in range(M):
    s,c=map(int,input().split())
    SC[s].append(c)
if(N == 1):
    print(0)
    sys.exit()
ans = [i*10**(N - 1) for i in SC[1] if i != 0]
SC.pop(1)
for item in SC.items():
    keta=item[0]
    for kazu in item[1]:
        number = kazu * 10 ** (N - keta)
        for i in range(len(ans)):
            a = ans.pop(0)
            ans.append(a + number)
print(min(ans))


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

for _ in range(M):
    s,c=map(int,input().split())
    SC.append([s,c])

ans=-1
for i in range(10**N):
    if(len(str(i)) == N):
        for j in range(M):
            s=SC[j][0] - 1
            c=SC[j][1]
            tmp=list(str(i))
            if(tmp[s] != str(c) ):
                break
        else:
            if(ans == -1):
                ans=i
            else:
                ans=min(ans,i)
print(ans)

Buggy python submission (verdict: Runtime Error):
A = []

for _ in range(3):
    lis=list(map(int,input().split()))
    A.append(lis)

N = int(input())
ans=[]
for _ in range(N):
    b=int(input())
    for i in range(3):
        if(b in A[i]):
            ans.append([i+1,A[i].index(b)+1])
            break
tate=False
if(ans == []):
    print("No")
else:
    counter1=[0,0,0]
    counter2=[0,0,0]
    counter3=0
    for a in ans:
        if(a[0]==1):
            counter1[0]+=1
        elif(a[0] == 2):
            counter1[1]+=1
        elif(a[0] == 3):
            counter1[2]+=1

        if(a[1] == 1):
            counter2[0]+=1
        elif(a[1] == 2):
            counter2[1]+=1
        elif(a[1] == 3):
            counter2[2]+=1
        if(a[0] == a[1] or a[0] == 1 and a[1] == 3 or a[1]==1 and a[0]==3):
            counter3+=1

    if(3 in counter1 or 3 in counter2 or counter3 >=3):
        print("Yes")
    else:
        print("No")


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

for _ in range(M):
    s,c=map(int,input().split())
    SC.append([s,c])

ans=-1
for i in range(10**N):
    if(len(str(i)) == N):
        for j in range(M):
            s=SC[j][0] - 1
            c=SC[j][1]
            tmp=list(str(i))
            if(tmp[s] != str(c) ):
                break
        else:
            if(ans == -1):
                ans=i
            else:
                ans=min(ans,i)
print(ans)