Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02947 (python)

Fixed submission:
from math import factorial
n = int(input())
ans_list = []
num_list = []
for i in range(n):
    s = list(input())
    s.sort()
    ans_list.append("".join(s))
ans_list.sort()
count = 1
for i in range(n-1):
    if ans_list[i] == ans_list[i+1]:
        count += 1
    else:
        num_list.append(count)
        count = 1
num_list.append(count)
ans = 0
for i in range(len(num_list)):
    if num_list[i] != 1:
        ans += factorial(num_list[i]) // factorial(2) // factorial(num_list[i]-2)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial
n = int(input())
ans_list = []
num_list = []
for i in range(n):
    s = list(input())
    s.sort()
    ans_list.append("".join(s))
ans_list.sort()
count = 1
for i in range(n-1):
    if ans_list[i] == ans_list[i+1]:
        count += 1
    else:
        num_list.append(count)
        count = 1
num_list.append(count)
ans = 0
for i in range(len(num_list)):
    if num_list[i] != 1:
        ans += factorial(num_list[i]) / factorial(2) / factorial(num_list[i]-2)
print(int(ans))
Problem p03043 (python)

Fixed submission:
n,k = map(int,input().split())
coin = [0]*n
while k > 1:
    for i in range(min(int(k-1/1e10),n)):
        coin[i] += 1
    k /= 2
ans = 0
for i in range(n):
    ans += 1 / (2**coin[i] * n)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
coin = [0]*n
for i in range(k-1):
    coin[i] += 1
while k > 1:
    k /= 2
    for i in range(min(int(k),n)):
        coin[i] += 1
ans = 0
for i in range(n):
    ans += (1/2)**coin[i]
print(ans / n)
Problem p03061 (python)

Fixed submission:
n = int(input())
v = list(map(int,input().split()))

def gcd(a,b):
  while b != 0:
    a, b = b, a % b
  return a

l_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[i-1])
    l_ans[i] = g
r_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[n-i])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)

Buggy submission (verdict: Runtime Error):
l_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[i-1])
    l_ans[i] = g
r_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[n-i])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)
Problem p03274 (python)

Fixed submission:
n,k = map(int,input().split())
x = list(map(int,input().split()))
l = 0
r = k-1
ans = 0
if x[l] <= 0 and x[r] <= 0:
    ans = abs(x[l])
elif x[l] >= 0 and x[r] >= 0:
    ans = x[r]
else:
    ans = min(abs(x[l]), x[r]) * 2 + max(abs(x[l]), x[r])
for i in range(n-k):
    l += 1
    r += 1
    if x[l] <= 0 and x[r] <= 0:
        ans = min(ans,abs(x[l]))
    elif x[l] >= 0 and x[r] >= 0:
        ans = min(ans, x[r])
    else:
        ans = min(ans, min(abs(x[l]), x[r]) * 2 + max(abs(x[l]), x[r]))

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
x = list(map(int,input().split()))
x_sei = []
x_hu = []
for i in range(n):
    if x[i] < 0:
        x_hu.append(x[i])
    else:
        x_sei.append(x[i])
x_hu.reverse()
if not x_hu:
    print(x_sei[k-1])
    exit()
if not x_sei:
    print(abs(x_hu[k-1]))
    exit()
cnt = 0
sei_i = 0
hu_i = 0
sei_nax = 0
hu_nax = 0
while sei_i + hu_i != k:
    a = x_sei[sei_i]
    b = x_hu[hu_i]
    if a <= abs(b):
        sei_i += 1
        sei_nax = a
    else:
        hu_i += 1
        hu_nax = b
print(min(sei_nax, abs(hu_nax))*2+max(sei_nax, abs(hu_nax)))
Problem p03607 (python)

Fixed submission:
n = int(input())
ans = 0
d = dict()
for i in range(n):
    a = int(input())
    if a not in d:
        d[a] = 0
    d[a] += 1
da = list(d.values())
for i in range(len(da)):
    if da[i] % 2 == 1:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [0] * 100000
ans = 0
for i in range(n):
    a[int(input())-1] += 1
for i in range(len(a)):
    if a[i] % 2 == 1:
        ans += 1
print(ans)
Problem p03612 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if a[i] == i+1:
        a[i], a[i+1] = a[i+1], a[i]
        ans += 1
if a[-1] == n:
    ans += 1
print(ans)

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

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

Fixed submission:
n = int(input())
def gcd(a,b):
    while b != 0:
        a, b = b, a % b
    return a
