Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
 
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    n=len(d[0])
    for k in range(n):
        for i in range(n):
            for j in range(n):
              s = d[i][k] + d[k][j]
              d[i][j] = min(d[i][j],s)
    return d
 
N,M,R=[int(x) for x in input().split()]
r=[int(x)-1 for x in input().split()]
 
#INF = float("inf")
route_list=[[10**8]*N for _ in range(N)]
 
for i in range(M):
    a,b,c=[int(x) for x in input().split()]
    route_list[a-1][b-1]=c
    route_list[b-1][a-1]=c
 
wa_list=warshall_floyd(route_list)
ans=30**9
 
for perm in permutations(r):
    #print(perm)
    cur = sum(wa_list[v][u] for v, u in zip(perm, perm[1:]))
    ans = min(ans, cur)
 
print(ans)


Fixed submission:
import numpy as np
from scipy.sparse.csgraph import dijkstra
import itertools
from scipy.sparse import csr_matrix
inf = 1 + 10**8
n, m, r = list(map(int, input().split()))
r = list(map(int, input().split()))
graph = np.full((n+1,n+1), inf)
for i in range(m):
    a,b,c = list(map(int, input().split()))
    graph[a][b] = c
    graph[b][a] = c
p_list = list(itertools.permutations(r,len(r)))
graph = dijkstra(csr_matrix(graph))
min_cost = inf * 200
for i in p_list:
    candidate = 0
    for j in range(len(i) - 1):
        candidate += graph[i[j]][i[j + 1]]
    if min_cost > candidate:
        min_cost = candidate
print(int(min_cost))
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if i == n - 1 and i + 1 == p[i]:
        count += 1
    if i + 1 == p[i]:
        tmp = p[i]
        p[i] = p[i+1]
        p[i+1] = tmp
        count += 1
print(count)


Fixed submission:
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if i == n - 1 and i + 1 == p[i]:
        count += 1
    elif i + 1 == p[i]:
        tmp = p[i]
        p[i] = p[i+1]
        p[i+1] = tmp
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if i + 1 == p[i]:
        tmp = p[i]
        p[i] = p[i+1]
        p[i+1] = tmp
        count += 1
print(count)


Fixed submission:
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if i == n - 1 and i + 1 == p[i]:
        count += 1
    elif i + 1 == p[i]:
        tmp = p[i]
        p[i] = p[i+1]
        p[i+1] = tmp
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
#値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    #検索済みに追加
    finished.add(node_n)
    #そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    #対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            #検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1],finished)

q,k = list(map(int, input().split()))
dfs(k, 0, set())
#各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s] + path[g])

Fixed submission:
import sys
sys.setrecursionlimit(200000)
n = int(input())
#値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    #検索済みに追加
    finished.add(node_n)
    #そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    #対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            #検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1],finished)

q,k = list(map(int, input().split()))
dfs(k, 0, set())
#各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s] + path[g])

Buggy python submission (verdict: Runtime Error):
n = int(input())
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]
for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    finished.add(node_n)
    path[node_n] = distance
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            dfs(next, distance + i[1],finished)
q,k = list(map(int, input().split()))
dfs(k,0,set())
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s]+path[g])

Fixed submission:
import sys
sys.setrecursionlimit(200000)
n = int(input())
#値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    #検索済みに追加
    finished.add(node_n)
    #そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    #対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            #検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1],finished)

q,k = list(map(int, input().split()))
dfs(k, 0, set())
#各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s] + path[g])
Buggy python submission (verdict: Runtime Error):
h, w = list(map(int, input().split()))
n = int(input())
ans = [[0 for i in range(w)] for j in range(w)]
dec = 1
p = 1
cnt = 0
index = 0
a = list(map(int, input().split()))
for i in range(h):
    while 0 <= index < w:
        if cnt == a[p-1]:
            p += 1
            cnt = 0
        ans[i][index] = p
        cnt += 1
        index += dec
    dec *= (-1)
    index += dec
for i in range(h):
    for j in range(w):
        print("{} ".format(ans[i][j]), end = '')
    print()
    

Fixed submission:
h, w = list(map(int, input().split()))
n = int(input())
ans = [[0 for i in range(w)] for j in range(h)]
dec = 1
p = 1
cnt = 0
index = 0
a = list(map(int, input().split()))
for i in range(h):
    while 0 <= index < w:
        if cnt == a[p-1]:
            p += 1
            cnt = 0
        ans[i][index] = p
        cnt += 1
        index += dec
    dec *= (-1)
    index += dec
