Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    a = []
    for i in range(n):
        a.append(list(map(int, readline().split())))

    ans = INF
    for _ in range(n - 1):
        cnt = [0] * (m + 1)
        for i in range(n):
            cnt[a[i][0]] += 1
        max_cnt = max(cnt)
        ans = min(ans, max_cnt)
        max_num = cnt.index(max_cnt)
        for i in range(n):
            a[i].remove(max_num)

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = map(int, readline().split())
    a = []
    for i in range(n):
        a.append(list(map(int, readline().split())))

    ans = INF
    for _ in range(m):
        cnt = [0] * (m + 1)
        for i in range(n):
            cnt[a[i][0]] += 1
        max_cnt = max(cnt)
        ans = min(ans, max_cnt)
        max_num = cnt.index(max_cnt)
        for i in range(n):
            a[i].remove(max_num)

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    odd = a[0::2]
    even = a[1::2]

    if n % 2 == 0:
        print(*even[::-1], *odd)
    else:
        print(*odd[::-1], *even)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    odd = a[0::2]
    even = a[1::2]

    if n % 2 == 0:
        res = even[::-1] + odd
        print(*res)
    else:
        res = odd[::-1] + even
        print(*res)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    dup = 0
    for i in range(1, n + 2):
        if a.count(i) == 2:
            dup = i

    first = a.index(dup)
    second = a[first + 1:].index(dup) + first + 1

    print(n)

    p = first
    q = (n + 1) - second - 1

    c1 = n + 1
    c2 = 1

    for i in range(2, n + 2):
        c1 *= (n + 1 - (i - 1))
        c1 %= MOD
        c1 *= pow(i, MOD - 2, MOD)
        c1 %= MOD
        c2 *= (p + q - (i - 2))
        c2 %= MOD
        c2 *= pow(i - 1, MOD - 2, MOD)
        c2 %= MOD
        print((c1 - c2) % MOD)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    appeared = set()
    dup = 0

    for x in a:
        if x in appeared:
            dup = x
            break
        else:
            appeared.add(x)

    first = a.index(dup)
    second = a[first + 1:].index(dup) + first + 1

    print(n)

    p = first
    q = (n + 1) - second - 1

    c1 = n + 1
    c2 = 1

    for i in range(2, n + 2):
        c1 *= (n + 1 - (i - 1))
        c1 %= MOD
        c1 *= pow(i, MOD - 2, MOD)
        c1 %= MOD
        c2 *= (p + q - (i - 2))
        c2 %= MOD
        c2 *= pow(i - 1, MOD - 2, MOD)
        c2 %= MOD
        print((c1 - c2) % MOD)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B, C = map(int, readline().split())

    if A[-1] == B[0] and B[-1] == C[0]:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B, C = input().split()

    if A[-1] == B[0] and B[-1] == C[0]:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def dfs(cur):
        if not edge[cur]:
            return 0
        else:
            m = [0] * len(edge[cur])
            for i, nx in enumerate(edge[cur]):
                m[i] = dfs(nx)
            m.sort(reverse=True)
            for i in range(len(m)):
                m[i] += (i + 1)
            return max(m)

    from collections import defaultdict, deque
    n = int(readline())
    edge = defaultdict(list)

    for i in range(2, n + 1):
        a = int(readline())
        edge[a].append(i)

    ans = dfs(1)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def dfs(cur):
        if not edge[cur]:
            return 0
        else:
            for i, nx in enumerate(edge[cur]):
                dp[nx] = dfs(nx)
            m = []
            for nx in edge[cur]:
                m.append(dp[nx])
            m.sort(reverse=True)
            for i, x in enumerate(m):
                m[i] = x + i + 1
            return max(m)

    from collections import defaultdict
    n = int(readline())
    edge = defaultdict(list)
    dp = [-1] * (n + 1)

    for i in range(2, n + 1):
        a = int(readline())
        edge[a].append(i)

    ans = dfs(1)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
