Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans=0
for i in range(N+1):
    if A[i]>K:
        break
    else:
        ans=max(ans,i)
        for j in range(M+1):
            if A[i]+B[j]>K:
                break
            else:
                ans=max(ans,i+j)
print(ans)   

Fixed submission:

N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i-1
        break
else:
    ans1=N
ans2=0
ans3=0
# print(ans1)
for i in range(ans1+1):
#     print(i)
    while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
        ans2+=1
#         print(ans1,ans2,i)
    ans3=max(ans3,ans1+ans2-1)
print(ans3)
Buggy python submission (verdict: Runtime Error):
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)

    if x1<len(P) and P[x1]!=A:
        print(A)
        break
        
    if x2<len(P) and P[x2]!=B:
        print(B)
        break

Fixed submission:
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)
    if x1<len(P) and P[x1]!=A:
        print(A)
        break
    if x2<len(P) and P[x2]!=B:
        print(B)
        break
    if x2==len(P):
        print(B)
        break

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()

P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)

    if P[x1]!=A:
        print(A)
        break
        
    if P[x2]!=B:
        print(B)
        break
        

Fixed submission:
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)
    if x1<len(P) and P[x1]!=A:
        print(A)
        break
    if x2<len(P) and P[x2]!=B:
        print(B)
        break
    if x2==len(P):
        print(B)
        break

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if P[x]!=X:
    print(X)
    sys.exit()

A=X
B=X

while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)
    if P[x1]!=A:
        print(A)
        break
    if P[x2]!=B:
        print(B)
        break
        

Fixed submission:
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)
    if x1<len(P) and P[x1]!=A:
        print(A)
        break
    if x2<len(P) and P[x2]!=B:
        print(B)
        break
    if x2==len(P):
        print(B)
        break
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=1
for i in A:
    ans*=i
if ans>10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
import sys
N=int(input())
A=list(map(int,input().split()))
if 0 in A:
    print(0)
    sys.exit()
    
ans=1
for i in A:
    ans*=i
    if ans>10**18:
        print(-1)
        sys.exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
import re
T=input()
N=len(re.findall(r'\?',T))
A=[]
def dfs(nums,length):
    if length==N:
        A.append(nums)
        return
    for i in range(0,2):
        new_nums=nums+[i]
        dfs(new_nums,length+1)
dfs([],0)
D={0:'P',1:'D'}
ans=0
ans2=''
for i in A:
    count=0
    new_T=''
    for j in T:
        if j=='?':
            j=D[i[count]]
            count+=1
        new_T=new_T+j
    if ans<=len(re.findall(r'PD',new_T))+len(re.findall(r'D',new_T)):
        ans2=new_T
print(ans2)

Fixed submission:
T=input()
new_T=''
for i in T:
    if i=='?':
        i='D'
    new_T=new_T+i
print(new_T)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(N):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0
while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.appendleft(i)
print('Yes')
print(*visited2[2:],sep='\n')

Fixed submission:
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(M):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0

while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.append(i)
print('Yes')
print(*visited2[2:],sep='\n')

Buggy python submission (verdict: Runtime Error):
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(N):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0
while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.append(i)
print('Yes')
print(*visited2[2:],sep='\n')

Fixed submission:
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(M):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0

while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.append(i)
print('Yes')
print(*visited2[2:],sep='\n')
Buggy python submission (verdict: Runtime Error):
N,M,X=list(map(int,input().split()))
C=[list(map(int,input().split())) for i in range(N)]
result=[]
for i in range(2**N):
    A=[]
    for j in range(N):
        if (i>>j)&1:
            A.append(C[j])
    result.append(A)
inf=float('inf')
ans2=inf

for i in result:
    D=dict()
    ans1=0
    if i!=[]:
        for j in i:
            ans1+=j[0]
            D[1]=D.get(1,0)+j[1]
            D[2]=D.get(2,0)+j[2]
            D[3]=D.get(3,0)+j[3]
            
        if (D[1]>=X) and (D[2]>=X) and (D[3]>=X):
            ans2=min(ans2,ans1)
