Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int,input().split())
A = [["#"] + [s for s in input()] + ["#"] for k in range(H)]
A = [["#"]*(W+2)] + A + [["#"]*(W+2)]


que = []
for k in range(1,H+1):
    for l in range(1,W+1):
        if A[k][l] == "#":
            que.append([k,l])
if len(que) == H*W:
    print(0)
    exit(0)
ans = 0
while True:
    t = []
    while len(que) > 0:
        s = que.pop()
        k, l = s[0], s[1]
        if A[k][l-1] == ".":
            A[k][l-1] = "#"
            t.append([k,l-1])
        if A[k][l+1] == ".":
            A[k][l+1] = "#"
            t.append([k,l+1])
        if A[k-1][l] == ".":
            A[k-1][l] = "#"
            t.append([k-1,l])
        if  A[k+1][l] == ".":
            A[k+1][l] = "#"
            t.append([k+1,l])
    if len(t) > 0:
        ans += 1
        que = t
    else:
        break
print(ans)


Fixed submission:
H, W = map(int,input().split())
A = [["#"] + [s for s in input()] + ["#"] for k in range(H)]
A = [["#"]*(W+2)] + A + [["#"]*(W+2)]


que = []
for k in range(1,H+1):
    for l in range(1,W+1):
        if A[k][l] == "#":
            que.append([k,l])
if len(que) == H*W:
    print(0)
    exit(0)
ans = 0
while True:
    t = []
    while len(que) > 0:
        s = que.pop()
        k, l = s[0], s[1]
        if A[k][l-1] == ".":
            A[k][l-1] = "#"
            t.append([k,l-1])
        if A[k][l+1] == ".":
            A[k][l+1] = "#"
            t.append([k,l+1])
        if A[k-1][l] == ".":
            A[k-1][l] = "#"
            t.append([k-1,l])
        if  A[k+1][l] == ".":
            A[k+1][l] = "#"
            t.append([k+1,l])
    if len(t) > 0:
        ans += 1
        que = t
    else:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
S = input()
L = []
t = 1
for k in range(1,N):
    if S[k-1] == S[k]:
        t += 1
    else:
        L.append(t)
        t = 1
L.append(t)
l = len(L)
if S[0] == "0":
    ans = sum(L[:2*K])
    for k in range(l-2*K+1):
        if k%2 == 1:
            ans = max(ans,sum(L[k:k+2*K+1]))
else:
    ans = sum(L[:2*K+1])
    for k in range(l-2*K+1):
        if k%2 == 0:
            ans = max(ans,sum(L[k:k+2*K+1]))
print(ans)


Fixed submission:
N, K = map(int,input().split())
S = input()
L = []
t = 1
for k in range(1,N):
    if S[k-1] == S[k]:
        t += 1
    else:
        L.append(t)
        t = 1
L.append(t)
l = len(L)
A = [0 for k in range(l+2)]

for k in range(l):
    A[k+1] = A[k] + L[k]
A[l+1] = A[l]
if S[0] == "0":
    ans = A[min(l,2*K)]
    if l%2 == 1:
        for k in range(l-2*K+1):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
else:
    ans = A[min(l,2*K+1)]
    if l%2 == 1:
        for k in range(l-2*K):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K+1):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
S = input()
L = []
t = 1
for k in range(1,N):
    if S[k-1] == S[k]:
        t += 1
    else:
        L.append(t)
        t = 1
L.append(t)
l = len(L)
if S[0] == "0":
    ans = sum(L[:2*K])
    for k in range(l-2*K+1):
        if k%2 == 1:
            ans = max(ans,sum(L[k:k+2*K+1]))
else:
    ans = sum(L[:2*K+1])
    for k in range(l-2*K+1):
        if k%2 == 0:
            ans = max(ans,sum(L[k:k+2*K+1]))
print(ans)