# 最小公倍数
def lcm(a,b):
    return a // gcd(a,b) * b

ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(ans,t)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
import functools
from functools import reduce

def gcd(numbers):
    return reduce(functools.gcd, numbers)

def lcm_base(x, y):
    return x // functools.gcd(x, y) * y

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


num = []
for i in range(n):
    num.append(int(input()))
print(lcm(num))

Buggy submission (verdict: Runtime Error):
n = int(input())
import functools
from functools import reduce

def gcd(numbers):
    return reduce(functools.gcd, numbers)

def lcm_base(x, y):
    return x // functools.gcd(x, y) * y

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


num = []
for i in range(n):
    num.append(int(input()))
print(lcm(num))

Buggy submission (verdict: Runtime Error):
n = int(input())
import functools
from functools import reduce

def gcd(numbers):
    return reduce(functools.gcd, numbers)

def lcm_base(x, y):
    return x // functools.gcd(x, y) * y

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


num = []
for i in range(n):
    num.append(int(input()))
print(lcm(num))

Buggy submission (verdict: Runtime Error):
n = int(input())
import math
from functools import reduce

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

def lcm_base(x, y):
    return x // math.gcd(x, y) * y

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


num = []
for i in range(n):
    num.append(int(input()))
print(lcm(num))
Problem p03673 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a1 = []
a2 = []
for i in range(n):
    if i % 2 == 0:
        a1.append(a[i])
    else:
        a2.append(a[i])
if n % 2 == 0:
    a2.reverse()
    print(*a2+a1)
else:
    a1.reverse()
    print(*a1+a2)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a1 = []
a2 = []
for i in range(n):
    if i % 2 == 0:
        a1.append(a[i])
    else:
        a2.append(a[i])
if n % 2 == 0:
    rev = list(reversed(a2))
    print(*rev, *a1)
else:
    rev = list(reversed(a1))
    print(*rev, *a2)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a1 = []
a2 = []
for i in range(n):
    if i % 2 == 0:
        a1.append(a[i])
    else:
        a2.append(a[i])
if n % 2 == 0:
    rev = reversed(a2)
    print(*rev, *a1)
else:
    rev = reversed(a1)
    print(*rev, *a2)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
a1 = []
a2 = []
for i in range(n):
    if i % 2 == 0:
        a1.append(a[i])
    else:
        a2.append(a[i])
if n % 2 == 0:
    rev = reversed(a2)
    print(*rev, *a1)
else:
    rev = reversed(a1)
    print(*rev, *a2)
Problem p03696 (python)

Fixed submission:
n = int(input())
s = list(input())
leng = []
cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        leng.append([s[i], cnt])
        cnt = 1
if s[-1] == "(":
    leng.append(["(", cnt])
else:
    leng.append([")", cnt])
if s[0] == ")":
    leng.insert(0,["(", leng[0][1]])
if s[-1] == "(":
    leng.insert(len(leng),[")", leng[-1][1]])

leng2 = []
for i in range(0, len(leng), 2):
    l = leng[i]
    r = leng[i+1]
    if l[1] == r[1]:
        pass
    elif l[1] < r[1]:
        leng2.append([")",r[1]-l[1]])
    else:
        leng2.append(["(", l[1]-r[1]])

lc = 0
rc = 0
for i in range(len(leng2)):
    if leng2[i][0] == "(":
        lc += leng2[i][1]
    else:
        rc += leng2[i][1]
    if rc - lc > 0:
        leng[0][1] += rc-lc
        lc = 0
        rc = 0
leng[-1][1] += lc-rc

ans = []
for i in range(len(leng)):
    tar = leng[i]
    for j in range(tar[1]):
        ans.append(tar[0])
