Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
Sum = [0]*(N+1)
for i in range(N):
	if S[i] == 'A' and S[i+1] == 'C':
		Sum[i+1] = Sum[i] + 1
	else:
		Sum[i+1] = Sum[i]

for i in range(Q):
	l, r = map(int, input().split())
	print(Sum[r-1] - Sum[l-1])
	

Fixed submission:
N, Q = map(int, input().rstrip().split())
S = [i for i in input()]

list_lr = [list(map(int, input().rstrip().split())) for i in range(Q)]

t = [0]
ct = 0
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ct += 1
    t.append(ct)

for i in list_lr:
    l, r = i[0], i[1]
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().rstrip().split())
S = [i for i in input()]

for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        S[i], S[i+1] = 2, -1
    else:
        if type(S[i]) != int:
            S[i] = 0

if type(S[-1]) == str:
    S[-1] = 0

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]
    if s[0] == -1 and s[-1] == 2:
        ans = sum(s)-1
    elif s[0] == -1 and (s[-1] == -1 or s[-1] == 0):
        ans = sum(s)+1
    elif s[-1] == 2 and (s[0] == 2 or s[1] == 0):
        ans = sum(s)-2
    else:
        ans = sum(s)

    print(int(ans))


Fixed submission:
N, Q = map(int, input().rstrip().split())
S = [i for i in input()]

list_lr = [list(map(int, input().rstrip().split())) for i in range(Q)]

t = [0]
ct = 0
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ct += 1
    t.append(ct)

for i in list_lr:
    l, r = i[0], i[1]
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().rstrip().split())
S = input()

count = [0 for i in range(len(S))]

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]

    print(s.count('AC'))


Fixed submission:
N, Q = map(int, input().rstrip().split())
S = [i for i in input()]

list_lr = [list(map(int, input().rstrip().split())) for i in range(Q)]

t = [0]
ct = 0
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ct += 1
    t.append(ct)

for i in list_lr:
    l, r = i[0], i[1]
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().rstrip().split())
S = input()

count = [0 for i in range(len(S))]

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]
    count = 0
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'C':
            count += 1

    print(count)


Fixed submission:
N, Q = map(int, input().rstrip().split())
S = [i for i in input()]

list_lr = [list(map(int, input().rstrip().split())) for i in range(Q)]

t = [0]
ct = 0
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ct += 1
    t.append(ct)

for i in list_lr:
    l, r = i[0], i[1]
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

list_tmp = []
list_A = []
dict_AB = {}
for i in range(N):
    A, B = map(int, input().split())
    if dict_AB.get(A) is None:
        dict_AB[A] = B
    else:
        list_tmp.append((A, B))
    list_A.append(A)

list_A.sort()

ct = 0
money = 0
for i in list_A:
    A = i
    tmp = copy.deepcopy(list_tmp)
    if tmp:
        for j in list_tmp:
            if j[0] == A:
                B = j[1]
                list_tmp.remove((A, B))
                break
            else:
                B = dict_AB[A]
    else:
        B = dict_AB[A]

    money += A*B
    ct += B
    if ct >= M:
        money -= (ct - M)*A
        break

print(money)


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

AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))

AB.sort(key=lambda x: (x[0], x[1]))

ct = 0
money = 0
for i in AB:
    A, B = i[0], i[1]
    for i in range(B):
        money += A
        ct += 1
        if ct == M:
            break
    if ct == M:
        break

print(money)

Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

list_tmp = []
list_A = []
dict_AB = {}
for i in range(N):
    A, B = map(int, input().split())
    if dict_AB.get(A) is None:
        dict_AB[A] = B
    else:
        list_tmp.append((A, B))
    list_A.append(A)

list_A.sort()

ct = 0
money = 0
for i in list_A:
    A = i
    tmp = copy.deepcopy(list_tmp)
    if tmp:
        for j in list_tmp:
            if j[0] == A:
                B = j[1]
                list_tmp.remove((A, B))
                break
            else:
                B = dict_AB[A]
    else:
        B = dict_AB[A]
    for j in range(B):
        money += A
        ct += 1
        if ct == M:
            break
    if ct == M:
        break

print(money)


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

AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))

AB.sort(key=lambda x: (x[0], x[1]))

ct = 0
money = 0
for i in AB:
    A, B = i[0], i[1]
    for i in range(B):
        money += A
        ct += 1
        if ct == M:
            break
    if ct == M:
        break

print(money)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

