Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
def lcm(x, y):
    return (x // math.gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)

Fixed submission:
from fractions import gcd
def lcm(x, y):
    return (x // gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
def lcm(x, y):
    return (x // math.gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)

Fixed submission:
from fractions import gcd
def lcm(x, y):
    return (x // gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return x // math.gcd(x, y) *y
a,b = map(int,input().split())
ans = lcm(a,b)
print(ans)

Fixed submission:
from fractions import gcd
def lcm(x, y):
    return (x // gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return x // math.gcd(x, y) *y
a,b = map(int,input().split())
ans = lcm(a,b)
print(ans)

Fixed submission:
from fractions import gcd
def lcm(x, y):
    return (x // gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return x // math.gcd(x, y) * y
a,b = map(int,input().split())
print(lcm(a,b))

Fixed submission:
from fractions import gcd
def lcm(x, y):
    return (x // gcd(x, y) *y)
a,b = map(int,input().split())
ans = lcm(a, b)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
if s == "SUN":
    print(7)
elif s == "MON:
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED"
    print(4)
elif s == "THU"
    print(3)
elif s == "FRI"
    print(2)
else:
    print(1)

Fixed submission:
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split())
cnt = 0
for i in range(0,n):
    if p[i]!=i+1:
        cnt+=1
if cnt>2:
    print("NO")
else:
    print("YES")

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
flag = 0
ans = True
for i in range(0,n):
    if p[i] != i+1 and flag<=2:
        flag+=1
        if p[p[i]-1] == i+1:
            continue
        else:
            ans = False
    elif i+1 != p[i]:
        ans = False
if ans:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
import math
from collections import Counter
mod = 1000000007
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
flag = 1
if n % 2 == 0:
    start = 1
else:
    if c[0] != 1:
        flag = 0
    start = 2
for i in range(start, n, 2):
    if c[i] != 2:
        flag = 0
        break
if flag == 0:
    print(0)
else:
    print(int(math.pow(2, n // 2)) % mod)


Fixed submission:
n = int(input())
s = list(map(int, input().split()))
s_set = set(s)
count = 2 ** ((n) // 2)
if (sum(s) == 2 * sum(s_set)):
    print(count % (10 ** 9 + 7))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import math
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
flag = 1
if n % 2 == 0:
    start = 1
else:
    if c[0] != 1:
        flag = 0
    start = 2
for i in range(start, n, 2):
    if c[i] != 2:
        flag = 0
        break
if flag == 0:
    print(0)
else:
    print(int(math.pow(2, n // 2)))


Fixed submission:
n = int(input())
s = list(map(int, input().split()))
s_set = set(s)
count = 2 ** ((n) // 2)
if (sum(s) == 2 * sum(s_set)):
    print(count % (10 ** 9 + 7))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import math
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
flag = 1
if n % 2 == 0:
    start = 1
else:
    if c[0] < 1:
        flag = 0
    start = 2
for i in range(start, n, 2):
    if c[i] != 2:
        flag = 0
        break
if flag == 0:
    print(0)
    exit()
else:
    print(int(math.pow(2, n // 2)))


Fixed submission:
n = int(input())
s = list(map(int, input().split()))
s_set = set(s)
count = 2 ** ((n) // 2)
if (sum(s) == 2 * sum(s_set)):
    print(count % (10 ** 9 + 7))
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t, a = map(int, input().split())
for i in range(1, n):
    x, y = map(int, input().split())
    i = 1
    c, d = x, y
    while c < t or d< a:
        c = x * i
        d = y * i
        i += 1
    t, a = c, d
print(t + a)

Fixed submission:
n = int(input())
t, a = map(int, input().split())
for i in range(1, n):
    x, y = map(int, input().split())
    i = max(t // x, a // y)
    c, d = x, y
    while c < t or d< a:
        c = x * i
        d = y * i
        i += 1
    t, a = c, d
print(t + a)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,N = [int(x) for x in input().split()]

def f(x):
    return int(A*x/B) - A * int(x/B)

R = f(N)
for xb in range(N//B):
    x = (xb+1) * B - 1
    R = max(R,f(x))
print(R)

Fixed submission:
A,B,N = [int(x) for x in input().split()]

def f(x):
    return int(A*x/B) - A * int(x/B)

print(f(min(B-1,N)))
Buggy python submission (verdict: Time Limit Exceeded):
import math as mt
import itertools as iters

K = int(input())
A = 0
for a,b,c in iters.product(range(1,K+1),repeat=3):
    A += mt.gcd(a,mt.gcd(b,c))
print(A)

Fixed submission:
import math as mt
import itertools as iters

K = int(input())
A = 0
for a,b,c in iters.product(range(1,K+1),repeat=3):
    A += mt.gcd(a,mt.gcd(b,c))
print(A)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]

sys.setrecursionlimit(10**9)
DP = [0]*(H+1)

for x in range(1,H+1):
    DP[x] = min(DP[max(x-a,0)] + b for a,b in M)

print(DP[H])

Fixed submission:
from functools import lru_cache
import sys

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]

sys.setrecursionlimit(10**9)
DP = [0]*(H+1)

for x in range(1,H+1):
    DP[x] = min(DP[max(x-a,0)] + b for a,b in M)

print(DP[H])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]
#print(*M, sep='\n') #配列開業表示の仕方
sys.setrecursionlimit(10**9)
@lru_cache(maxsize=None)
def DP(hp):
    global M
    if hp <= 0:
        return 0
    res = min([DP(hp-a)+b for a,b in M])
    return res

print(DP(H))

Fixed submission:
from functools import lru_cache
import sys

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]

sys.setrecursionlimit(10**9)
DP = [0]*(H+1)

for x in range(1,H+1):
    DP[x] = min(DP[max(x-a,0)] + b for a,b in M)

print(DP[H])

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]
#print(*M, sep='\n') #配列開業表示の仕方
sys.setrecursionlimit(10**9)
@lru_cache(maxsize=None)
def DP(hp):
    global M
    if hp <= 0:
        return 0
    res = min([DP(hp-a)+b for a,b in M])
    return res

print(DP(H))

Fixed submission:
from functools import lru_cache
import sys

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]

sys.setrecursionlimit(10**9)
DP = [0]*(H+1)

for x in range(1,H+1):
    DP[x] = min(DP[max(x-a,0)] + b for a,b in M)

print(DP[H])

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]
#print(*M, sep='\n') #配列開業表示の仕方

@lru_cache(maxsize=None)
def DP(hp):
    global M
    if hp <= 0:
        return 0
    res = min([DP(hp-a)+b for a,b in M])
    return res

print(DP(H))

Fixed submission:
from functools import lru_cache
import sys

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]

sys.setrecursionlimit(10**9)
DP = [0]*(H+1)

for x in range(1,H+1):
    DP[x] = min(DP[max(x-a,0)] + b for a,b in M)

print(DP[H])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(i) for i in input().rstrip().split(' ')]
c = 0
for i,p in enumerate(P):
    for q in P[:i+1]:
        if p > q:
           break
    else:
        c += 1
print(c)

Fixed submission:
N = int(input())
P = [int(i) for i in input().rstrip().split(' ')]
c = 0
m = 2*10**5
for i,p in enumerate(P):
    if m >= p:
        m = p
        c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(i) for i in input().rstrip().split(' ')]
c = 0
for i,p in enumerate(P):
    if all([p <= q for q in P[:i+1]]):
        c += 1
print(c)

Fixed submission:
N = int(input())
P = [int(i) for i in input().rstrip().split(' ')]
c = 0
m = 2*10**5
for i,p in enumerate(P):
    if m >= p:
        m = p
        c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
import math as mt
N = int(input())

if N % 2 == 1 and N == 0:
    print(0)
    exit()

r = 0
L = int(mt.log(N,5))
for i in range(1,L+1):
    p = N//(5**i)//2
    r += p
    #print(N,5**i,p)
print(r)

Fixed submission:
import math as mt
N = int(input())

if N % 2 == 1 or N < 2:
    print(0)
    exit()

r = 0
L = int(mt.log(N,5))
for i in range(1,L+1):
    p = N//(5**i)//2
    r += p
    #print(N,5**i,p)
print(r)

Buggy python submission (verdict: Runtime Error):
import math as mt
N = int(input())

if N % 2 == 1:
    print(0)
    exit()

r = 0
L = int(mt.log(N,5))
for i in range(1,L+1):
    p = N//(5**i)//2
    r += p
    #print(N,5**i,p)
print(r)

Fixed submission:
import math as mt
N = int(input())

if N % 2 == 1 or N < 2:
    print(0)
    exit()

r = 0
L = int(mt.log(N,5))
for i in range(1,L+1):
    p = N//(5**i)//2
    r += p
    #print(N,5**i,p)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
C = [1 for _ in range(len(S))]
b1 = C[::]
b2 = C[::]
for n in range(10**5+5):
    C = [0 for _ in range(len(S))]
    for i,s in enumerate(S):
        if s == "R":
            C[i+1] += b1[i]
        else:
            C[i-1] += b1[i]
    if C == b2:
        if n%2==1:
            print(*C)
        else:
            print(*b1)
        break
    b2 = b1[::]
    b1 = C[::]

Fixed submission:
S = input()
C = [0 for _ in range(len(S))]
b = "R"
l,r = 0,0
for i,s in enumerate(S):
    if s != b and s == "L":
        #print("ST",i)
        for j in range(1,i+1):
            #print("#l",i,j,S[i-j])
            if S[i-j] == "L":
                l = j - 1
                break
        else:
            l = j
        j = 0
        for j in range(1,len(S)-i):
            #print("#r",i,j,S[i+j])
            if S[i+j] == "R":
                r = j
                break
        else:
            r = j + 1
        #print(i,l,r)
        C[i] = (r+1)//2 + l//2
        C[i-1] = r//2 + (l+1)//2
    b = s
print(*C)
Buggy python submission (verdict: Runtime Error):
import math as mt
N,K = [int(i) for i in input().rstrip().split()]
R = 0
for n in range(1,N+1):
    l = mt.floor(mt.log2((K-1)/n))+1
    if l <= 0:
        R += 1/N*(N-n+1)
        #print(K,n,l,R)
        print(R)
        break
    else:
        R += 1/N*0.5**l
        #print(K,n,l,R)

Fixed submission:
import math as mt
N,K = [int(i) for i in input().rstrip().split()]
R = 0
for n in range(1,N+1):
    l = mt.floor(mt.log2(K/n) - 0.1**9)+1
    if l <= 0:
        R += 1/N*(N-n+1)
        #print(K,n,l,R)
        break
    else:
        R += 1/N*0.5**l
        #print(K,n,l,R)
print(R)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(i) for i in input().rstrip().split()]
H = [int(i) for i in input().rstrip().split()]
H = [H[0]]*K + H
C = [0]*K
for i,h in enumerate(H):
    if i < K: continue
    c = [C[-1-j]+abs(H[i-j-1]-h) for j in range(K)]
    C += [min(c)]
print(C[-1])

Fixed submission:
N,K = [int(i) for i in input().rstrip().split()]
H = [int(i) for i in input().rstrip().split()]
H = [H[0]]*K + H
C = [0]*K
for i,h in enumerate(H):
    if i < K: continue
    c = [C[-1-j]+abs(H[i-j-1]-h) for j in range(K)]
    C += [min(c)]
print(C[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W = [int(i) for i in input().rstrip().split()]
F = [[int(i) for i in input().rstrip().split()] for _ in range(N)]

def dp(f,w):
    global F
    if w < 0:
        return -10**9
    if f == 0:
        if w < F[0][0]:
            return 0
        else:
            return F[0][1]
    return max(dp(f-1,w),dp(f-1,w-F[f][0])+F[f][1])

print(dp(N-1,W))

Fixed submission:
N,W = [int(i) for i in input().rstrip().split()]
F = [[int(i) for i in input().rstrip().split()] for _ in range(N)]

DP = []
for w,v in F:
    if DP == []:
        DP = [0]*w+[v]*(W-w+1)
    else:
        dp = DP[::]
        for w2 in range(w,W+1):
            dp[w2] = max(DP[w2-w] + v, DP[w2])
        DP = dp
    #print(DP)
print(DP[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,W = [int(i) for i in input().rstrip().split()]
F = [[int(i) for i in input().rstrip().split()] for _ in range(N)]

DP = []
for w,v in F:
    if DP == []:
        DP = [0]*w+[v]*(W-w+1)
    else:
        dp = DP[::]
        for w2 in range(w,W+1):
            dp[w2] = max(DP[w2-w] + v, DP[w2])
        DP = dp
    #print(DP)
print(DP[-1])

Fixed submission:
N,W = [int(i) for i in input().rstrip().split()]
F = [[int(i) for i in input().rstrip().split()] for _ in range(N)]

DP = []
for w,v in F:
    if DP == []:
        DP = [0]*w+[v]*(W-w+1)
    else:
        dp = DP[::]
        for w2 in range(w,W+1):
            dp[w2] = max(DP[w2-w] + v, DP[w2])
        DP = dp
    #print(DP)
print(DP[-1])
Buggy python submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
 	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Fixed submission:
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
  if cur == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
if H==1 or W==1:
    print("1")
elif W%2==0:
    result = (W/2)*H
else:
    if H%2==0:
        result=W*(H/2)
    else :
        result=W*(H-1)/2+(W+1)/2
print(str(round(result)))


Fixed submission:
H, W = map(int, input().split())
result = 0
if H==1 or W==1:
    result = 1
elif W%2==0:
    result = (W/2)*H
else:
    if H%2==0:
        result=W*(H/2)
    else :
        result=W*(H-1)/2+(W+1)/2
print(str(round(result)))
Buggy python submission (verdict: Runtime Error):
import math
import numpy
a,b,c = map(int, input().split())
d = c - a - b
if d > 0 and d * D > 4 * a * b:
    print("Yes")
else:
    print("No")


Fixed submission:
import math
import numpy
a,b,c = map(int, input().split())
d = c - a - b
if d > 0 and d * d > 4 * a * b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
A,B,M=map(int,input().split())

a=list(map(int,input().split()))
b=list(map(int,input().split()))

x=[0]*M
y=[0]*M
c=[0]*M

for i in range(M):
    x[i],y[i],c[i]=map(int,input().split())
min=a[0]+b[0]
min1=0
for i in range(A):
    for j in range(B):
        for t in range(M):
            if i+1==x[t] and j+1==y[t]:
                min1=a[i]+b[j]-c[t]
            else:
                min1=a[i]+b[j]
            if min >= min1:
                min = min1
print(min)


Fixed submission:
A,B,M=map(int,input().split())

a=list(map(int,input().split()))
b=list(map(int,input().split()))

price=[0]*(M+1)

price[0] = min(a)+min(b)

for i in range(M):
    x, y, c = map(int,input().split())
    price[i + 1] = a[x-1] + b[y-1] - c

print(min(price))
Buggy python submission (verdict: Runtime Error):
# AtCoder Beginner Contest 158 - C - Tax Increase
# お送り頂いたコードをもとにした解法（該当する元の金額を二重の for 文で検査する）

A,B = list(map(int,input().split()))
z=0

#【註】手を加えたのは、コメントを付した 2 箇所のみとなります。
# 8% の消費税の場合、この計算では「消費税計算において小数点以下が切り捨てになる」ことを反映できず、
# 計算結果が誤差を生じてしまいます。たとえば 8% 時の消費税額が 1 円の場合は、本来であれば価格が 13 円～24 円のレンジに
# 収まらなければなりませんが、当初の計算では 12 円から 25 円のレンジになってしまいます。

#for x in range(int(25*A/2),int(25*(A+1)/2)):
for x in range(int(((25*A)+1)/2),int((25*(A+1)-1)/2)):
    for y in range(int(10*B),int(10*(B+1))):
        if x==y:
            print(x)
            break
        else:
            z += 1
    if x==y:
        break
#if z==(int(25*(A+1)/2)-int(25*A/2))*(int(10*(B+1))-int(10*B)):    
if z==(int((25*(A+1)-1)/2)-int(((25*A)+1)/2))*(int(10*(B+1))-int(10*B)):    
    print(-1)


A,B = list(map(int,input().split()))
found = False
for i in range(1010):
    A_tax = int(i * 0.08)
    B_tax = int(i * 0.10)
    if A == A_tax and B == B_tax:
        print(i)
        found = True
        break
if not found:
    print("-1")

Fixed submission:
A,B = list(map(int,input().split()))
found = False
for i in range(1010):
    A_tax = int(i * 0.08)
    B_tax = int(i * 0.10)
    if A == A_tax and B == B_tax:
        print(i)
        found = True
        break
if not found:
    print("-1")
Buggy python submission (verdict: Runtime Error):
bingonum=[[0,0,0],[0,0,0],[0,0,0]]
bingo=[["False","False","False"],["False","False","False"],["False","False","False"]]
for i in range(3):
    bingonum[i][0],bingonum[i][1],bingonum[i][2] = map(int,input().split())

N = int(input())
b=[]
for _ in range(N):
    b.append(int(input())
for x in range(N):
    for i in range(3):
        for j in range(3):
            if bingonum[i][j]==b[x]:
                bingo[i][j]="True"

IsBingo = "No"
for i in range(3):
    if bingo[i][0] =="True" and bingo[i][1] =="True" and bingo[i][2] =="True":
        IsBingo="Yes"
    if bingo[0][i] =="True" and bingo[1][i] =="True" and bingo[2][i] =="True":
        IsBingo="Yes"
if (bingo[0][0] =="True" and bingo[1][1] =="True" and bingo[2][2] =="True") or (bingo[0][2] =="True" and bingo[1][1] =="True" and bingo[2][0]=="True"):
    IsBingo="Yes"
print(IsBingo)

Fixed submission:
#Biginner Contest 157 B-Bingo
#二次元配列を使う(3*3)
bingonum=[[0,0,0],[0,0,0],[0,0,0]]
bingo=[["False","False","False"],["False","False","False"],["False","False","False"]]
for i in range(3):
    bingonum[i][0],bingonum[i][1],bingonum[i][2] = map(int,input().split())

N = int(input())
b=[]
for _ in range(N):
    b.append(int(input()))

for x in range(N):
    for i in range(3):
        for j in range(3):
            if bingonum[i][j]==b[x]:
                bingo[i][j]="True"

IsBingo = "No"
for i in range(3):
    if bingo[i][0] =="True" and bingo[i][1] =="True" and bingo[i][2] =="True":
        IsBingo="Yes"
    if bingo[0][i] =="True" and bingo[1][i] =="True" and bingo[2][i] =="True":
        IsBingo="Yes"
if (bingo[0][0] =="True" and bingo[1][1] =="True" and bingo[2][2] =="True") or (bingo[0][2] =="True" and bingo[1][1] =="True" and bingo[2][0]=="True"):
    IsBingo="Yes"
print(IsBingo)
Buggy python submission (verdict: Runtime Error):
import math

N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a, b = map(int,input().split())
    s.append(a)
    c.append(b)

found = False

for i in range(pow(10,2), pow(10,3)):
   
    i_str = str(i)

    passed = True
    for j in range(M):
        if not i_str[s[j]] == c[j]:
            passed = False
            break
    if passed:
        found = True
        print(i)

if not found:
    print("-1")

Fixed submission:
N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a, b = map(int,input().split())
    s.append(a)
    c.append(b)

okflag = True

for i in range(M):

    if not okflag:
         break
    for j in range(M):
     if not okflag:
         break
     if not (i==j):
        if s[i]==s[j] and c[i]!=c[j]:
            okflag = False
            print("-1")
if okflag:
    answer = ["x"] * N

    for i in range(M):
        answer[s[i]-1] = str(c[i])
    
    if N == 1 and answer[0] == "x":
        print("0")
    elif N == 1 and not answer[0] == "x":
        print(answer[0])

    elif not N == 1 and answer[0] == "0":
        print("-1")
    
    elif not N == 1:
        for i in range(N):
            if answer[i] == "x":
                if i == 0:
                    answer[i] = "1"
                else:
                    answer[i] = "0"
        result = ''.join(answer)
        print(result)

Buggy python submission (verdict: Runtime Error):

N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a, b = map(int,input().split())
    s.append(a)
    c.append(b)

okflag = True

for i in range(M):

    if not okflag:
         break
    for j in range(M):
     if not okflag:
         break
     if not (i==j):

        if s[i]==s[j] and c[i]!=c[j]:

            okflag = False
            print("No")

if okflag:
    answer = ["0"] * N
    for i in range(M):
        answer[s[i]] = str(c[i])
    if not N == 1 and answer[0] == "0":
        answer[0] = "1"
    result = ''.join(answer)
    print(result)
    


Fixed submission:
N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a, b = map(int,input().split())
    s.append(a)
    c.append(b)

okflag = True

for i in range(M):

    if not okflag:
         break
    for j in range(M):
     if not okflag:
         break
     if not (i==j):
        if s[i]==s[j] and c[i]!=c[j]:
            okflag = False
            print("-1")
if okflag:
    answer = ["x"] * N

    for i in range(M):
        answer[s[i]-1] = str(c[i])
    
    if N == 1 and answer[0] == "x":
        print("0")
    elif N == 1 and not answer[0] == "x":
        print(answer[0])

    elif not N == 1 and answer[0] == "0":
        print("-1")
    
    elif not N == 1:
        for i in range(N):
            if answer[i] == "x":
                if i == 0:
                    answer[i] = "1"
                else:
                    answer[i] = "0"
        result = ''.join(answer)
        print(result)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())

a = 0

for i in range(N):
    for ii in range(N):
        iii = N - i - ii
        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y and J == N:
                print(i,ii,iii)
                a += 1
                break

        #for iii in range(N):
        #    ans = 10000 * i + 5000 * ii + 1000 * iii
        #    J = i + ii + iii
        #    if ans == Y and J == N:
        #        print(i,ii,iii)
        #        a += 1
        #        break
        #if a != 0:
        #    break
    if a != 0:
        break

if a == 0:
    print(-1,-1,-1)


Fixed submission:
N, Y = map(int, input().split())

a = 0

for i in range(N+1):
    for ii in range(N+1):
        iii = N - i - ii
        if iii < 0:
            break
        ans = 10000 * i + 5000 * ii + 1000 * iii
        if ans == Y:
                print(i,ii,iii)
                a += 1
                break

        #for iii in range(N):
        #    ans = 10000 * i + 5000 * ii + 1000 * iii
        #    J = i + ii + iii
        #    if ans == Y and J == N:
        #        print(i,ii,iii)
        #        a += 1
        #        break
        #if a != 0:
        #    break
    if a != 0:
        break

if a == 0:
    print(-1,-1,-1)