Fixed submission:
N, K = map(int,input().split())
S = input()
L = []
t = 1
for k in range(1,N):
    if S[k-1] == S[k]:
        t += 1
    else:
        L.append(t)
        t = 1
L.append(t)
l = len(L)
A = [0 for k in range(l+2)]

for k in range(l):
    A[k+1] = A[k] + L[k]
A[l+1] = A[l]
if S[0] == "0":
    ans = A[min(l,2*K)]
    if l%2 == 1:
        for k in range(l-2*K+1):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K):
            if k%2 == 1:
                ans = max(ans,A[k+2*K+1]-A[k])
else:
    ans = A[min(l,2*K+1)]
    if l%2 == 1:
        for k in range(l-2*K):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])
    else:
        for k in range(l-2*K+1):
            if k%2 == 0:
                ans = max(ans,A[k+2*K+1]-A[k])

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if dp[match-A[k][1]] == keta-1:
            ans += str(A[k][0])
            match -= A[k][1]
            keta -= 1
            break
print(ans)

Fixed submission:
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if match-A[k][1] >= 0:
            if dp[match-A[k][1]] == keta-1:
                ans += str(A[k][0])
                match -= A[k][1]
                keta -= 1
                break
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if dp[match-A[k][1]] == keta-1:
            ans += str(A[k][0])
            match -= A[k][1]
            keta -= 1
            break
print(ans)


Fixed submission:
N, M = map(int,input().split())
L = list(map(int,input().split()))
K = [0,2,5,5,4,5,6,3,7,6]
A = sorted([[L[k],K[L[k]]] for k in range(M)])[::-1]
dp = [0 for k in range(N+1)]

for k in range(1,N+1):
    t = -float("inf")
    for j in range(M):
        if k-A[j][1]>=0:
            t = max(t, dp[k-A[j][1]]+1)
    dp[k] = t

ans = ""
keta = dp[N]
match = N
while keta > 0:
    for k in range(M):
        if match-A[k][1] >= 0:
            if dp[match-A[k][1]] == keta-1:
                ans += str(A[k][0])
                match -= A[k][1]
                keta -= 1
                break
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int,input().split())

def keisan(n,x):
    if x <= 1:
        return 0
    elif 1 < x <= 2**(n+1) - 2:
        return keisan(n-1,x-1)
    elif x == 2**(n+1) - 1:
        return 2**n
    else:
        return 2**n + keisan(n-1,x-(2**(n+1)-1))

print(keisan(N,X))


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

def keisan(n,x):
    if n == 1:
        if x <= 1:
            return 0
        elif 2 <= x <= 4:
            return x-1
        else:
            return 3
    if x <= 1:
        return 0
    elif 1 < x <= 2**(n+1) - 2:
        return keisan(n-1,x-1)
    elif x == 2**(n+1) - 1:
        return 2**n
    else:
        return 2**n + keisan(n-1,x-(2**(n+1)-1))

print(keisan(N,X))
Buggy python submission (verdict: Time Limit Exceeded):
# AGC 028 A
N, M = map(int, input().split())
S = input()
T = input()

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

if S[0] != T[0]:
    print(-1)
    exit(0)
if S == T:
    print(N)
    exit(0)

L = lcm(N,M)
p = L//N
q = L//M
U = ""
k = 0