for i in range(h):
    for j in range(w):
        print("{} ".format(ans[i][j]), end = '')
    print()
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = 0
pre = a[1] - a[0]
i = 2
while i < n:
    if pre * (a[i] - a[i-1]) < 0:
        ans += 1
        i += 1
        if i == n:
            break
    pre = a[i] - a[i-1]
    i += 1
print(ans+1)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
if n <= 2:
    print(1)
    exit()
pre = a[1] - a[0]
i = 2
while i < n:
    if pre * (a[i] - a[i-1]) < 0:
        ans += 1
        pre = 0
        i += 1
        if i == n:
            break
    if a[i] != a[i-1]:
        pre = a[i] - a[i-1]
    i += 1
print(ans + 1)
Buggy python submission (verdict: Runtime Error):
import itertools
import bisect
x = int(input())
acc = list(itertools.accumulate(list(range(1, x+1))))
index = bisect.bisect_left(acc, x)
#print(acc)
if acc[index] == x:
    print(index+1)
else:
    print(index+1)

Fixed submission:
x = int(input())
total = 0
for i in range(1,x+1):
    total += i
    if total >= x:
        print(i)
        exit()
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
adjacent_list = [[] for i in range(n+1+m+1)]
for i in range(1,n+1):
    for j in list(map(int, input().split()))[1:]:
        adjacent_list[i].append(j)
        adjacent_list[i].append(j)
finished = set()
def dfs(node):
    finished.add(node)
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
dfs(1)
flag = True
for i in range(1,n+1):
    if i not in finished:
        flag = False
if flag:
    print("YES")
else:
    print("NO")

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,m = map(int, input().split())
adjacent_list = [[] for i in range(n+1+m+1)]
for i in range(1,n+1):
    for j in list(map(int, input().split()))[1:]:
        adjacent_list[i].append(j+n)
        adjacent_list[j+n].append(i)
finished = set()
def dfs(node):
    finished.add(node)
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
dfs(1)
flag = True
for i in range(1,n+1):
    if i not in finished:
        flag = False
if flag:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
z_asc = ord('z')
for i in range(len(s)):
    tmp = ord(s[i])
    if 1 + z_asc - tmp <= k and s[i] != 'a':
        k -= 1 + z_asc - tmp
        s[i] = 'a'
if k % 26 != 0:
    s[-1] = chr(ord(s[-1]) + k)
ans = "".join(s)
print(ans)



Fixed submission:
s = list(input())
k = int(input())
z_asc = ord('z')
for i in range(len(s)):
    tmp = ord(s[i])
    if 1 + z_asc - tmp <= k and s[i] != 'a':
        k -= 1 + z_asc - tmp
        s[i] = 'a'
if k % 26 != 0:
    s[-1] = chr(ord(s[-1]) + k%26)
ans = "".join(s)
print(ans)

Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())
z_asc = ord('z')
for i in range(len(s)):
    tmp = ord(s[i])
    if 1 + z_asc - tmp <= k and s[i] != 'a':
        k -= 1 + z_asc - tmp
        s[i] = 'a'
if k % 26 != 0:
    s[-1] = chr(ord(s[-1]) + k)
print("".join(s))



Fixed submission:
s = list(input())
k = int(input())
z_asc = ord('z')
for i in range(len(s)):
    tmp = ord(s[i])
    if 1 + z_asc - tmp <= k and s[i] != 'a':
        k -= 1 + z_asc - tmp
        s[i] = 'a'
if k % 26 != 0:
    s[-1] = chr(ord(s[-1]) + k%26)
ans = "".join(s)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
s = set(list(s))
if s in "N" != s in "S":
    print("No")
    exit()
if s in "W" != s in "E":
    print("No")
    exit()
print("Yes")

Fixed submission:
s = input()
s = set(list(s))
if ("N" in s) != ("S" in s):
    print("No")
    exit()
if ("E" in s) != ("W" in s):
    print("No")
    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
mod =10**9 + 7
N=int(input())
a=10**N
b=a*((8/10)**N)
print(int(a-b)/mod)