ct = 0
while True:
    ct += S.count('01')
    S = S.replace('01', '')
    ct += S.count('10')
    S = S.replace('10', '')
    if not S.count('01') and not S.count('10'):
        break

print(ct*2)


Fixed submission:
S = input()

red = S.count('0')
blue = S.count('1')

print(2*(min(red, blue)))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

dif = []
for i in range(M-1):
    dif.append(A[i+1] - A[i])

for i in range(N-1):
    dif.remove(max(dif))

print(sum(dif))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

dif = []
for i in range(M-1):
    dif.append(A[i+1] - A[i])

dif.sort(reverse=True)
dif = dif[N-1:]

print(sum(dif))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(i) for i in input().split()]

INF = float('inf')
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    tmp = INF
    step = max(0, i-K)
    for j in range(step, i):
        tmp = min(tmp, dp[j] + abs(h[i] - h[j]))
    dp[i] = tmp

print(dp[N-1])


Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]

INF = float('inf')
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    tmp = INF
    step = max(0, i-K)
    for j in range(step, i):
        tmp = min(tmp, dp[j] + abs(h[i] - h[j]))
    dp[i] = tmp

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * N

dp[0] = 0
for i in range(1, N):
    step = K+1 if K < i else i+1
    dp[i] = dp[i-1] + abs(h[i]-h[i-1])
    for j in range(2, step):
        dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
        
print(dp[N-1])


Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]

INF = float('inf')
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    tmp = INF
    step = max(0, i-K)
    for j in range(step, i):
        tmp = min(tmp, dp[j] + abs(h[i] - h[j]))
    dp[i] = tmp

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**9] * N

dp[0] = 0
for i in range(1, N):
    step = K+1 if K < i else i+1
    for j in range(1, step):
        dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]))
        
print(dp[N-1])


Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]

INF = float('inf')
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    tmp = INF
    step = max(0, i-K)
    for j in range(step, i):
        tmp = min(tmp, dp[j] + abs(h[i] - h[j]))
    dp[i] = tmp

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

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

dp = [[0]*(W+1) for _ in range(N)]
for i in range(weight[0], W+1):
    dp[0][i] = value[0]

for i in range(1, N):
    for ws in range(W+1):
        if ws - weight[i] >= 0:
            dp[i][ws] = dp[i-1][ws - weight[i]] + value[i]
        dp[i][ws] = max(dp[i][ws], dp[i-1][ws])

print(dp[N-1][W])

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

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

dp = [[0]*(W+1) for _ in range(N)]
for i in range(weight[0], W+1):
    dp[0][i] = value[0]

for i in range(1, N):
    for ws in range(W+1):
        if ws - weight[i] >= 0:
            dp[i][ws] = dp[i-1][ws - weight[i]] + value[i]
        dp[i][ws] = max(dp[i][ws], dp[i-1][ws])

print(dp[N-1][W])

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

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

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

print(dp[N][W])

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

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

dp = [[0]*(W+1) for _ in range(N)]
for i in range(weight[0], W+1):
    dp[0][i] = value[0]

for i in range(1, N):
    for ws in range(W+1):
        if ws - weight[i] >= 0:
            dp[i][ws] = dp[i-1][ws - weight[i]] + value[i]
        dp[i][ws] = max(dp[i][ws], dp[i-1][ws])

print(dp[N-1][W])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
INF = float('inf')
weight = [0] * N
value = [0] * N
Max_v = 0
for i in range(N):
    w, v = map(int, input().split())
    weight[i], value[i] = w, v
    Max_v += v

dp = [[INF]*(Max_v+1) for _ in range(N)]
for i in range(0, value[0]+1):
    dp[0][i] = weight[0] if i else 0

for i in range(1, N):
    for vs in range(Max_v+1):
        if vs - value[i] >= 0:
            dp[i][vs] = dp[i-1][vs - value[i]] + weight[i]
        else:
            dp[i][vs] = weight[i]
        dp[i][vs] = min(dp[i][vs], dp[i-1][vs])

for i in reversed(range(Max_v+1)):
    if dp[N-1][i] <= W:
        print(i)
        break


Fixed submission:
N, W = map(int, input().split())
INF = float('inf')
weight = [0] * N
value = [0] * N
Max_v = 0
for i in range(N):
    w, v = map(int, input().split())
    weight[i], value[i] = w, v
    Max_v += v

dp = [[INF]*(Max_v+1) for _ in range(N)]
for i in range(0, value[0]+1):
    dp[0][i] = weight[0] if i else 0