print("".join(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())
leng = []
cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        leng.append([s[i], cnt])
        cnt = 1
if s[-1] == "(":
    leng.append(["(", cnt])
else:
    leng.append([")", cnt])
if s[0] == ")":
    leng.insert(0,["(", leng[0][1]])
if s[-1] == "(":
    leng.insert(len(leng),[")", leng[-1][1]])

leng2 = []
for i in range(0, len(leng), 2):
    l = leng[i]
    r = leng[i+1]
    if l[1] == r[1]:
        pass
    elif l[1] < r[1]:
        leng2.append([")",r[1]-l[1]])
    else:
        leng2.append(["(", l[1]-r[1]])

lc = 0
rc = 0
while leng2:
    if leng2[0][0] == ")":
        leng[0][1] += leng2[0][1]
        u = leng2.pop(0)
    else:
        break
while leng2:
    if leng2[-1][0] == "(":
        leng[-1][1] += leng2[-1][1]
        u = leng2.pop()
    else:
        break
lc = 0
rc = 0
for i in range(len(leng2)):
    tar = leng2[i]
    if tar[0] == "(":
        lc += tar[1]
    else:
        rc += tar[1]
if lc > rc:
    s[-1][1] += lc-rc
elif lc < rc:
    s[0][1] += rc-lc

ans = []
for i in range(len(leng)):
    tar = leng[i]
    for j in range(tar[1]):
        ans.append(tar[0])
print("".join(ans))
Problem p02811 (python)

Fixed submission:
n,k=map(int,input().split())
if 500 * n >= k:print("Yes")
else:print("No")

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if 500 * n >= k:print("Yes")
  else:print("No")
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split())
if a==b:print(a*2)
else:print(max(a,b)*2-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a==b:print(a*2)
else print(max(a,b)*2-1)

Buggy submission (verdict: Runtime Error):
a,b=int(input())
if a==b:print(a*2)
else print(max(a,b)*2-1)
Problem p03697 (python)

Fixed submission:
A,B=map(int,input().split());print(A+B if A+B<10 else "error")

Buggy submission (verdict: Runtime Error):
A,B=map(in,input().split());print(A+B if A+B<10 else "error")
Problem p02553 (python)

Fixed submission:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log,floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b,c,d = MAP()

print(max(a*c,a*d,b*c,b*d))

Buggy submission (verdict: Runtime Error):
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log,floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b,c,d = MAP()

print(max(a*c,a*d,b*c,b*d))
Problem p02690 (python)

Fixed submission:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

dd=defaultdict(int)
#take care of 0
for i in range(0, 121):
    for j in range(i+1):
        temp = i**5 - j**5
        dd[temp] = (i, j)
        temp1 = i**5 + j**5
        dd[temp1] = (i, -j)
# print(dd[2066178367])
x = INT()
if(dd[x]!=0):
    print(dd[x][0], dd[x][1])

Buggy submission (verdict: Runtime Error):
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

dd=defaultdict(int)
#take care of 0
for i in range(0, 81):
    for j in range(i):
        temp = i**5 - j**5
        dd[temp] = (i, j)
        temp1 = i**5 + j**5
        dd[temp1] = (i, -j)

x = INT()

print(*dd[x])
Problem p03166 (python)

Fixed submission:
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 9)
def solve(num):
    #base case:
    if(dic[num]==0):
        return 0

    mx = 0
    for el in dic[num]:
        if(dp[el]==-1):
            temp1 = solve(el)
            mx = max(mx, 1 + temp1)
            dp[el] = temp1
        else:
            mx = max(mx, 1 + dp[el])

    return mx

n, m = map(int, input().split())
dic = defaultdict(int)

for _ in range(m):
    xtemp, ytemp = map(int, input().split())
    if(xtemp not in dic):
        dic[xtemp] = []
        dic[xtemp].append(ytemp)
    else:
        dic[xtemp].append(ytemp)
#init dp:
dp = [-1]*(n+1)

mxGl = 0
keys = list(dic.keys())
for node in keys:
    if(dp[node]==-1):
        temp = solve(node)
        dp[node] = temp
        mxGl = max(mxGl, temp)
    else:
        mxGl = max(mxGl, dp[node])
print(mxGl)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter

def solve(num):
    #base case:
    if(dic[num]==0):
        return 0

    mx = 0
    for el in dic[num]:
        if(dp[el]==-1):
            temp1 = solve(el)
            mx = max(mx, 1 + temp1)
            dp[el] = temp1
        else:
            mx = max(mx, 1 + dp[el])

    return mx

n, m = map(int, input().split())
dic = defaultdict(int)

for _ in range(m):
    xtemp, ytemp = map(int, input().split())
    if(xtemp not in dic):
        dic[xtemp] = []
        dic[xtemp].append(ytemp)
    else:
        dic[xtemp].append(ytemp)
#init dp:
dp = [-1]*(n+1)

mxGl = 0
keys = list(dic.keys())
for node in keys:
    if(dp[node]==-1):
        temp = solve(node)
        dp[node] = temp
        mxGl = max(mxGl, temp)
    else:
        mxGl = max(mxGl, dp[node])
print(mxGl)
Problem p03167 (python)

Fixed submission:
def list2d(a, b, c): return [[c] * b for i in range(a)]
mod =10**9+7
H, W = map(int, input().split())

grid = []

for _ in range(H):
    grid.append(list(input()))