if gcd(M,N) > 1:
    for k in range(1,L):
        if k%p == 0 and k%q == 0:
            if S[k//p] != T[k//q]:
                print(-1)
                exit(0)
    print(L)
else:
    print(L)


Fixed submission:
# AGC 028 A
N, M = map(int, input().split())
S = input()
T = input()

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

if S[0] != T[0]:
    print(-1)
    exit(0)
if S == T:
    print(N)
    exit(0)

L = lcm(N,M)
p = L//N
q = L//M
U = ""
k = 0

if gcd(M,N) > 1:
    for k in range(1,L):
        if k%p == 0 and k%q == 0:
            if S[k//p] != T[k//q]:
                print(-1)
                exit(0)
    print(L)
else:
    print(L)
Buggy python submission (verdict: Runtime Error):
import math

N, S = map(int,input().split())
x = list(map(int,input().split()))
x.append(S)
x = sorted(x)
t = x[1]-x[0]

for k in range(N-1):
    t = math.gcd(t,x[k+1]-x[k])

print(t)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

N, S = map(int,input().split())
x = list(map(int,input().split()))
x.append(S)
x = sorted(x)
t = x[1]-x[0]

for k in range(N):
    t = gcd(t,x[k+1]-x[k])

print(t)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
A = list(map(int, input().split()))
ans = 0

S = [0 for k in range(N)]
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
S = [0] + S

for k in range(N+1):
    for l in range(k+1,N+1):
        if (S[l]-S[k])%M == 0:
            ans += 1
print(ans)

Fixed submission:
from collections import Counter
N, M = map(int,input().split())
A = list(map(int, input().split()))
ans = 0

S = [0 for k in range(N)]
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
S = [0] + S
for k in range(N+1):
    S[k] %= M

C = Counter(S)
for a in C:
    if C[a] >= 2:
        ans += (C[a]*(C[a]-1))//2
print(ans)

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

S = [0 for k in range(N)]
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
S = [0] + S

for k in range(N+1):
    for l in range(k+1,N+1):
        if (S[l]-S[k])%M == 0:
            ans += 1
print(ans)

Fixed submission:
from collections import Counter
N, M = map(int,input().split())
A = list(map(int, input().split()))
ans = 0

S = [0 for k in range(N)]
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
S = [0] + S
for k in range(N+1):
    S[k] %= M

C = Counter(S)
for a in C:
    if C[a] >= 2:
        ans += (C[a]*(C[a]-1))//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = []
 
for k in range(N):
    B.append(A[k]-(k+1))

C = sorted(B)

if N%2==0:
    b = C[N//2]
else:
    b = (C[N//2]+C[1+N//2])//2

ans = 0
for k in B:
    ans += abs(k-b)

print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = []

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

for k in range(N):
    B.append(A[k]-(k+1))

C = sorted(B)
ans = 0
if N%2==1:
    b = C[N//2]
    for k in B:
        ans += abs(k-b)
else:
    b1 = (C[N//2]+C[-1+N//2])//2
    b2 = 1+(C[N//2]+C[-1+N//2])//2
    ans1 = 0
    ans2 = 0
    for k in B:
        ans1 += abs(k-b1)
        ans2 += abs(k-b2)
    ans = min(ans1,ans2)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
p = A.index(1)

if p+1<=K or N-p<=K:
    print(N//(K-1))
    exit(0)
if K%2==1:
    print(1+((p+1)-(K-1)//2)//(K-1) + (N-(p+(K-1)//2))//(K-1))
else:
    print(1+min(((p+1)-K//2-1)//(K-1) + (N-(p+K//2))//(K-1)),((p+1)-K//2)//(K-1) + (N-(p+K//2-1))//(K-1))

Fixed submission:
import math
N, K = map(int,input().split())
A = list(map(int,input().split()))

print(math.ceil((N-1)/(K-1)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(A)

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Z = Y.copy()
Z.sort()

A = [0 for k in range(N)]

for k in range(N):
    A[Z[k][1]] = (Z[:Y[k][1]]+Z[Y[k][1]+1:])[N//2-1][0]

for x in A:
    print(x)

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Z = sorted(Y)
A = [0 for k in range(N)]

for k in range(N):
    A[Z[k][1]] = (Z[:Y[k][1]]+Z[Y[k][1]+1:])[N//2-1][0]

for x in A:
    print(x)

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(x)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int, input().split()))

for k in range(N):
    print(sorted(X[:k]+X[k+1:])[N//2-1])

Fixed submission:
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(x)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(list(map(int,input().split())))
M = max(A)

t = 7+10*9
if M%2 == 0:
    m = M//2
    p = 0
    for k in range(N):
        if abs(m-A[k]) < t:
            t = abs(m-A[k])
            p = k
    print(M,A[p])
else:
    m = M//2
    l = 1 + M//2
    for k in range(N):
        if abs(m-A[k]) < t:
            t = abs(m-A[k])
            p = k
        elif abs(l-A[k]) < t:
            t = abs(l-A[k])
            p = k
    print(M,A[p])



Fixed submission:
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = p//2

while True:
    if q in A and p != q:
        print(p,q)
        exit(0)
    elif r in A:
        print(p,r)
        exit(0)
    else:
        q+=1
        r-=1

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = p//2
while True:
    if q in A and p != q:
        print(p,q)
        exit(0)
    elif r in A and p != r:
        print(p,r)
        exit(0)
    else:
        q+=1
        r-=1

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
B = list(map(int, input().split()))
A = []
s = 0
ans = 0

for i in range(N):
    A = B[:i]+B[i+1:]
    for j in range(N-1):
        ans += abs(s-A[j])
        s = A[j]
    ans += abs(A[N-2])
    print(ans)
    s = 0
    ans = 0
    A = []


Fixed submission:
N = int(input())
B = list(map(int, input().split()))
A = [0] + B + [0]
s = 0
t = 0

for i in range(1,N+2):
    t += abs(s-A[i])
    s = A[i]

for i in range(1,N+1):
    print(t + abs(A[i-1]-A[i+1]) - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
B = list(map(int, input().split()))
A = []
s = 0
ans = 0

for i in range(N):
    for j in range(N):
        if i != j:
            A.append(B[j])
    for j in range(N-1):
        ans += abs(s-A[j])
        s = A[j]
    ans += abs(A[N-2])
    print(ans)
    s = 0
    ans = 0
    A = []


Fixed submission:
N = int(input())
B = list(map(int, input().split()))
A = [0] + B + [0]
s = 0
t = 0

for i in range(1,N+2):
    t += abs(s-A[i])
    s = A[i]

for i in range(1,N+1):
    print(t + abs(A[i-1]-A[i+1]) - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
B = list(map(int, input().split()))
A = []
s = 0
ans = 0

for i in range(N):
    for j in range(N):
        if i != j:
            A.append(B[j])
    for j in range(N-1):
        ans += abs(s-A[j])
        s = A[j]
    ans += abs(A[N-2])
    print(ans)
    s = 0
    ans = 0
    A = []


Fixed submission:
N = int(input())
B = list(map(int, input().split()))
A = [0] + B + [0]
s = 0
t = 0

for i in range(1,N+2):
    t += abs(s-A[i])
    s = A[i]

for i in range(1,N+1):
    print(t + abs(A[i-1]-A[i+1]) - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1]))
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
x = [0]*(H*W+1)
y = [0]*(H*W+1)
for k in range(W):
    for l in range(H):
        x[A[l][k]] = k+1
        y[A[l][k]] = l+1

for _ in range(int(input())):
    L, R = map(int,input().split())
    ans = 0
    while L < R:
        ans += abs(x[L]-x[L+D])+abs(y[L]-y[L+D])
        L += D
    print(ans)


Fixed submission:
H, W, D = map(int,input().split())
px = [0 for k in range(H*W+D+1)]
py = [0 for k in range(H*W+D+1)]
S = [list(map(int,input().split())) for k in range(H)]

for j in range(W):
    for i in range(H):
        px[S[i][j]] = i
        py[S[i][j]] = j

d = [0 for k in range(H*W+D+1)]
for k in range(H*W,0,-1):
    d[k] = d[k+D] + abs(px[k]-px[k+D]) + abs(py[k]-py[k+D])

Q = int(input())
for k in range(Q):
    L, R = map(int,input().split())
    print(d[L]-d[R])

Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
x = [0]*(H*W+1)
y = [0]*(H*W+1)
for k in range(W):
    for l in range(H):
        x[A[l][k]] = k+1
        y[A[l][k]] = l+1

for _ in range(int(input())):
    L, R = map(int,input().split())
    ans = 0
    while L < R:
        ans += abs(x[L]-x[L+D])+abs(y[L]-y[L+D])
        L += D
    print(ans)


Fixed submission:
H, W, D = map(int,input().split())
px = [0 for k in range(H*W+D+1)]
py = [0 for k in range(H*W+D+1)]
S = [list(map(int,input().split())) for k in range(H)]

for j in range(W):
    for i in range(H):
        px[S[i][j]] = i
        py[S[i][j]] = j

d = [0 for k in range(H*W+D+1)]
for k in range(H*W,0,-1):
    d[k] = d[k+D] + abs(px[k]-px[k+D]) + abs(py[k]-py[k+D])

Q = int(input())
for k in range(Q):
    L, R = map(int,input().split())
    print(d[L]-d[R])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = set(A)

ans = 0
for k in B:
    if k < A.count(k):
        ans += A.count(k)-k
    elif k > A.count(k):
        ans += A.count(k)

print(ans)

Fixed submission:
# ABC082C
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = Counter(A)
ans = 0

for x in B:
    if x < C[x]:
        ans += C[x]-x
    elif x > C[x]:
        ans += C[x]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = set(A)

ans = 0
for k in B:
    if k < A.count(k):
        ans += A.count(k)-k
    elif k > A.count(k):
        ans += A.count(k)

print(ans)

Fixed submission:
# ABC082C
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = Counter(A)
ans = 0

for x in B:
    if x < C[x]:
        ans += C[x]-x
    elif x > C[x]:
        ans += C[x]

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
x, y = map(int, input().split())

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

d = [[a[0],0]]
for k in range(1,len(a)):
    n = []
    if k%2 == 1:
        for e in d:
            n.append([e[0],e[1]+a[k]])
            n.append([e[0],e[1]-a[k]])
    else:
        for e in d:
            n.append([e[0]+a[k],e[1]])
            n.append([e[0]-a[k],e[1]])
    d = list(set(n))

print("Yes" if [x,y] in d else "No")


Fixed submission:
S = input()
x, y = map(int, input().split())

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

X = [a[0]]
Y = [0]

for k in range(1,len(a)):
    if k%2 == 0:
        nx = []
        for e in X:
            nx.append(e+a[k])
            nx.append(e-a[k])
        X = list(set(nx))
    else:
        ny = []
        for e in Y:
            ny.append(e+a[k])
            ny.append(e-a[k])
        Y = list(set(ny))

print("Yes" if x in X and y in Y else "No")

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
x, y = map(int, input().split())

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

d = [[a[0],0]]
for k in range(1,len(a)):
    n = []
    if k%2 == 1:
        for e in d:
            n.append([e[0],e[1]+a[k]])
            n.append([e[0],e[1]-a[k]])
    else:
        for e in d:
            n.append([e[0]+a[k],e[1]])
            n.append([e[0]-a[k],e[1]])
    d = n

print("Yes" if [x,y] in d else "No")

Fixed submission:
S = input()
x, y = map(int, input().split())

a = []
t = 0
for s in S:
    if s == "F":
        t += 1
    else:
        a.append(t)
        t = 0
a.append(t)

if a == []:
    if x == y == 0:
        print("Yes")
        exit(0)
    else:
        print("No")
        exit(0)

X = [a[0]]
Y = [0]

for k in range(1,len(a)):
    if k%2 == 0:
        nx = []
        for e in X:
            nx.append(e+a[k])
            nx.append(e-a[k])
        X = list(set(nx))
    else:
        ny = []
        for e in Y:
            ny.append(e+a[k])
            ny.append(e-a[k])
        Y = list(set(ny))

print("Yes" if x in X and y in Y else "No")