Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from itertools import accumulate
N=int(input())
A=[int(i) for i in input().split()]
GCD=[]
if len(A)==2:
    print(max(A))
else:
    for i in range(N):
        B=A.copy()
        B.remove(B[i])
        C=list(accumulate(B,gcd))
        GCD.append(C[-1])
    print(max(GCD))

Fixed submission:
try:
    from fractions import gcd
except:
    from math import gcd
from itertools import accumulate
N=int(input())
A=[int(i) for i in input().split()]
l=[0]+list(accumulate(A,gcd))
g=list(reversed(list(accumulate(reversed(A),gcd))))+[0]

print(max([gcd(l[i-1],g[i]) for i in range(1,N+1)]))

Buggy python submission (verdict: Runtime Error):
from math import gcd
from itertools import accumulate
N=int(input())
A=[int(i) for i in input().split()]
GCD=[]
if len(A)==2:
    print(max(A))
else:
    for i in range(N):
        B=A.copy()
        B.remove(B[i])
        C=list(accumulate(B,gcd))
        GCD.append(C[-1])
    print(max(GCD))

Fixed submission:
try:
    from fractions import gcd
except:
    from math import gcd
from itertools import accumulate
N=int(input())
A=[int(i) for i in input().split()]
l=[0]+list(accumulate(A,gcd))
g=list(reversed(list(accumulate(reversed(A),gcd))))+[0]