print('ABC' if input()[1] == 'R' else 'ARC)

Fixed submission:
print('ABC' if input()[1] == 'R' else 'ARC')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

M = 10**9+7
ans = 0

def f(a, b, c):
    return a%M*b%M*c%M

for i in range(60):
    count = 0
    b = 1<<i
    for a in A:
        if (a&b) != 0:
            count += 1
    ans = (ans+f(count, N-count, b))%M

print(ans)


Fixed submission:
N,*A=map(int,open(0).read().split())
print(sum((b:=1<<i)*(z:=sum(1 for a in A if a&b==0))*(N-z)%(mod:=10**9+7) for i in range(60))%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
M = 10**9+7
ans = 0

for i in range(61):
    b = 1<<i
    count = 0
    for a in A:
        c = a & b
        if c != 0:
            count += 1
    ans += b*count*(N-count)

print(ans%M)


Fixed submission:
N,*A=map(int,open(0).read().split())
print(sum((b:=1<<i)*(z:=sum(1 for a in A if a&b==0))*(N-z)%(mod:=10**9+7) for i in range(60))%mod)
Buggy python submission (verdict: Runtime Error):
X = int(input())
s = str(X)
n = int(s[0])
x = int(s[1:])
print(0 if x > 5*n else 1)


Fixed submission:
X = int(input())
n = X//100
X -= 100*n
print(0 if X > 5*n else 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = tuple(map(int, input()))

ans = 0
for i in range(1000):
    ii = i
    key = ii%10
    count = 0
    for j in range(N):
        if key == S[j]:
            count += 1
            if count == 3:
                ans += 1
                break
            ii //= 10
            key = ii%10

print(ans)


Fixed submission:
N = int(input())
S = tuple(map(int, input()))

ans = 0
for i in range(1000):
    ii = i
    key = ii%10
    count = 0
    for s in S:
        if key == s:
            count += 1
            if count == 3:
                ans += 1
                break
            ii //= 10
            key = ii%10

print(ans)
Buggy python submission (verdict: Runtime Error):
#include <stdio.h>

int main(void)
{
  int N, K;
  scanf("%d %d", &N, &K);
  ans = 0;
  for(int i = 0; i < N; i++){
    int h;
    scanf("%d", &h);
    if(K <= h)
    	ans++;
  }
  printf("%d", ans);
}

Fixed submission:
N, K = map(int, input().split())
h = map(int, input().split())
ans = 0
for i in h:
  if K <= i:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

d = np.array([[0, 0, 0, 0, 0, 0],
            [2, 0, 9, 0, 0, 0],
            [0, 3, 0, 0, 0, 0],
            [0, 0, 4, 0, 0, 0],
            [0, 0, 0, 5, 0, 0],
            [0, 0, 0, 0, 6, 0],
            [2, 0, 7, 0, 0, 0],
            [0, 8, 0, 0, 0, 0],
            [2, 0, 9, 11, 0, 0],
            [0, 10, 0, 0, 0, 0],
            [0, 0, 0, 11, 0, 0],
            [0, 0, 0, 0, 0, 12],
            [0, 0, 13, 0, 0, 0],
            [2, 1, 9, 0, 0, 0]], dtype = 'int32')
s = 1
for c in input():
    s = d[s][id[c]] if c in {'d': 0, 'r': 1, 'e': 2, 'a': 3, 'm': 4, 's': 5} else 0
    if s == 0:
        break
print("YES" if s in {1, 6, 8, 13} else "NO")


Fixed submission:
import numpy as np

d = np.array([[0, 0, 0, 0, 0, 0],
            [2, 0, 9, 0, 0, 0],
            [0, 3, 0, 0, 0, 0],
            [0, 0, 4, 0, 0, 0],
            [0, 0, 0, 5, 0, 0],
            [0, 0, 0, 0, 6, 0],
            [2, 0, 7, 0, 0, 0],
            [0, 8, 0, 0, 0, 0],
            [2, 0, 9, 11, 0, 0],
            [0, 10, 0, 0, 0, 0],
            [0, 0, 0, 11, 0, 0],
            [0, 0, 0, 0, 0, 12],
            [0, 0, 13, 0, 0, 0],
            [2, 1, 9, 0, 0, 0]], dtype = 'int32')
s = 1
S = input()
N = len(S)
id = {'d': 0, 'r': 1, 'e': 2, 'a': 3, 'm': 4, 's': 5}
for c in S:
    s = d[s][id[c]] if c in id else 0
    if s == 0:
        break

print("YES" if s in {1, 6, 8, 13} else "NO")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

ok = [True]*10;

d = [int(s) for s in input().split()]

for i in d:
    ok[i] = False

ans = 0
for i in range(N, 10*N+1):
    j = i
    while j > 0 and ok[j%10]:
        j /= 10
    if j == 0:
        ans = i
        break

print(ans)


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

ok = [True]*10

d = [int(s) for s in input().split()]

for i in d:
    ok[i] = False

ans = 0
for i in range(N, 10*N+1):
    j = i
    while j > 0 and ok[j%10]:
        j //= 10
    if j == 0:
        ans = i
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    x, y = i2(N)

    Mw = max(x[i]+y[i] for i in range(N))
    mw = min(x[i]+y[i] for i in range(N))
    Mz = max(abs(a[i]-y[i]) for i in range(N))
    mz = min(abs(x[i]-y[i]) for i in range(N))

    print(max(Mz-mz, Mw-mw))
    


if __name__ == '__main__':
    main()


Fixed submission:
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    x, y = i2(N)

    Mw = max(x[i]+y[i] for i in range(N))
    mw = min(x[i]+y[i] for i in range(N))
    Mz = max(x[i]-y[i] for i in range(N))
    mz = min(x[i]-y[i] for i in range(N))

    print(max(Mz-mz, Mw-mw))
    


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def lcm(a, b):
    return a*b//math.gcd(a, b)


def main():
    N = ii()
    A = list(mi())

    l = 1
    g = A[0]
    k = 1

    for i in range(N):
        l = lcm(l, A[i])
        g = math.gcd(g, A[i])
        k *= A[i]

    if l == k:
        print('pairwise coprime')
    elif g == 1:
        print('setwise coprime')
    else:
        print('not coprime')

if __name__ == '__main__':
    main()


Fixed submission:
import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def sieve(n):
    res = [i for i in range(n)]

    i = 2
    while i*i < n:
        if res[i] < i:
            i += 1
            continue
        j = i*i
        while j < n:
            if res[j] == j:
                res[j] = i
            j += i
        i += 1

    return res

def factor(n, min_factor):
    res = set()
    while n > 1:
        res.add(min_factor[n])
        n //= min_factor[n]

    return res

def main():
    N = ii()
    A = np.array(list(mi()))

    m = max(A)
    s = sieve(m+1)
    d = defaultdict(bool)
    
    g = np.gcd.reduce(A)
    if g > 1:
        print('not coprime')
        return

    for a in A:
        f = factor(a, s)
        for v in f:
            if d[v]:
                print('setwise coprime')
                return
            d[v] = True

    print('pairwise coprime')



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def isOK(i, A, K):
    return K >= sum((a-1)//i for a in A)

def b_serach(A, K):
    ng = -1
    ok = 10**9+1

    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if isOK(mid, A, K):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = mi()
    A = list(mi())
    print(b_serach(A, K))


if __name__ == '__main__':
    main()

Fixed submission:
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def isOK(i, A, K):
    if i == 0:
        return False
    return K >= sum((a-1)//i for a in A)

def b_serach(A, K):
    ng = -1
    ok = 10**9+1

    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if isOK(mid, A, K):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = mi()
    A = list(mi())
    print(b_serach(A, K))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    X, Y = list(mi())
    if 4*X-Y >= 0 and (4*X-Y)%2 == 0 and a <= X:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Fixed submission:
MOD = 10**9+7

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    X, Y = list(mi())
    if 4*X-Y >= 0 and (4*X-Y)%2 == 0 and (4*X-Y)//2<= X:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate

def mi():
    return map(int, input().split())

def main():
    N, K = mi()
    A = list(mi())

    for _ in range(K):
        l = [0]*N
        for i in range(N):
            left = max(i-A[i], 0)
            right = min(i+A[i]+1, N)
            l[left] += 1
            if right < N:
                l[right] -= 1
        if A != list(accumulate(l)):
            A = accumulate(l)
        else:
            break
    print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()

Fixed submission:
from itertools import accumulate

def mi():
    return map(int, input().split())

def main():
    N, K = mi()
    A = list(mi())

    for _ in range(K):
        l = [0]*N
        for i in range(N):
            left = max(i-A[i], 0)
            right = min(i+A[i]+1, N)
            l[left] += 1
            if right < N:
                l[right] -= 1
        if A != list(accumulate(l)):
            A = list(accumulate(l))
        else:
            break
    print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

def mi():
    return map(int, input().split())

def BIT_query(idx, BIT):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def main():
    N, K = mi()
    A = list(mi())

    for _ in range(K):
        l = [0]*N
        for i in range(N):
            left = max(i-A[i], 0)
            right = min(i+A[i]+1, N)
            l[left] += 1
            if right < N:
                l[right] -= 1
        A = list(accumulate(l))
    print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()

Fixed submission:
from itertools import accumulate

def mi():
    return map(int, input().split())

def main():
    N, K = mi()
    A = list(mi())

    for _ in range(K):
        l = [0]*N
        for i in range(N):
            left = max(i-A[i], 0)
            right = min(i+A[i]+1, N)
            l[left] += 1
            if right < N:
                l[right] -= 1
        if A != list(accumulate(l)):
            A = list(accumulate(l))
        else:
            break
    print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
S = input()
n = len(S)
a = [0]*(n+1)
l = [0]*2019
t = pow(10, n-1)

a[0] = int(S)
l[a[0]%2019] += 1

for i in range(n):
    a[i+1] = a[i] - int(S[i])*t
    l[a[i+1]%2019] += 1
    t = t // 10

print(sum(map(lambda x: x*(x-1)//2, l)))


Fixed submission:
S, W = map(int, input().split())
if W >= S:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A == B == C:
    print(0 if A%2 else -1)
else:
    cnt = 0
    while A%2==0 and B%2==0 and C%2==0:
        A, B, C = (B+C)//2, (C+A)//2, (A+B)//2
        cnt += 1
    print(cnt)


Fixed submission:
S = input()
if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, A, B, C = map(int, input().split())
p, q, r = [list(map(int, input().split())) for _ in range(3)]

p = list(map(lambda x: [x, 'p'], p))
q = list(map(lambda x: [x, 'q'], q))
r = list(map(lambda x: [x, 'r'], r))

l = p+q+r

l.sort(reverse=True)

x = 0
y = 0

sum = 0

while not (x == X and y == Y):
    apple = l.pop(0)
    if apple[1] == 'p' and x < X:
        x += 1
        sum += apple[0]
    if apple[1] == 'q' and y < Y:
        y += 1
        sum += apple[0]
    if apple[1] == 'r':
        if X-x < Y-y and y < Y:
            y += 1
            sum += apple[0]
        if Y-y <= X-x and x < X:
            x += 1
            sum += apple[0]

print(sum)
        

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p, q, r = [list(map(int, input().split())) for _ in range(3)]

p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]

l = p+q+r

l.sort(reverse=True)

print(sum(l[:X+Y]))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = [input().split() for i in range(Q)]

for i in range(Q):
    if Query[i][0] == '1':
        S = S[::-1]
    else:
        F = Query[i][1]
        C = Query[i][2]
        if F == '1':
            S = C + S
        else:
            S = S + C

print(S)


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())
Query = [input().split() for i in range(Q)]
order = 1

for i in range(Q):
    if Query[i][0] == '1':
        order *= -1
    else:
        F = Query[i][1]
        C = Query[i][2]

        if F == '1':
            if order == 1:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if order == 1:
                S.append(C)
            else:
                S.appendleft(C)

S = ''.join(list(S))

print(S[::order])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [map(int, input().split()) for _ in range(M)]
s, c = [list(i) for i in zip(*sc)]

def isOK(num):
    str_num = str(num)
    l = len(str_num)
    if l != N:
        return False
    for i in range(M):
        if str_num[s[i]-1] != str(c[i]):
            return False

    return True

ans = -1

for i in range(10**N):
    if isOK(i):
        ans = i
        break

print(ans)

Fixed submission:
N, M = map(int, input().split())
if M:
    sc = [map(int, input().split()) for _ in range(M)]
    s, c = [list(i) for i in zip(*sc)]

    def isOK(num):
        str_num = str(num)
        l = len(str_num)
        if l != N:
            return False
        for i in range(M):
            if str_num[s[i]-1] != str(c[i]):
                return False

        return True

    ans = -1

    for i in range(10**N):
        if isOK(i):
            ans = i
            break

    print(ans)
else:
    print(10**(N-1) if N != 1 else 0)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [map(int, input().split()) for _ in range(M)]
s, c = [list(i) for i in zip(*sc)]

def isOK(num):
    l = len(str(num))
    if l != N:
        return False
    for i in range(M):
        if str(num)[s[i]-1] != str(c[i]):
            return False

    return True

ans = -1

for i in range(1000):
    if isOK(i):
        ans = i
        break

print(ans)

Fixed submission:
N, M = map(int, input().split())
if M:
    sc = [map(int, input().split()) for _ in range(M)]
    s, c = [list(i) for i in zip(*sc)]

    def isOK(num):
        str_num = str(num)
        l = len(str_num)
        if l != N:
            return False
        for i in range(M):
            if str_num[s[i]-1] != str(c[i]):
                return False

        return True

    ans = -1

    for i in range(10**N):
        if isOK(i):
            ans = i
            break

    print(ans)
else:
    print(10**(N-1) if N != 1 else 0)
Buggy python submission (verdict: Runtime Error):
10
ZABCDBABCQ
---
2
===
19
THREEONEFOURONEFIVE
---
0
===
33
ABCCABCBABCCABACBCBBABCBCBCBCABCB
---
5
===


Fixed submission:
N= int(input())
S = input()
print(S.count('ABC'))