dp = list2d(H, W, 0)
for i in range(H-1, -1, -1):
    if(grid[i][W-1] == '#'):
        break
    dp[i][W-1] = 1

for j in range(W-1, -1, -1):
    if(grid[H-1][j]=='#'):
        break
    dp[H-1][j] = 1

for row in range(H-2, -1, -1):
    for col in range(W-2, -1, -1):
        if(grid[row][col] == '.'):
            dp[row][col] = (dp[row][col+1] + dp[row+1][col])%mod
        else:
            dp[row][col] = 0
print(dp[0][0]%mod)

Buggy submission (verdict: Runtime Error):
20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
Problem p02564 (python)

Fixed submission:

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

def scc(N, g, rg):
    V = list(range(N))


    def dfs(u, done, o):
        done.add(u)
        for v in g[u]:
            if v in done:
                continue
            done.add(v)
            dfs(v, done, o)
        o.append(u)

    def dfs_rev(u, done, c):
        done.add(u)
        c.append(u)
        for v in rg[u]:
            if v in done:
                continue
            dfs_rev(v, done, c)

    done = set()
    o = []
    for v in V:
        if v in done:
            continue
        dfs(v, done, o)


    done = set()
    ans = []
    while o:
        u = o.pop()
        if u in done:
            continue
        vv = []
        dfs_rev(u, done, vv)
        ans.append(vv)


    return ans


def atcoder_practice2_g():
    N, M = map(int, input().split())

    g = defaultdict(list)
    rg = defaultdict(list)
    for _ in range(M):
        a, b = map(int, input().split())
        g[a].append(b)
        rg[b].append(a)
    vv = scc(N, g, rg)
    print(len(vv))
    for r in vv:
        print(len(r), *r)


def test():
    g = {
        1: [2],
        5: [2],
        2: [4, 3],
        3: [4, 7, 6],
        4: [5, 8],
        6: [9],
        7: [8],
        8: [9],
        9: [7, 10],
        10: []
    }

    vv = scc(g)
    for r in vv:
        print(r)


if __name__ == "__main__":
    # test()
    atcoder_practice2_g()

Buggy submission (verdict: Runtime Error):

from collections import defaultdict


def scc(g):
    rg = defaultdict(list)
    V = set()
    for u, e in g.items():
        V.add(u)
        for v in e:
            V.add(v)
            rg[v].append(u)


    o = []
    done = set()
    def dfs(u):
        done.add(u)
        for v in g[u]:
            if v in done:
                continue
            dfs(v)
            done.add(v)
        # o[u] = len(o)
        o.append(u)

    for v in V:
        if v in done:
            continue
        dfs(v)

    done = set()
    ans = []
    while o:
        u = o.pop()
        if u in done:
            continue
        done.add(u)
        s = [u]
        vv = []

        while s:
            u = s.pop()
            vv.append(u)
            for v in rg[u]:
                if v in done:
                    continue
                s.append(v)
                done.add(v)
        ans.append(vv)

    return ans


def atcoder_practice2_g():
    N, M = map(int, input().split())

    g = defaultdict(list)
    for _ in range(M):
        a, b = map(int, input().split())
        g[a].append(b)
    vv = scc(g)
    print(len(vv))
    for r in vv:
        print(len(r), *r)


def test():
    g = {
        1: [2],
        5: [2],
        2: [4, 3],
        3: [4, 7, 6],
        4: [5, 8],
        6: [9],
        7: [8],
        8: [9],
        9: [7, 10],
        10: []
    }

    vv = scc(g)
    for r in vv:
        print(r)


if __name__ == "__main__":
    # test()
    atcoder_practice2_g()
Problem p02761 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, SC):

    for i in range(1000):
        i = str(i)
        if len(i) != N:
            continue

        for s, c in SC:
            if int(i[s-1]) != c:
                break
        else:
            return i


    return -1


def main():
    N, M = read_int_n()
    SC = [read_int_n() for _ in range(M)]
    print(slv(N, M, SC))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, SC):
    ans = 0
    number = [None] * M
    for s, c in SC:
        if number[s-1] is None:
            number[s-1] = c
        elif number[s-1] != c:
            return -1

    if number[0] == 0:
        return -1
    if number[0] is None:
        number[0] = 1

    for i in range(M):
        if number[i] is None:
            number[i] = 0

    return int(''.join(map(str, number)))


def main():
    N, M = read_int_n()
    SC = [read_int_n() for _ in range(M)]
    print(slv(N, M, SC))


if __name__ == '__main__':
    main()