if ans2==inf:
    print(-1)
else:
    print(ans2)     

Fixed submission:
N,M,X=list(map(int,input().split()))
C=[list(map(int,input().split())) for i in range(N)]
result=[]
for i in range(2**N):
    A=[]
    for j in range(N):
        if (i>>j)&1:
            A.append(C[j])
    result.append(A)
inf=float('inf')
ans2=inf

for i in result:
    D=dict()
    ans1=0
    ans3=0
    if i!=[]:
        for j in i:
            ans1+=j[0]
            for k,value in enumerate(j):
                if k!=0:
                    D[k]=D.get(k,0)+value
            
        for j in D.values():
            if j>=X:
                ans3+=1
        if ans3==M:
            ans2=min(ans2,ans1)
if ans2==inf:
    print(-1)
else:
    print(ans2)
Buggy python submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]

B=[0]*N
for i in A:
    if H[i[0]]>H[i[1]]:
        B[i[0]]=1
    if H[i[0]]<H[i[1]]:
        B[i[1]]=1
print(B.count(0))

Fixed submission:
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]-1]>H[i[1]-1]:
        B[i[1]-1]=1
    elif H[i[0]-1]<H[i[1]-1]:
        B[i[0]-1]=1
    else:
        B[i[0]-1]=1
        B[i[1]-1]=1
print(B.count(0))

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

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]]>H[i[1]]:
        B[i[0]]=1
    elif H[i[0]]<H[i[1]]:
        B[i[1]]=1
print(B.count(0))

Fixed submission:
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]-1]>H[i[1]-1]:
        B[i[1]-1]=1
    elif H[i[0]-1]<H[i[1]-1]:
        B[i[0]-1]=1
    else:
        B[i[0]-1]=1
        B[i[1]-1]=1
print(B.count(0))

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

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]]>H[i[1]]:
        B[i[0]]=1
    elif H[i[0]]<H[i[1]]:
        B[i[i]]=1
print(B.count(0))

Fixed submission:
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]-1]>H[i[1]-1]:
        B[i[1]-1]=1
    elif H[i[0]-1]<H[i[1]-1]:
        B[i[0]-1]=1
    else:
        B[i[0]-1]=1
        B[i[1]-1]=1
print(B.count(0))

Buggy python submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
B=[0]*N
from functools import lru_cache
@lru_cache(maxsize=1000)
for i in A:
    ans=max(H[i[0]-1],H[i[1]-1])
    B[H.index(ans)]=B[H.index(ans)]+1
print(B.count(0))

Fixed submission:
N,M=list(map(int,input().split()))
H=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]

B=[0]*N
# from functools import lru_cache
# @lru_cache(maxsize=1000)
# def yapoos()
for i in A:
    if H[i[0]-1]>H[i[1]-1]:
        B[i[1]-1]=1
    elif H[i[0]-1]<H[i[1]-1]:
        B[i[0]-1]=1
    else:
        B[i[0]-1]=1
        B[i[1]-1]=1
print(B.count(0))
Buggy python submission (verdict: Time Limit Exceeded):
A,B,N=map(int,input().split())
count=0
x=0
for i in range(N+1):
    result=(i/B)-(int(i/B))
    if count<result:
        count=result
        x=i
result=int(A*x/B)-(A*int(x/B))
print(result)

Fixed submission:
A,B,N=map(int,input().split())
x=min(B-1,N)
print(int(A*x/B)-A*int(x/B))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,N=map(int,input().split())
count=0
for i in range(N+1):
    result=int(A*i/B)-(A*int(i/B))
#     print(result)
    if count<result:
        count=result
print(count)

Fixed submission:
A,B,N=map(int,input().split())
x=min(B-1,N)
print(int(A*x/B)-A*int(x/B))
Buggy python submission (verdict: Runtime Error):
N=int(input())
kuji=[list(map(str,input().split())) for i in range(N)] 
print(len(set(kuji)))