for i in range(1, N):
    for vs in range(Max_v+1):
        if vs - value[i] >= 0:
            dp[i][vs] = dp[i-1][vs - value[i]] + weight[i]
        else:
            dp[i][vs] = weight[i]
        dp[i][vs] = min(dp[i][vs], dp[i-1][vs])

for i in reversed(range(Max_v+1)):
    if dp[N-1][i] <= W:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

ls, lt = len(s), len(t)

dp = [[0]*(lt+1) for _ in range(ls+1)]
for i in range(1, ls+1):
    for j in range(1, lt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)
        dp[i][j] = max(dp[i][j], dp[i][j-1])
        dp[i][j] = max(dp[i][j], dp[i-1][j])

ans = ''
while ls > 0 and lt > 0:
    if dp[ls][lt] == dp[ls-1][lt]:
        ls -= 1
    elif dp[ls][lt] == dp[ls][lt-1]:
        lt -= 1
    else:
        ans = t[lt-1] + ans
        ls -= 1
        lt -= 1

print(ans)


Fixed submission:
s = input()
t = input()

ls, lt = len(s), len(t)

dp = [[0]*(lt+1) for _ in range(ls+1)]
for i in range(1, ls+1):
    for j in range(1, lt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)
        dp[i][j] = max(dp[i][j], dp[i][j-1])
        dp[i][j] = max(dp[i][j], dp[i-1][j])

ans = ''
while ls > 0 and lt > 0:
    if dp[ls][lt] == dp[ls-1][lt]:
        ls -= 1
    elif dp[ls][lt] == dp[ls][lt-1]:
        lt -= 1
    else:
        ans = t[lt-1] + ans
        ls -= 1
        lt -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = input().split()

vv = list(set(v))

count = []
for i in vv:
    count.append((v.count(i), i))

count.sort(key=lambda x: x[0], reverse=True)
vv = [i[1] for i in count]

if len(vv) >= 2:
    vvv = vv.copy()

    min = 10**6
    for i in vv:
        vvv.remove(i)
        for j in vvv:
            if 10-(v.count(i)+v.count(j)) > min:
                pass
            else:
                ct = 0
                a = [i if k % 2 == 0 else j for k in range(n)]
                for k in range(n):
                    if a[k] != v[k]:
                        ct += 1
                if ct < min:
                    min = ct
        vvv.append(i)
    print(min)
else:
    print(int(n/2))


Fixed submission:
import collections

n = int(input())
v = input().split()

e = [v[i] for i in range(n) if i % 2 == 0]
o = [v[i] for i in range(n) if i % 2 == 1]

c_e = collections.Counter(e).most_common()
c_o = collections.Counter(o).most_common()

e_0 = c_e[0]
o_0 = c_o[0]

if e_0 != o_0:
    print(len(e) - e_0[1] + len(o) - o_0[1])