Fixed submission:
mod =10**9 + 7
N=int(input())
a=10**N
b=9**N
c=8**N
print((a-(2*b)+c)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
MOD=1000000007
N=input()
A = [int(x) for x in input().split()]
l=len(A)
s=0
for i in range(l):
    B=A[i+1:l]
    s+=A[i]*sum(B)
print(s%MOD)


Fixed submission:
MOD=1000000007
N=input()
A = list(map(int,input().split()))
l=len(A)
s=0
B=sum(A)
for i in range(l):
    B-=A[i]
    s+=A[i]*B
print(s%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD=1000000007
N=input()
A = [int(x) for x in input().split()]
l=len(A)
s=0
for i in range(l):
    B=A[i+1:l]
    s+=A[i]*sum(B)
print(s%MOD)

Fixed submission:
MOD=1000000007
N=input()
A = list(map(int,input().split()))
l=len(A)
s=0
B=sum(A)
for i in range(l):
    B-=A[i]
    s+=A[i]*B
print(s%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD=1000000007
N=input()
A=list(map(int,input().split()))
l=len(A)
s=0
for i in range(l):
    for j in range(i+1,l):
        s+=A[i]*A[j]
print(s%MOD)

Fixed submission:
MOD=1000000007
N=input()
A = list(map(int,input().split()))
l=len(A)
s=0
B=sum(A)
for i in range(l):
    B-=A[i]
    s+=A[i]*B
print(s%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())
a=7
for i in range(1,K+1):
    if a%K==0:
        print(i)
        exit()
    a=a*10+7
print(-1)

Fixed submission:
K=int(input())
a=7
for i in range(1,K+1):
    if a%K==0:
        print(i)
        exit()
    a=(a*10+7)%K
print(-1)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=0,0,0,0
N=int(input())
S=[input() for _ in range(N)]
for i in range(N):
    if S[i]=='AC':
        a=a+1
    elif S[i]=='WA':
        b=b+1
    elif S[i]=='TLE':
        c=c+1
    elif S[i]=='RE':
        d=d+1
print('AC x　'+str(a))        
print('WA ×　'+str(b))    
print('TLE ×　'+str(c))       
print('RE ×　'+str((d)) 

Fixed submission:
n = int(input())
ans_ac = 0
ans_wa = 0
ans_tle = 0
ans_re = 0

for i in range(n):
    s = input()
    if s == 'AC':
        ans_ac += 1
    elif s == 'WA':
        ans_wa += 1
    elif s == 'TLE':
        ans_tle += 1
    else:
        ans_re += 1
        
print('AC x '+str(ans_ac))
print('WA x '+str(ans_wa))
print('TLE x '+str(ans_tle))
print('RE x '+str(ans_re))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=0
N=int(input())
S=[input() for _ in range(N)]
for i in range(N):
    if S[i]=='AC':
        a=a+1
    elif S[i]=='WA':
        b=b+1
    elif S[i]=='TLE':
        c=c+1
    elif S[i]=='RE':
        d=d+1
print('AC ×　{}'.format(a))        
print('WA ×　{}'.format(b))       
print('TLE ×　{}'.format(c))       
print('RE ×　{}'.format(d))  

Fixed submission:
n = int(input())
ans_ac = 0
ans_wa = 0
ans_tle = 0
ans_re = 0

for i in range(n):
    s = input()
    if s == 'AC':
        ans_ac += 1
    elif s == 'WA':
        ans_wa += 1
    elif s == 'TLE':
        ans_tle += 1
    else:
        ans_re += 1
        
print('AC x '+str(ans_ac))
print('WA x '+str(ans_wa))
print('TLE x '+str(ans_tle))
print('RE x '+str(ans_re))
Buggy python submission (verdict: Runtime Error):
X=map(int,input().split())
for i in range(1,6):
    if X[i]==0:
        print(i)
        exit()

Fixed submission:
X=list(map(int,input().split()))
for i in range(0,5):
    if X[i]==0:
        print(i+1)
        break
Buggy python submission (verdict: Runtime Error):
101 9901 999999000001

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
s=1
if 0 in A:
    print(0)
    exit()
for i in range(N):
    s*=A[i]
    if s>10**18:
        print(-1)
        exit()
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
s=1
for i in range(N):
    s*=A[i]
if s<=10**18:
    print(s)
else:
    print(-1)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
s=1
if 0 in A:
    print(0)
    exit()
for i in range(N):
    s*=A[i]
    if s>10**18:
        print(-1)
        exit()
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
s=1
l=len(A)
for i in range(l):
    s*=A[i]
if s<=10**18:
    print(s)
else:
    print(-1)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
s=1
if 0 in A:
    print(0)
    exit()
for i in range(N):
    s*=A[i]
    if s>10**18:
        print(-1)
        exit()
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,K=map(int,input().split())
for i in range(C+1):
    for j in range(B+1):
        for k in range(A+1):
            if i+j+k==K:
                print(-1*i+k)
                exit()

Fixed submission:
A,B,C,K=map(int,input().split())
if A>=K:
    print(K)
elif A+B>=K:
    print(A)
else:
    print(A-(K-A-B))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
l=[False for _ in range(N)]
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for j in range(N):
        if l[j]==A[j]:
            l[j]=True
print(list.count(False)) 

Fixed submission:
N,K=map(int,input().split())
l=[False for x in range(N)]
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for j in A:
        l[j-1]=True
print(l.count(False))

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
l=[False for _ in range(N)]
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for j in range(N):
        if l[i]==A[i]:
            l[i]=True
print(list.count(False))

Fixed submission:
N,K=map(int,input().split())
l=[False for x in range(N)]
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for j in A:
        l[j-1]=True
print(l.count(False))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
l=[]
S=[input() for _ in range(N)]
x=0
for i in range(N):
    if S[i]  not in l:
        l.append(S[i])
        x+=1
print(x)  

Fixed submission:
N=int(input())
l=[]
S=[input() for _ in range(N)]
S=list(set(S))
print(len(S))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

Fixed submission:
from math import gcd
K=int(input())
s=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            s+=gcd(gcd(i,j),k)
print(s)
Buggy python submission (verdict: Runtime Error):
K,N=map(int,input().split())
A=list(map(int,input().split()))
l=[]
A+=A[0]+K
for i in range(N):
    l.append(A[i+1]-A[i])
print(K-max(l))

Fixed submission:
K,N=map(int,input().split())
A=list(map(int,input().split()))
l=[]
A.append(A[0]+K)
for i in range(N):
    l.append(A[i+1]-A[i])
print(K-max(l))

Buggy python submission (verdict: Time Limit Exceeded):
K,N=map(int,input().split())
A=list(map(int,input().split()))
l=[]
s=0
for i in range(N):
    A.append(A[i]+K)
for i in range(N):
    for j in range(N-1):
        s+=A[i+1]-A[i]
    l.append(s)
    s=0
print(min(l))

Fixed submission:
K,N=map(int,input().split())
A=list(map(int,input().split()))
l=[]
A.append(A[0]+K)
for i in range(N):
    l.append(A[i+1]-A[i])
print(K-max(l))

Buggy python submission (verdict: Time Limit Exceeded):
K,N=map(int,input().split())
A=list(map(int,input().split()))
l=[]
s=0
for i in range(N):
    A.append(A[i]+K)
for i in range(N):
    for j in range(N-1):
        s+=A[i+1]-A[i]
    l.append(s)
    s=0
print(min(l))

Fixed submission:
K,N=map(int,input().split())
A=list(map(int,input().split()))
l=[]
A.append(A[0]+K)
for i in range(N):
    l.append(A[i+1]-A[i])
print(K-max(l))
Buggy python submission (verdict: Time Limit Exceeded):
H,A,B=map(int,input().split())
l=[]
s=0
while s!=H:
    for i in range(A):
        if s==H:
            break
        s+=1
        l.append('b')
    for j in range(B):
        if s==H:
            break
        s+=1
        l.append('a')
print(l.count('b'))

Fixed submission:
N,A,B=map(int,input().split())
s=0
a=N//(A+B)
s+=A*a
b=N-a*(A+B)
if b>=A:
    s+=A
else:
    s+=b
print(s)

Buggy python submission (verdict: Runtime Error):
H,A,B=map(int,input().split())
l=[]
s=0
while True:
    for i in range(A):
        if s==H:
            print(l.count('b'))
            exit()
        s+=1
        list.append('b')
    for j in range(B):
        if s==H:
            print(l.count('b'))
            exit()
        s+=1
        list.append('a')


Fixed submission:
N,A,B=map(int,input().split())
s=0
a=N//(A+B)
s+=A*a
b=N-a*(A+B)
if b>=A:
    s+=A
else:
    s+=b
print(s)
Buggy python submission (verdict: Runtime Error):
B=[]
for i in range(3):
    A=list(map(int,input().split()))
    B.append(A[0])
    B.append(A[1])
    B.append(A[2])
N=int(input())
for j in range(N):
    b=int(input())
    if b in B:
        B[B.index(b)]=0
if B[0],B[1],B[2]==0,0,0:
    print('Yes')
elif B[3],B[4],B[5]==0,0,0:
    print('Yes')
elif B[6],B[7],B[8]==0,0,0:
    print('Yes')
elif B[0],B[3],B[6]==0,0,0:
    print('Yes')
elif B[1],B[4],B[7]==0,0,0:
    print('Yes')
elif B[2],B[5],B[8]==0,0,0:
    print('Yes')
elif B[0],B[4],B[8]==0,0,0:
    print('Yes')
elif B[2],B[4],B[6]==0,0,0:
    print('Yes')
else:
    print('No')

Fixed submission:
B=[]
for i in range(3):
    A=list(map(int,input().split()))
    B.append(A[0])
    B.append(A[1])
    B.append(A[2])
N=int(input())
for j in range(N):
    b=int(input())
    if b in B:
        B[B.index(b)]=0
if B[0]==0 and B[1]==0 and B[2]==0:
    print('Yes')
elif B[3]==0 and B[4]==0 and B[5]==0:
    print('Yes')
elif B[6]==0 and B[7]==0 and B[8]==0:
    print('Yes')
elif B[0]==0 and B[3]==0 and B[6]==0:
    print('Yes')
elif B[1]==0 and B[4]==0 and B[7]==0:
    print('Yes')
elif B[2]==0 and B[5]==0 and B[8]==0:
    print('Yes')
elif B[0]==0 and B[4]==0 and B[8]==0:
    print('Yes')
elif B[2]==0 and B[4]==0 and B[6]==0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
n=['0']*N
for i in range(M):
    s,c=map(str,input().split())
    S.append(s)
    if n[int(s)-1]!='0' and n[int(s)-1]!=c:
        print(-1)
        exit()
    if s=='1' and c=='0':
        print(-1)
        exit()
    n[int(s)-1]=c
if n[0]=='0':
    n[0]='1'
print(''.join(n))

Fixed submission:
N,M=map(int,input().split())
n=['0']*N
a=0
for i in range(M):
    s,c=map(str,input().split())
    if n[int(s)-1]!='0' and n[int(s)-1]!=c:
        a=1
    if s=='1' and c=='0' and N!=1:
        a=1
    n[int(s)-1]=c
if n[0]=='0' and N!=1:
    n[0]='1'
if a==0:
    print(''.join(n))
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[input() for _ in range(N)]
s=sorted(list(set(S)))
l=len(s)
x=[0]*l
for i in range(l):
    x[i]+=S.count(s[i])
m=max(x)
for i in range(l):
    if m==x[i]:
        print(s[i])

Fixed submission:
import collections

N=int(input())
S=sorted([input() for _ in range(N)])
s=sorted(list(set(S)))
l=len(s)
c=collections.Counter(S)
max_v = max(c.values())
for i in range(l):
    if max_v==c[s[i]]:
        print(s[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[input() for _ in range(N)]
s=sorted(list(set(S)))
l=len(s)
x=[0]*l
for i in range(l):
    x[i]+=S.count(s[i])
m=max(x)
for i in range(l):
    if m==x[i]:
        print(s[i])

Fixed submission:
import collections

N=int(input())
S=sorted([input() for _ in range(N)])
s=sorted(list(set(S)))
l=len(s)
c=collections.Counter(S)
max_v = max(c.values())
for i in range(l):
    if max_v==c[s[i]]:
        print(s[i])
Buggy python submission (verdict: Runtime Error):
S,T=map(input().split())
A,B=map(int,input().split())
U=input()
if U==S:
    A=A-1
else:
    B=B-1
print(A,B)

Fixed submission:
S,T=map(str,input().split())
A,B=map(int,input().split())
U=input()
if U==S:
    A=A-1
else:
    B=B-1
print(A,B)
Buggy python submission (verdict: Runtime Error):
S=input()
for i in range(len(S)):
    S[i]='×'
print(S)

Fixed submission:
S=input()
a=[]
for i in range(len(S)):
    a.append('x')
print(''.join(a))
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
for i in range(K):
    if A>=1:
        A-=1
    elif B>=1:
        B-=1
    elif A==0 and B==0:
        break
print(A,B)

Fixed submission:
A,B,K=map(int,input().split())
if A>=K:
    print(A-K,B)
elif A+B>=K:
    print(0,B-(K-A))
else:
    print(0,0)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
for i in range(K):
    if A>=1:
        A-=1
    elif B>=1:
        B-=1
    elif A==0 and B==0:
        break
print(A,B)

Fixed submission:
A,B,K=map(int,input().split())
if A>=K:
    print(A-K,B)
elif A+B>=K:
    print(0,B-(K-A))
else:
    print(0,0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
if N%2!=0:
    print('No')
for i in range(N/2):
    if S[i]!=S[N/2+i]:
        print('No')
        exit()
print('Yes')

Fixed submission:
N=int(input())
S=input()
if N%2!=0:
    print('No')
    exit()
for i in range(int(N/2)):
    if S[i]!=S[int(N/2)+i]:
        print('No')
        exit()
print('Yes')

Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
if N%2==0:
    print('No')
for i in range(N/2):
    if S[i]!=S[N/2+i]:
        print('No')
        exit()
print('Yes')

Fixed submission:
N=int(input())
S=input()
if N%2!=0:
    print('No')
    exit()
for i in range(int(N/2)):
    if S[i]!=S[int(N/2)+i]:
        print('No')
        exit()
print('Yes')