print(max([gcd(l[i-1],g[i]) for i in range(1,N+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x,y):
    while y!=0:
        x,y=y,x%y
    else:
        return x

N=int(input())
A=[int(i) for i in input().split()]
GCD=[]
if len(A)==2:
    print(max(A))
else:
    for i in range(N):
        B=A.copy()
        B.remove(B[i])
    
        a=gcd(B[0],B[1])
        for k in range(N-3):
            a=gcd(a,B[k+2])
        GCD.append(a)
    print(max(GCD))

Fixed submission:
try:
    from fractions import gcd
except:
    from math import gcd
from itertools import accumulate
N=int(input())
A=[int(i) for i in input().split()]
l=[0]+list(accumulate(A,gcd))
g=list(reversed(list(accumulate(reversed(A),gcd))))+[0]

print(max([gcd(l[i-1],g[i]) for i in range(1,N+1)]))
Buggy python submission (verdict: Runtime Error):
N=int(input())
H=[int(i) for i in input().split()]
hotel=0
for i in range(N):
    count=0
    for k in range(i):
        if H[k]<=H[i]:
            count+=1
        continue
            
    if count==i:5
        hotel+=1


print(hotel)

Fixed submission:
N=int(input())
H=[int(i) for i in input().split()]
hotel=0
for i in range(N):
    count=0
    for k in range(i):
        if H[k]<=H[i]:
            count+=1
        continue
            
    if count==i:
        hotel+=1


print(hotel)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(k) for k in input().split()]
C=[int(h) for h in input().split()]
A.sort()
B.sort()
C.sort()
deli=[]

for i in A:
    for j in B:
        for k in C:
            deli.append(i+j+k)
deli.sort(reverse=True)
for i in range(min(K,X*Y*Z)):
    print(deli[i])

Fixed submission:
X,Y,Z,K=map(int,input().split())
A=sorted([int(i) for i in input().split()],reverse=True)
B=sorted([int(i) for i in input().split()],reverse=True)
C=sorted([int(i) for i in input().split()],reverse=True)
bi_deli=[]
for i in range(min(X,K)):
    for j in range(min(Y,K)):
        if (i+1)*(j+1)>K:
            break
        bi_deli.append(A[i]+B[j])
bi_deli.sort(reverse=True)
tri_deli=[]
for k in range(min(len(bi_deli),K)):
    for l in range(min(Z,K)):
        if (k+1)*(l+1)>K:
            break
        tri_deli.append(bi_deli[k]+C[l])
tri_deli.sort(reverse=True)

print(*tri_deli[:K],sep='\n')
Buggy python submission (verdict: Runtime Error):
S=input()
C=[]
count=0
for i in S:
    if i in {'A','C','G','T'}:
        count += 1
        continue
    elif i not in {'A','C','G','T'}:
        C.append(count)
        count=0
        continue
    
print(max(C))

Fixed submission:
S=list(input())
Count=[]
for i in range(len(S)):
    if S[i] in ['A','C','T','G']:
        Count.append(1)
    else:
        Count.append(0)
c=0
m=[]
for i in range(len(S)):
    if Count[i]==1:
        c+=1
        m.append(c)
        continue
    else:
        c*=0
        m.append(c)
        continue


print(max(m))
Buggy python submission (verdict: Runtime Error):
import sys
import math


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    a = A[0]
    B = set()
    for i in range(1, N):
        g = math.gcd(A[i], a)
        if g == 1:
            B.add(1)
        elif g == a:
            continue
        else:
            B.add(g)
    if len(B) == 0:
        print(a)
    else:
        print(min(B))


if __name__ == "__main__":
    main()


Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
while len(a)>1:
    c=[]
    d=min(a)
    for i in range(len(a)):
        if a[i]!=d:
            div=a[i]%d
            if div!=0:
                c.append(div)
    c.append(d)        
    a=c
print(a[0])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
x=sorted([int(i) for i in input().split()])
if n>=m:
    print(0)
else:
    r=[]
    for i in range(m-1):
        r.append(x[i+1]-x[i])
    for i in range(n-1):
        r.remove(max(r))
    print(sum(r))


Fixed submission:
n,m=map(int,input().split())
x=sorted([int(i) for i in input().split()])
if n>=m:
    print(0)
else:
    r=[]
    for i in range(m-1):
        r.append(x[i+1]-x[i])
    r.sort()
    if n!=1:
        print(sum(r[:-n+1]))
    else:
        print(sum(r))
Buggy python submission (verdict: Time Limit Exceeded):
S=int(input())
count=1
while S!=8:
    if S%2==0:
        S//=2
        count+=1
    else:
        S=S*3+1
        count+=1
else:
    print(count+4)

Fixed submission:
S=int(input())
count=1
for i in range(1000000):
    if S==8:
        print(count+4)
        break
    elif S==4:
        print(count+3)
        break
    elif S==2:
        print(count+3)
        break
    elif S==1:
        print(count+3)
        break
    elif S%2==0:
        S//=2
        count+=1
    else:
        S=S*3+1
        count+=1

Buggy python submission (verdict: Time Limit Exceeded):
S=int(input())
a=[S]

while a[-1]!=8:
    if a[-1]%2==0:
        a.append(a[-1]//2)
    else:
        a.append(a[-1]*3+1)

else:
    print(len(a)+4)
    

Fixed submission:
S=int(input())
count=1
for i in range(1000000):
    if S==8:
        print(count+4)
        break
    elif S==4:
        print(count+3)
        break
    elif S==2:
        print(count+3)
        break
    elif S==1:
        print(count+3)
        break
    elif S%2==0:
        S//=2
        count+=1
    else:
        S=S*3+1
        count+=1
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N, K = map(int, input().split())
    H = [0] + list(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF for _ in range(N + 1)]
    dp[1] = 0
    for i in range(1, N):
        for k in range(1, K + 1):
            if i + k <= N:
                tmp = dp[i] + abs(H[i + k] - H[i])
                if dp[i + k] > tmp:
                    dp[i + k] = tmp

    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N, K = map(int, input().split())
    H = [0] + list(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF for _ in range(N + 1)]
    dp[1] = 0
    for i in range(1, N):
        for k in range(1, K + 1):
            if i + k <= N:
                tmp = dp[i] + abs(H[i + k] - H[i])
                if dp[i + k] > tmp:
                    dp[i + k] = tmp

    print(dp[-1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
N=[[] for i in range(n)]
P=[]
Y=[]
for i in range(m):
    p,y=map(int,input().split())
    P.append(p)
    Y.append(y)
    N[p-1].append(y)
for i in N:
    i.sort()
for k in range(m):
    a='{0:06d}'.format(P[k])
    b='{0:06d}'.format(N[P[k]-1].index(Y[k])+1)
    print(a+b)

Fixed submission:
n,m=map(int,input().split())
city=list(list(map(int,input().split()))+[i] for i in range(m))
city.sort(key=lambda x:x[1])
city.sort(key=lambda x:x[0])
for j,l in enumerate(city):
    if j!=0 and city[j-1][0]==city[j][0]:
        city[j].append(city[j-1][3]+1)
    elif j!=0 and city[j-1][0]!=city[j][0]:
        city[j].append(1)
    else:
        city[j].append(1)
city.sort(key=lambda x:x[2])
for k in range(m):
    print('{0:06d}{1:06d}'.format(city[k][0],city[k][3]))
Buggy python submission (verdict: Time Limit Exceeded):
n,x=map(int,input().split())
a=list(map(int,input().split()))
happy=[]
for i in range(2**n):
    cnt=0
    ans=0
    for j in range(n):
        if ((i>>j)&1):
            cnt+=a[j]
            ans+=1
    if cnt==x:
        happy.append(ans)
    elif cnt<x:
        if 1<=ans:
            happy.append(ans-1)
        else:
            happy.append(0)
print(max(happy))

Fixed submission:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
cnt=0
ans=0
for i in range(n):
    cnt+=a[i]
    ans+=1
    if x<=cnt:
        break
if x==cnt:
    print(ans)
else:
    print(ans-1)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
X=[int(i) for i in input().split()]+[0]
X.sort()
sn=X.index(0)
road=[]
for j in range(sn):
    if X[j+k]>0:
        road.append(abs(X[j]-0)+abs(X[j+k]-X[j]))
    else:
        road.append(abs(X[j]-0)+abs(X[j+k-1]-X[j]))

for j in range(sn+1,n-k+1):
    road.append(abs(X[j]-0)+abs(X[j+k-1]-X[j]))

if len(road)>0:
    print(min(road))
else:
    print(0)

Fixed submission:
n,k=map(int,input().split())
X=[int(i) for i in input().split()]
road=[]
for i in range(n-k+1):
    if X[i]<=0 and X[i+k-1]>=0:
        r=min(abs(X[i]),X[i+k-1])+X[i+k-1]-X[i]
    elif X[i]<=0 and X[i+k-1]<=0:
        r=abs(X[i])
    else:
        r=X[i+k-1]
    road.append(r)

print(min(road))

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
X=[int(i) for i in input().split()]+[0]
X.sort()
sn=X.index(0)
print(X)
road=[]
for j in range(sn):
    if X[j+k]>0:
        road.append(abs(X[j]-0)+abs(X[j+k]-X[j]))
    else:
        road.append(abs(X[j]-0)+abs(X[j+k-1]-X[j]))

for j in range(sn+1,n-k+1):
    road.append(abs(X[j]-0)+abs(X[j+k-1]-X[j]))

if len(road)>0:
    print(min(road))
else:
    print(0)

Fixed submission:
n,k=map(int,input().split())
X=[int(i) for i in input().split()]
road=[]
for i in range(n-k+1):
    if X[i]<=0 and X[i+k-1]>=0:
        r=min(abs(X[i]),X[i+k-1])+X[i+k-1]-X[i]
    elif X[i]<=0 and X[i+k-1]<=0:
        r=abs(X[i])
    else:
        r=X[i+k-1]
    road.append(r)

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


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    if N < 105:
        print(0)
        return

    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

    cnt = 1
    for n in range(106, N + 1):
        d = make_divisors(n)
        if len(d) == 8:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Fixed submission:

N=int(input())
if N<105:
  print(0)
elif 105<=N<135:
  print(1)
elif 135<=N<165:
  print(2)
elif 165<=N<189:
  print(3)
elif 189<=N<195:
  print(4)
else:
  print(5)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from math import gcd
def lcm_(x,y):
    return x*y//gcd(x,y)
def lcm(numbers):
    return list(accumulate(numbers,lcm_))
n=int(input())
A=[int(i) for i in input().split()]
L=lcm(A)[-1]-1
f=0
for i in A:
    f+=L%i

print(f)

Fixed submission:
from itertools import accumulate
from fractions import gcd
def lcm_(x,y):
    return x*y//gcd(x,y)
def lcm(numbers):
    return list(accumulate(numbers,lcm_))
n=int(input())
A=[int(i) for i in input().split()]
L=lcm(A)[-1]-1
f=0
for i in A:
    f+=L%i

print(f)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
A=[int(i) for i in input().split()]
for i in range(n):
    A[i]-=i+1
ans=[]
for j in range(min(A),max(A)+1):
    B=A
    for i in range(n):
        B[i]-=j
        B[i]=abs(B[i])
    ans.append(sum(B))
print(min(ans))

Fixed submission:
n=int(input())
A=[int(i) for i in input().split()]
for i in range(n):
    A[i]-=i+1
A.sort()
if n%2==0:
    B=A.copy()
    C=A.copy()
    for i in range(n):
        s=A[n//2]
        B[i]=abs(B[i]-s)
    a=sum(B)
    for i in range(n):
        t=A[n//2-1]
        C[i]=abs(C[i]-t)
    b=sum(C)

    print(min(a,b))
else:
    B=A.copy()
    for i in range(n):
        B[i]=abs(B[i]-A[n//2])
    print(sum(B))
Buggy python submission (verdict: Runtime Error):
import math
n.k=map(int,input().split())
A=[int(i) for i in input().split()]
print(math.ceil(n/k))


Fixed submission:
import math
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
print(1+math.ceil((n-k)/(k-1)))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=list(input())
w=n-S.count('W')
p=[]
for i in range(n):
    s=w-i+2*S[:i].count('W')
    p.append(s)

print(min(p))


Fixed submission:
n=int(input())
S=list(input())
R=[0]
for i in range(n):
    R.append(R[i]+(S[i]=='W'))
print(min([R[i]+n-i-1-(R[-1]-R[i+1]) for i in range(n)] ))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=list(input())
p=[]
for i in range(n):
    s=S[:i].count('W')+S[i+1:].count('E')
    p.append(s)

print(min(p))


Fixed submission:
n=int(input())
S=list(input())
R=[0]
for i in range(n):
    R.append(R[i]+(S[i]=='W'))
print(min([R[i]+n-i-1-(R[-1]-R[i+1]) for i in range(n)] ))
Buggy python submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    if A[0] != 0:
        print(-1)
        return
    answer = 0
    for i in range(N - 1):
        if A[i + 1] - A[i] > 1:
            print(-1)
            return
        elif A[i + 1] == A[i]:
            answer += A[i]
        elif A[i + 1] == A[i] + 1:
            flag = A[i + 1]
        else:
            answer += flag
            flag = 0
    answer += flag
    print(answer)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    if A[0] != 0:
        print(-1)
        return
    answer = 0
    flag = 0
    for i in range(N - 1):
        if A[i + 1] - A[i] > 1:
            print(-1)
            return
        elif A[i + 1] == A[i]:
            answer += A[i]
        elif A[i + 1] == A[i] + 1:
            flag = A[i + 1]
        else:
            answer += flag
            flag = A[i + 1]
    answer += flag
    print(answer)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
if abs(c-a)<=d:
  print('Yes')
elif abc(b-a)<=d and abs(c-b)<=d:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c,d=map(int,input().split())
if abs(c-a)<=d:
  print('Yes')
elif abs(b-a)<=d and abs(c-b)<=d:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
s=[0]
for i in range(n):
    s.append(s[-1]+A[i])
cnt=[]
S=set(s)
for i in S:
    cnt.append(s.count(i))
ans=0
for i in cnt:
    if 1<i:
        ans+=i*(i-1)//2
print(ans)


Fixed submission:
n=int(input())
A=list(map(int,input().split()))
s=[0]
for i in range(n):
    s.append(s[-1]+A[i])
s.sort()
ans=0
cnt=1
for i in range(1,n+1):
    if s[i-1]==s[i]:
        cnt+=1
    else:
        if 2<=cnt:
            ans+=(cnt*(cnt-1))//2
            cnt=1
        else:
            cnt=1
if 2<=cnt:
    ans+=(cnt*(cnt-1))//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
s=[0]
for i in range(n):
    s.append(s[-1]+A[i])
cnt=0
for i in range(n):
    for j in range(i+1,n+1):
        if s[i]==s[j]:
            cnt+=1
print(cnt)


Fixed submission:
n=int(input())
A=list(map(int,input().split()))
s=[0]
for i in range(n):
    s.append(s[-1]+A[i])
s.sort()
ans=0
cnt=1
for i in range(1,n+1):
    if s[i-1]==s[i]:
        cnt+=1
    else:
        if 2<=cnt:
            ans+=(cnt*(cnt-1))//2
            cnt=1
        else:
            cnt=1
if 2<=cnt:
    ans+=(cnt*(cnt-1))//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from functools import reduce


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)

MOD = 10 ** 9 + 7


def main():
    def cmb(N, A):
        num = reduce(lambda x, y: x * y % MOD, range(N, N - A, -1))
        den = reduce(lambda x, y: x * y % MOD, range(1, A + 1))
        # pow(den,MOD-2,MOD)はdenの逆元
        return num * pow(den, MOD - 2, MOD) % MOD

    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    C = 0
    ans = -1
    for a in A:
        if a == 0:
            c = 1
        else:
            c = cmb(n, a)
        if c > C:
            C = c
            ans = a
        elif c < ans:
            break

    print(n, ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    _ = int(input())
    A = list(map(int, input().split()))
    A.sort()
    n = A[-1]
    ans = -1
    for a in A:
        if a + 1 <= n / 2:
            ans = a
        else:
            b = n - a
            if b > ans:
                ans = a

    print(n, ans)


if __name__ == "__main__":
    main()
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:
        print(i)
    elif i>=B-K+1:
        print(i)
    else:
        continue



Fixed submission:
A,B,K=map(int,input().split())
l=[int(i) for i in range(A,min(B+1,A+K))]
s=[int(i) for i in range(max(B-K+1,A+K-1),B+1)]
l=l+s
L=list(set(l))
L.sort()
for i in L:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int,input().split())
X=range(A,B+1)
i=0
while i<=len(X)-1:
    if i<=K-1 or i>=len(X)-K:
        print(X[i])
        i+=1
    else:
        i+=1


Fixed submission:
A,B,K=map(int,input().split())
l=[int(i) for i in range(A,min(B+1,A+K))]
s=[int(i) for i in range(max(B-K+1,A+K-1),B+1)]
l=l+s
L=list(set(l))
L.sort()
for i in L:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[0]+[int(i) for i in input().split()]+[0]
cost=[abs(a[i+1]-a[i]) for i in range(n+1)]
#print(cost)
for i in range(n):
    Cost=cost[:i]+cost[i+2:]+[abs(a[i+2]-a[i])]
    #print(Cost)
    print(sum(Cost))



Fixed submission:
n=int(input())
a=[0]+[int(i) for i in input().split()]+[0]
cost=[abs(a[i+1]-a[i]) for i in range(n+1)]
C=sum(cost)
#print(cost)
for i in range(1,n+1):
    Co=C-(abs(a[i+1]-a[i]))-abs((a[i]-a[i-1]))+abs(a[i+1]-a[i-1])
    print(Co)
Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
count=0
for i in range(len(s)):
    if s[i]==t[i]:
        count=1
        continue
    elif s[i]<t[i]:
        count=2
        break
    else:
        count=0
        break
if count==1:
    if len(s)<len(t):
        print('Yes')
    else:
        print('No')
elif count==2:
    print('Yes')
else:
    print('No')


Fixed submission:
s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)

for i in range(min(len(s),len(t))):
    if s[i]==t[i]:
        count=1
        continue
    elif s[i]<t[i]:
        count=2
        break
    else:
        count=0
        break
if count==1:
    if len(s)<len(t):
        print('Yes')
    else:
        print('No')
elif count==2:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
count=0
for i in range(len(s)):
    if s[i]==t[i]:
        count+=1
        continue
    elif s[i]<t[i]:
        print('Yes')
        count=0
        break
    else:
        print('No')
        count=0
        break
if count!=0 and len(s)<len(t):
    print('Yes')
elif count!=0 and len(s)>=len(t):
    print('No')


Fixed submission:
s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)

for i in range(min(len(s),len(t))):
    if s[i]==t[i]:
        count=1
        continue
    elif s[i]<t[i]:
        count=2
        break
    else:
        count=0
        break
if count==1:
    if len(s)<len(t):
        print('Yes')
    else:
        print('No')
elif count==2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
A=[int(i) for i in input().split()]
list_a=copy.deepcopy(A)
set_A=set(list_a)
ans=0
for i in set_A:
    a=A.count(i)
    if a<i:
        ans+=a
    elif i<a:
        ans+=a-i

print(ans)

Fixed submission:
from collections import Counter
n=int(input())
A=Counter([int(i) for i in input().split()])
#print(A)
ans=0
for i in A.items():
#    print(i)
    k=i[0]
    l=i[1]
    if k<l:
        ans+=l-k
    elif l<k:
        ans+=l

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n=int(input())
A=sorted([int(i) for i in input().split()])
list_a=copy.deepcopy(A)
set_A=set(list_a)
ans=0
for i in set_A:
    a=A.count(i)
    if a<i:
        ans+=a
    elif i<a:
        ans+=a-i

print(ans)


Fixed submission:
from collections import Counter
n=int(input())
A=Counter([int(i) for i in input().split()])
#print(A)
ans=0
for i in A.items():
#    print(i)
    k=i[0]
    l=i[1]
    if k<l:
        ans+=l-k
    elif l<k:
        ans+=l

print(ans)