Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l = [list(map(int, input().split())) for _ in range(Q)]
for i in range(Q):
	print(S[l[i][0] - 1: l[i][1]].count("AC"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
count = [0]*N  # count[i] は i 番目まで S[:i+1] の解
for i in range(1, N):
    count[i] = count[i-1]
    if S[i-1: i+1] == "AC":
        count[i] += 1
for _ in range(Q):
    l,r = map(int, input().split())
    print(count[r-1] - count[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
for i in range(Q):
	l, r = map(int, input().split())
	print(S[l - 1: r].count("AC"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
count = [0]*N  # count[i] は i 番目まで S[:i+1] の解
for i in range(1, N):
    count[i] = count[i-1]
    if S[i-1: i+1] == "AC":
        count[i] += 1
for _ in range(Q):
    l,r = map(int, input().split())
    print(count[r-1] - count[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from itertools import combinations

MOD = 10**9 + 7

N = int(input())
S = input()
c = Counter(S)

ans = 0

for i in range(1, len(c)+1):
    # i文字の部分文字列を考えると、i種類の文字が使われているので
    for keys in combinations(c.keys(), i):
        res = 1
        for k in keys:
            res *= (c[k])
        ans += res
        ans %= MOD

print(ans)


Fixed submission:
from collections import Counter

MOD = 10**9 + 7

N = int(input())
S = input()

c = Counter(S)

ans = 1
for k in c.keys():
    ans *= c[k]+1
    ans %= MOD

ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
while "01" in S or "10" in S:
	S = S.replace("10", "").replace("01", "")
print(N - len(S))


Fixed submission:
S = input()
One = S.count("1")
Zero = S.count("0")
print(len(S) - max(One, Zero) + min(One, Zero))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [0] * M
count = 0
ans = 0
for k in range(N):
	A[k] = list(map(int, input().split()))
for i in range(1, M + 1):
	for j in range(N):
		if i in A[j][1:]:
			count += 1
	if count == N:
		ans += 1
	count = 0
print(ans)


Fixed submission:
N, M = map(int, input().split())
A =[list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(1, A[0][0] + 1):
	flag = True
	a = A[0][i]
	for j in range(1, N):
		if not a in A[j][1:]:
			flag = False
	if flag:
		ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
ans = [0, 0, 0, 0]
for i in range(3):
	x = list(map(int, input().split()))
	for xi in x:
		ans[xi] += 1
if sorted(ans) == [1, 1, 2, 2]:
	print("YES")
else:
	print("NO")


Fixed submission:
ans = [0, 0, 0, 0]
for i in range(3):
	x = list(map(int, input().split()))
	for xi in x:
		ans[xi - 1] += 1
if sorted(ans) == [1, 1, 2, 2]:
	print("YES")
else:
	print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])


Fixed submission:
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N + 1)]
dp[0] = 0
for i in range(N):
	for j in range(1, min(K + 1, N - i + 1)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[j] - h[i]))
print(dp[N])


Fixed submission:
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N):
	for j in range(K):
		if i - K + j >= 0:
			dp[i] = min(dp[i], dp[i - K + j] + abs(h[i] - h[i - K + j]))
print(dp[N - 1])


Fixed submission:
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N):
	for j in range(K):
		if i + j + 1 < N:
			dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i + j + 1] - h[i]))
		else:
			break
print(dp[N - 1])


Fixed submission:
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
	for j in range(K):
		if i > j:
			dp[i] = min(dp[i], dp[i - (j + 1)] + abs(h[i] - h[i - (j + 1)]))
print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a, b, c = [map(int, input().split()) for _ in range(N)]
dp = [0, 0, 0] * N
dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))


Fixed submission:
N = int(input())
a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
	a[i], b[i], c[i] = map(int, input().split())
dp = [[0] * 3 for _ in range(N)]
dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
	for j in range(W + 1):
		if j - w[i] >= 0:
			dp[i + 1][j] = dp[i][j - w[i]] + v[i]
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])


Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
	for j in range(W + 1):
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
	for j in range(W + 1):
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])


Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
	for j in range(W + 1):
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
	for j in range(W + 1):
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])
# print(dp)


Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
	for j in range(W + 1):
		if j - w[i] >= 0:
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i])
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
from sympy import factorint

N, P = map(int, input().split())
f = factorint(P)