else:
    if len(c_e) == 1:
        e_1 = [0, 0]
    else:
        e_1 = c_e[1]
    if len(c_o) == 1:
        o_1 = [0, 0]
    else:
        o_1 = c_o[1]
    print(min(len(e)-e_0[1]+len(o)-o_1[1], len(e)-e_1[1]+len(o)-o_0[1]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = input().split()

vv = list(set(v))

if len(vv) >= 2:
    vvv = vv.copy()

    min = 10**6
    for i in vv:
        vvv.remove(i)
        for j in vvv:
            ct = 0
            a = [i if k % 2 == 0 else j for k in range(n)]
            for k in range(n):
                if a[k] != v[k]:
                    ct += 1
            if ct < min:
                min = ct
        vvv.append(i)
    print(min)
else:
    print(int(n/2))


Fixed submission:
import collections

n = int(input())
v = input().split()

e = [v[i] for i in range(n) if i % 2 == 0]
o = [v[i] for i in range(n) if i % 2 == 1]

c_e = collections.Counter(e).most_common()
c_o = collections.Counter(o).most_common()

e_0 = c_e[0]
o_0 = c_o[0]

if e_0 != o_0:
    print(len(e) - e_0[1] + len(o) - o_0[1])
else:
    if len(c_e) == 1:
        e_1 = [0, 0]
    else:
        e_1 = c_e[1]
    if len(c_o) == 1:
        o_1 = [0, 0]
    else:
        o_1 = c_o[1]
    print(min(len(e)-e_0[1]+len(o)-o_1[1], len(e)-e_1[1]+len(o)-o_0[1]))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
x = list(map(int, input().split()))

if 0 in x:
    K -= 1
    x.remove(0)

Min = -1
for i in x:
    goal = i
    if goal > 0:
        path = [j for j in x if j < goal]
        if len(path) < K-1:
            pass
        else:
            path = path[-K+1:]
            le = min(path)
            dis = abs(0-le)+abs(goal-le)
            if Min == -1:
                Min = dis
            else:
                if dis < Min:
                    Min = dis
    else:
        path = [j for j in x if j > goal]
        if len(path) < K-1:
            pass
        else:
            path = path[:K-1]
            re = max(path)
            dis = abs(0-re)+abs(goal-re)
            if Min == -1:
                Min = dis
            else:
                if dis < Min:
                    Min = dis

if Min == -1:
    Min = 0

print(Min)


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

Min = 10**9
for i in range(N-K+1):
    x_l = x[i]
    x_r = x[i+K-1]
    ans_1 = abs(x_l-0) + abs(x_l-x_r)
    ans_2 = abs(x_r-0) + abs(x_l-x_r)
    Min = min(Min, ans_1, ans_2)

print(Min)
Buggy python submission (verdict: Runtime Error):
import sys

S, K = [int(i) for i in input()], int(input())

if S[0] == 1:
    for i in range(1, len(S)):
        if S[i] == 1:
            pass
        else:
            idx = i
            break
else:
    print(S[0])
    sys.exit()

if K-1 < idx:
    print(1)
else:
    print(S[idx])


Fixed submission:
import sys

S, K = [int(i) for i in input()], int(input())

if S[0] == 1:
    length = 1
    for i in range(1, len(S)):
        if S[i] == 1:
            length += 1
            pass
        else:
            idx = i
            break
else:
    print(S[0])
    sys.exit()

if len(S) == length:
    print(1)
else:
    if K-1 < idx:
        print(1)
    else:
        print(S[idx])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = input().split()
count = 0
if N = K:
    print(1)
else:
    count += 1
    rem = N-K
    add = 1 if (N-K)%(K-1) else 0
    count += (N-K)//(K-1) + add
    print(count)

Fixed submission:
N, K = map(int, input().split())
A = input().split()
count = 0
if N == K:
    print(1)
else:
    count += 1
    rem = N-K
    add = 1 if (N-K)%(K-1) else 0
    count += (N-K)//(K-1) + add
    print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

Max = 0
for i in range(N):
    if i == 0:
        Max = S[1:].count('W')
    elif i < N-1:
        ct = S[:i].count('E') + S[i+1:].count('W')
        Max = max(Max, ct)
    else:
        Max = max(Max, S[:-1].count('E'))

ans = N-1 - Max

print(ans)

Fixed submission:
N = int(input())
S = input()

ct_sum = []
ct_E, ct_W = 0, 0
for i in S:
    if i == 'E':
        ct_E += 1
    else:
        ct_W += 1
    ct_sum.append((ct_E, ct_W))

Max = 0
for i in range(N):
    if i == 0:
        E_l = 0
    else:
        E_l = ct_sum[i-1][0]
    W_i, W_e = ct_sum[i][1], ct_sum[N-1][1]
    W_r = W_e - W_i
    ct = E_l + W_r
    Max = max(Max, ct)

ans = N-1 - Max

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.append(0)

Sum = 0
for i in range(N+1):
    Sum += abs(A[i+1] - A[i])

for i in range(1, N+1):
    if (A[i-1] < A[i] < A[i+1]) or (A[i+1] < A[i] < A[i-1]):
        ans = Sum
    elif A[i] > A[i-1]:
        ans = Sum - 2 * abs(A[i] - max(A[i-1], A[i+1]))
    elif A[i] < A[i-1]:
        ans = Sum - 2 * abs(A[i] - min(A[i-1], A[i+1]))
    print(ans)


Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.append(0)

Sum = 0
for i in range(N+1):
    Sum += abs(A[i+1] - A[i])

for i in range(1, N+1):
    if (A[i-1] < A[i] < A[i+1]) or (A[i+1] < A[i] < A[i-1]):
        ans = Sum
    elif A[i] > A[i-1]:
        ans = Sum - 2 * abs(A[i] - max(A[i-1], A[i+1]))
    elif A[i] < A[i-1]:
        ans = Sum - 2 * abs(A[i] - min(A[i-1], A[i+1]))
    else:
        ans = Sum
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
csf = [[int(i) for i in input().split()] for j in range(N-1)]

for i in range(N-1):
    t = csf[i][1] + csf[i][0]

    for j in range(i+1, N-1):
        if t <= csf[j][1]:
            t = csf[j][1] + csf[j][0]
            continue
        num = 0
        while True:
            if csf[j][1]+num*csf[j][2] < t <= csf[j][1]+(num+1)*csf[j][2]:
                t = csf[j][1]+(num+1)*csf[j][2] + csf[j][0]
                break
            num += 1
    print(t)

print(0)


Fixed submission:
N = int(input())
csf = [[int(i) for i in input().split()] for j in range(N-1)]

for i in range(N-1):
    t = csf[i][1] + csf[i][0]

    for j in range(i+1, N-1):
        if t <= csf[j][1]:
            t = csf[j][1] + csf[j][0]
            continue
        if (t-csf[j][1]) % csf[j][2] == 0:
            t = csf[j][1] + csf[j][2]*((t-csf[j][1])//csf[j][2]) + csf[j][0]
        else:
            t = csf[j][1] + csf[j][2]*((t-csf[j][1])//csf[j][2]+1) + csf[j][0]
    print(t)

print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]

check = []

ans = 0
for i in a:
    if i not in check:
        check.append(i)
        tmp = a.count(i)
        if tmp < i:
            ans += tmp
        else:
            ans += tmp - i

print(ans)


Fixed submission:
from collections import Counter as ct

N = int(input())
a = [int(i) for i in input().split()]
c = ct(a)

ans = 0
for i, j in c.items():
    if i <= j:
        ans += j - i
    else:
        ans += j

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]

b = list(set(a))

ans = 0
for i in b:
    tmp = a.count(i)
    if tmp < i:
        ans += tmp
    else:
        ans += tmp - i

print(ans)


Fixed submission:
from collections import Counter as ct

N = int(input())
a = [int(i) for i in input().split()]
c = ct(a)

ans = 0
for i, j in c.items():
    if i <= j:
        ans += j - i
    else:
        ans += j

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]

b = list(set(a))

ans = 0
for i in b:
    if a.count(i) < i:
        ans += a.count(i)
    else:
        ans += a.count(i) - i

print(ans)


Fixed submission:
from collections import Counter as ct

N = int(input())
a = [int(i) for i in input().split()]
c = ct(a)

ans = 0
for i, j in c.items():
    if i <= j:
        ans += j - i
    else:
        ans += j

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(inout())
print(N**2 - A)

Fixed submission:
N = int(input())
A = int(input())
print(N**2 - A)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
memo = []
for i in range(N):
    A = int(input())
    if A in memo:
        memo.remove(A)
    else:
        memo.append(A)

print(len(memo))


Fixed submission:
from collections import Counter

N = int(input())
A = [int(input()) for i in range(N)]

c = list(Counter(A).items())

ans = 0
for i in c:
    if i[1] % 2:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
Min = min(a)-1
Max = max(a)+1
num = [[0 for i in range(N)] for j in range(Min, Max+1)]

idx = 0
for i in a:
    num[i-Min-1][idx] = 1
    num[i-Min][idx] = 1
    num[i-Min+1][idx] = 1
    idx += 1

ct = -1
for i in num:
    tmp = i.count(1)
    if tmp > ct:
        ct = tmp
        
print(ct)
        

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
Min = min(a)-1
Max = max(a)+1
ans = [0 for i in range(Min, Max+1)]

for i in a:
    ans[i-Min-1] += 1
    ans[i-Min] += 1
    ans[i-Min+1] += 1
        
print(max(ans))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
ct = list(Counter(A).items())
flg = 0
ct. sort(key=lambda x: x[0], reverse=True)
for i in ct:
    if i[1] >= 4 and flg == 0:
        ans = i[0]**2
        break
    if i[1] >= 2 and flg == 0:
        flg = 1
        ans = i[0]
    elif i[1] >= 2 and flg == 1:
        ans *= i[0]
        break
print(ans)

Fixed submission:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
ct = list(Counter(A).items())
flg = 0
ct. sort(key=lambda x: x[0], reverse=True)
for i in ct:
    if i[1] >= 4 and flg == 0:
        flg = 2
        ans = i[0]**2
        break
    if i[1] >= 2 and flg == 0:
        flg = 1
        ans = i[0]
    elif i[1] >= 2 and flg == 1:
        flg = 2
        ans *= i[0]
        break

if flg != 2:
    print(0)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
print('ABC' + input())print('ABC' + input())

Fixed submission:
print('ABC' + input())