Fixed submission:
N=int(input())
listA=[input() for i in range(N)]
listB=set(listA)
print(len(listB))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
listA=[input() for i in range(N)]
listB=[]
[x for x in listA if not x in listB and listB.append(x)]
print(len(listB))

Fixed submission:
N=int(input())
listA=[input() for i in range(N)]
listB=set(listA)
print(len(listB))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=map(int,input().split())
if N>=sum(A):
    print(N-sum(A))
else:
    print(-1

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
ans=N-sum(A)
if ans<0:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))


for i in range(1,N+1):
    count=0
    for j in A:
        if i==j:
            count+=1
    print(count)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
counter=[0]*N
for i in A:
    counter[i-1]+=1
print(*counter,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
# N=7
A=list(map(int,input().split()))
# A=sorted(A)
B=[]
for i in range(N):
    B=[j for j in A if j-1==i]
    print(len(B))
    B=[]

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
counter=[0]*N
for i in A:
    counter[i-1]+=1
print(*counter,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
# N=7
A=list(map(int,input().split()))
# A=sorted(A)
B=[]
for i in range(N):
    B=[j for j in A if j-1==i]
    print(len(B))
    B=[]

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
counter=[0]*N
for i in A:
    counter[i-1]+=1
print(*counter,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
# N=7
A=list(map(int,input().split()))
A=sorted(A)
B=[]
for i in range(N):
    B=[j for j in A if j-1==i]
    print(len(B))
    B=[]

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
counter=[0]*N
for i in A:
    counter[i-1]+=1
print(*counter,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
# N=7
A=list(map(int,input().split()))
A=sorted(A)
B=[]
for i in range(N):
    for j in A:
        if j-1==i:
            B.append(j)
    print(len(B))
    B=[]

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
counter=[0]*N
for i in A:
    counter[i-1]+=1
print(*counter,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=gcd(i,j,k)
print(ans)  

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K=int(input())
a=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a.append(gcd(i,j,k))
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K=int(input())
a=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a.append(gcd(i,j,k))
print(sum(a))

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K=int(input())
a=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a.append(gcd(i,j,k))
print(sum(a))
Buggy python submission (verdict: Runtime Error):
N,K=list(map(int,input().split()))
ans=N
A=set()
while ans>0:
    A.add(ans)
    ans=ans-K
    A.add(ans)
print(min([abs(i) for i in A]))

Fixed submission:
N,K=list(map(int,input().split()))
print(min(N%K,K-N%K))
Buggy python submission (verdict: Time Limit Exceeded):
S='10'
Input=int(input())
A=[]
while Input!=len(A)+9:
    count=0
    for i in range(len(S)-1):
        if abs(int(S[i])-int(S[i+1])) <=1:
            count+=1
        if count==len(S)-1:
            A.append(S)
    S=str(int(S)+1)
print(int(A[-1]))

Fixed submission:
import heapq
K=int(input())
queue=[i for i in range(1,10)]
heapq.heapify(queue)
for i in range(K-1):
    n=heapq.heappop(queue)
    if n%10==0:
        heapq.heappush(queue,n*10+0)
        heapq.heappush(queue,n*10+1)
    elif n%10==9:
        heapq.heappush(queue,n*10+8)
        heapq.heappush(queue,n*10+9) 
    else:
        heapq.heappush(queue,n*10+(n%10))
        heapq.heappush(queue,n*10+(n%10)+1)
        heapq.heappush(queue,n*10+(n%10)-1)
print(queue[0])
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y=list(map(int,input().split()))
G=[]
for i in range(1,N):
    G.append([i,i+1])
G.append([X,Y])
graph=[[] for i in range(N+1)]
for i in range(N):
    u,*v=G[i]
    v.sort()
    for j in v:
        graph[u].append(j)
        graph[j].append(u)
counter=[[] for i in range(N+1)]
for j in range(1,N+1):
    stack=[j]
    visited=[-1 for i in range(N+1)]
    visited[j]=0
    while stack:
        n=stack.pop(0)
        for i in graph[n]:
            n_n=i
            if visited[n_n]<0:
                visited[n_n]=visited[n]+1
                stack.append(n_n)
    for i,value in enumerate(visited):
        for k in range(1,N):
            if value==k:
                counter[k].append([j,i])
for i,value in enumerate(counter):
    if not (i==0 or i==N):
        print(int(len(value)/2))

Fixed submission:
N,X,Y=list(map(int,input().split()))
A=[[] for i in range(N+1)]
for i in range(1,N):
    for j in range(i,N+1):
        A[int(min(j-i,abs(X-i)+abs(Y-j)+1))].append(1)
        
for i in range(N):
    if i!=0:
        print(sum(A[i]))
Buggy python submission (verdict: Runtime Error):
from math import factorial as f
f_1,f_2=0,0
if N>1:
    f_1=f(N)/(f(2)*f(N-2))
if M>1:
    f_2=f(M)/(f(2)*f(M-2))
print(int(f_1+f_2))

Fixed submission:
N,M=list(map(int,input().split()))
from math import factorial as f
f_1,f_2=0,0
if N>1:
    f_1=f(N)/(f(2)*f(N-2))
if M>1:
    f_2=f(M)/(f(2)*f(M-2))
print(int(f_1+f_2))
Buggy python submission (verdict: Runtime Error):
A,B=list(map(int,input().split()))
ans=[]
for i in range(1,1010):
    if int(i*0.08)==A and int(i*0.1)==B:
        ans.append(i)
print(min(ans))

Fixed submission:
A,B=list(map(int,input().split()))
ans=[]
for i in range(10):
    if A==(8*B*10+8*i)//100:
        ans.append(i)
if ans==[]:
    print(-1)
else:
    print(B*10+min(ans))
Buggy python submission (verdict: Runtime Error):
import sys
A=[list(map(int,input().split())) for i in range()]
N=int(input())
b=[list(map(int,input().split())) for i in range(N)]
flat=[j for i in A for j in i]
for i,value in enumerate(flat):
    if [value] in b:
         flat[i]=-1
for i in range(3):
    if flat[i]==flat[i+1]==flat[i+2]==-1:
        print('Yes')
        sys.exit()
    if flat[i]==flat[i+3]==flat[i+6]==-1:
        print('Yes')
        sys.exit()
if flat[0]==flat[4]==flat[8]==-1 or flat[2]==flat[4]==flat[6]==-1:
    print('Yes')
    sys.exit()
print('No')

Fixed submission:
import sys
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[list(map(int,input().split())) for i in range(N)]
flat=[j for i in A for j in i]
for i,value in enumerate(flat):
    if [value] in b:
         flat[i]=-1
for i in range(3):
    if flat[i*3]==flat[i*3+1]==flat[i*3+2]==-1:
        print('Yes')
        sys.exit()
    if flat[i]==flat[i+3]==flat[i+6]==-1:
        print('Yes')
        sys.exit()
if flat[0]==flat[4]==flat[8]==-1 or flat[2]==flat[4]==flat[6]==-1:
    print('Yes')
    sys.exit()
print('No')
Buggy python submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')

Fixed submission:
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1:
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')

Buggy python submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')

Fixed submission:
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
import sys
S=[-1 for i in range(N)]
visited=[[] for i in range(N)]

for i in A:
    S[i[0]-1]=i[1]
    visited[i[0]-1].append(i[1])
for i in visited:
    if len(set(i))>1:
        print(-1)
        sys.exit()
if len(S)>1:
    if S[0]==0:
        print(-1)
        sys.exit()
    if S[0]==-1:
        S[0]=1

for i,value in enumerate(S):
    if value==-1:
        S[i]=0

print(*S,sep='')