ans = 1
for k, v in f.items():
    if v >= N:
        ans *= k * (v//N)
print(ans)


Fixed submission:
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N, P = map(int, input().split())
f = Counter(prime_factorize(P))

ans = 1
for k, v in f.items():
    if v >= N:
        ans *= k ** (v//N)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = [int(input()) for _ in N]
print(sum(p) - max(p) // 2)


Fixed submission:
N = int(input())
p = [int(input()) for _ in range(N)]
print(sum(p) - max(p) // 2)
Buggy python submission (verdict: Runtime Error):
S = input()
ans = 753
for i in range(len(S) - 2):
	tmp = S[i] * 100 + S[i + 1] * 10 + S[i + 2]
	if abs(tmp - 753) < ans:
		ans = tmp
print(ans)


Fixed submission:
S = input()
ans = 753
for i in range(len(S) - 2):
	tmp = abs(int(S[i]) * 100 + int(S[i + 1]) * 10 + int(S[i + 2]) - 753)
	if tmp < ans:
		ans = tmp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop, heapify
from itertools import product

N = int(input())

hq = []

# initial setting
for c in product([3, 5, 7], repeat=3):
    heappush(hq, c[0]*100 + c[1]*10 + c[2])

ans = []
while (hq):
    now = heappop(hq)
    if now <= N:
        if (len(set(str(now))) == 3):
            ans.append(now)
        digit = pow(10, len(str(now)))
        for i in (3, 5, 7):
            heappush(hq, now*10 + i)
            heappush(hq, now + i*digit)

print(len(set(ans)))


Fixed submission:
N = int(input())

q = ["3", "5", "7"]
ans = 0
while q:
    now = q.pop(0)
    if int(now) <= N:
        for c in ("3", "5", "7"):
            q.append(now + c)
        if len(set(now)) == 3:
            ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop, heapify
from itertools import product

N = int(input())

hq = []

# initial setting
for c in product([3, 5, 7], repeat=3):
    heappush(hq, c[0]*100 + c[1]*10 + c[2])

ans = 0
while (hq):
    now = heappop(hq)
    if now <= N and (len(set(str(now))) == 3):
        ans += 1
    digit = pow(10, len(str(now)))
    if now*10 <= N:
        for i in (3, 5, 7):
            heappush(hq, now*10 + i)
    if now+3*digit <= N:
        for i in (3, 5, 7):
            heappush(hq, now + i*digit)
    hq = list(set(hq))
    heapify(hq)

print(ans)


Fixed submission:
N = int(input())

q = ["3", "5", "7"]
ans = 0
while q:
    now = q.pop(0)
    if int(now) <= N:
        for c in ("3", "5", "7"):
            q.append(now + c)
        if len(set(now)) == 3:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input())
for i in range(K):
	if i % 2 == 0:
		# takahashi
		if A % 2 == 1:
			A -= 1
		A, B = A // 2, B + A // 2
	else:
		# aoki
		if B % 2 == 1:
			B -= 1
		A, B = A + B // 2, B // 2
print(A, B)


Fixed submission:
A, B, K = map(int, input().split())
for i in range(K):
	if i % 2 == 0:
		# takahashi
		if A % 2 == 1:
			A -= 1
		A, B = A // 2, B + A // 2
	else:
		# aoki
		if B % 2 == 1:
			B -= 1
		A, B = A + B // 2, B // 2
print(A, B)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd

N, M = map(int, input().split())
S = input()
T = input()

L = N*M // gcd(N, M)
for i in range(N):
    for j in range(M):
        if M*i == N*j and S[i] != T[j]:
            print(-1)
            exit()

print(L)


Fixed submission:
from math import gcd

N, M = map(int, input().split())
S = input()
T = input()

L = N*M // gcd(N, M)

for i in range(N):
    if M*i % N == 0:
        j = M*i // N
        if S[i] != T[j]:
            print(-1)
            exit()

print(L)

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

N, M = map(int, input().split())
S = input()
T = input()

L = N*M // gcd(N, M)
X = ["0" for _ in range(L)]

for i in range(N):
    for j in range(M):
        if M*i == N*j and S[i] != T[j]:
            print(-1)
            exit()
        else:
            X[i*L//N] = S[i]
            X[j*L//M] = T[j]

print(L)


Fixed submission:
from math import gcd

N, M = map(int, input().split())
S = input()
T = input()

L = N*M // gcd(N, M)

for i in range(N):
    if M*i % N == 0:
        j = M*i // N
        if S[i] != T[j]:
            print(-1)
            exit()

print(L)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 1
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")


Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 1
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    print(S[ind])


Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
if set(S) == "1":
    print(1)
elif S[0] == "1" and K > 1:
    ind = 1
    while S[ind] == "1":
        ind += 1
    print(S[ind])
else:
    print(S[0])


Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] == "1" and K > 1:
    ind = 1
    while S[ind] == "1":
        ind += 1
    print(S[ind])
else:
    print(S[0])


Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] == "1":
    ind = 1
    while S[ind] == "1":
        ind += 1
    print(S[ind])
else:
    print(S[0])


Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] == "1":
    print(S[1])
else:
    print(S[0])


Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")
Buggy python submission (verdict: Runtime Error):
S = input()
ans = 0
for i in range(len(S)):
	if S[i] == "+":
        ans += 1
    else:
      	ans -= 1
print(ans)


Fixed submission:
S = input()
ans = 0
for i in range(len(S)):
	if S[i] == "+":
		ans += 1
	else:
		ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = float("inf")
for i in range(N):
	ans = min(ans, S[i + 1:].count("E") + S[: i].count("W"))
print(ans)


Fixed submission:
N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
from copy import copy

N = int(input())
X = list(map(int, input().split()))

for xi in X:
    Y = copy(X)
    Y.remove(xi)
    print(sorted(Y)[N // 2 - 1])


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

M_small = sorted(X)[N // 2 - 1]
M_large = sorted(X)[N // 2]

for xi in X:
    if xi <= M_small:
        print(M_large)
    else:
        print(M_small)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    numer = reduce(mul, range(n, n - r, -1))
    denom = reduce(mul, range(1, r + 1))
    return numer // denom


n = int(input())
a = list(map(int, input().split()))
ai = max(a)
ans_val = 0
for aj in set(a):
    if cmb(ai, aj) > ans_val:
        ans = [ai, aj]
        ans_val = cmb(ai, aj)
print(' '.join(map(str, ans)))


Fixed submission:
from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    numer = reduce(mul, range(n, n - r, -1))
    denom = reduce(mul, range(1, r + 1))
    return numer // denom


n = int(input())
a = list(map(int, input().split()))
ai = max(a)
diff = float("inf")
for aj in set(a):
    if abs(ai / 2 - aj) < diff:
        ans = [ai, aj]
        diff = abs(ai / 2 - aj)
print(' '.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
for i in range(A, B + 1):
	if i <= A + K - 1 or B - K + 1 <= i:
		print(i)


Fixed submission:
A, B, K = map(int, input().split())
if 2 * K >= B - A + 1:
	for k in range(A, B + 1):
		print(k)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)
Buggy python submission (verdict: Runtime Error):
x, y, z = input() * 3
print(x[0] + y[1] + z[2])

Fixed submission:
x, y, z = input(), input(), input()
print(x[0] + y[1] + z[2])
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))


Fixed submission:
import math
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))

Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print(math.ceil((a + b) / x))

Fixed submission:
import math
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in set(a):
	cnt = a.count(i)
	if cnt >= i:
		ans += cnt - i
	else:
		ans += cnt
print(ans)


Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in set(a):
	cnt = a.count(i)
	if cnt >= i:
		ans += cnt - i
	else:
		ans += cnt
print(ans)


Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in set(a):
	cnt = a.count(i)
	if cnt >= i:
		ans += cnt - i
	else:
		ans += cnt
print(ans)


Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in set(a):
	if i <= a.count(i):
		ans += a.count(i) - i
	else:
		ans += a.count(i)
print(ans)


Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in set(a):
	if i <= a.count(i):
		ans += a.count(i) - i
	else:
		ans += a.count(i)
print(ans)


Fixed submission:
import collections

N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A).most_common()[::-1]

ans = 0
while len(c) > K:
    res = c.pop(0)
    ans += res[1]
print(ans)


Fixed submission:
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A).most_common()[::-1]

ans = 0
if len(c) > K:
    for i in range(len(c) - K):
        ans += c[i][1]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def lucas(N):
    if N == 0:
        return 2
    elif N == 1:
        return 1
    else:
        return lucas(N-1) + lucas(N-2)

N = int(input())
print(lucas(N))


Fixed submission:
N = int(input())
L = [0] * 87  # 制約から
L[0] = 2
L[1] = 1
if N >= 2:
	for i in range(2, N + 1):
		L[i] = L[i - 1] + L[i - 2]
print(L[N])

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [0] * 86  # 86は制約から
L[0] = 2
L[1] = 1
if N >= 2:
	for i in range(2, N + 1):
		L[i] = L[i - 1] + L[i - 2]
print(L[N])


Fixed submission:
N = int(input())
L = [0] * 87  # 制約から
L[0] = 2
L[1] = 1
if N >= 2:
	for i in range(2, N + 1):
		L[i] = L[i - 1] + L[i - 2]
print(L[N])
Buggy python submission (verdict: Runtime Error):
r, g = map(int, input().split())
print(2 * g - r)


Fixed submission:
r, g = eval("int(input())," * 2)
print(2 * g - r)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ans = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"
        else:
            if 0 < i and i < H-1:
                li = [i-1, i, i+1]
            elif i == 0:
                li = [i, i+1]
            else:
                li = [i-1, i]
            if 0 < j and j < W-1:
                lj = [j-1, j, j+1]
            elif j == 0:
                lj = [j, j+1]
            else:
                lj = [j-1, j]
            ans[i][j] = str(sum([S[lii][ljj]=="#" for lii in li for ljj in lj]))

for i in range(H):
    s = "".join(ans[i])
    print(s)


Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
for i in range(H):
	for j in range(W):
		if S[i][j] == ".":
			cnt = 0
			if i != 0:
				cnt += S[i - 1][max(0, j - 1): min(j + 1, W - 1) + 1].count("#")
			cnt += S[i][max(0, j - 1): min(j + 1, W - 1) + 1].count("#")
			if i != H - 1:
				cnt += S[i + 1][max(0, j - 1): min(j + 1, W - 1) + 1].count("#")
			S[i][j] = str(cnt)
for x in range(H):
	print("".join(S[x]))