Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

if (A==1 and B!=1):
    print("Alice")
    exit()
 elif(B==1 and A!=1):
     print("Bob")   
   




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")
     


Fixed submission:
A,B = map(int,input().split())

if (A==1 and B!=1):
    print("Alice")
    exit()
elif(B==1 and A!=1):
    print("Bob")   
    exit()




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")

Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

if (A==1 and B!=1):
    print("Alice")
    exit()
 elif(B==1 and A!=1):
     print("Bob")   
   




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")
     


Fixed submission:
A,B = map(int,input().split())

if (A==1 and B!=1):
    print("Alice")
    exit()
elif(B==1 and A!=1):
    print("Bob")   
    exit()




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")

Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

if (A=1 and B!=1):
    print("Alice")
    
   




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")
     


Fixed submission:
A,B = map(int,input().split())

if (A==1 and B!=1):
    print("Alice")
    exit()
elif(B==1 and A!=1):
    print("Bob")   
    exit()




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")
Buggy python submission (verdict: Runtime Error):
A B C D = input()

if A*B>C*D:
    print(A*B)
elif C*D>A*B:
    print(C*D)
elif A*B==C*D:
    print(A*B)

Fixed submission:
A,B,C,D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)

if A*B>C*D:
    print(A*B)
elif C*D>A*B:
    print(C*D)
elif A*B==C*D:
    print(A*B)
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int>h(N);
  vector<int>dp(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
    dp.at(i) = 0;
  }
  dp.at(1) = abs(h.at(1) - h.at(0));
  for (int i = 2; i < N; i++) {
    dp.at(i) = min(dp.at(i-1) + abs(h.at(i-1) - h.at(i)), dp.at(i-2) + abs(h.at(i-2) - h.at(i)));
  }
  cout << dp.at(N-1);
}

Fixed submission:
N = int(input())
h = list(input().split())
for i in range(len(h)):
  h[i] = int(h[i])
dp = [0 for i in range(N)]
dp[1] = abs(h[0] - h[1])
for i in range(2,N):
  dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - 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 = [1000000000 for i in range(N)]
dp[0] = 0
for i in range(1, N):
  for j in range(1, K+1):
    if i >= j:
      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 = list(map(int,input().split()))
dp = [1000000000 for i in range(N)]
dp[0] = 0
for i in range(1, N):
  for j in range(1, K+1):
    if i >= j:
      dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
R =input()
if R<1200:
  print('ABC')
elif R<2800:
  print('ARC')
else:
  print('AGC')

Fixed submission:
R =int(input())
if R<1200:
  print('ABC')
elif R<2800:
  print('ARC')
else:
  print('AGC')
Buggy python submission (verdict: Runtime Error):
S = input()

red = 0  # 0
blue = 0 # 1
m = 0
for s in S:
	if s = '0':
		if blue != 0:
			blue -= 1
			m += 2
		else:
			red += 1
	elif s = '1':
		if red != 0:
			red -= 1
			m += 2
		else:
			blue += 1

print(m)

Fixed submission:
S = input()

red = 0  # 0
blue = 0 # 1
m = 0
for s in S:
	if s == '0':
		if blue != 0:
			blue -= 1
			m += 2
		else:
			red += 1
	elif s == '1':
		if red != 0:
			red -= 1
			m += 2
		else:
			blue += 1

print(m)

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

m = 0
while True:
	a = 0
	
	a += S.count('10')
	S = S.replace('10', '')

	a += S.count('01')
	S = S.replace('01', '')

	if a!=0:
		m += a
	else:
		break

print(2*m)


Fixed submission:
S = input()

red = 0  # 0
blue = 0 # 1
m = 0
for s in S:
	if s == '0':
		if blue != 0:
			blue -= 1
			m += 2
		else:
			red += 1
	elif s == '1':
		if red != 0:
			red -= 1
			m += 2
		else:
			blue += 1

print(m)
Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
S = list(map(int, input().split('/')))
X = [2019, 4, 30]

print('Heisei') if all([S[i] <= X[i] for i in range(3)]) else print('TBD')
Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
T, X = map(int, input().split())
print(T/X)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

k = [(K+1)&(1<<i) for i in range(40)]

c = [0]*40
for a in A:
	for i in range(40):
		if a&(1<<i):
			c[i] += 1

m = [0]*40
for i in range(40):
	if 2*c[i]<N:
		m[i] = (1<<i)*(N-c[i])
	else:
		m[i] = (1<<i)*c[i]

x = sum(A)
for i in reversed(range(40)):
	if k[i] != 0:
		x = max(x, sum(m[:i]+[(1<<i)*(N-c[i])]+k[i+1:]))

print(x)

Fixed submission:
T, X = map(int, input().split())
print(T/X)
Buggy python submission (verdict: Runtime Error):
./ABC/117/abc117B.py

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

x = max(L)
L.remove(x)
if x < sum(L):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
X = list(map(int, input().split()))

Y = sorted(X)
Y = list(map(lambda x,y:x-y, Y[1:],Y[:-1]))

for i in range(N-1):
	if Y != []:
		x = max(Y)
		Y.remove(x)
	else:
		break

print(sum(Y))


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

X.sort()
diffX = list(map(lambda x,y:x-y, X[1:], X[:-1]))
diffX.sort(reverse = True)

if N-1 >= len(diffX):
	print(0)
else:
	print(sum(diffX[N-1:]))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = list(map(int, input().split()))

Y = sorted(X)
Y = list(map(lambda x,y:x-y, Y[1:],Y[:-1]))

for i in range(N-1):
	x = max(Y)
	Y.remove(x)

print(sum(Y))


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

X.sort()
diffX = list(map(lambda x,y:x-y, X[1:], X[:-1]))
diffX.sort(reverse = True)

if N-1 >= len(diffX):
	print(0)
else:
	print(sum(diffX[N-1:]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

# ビットで使う使わないパターン表を作る
# Nが桁数、2のN乗がパターン数
max = 0
for i in range(0, 2 ** N):
    ptn = '0' + str(N) + 'b'
    bin_i = list(format(i, ptn))
    work = 0
    for j in range(0, N):
        if bin_i[j] == '1':
            work += V[j] - C[j]
    if max < work:
        max = work

print(max)

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

Rec = []
Chk = []

# (V-C)＋(V-C)..の結果を１つずつ見て一番高いものを記録
# 宝石ループ
work = None
for i in range(0, N):
    for j in range(0, N):
        if not(j in Chk) and (work == None or work < V[j] - C[j]):
            work = V[j] - C[j]
            work2 = j
    Chk.append(work2)
    if len(Rec) > 0:
        Rec.append(Rec[i - 1] + work)
    else:
        Rec.append(work)
    work = None

if max(Rec) > 0:
    print(max(Rec))
else:
    print('0')
Buggy python submission (verdict: Runtime Error):
# C - Stones

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

#print(list(S))
cnt = 0


# stones[i] == "#" のときに stones[i+1] == "." なら stones[i+1] = "#"にしてcnt ++する
def BlackToWhite(stones, len, i):
    global cnt
    if stones[0:i + 1]:
        if stones[i] == "#" and stones[i + 1] == ".":
            cnt += 1
            stones[i + 1] = "#"

        i += 1
        if i >= len - 1:
            print(cnt)
            exit()
        else:
            BlackToWhite(stones, len, i)
    else:
        print(cnt)
        exit()


BlackToWhite(list(S), N, 0)



Fixed submission:
N = int(input())
S = input()
ac = [0]

# 黒の累積和テーブルを作る
for i in range(N):
    if S[i] == "#":
        ac.append(ac[i] + 1)
    else:
        ac.append(ac[i])

#print(ac)

work_min = N
for j in range(0, N + 1):
    work_sum = ac[j] + (N - j - (ac[N] - ac[j]))
    if work_min > work_sum:
        work_min = work_sum

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

work = S
unfinished = True
cnt = 0
lenlog = 0

while unfinished:
    work = work.replace('01', '').replace('10', '')
    cnt = len(S) - len(work)

    if lenlog == len(work):
        unfinished = False
        print(cnt)
        quit()

    lenlog = len(work)

Fixed submission:
bin_str = str(input())  # 入力されたビット列そのまま文字列
bitdigits = len(bin_str)  # 桁数

cntzero = bin_str.count("0")
cntone = bin_str.count("1")

if cntzero < cntone:
    print(cntzero * 2)
else:
    print(cntone * 2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
monsters = list(map(int, input().split()))

monsters.sort(reverse=True)
#print(monsters)
ans = min(monsters)

while ans > 0:
    maxnum = max(monsters)
    minnum = min(monsters)
    maxidx = monsters.index(maxnum)

    if maxnum % minnum == 0:
        del monsters[maxidx]
        if len(monsters) == 1:
            print(monsters[0])
            quit()
    else:
        ans = maxnum % minnum
        monsters[maxidx] = ans


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

monsters.sort()  # 昇順
minnum = monsters[0]

cnt = len(monsters)
minidx = 0
while cnt > 1:
    for i in range(cnt - 1, 0, -1):
        monsters[i] = monsters[i] % monsters[0]

        if monsters[i] == 0:
            del monsters[i]

        elif monsters[i] == 1:
            print('1')
            quit()

    workmin = min(monsters)
    minidx = monsters.index(min(monsters))
    monsters[minidx] = monsters[0]
    monsters[0] = workmin

    cnt = len(monsters)

print(monsters[0])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split(' '))
H_list = list(map(int, input().split(' ')))

H_list.sort(reverse = True)

for i in range(K):
  del H_list[i]

print(sum(H_list))


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

H_list.sort(reverse = True)

del H_list[0:K]

print(sum(H_list))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[str(sorted(input())) for i in range(N)]
ans=0
for i in set(s):
    c=0
    for j in s:
        if i ==j:c+=1
    ans+=c*(c-1)//2
print(ans)

Fixed submission:
N=int(input())
s=sorted([str(sorted(input())) for i in range(N)])+[""]
ans=c=0
j=s[0]
for i in s[1:]:
    if i==j:
        c+=1
    else:
        j=i
        ans+=c*(c+1)//2
        c=0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
p,q=0,1
for i in range(1,n+1):
    p,q=q,(p+q)*(not i in a)
print(q%(10**9+7))


Fixed submission:
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
p,q=0,1
for i in range(1,n+1):
    p,q=q,(p+q)*(not i in a)
print(q%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
p,q=0,1
for i in range(1,n+1):
    p,q=q,(p+q)%(10**9+7)*(not i in a)
print(q)


Fixed submission:
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
p,q=0,1
for i in range(1,n+1):
    p,q=q,(p+q)*(not i in a)
print(q%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
a=input()
c=[0]*len(a)
for i in range(len(a)-1):
    if (a[i]+a[i+1])=="AC":c[i]=1
for i in range(b):
    d,e=map(int,input().split())
    print(c[d-1:e-1].count(1))

Fixed submission:
a,b=map(int,input().split())
a=input()
c=[0]*len(a)
for i in range(len(a)-1):
    if (a[i]+a[i+1])=="AC":c[i+1]=c[i]+1
    else:c[i+1]=c[i]
for i in range(b):
    d,e=map(int,input().split())
    print(c[e-1]-c[d-1])

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
a=input()
e=""
for i in range(b):
    c,d=map(int, input().split())
    e=e+str(a[c-1:d].count("AC"))+"\n"
print(e)

Fixed submission:
a,b=map(int,input().split())
a=input()
c=[0]*len(a)
for i in range(len(a)-1):
    if (a[i]+a[i+1])=="AC":c[i+1]=c[i]+1
    else:c[i+1]=c[i]
for i in range(b):
    d,e=map(int,input().split())
    print(c[e-1]-c[d-1])

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
a=input()
e=[]
for i in range(b):
    c,d=map(int, input().split())
    e.append(a[c-1:d].count("AC"))
for i in range(b):
    print(e[i])

Fixed submission:
a,b=map(int,input().split())
a=input()
c=[0]*len(a)
for i in range(len(a)-1):
    if (a[i]+a[i+1])=="AC":c[i+1]=c[i]+1
    else:c[i+1]=c[i]
for i in range(b):
    d,e=map(int,input().split())
    print(c[e-1]-c[d-1])
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
e=[]
for i in range(a):
    c,d=map(int, input().split())
    e+=[c]*d
e.sort()
print(sum(e[:b]))

Fixed submission:
a,b=map(int,input().split())
e=[]
for i in range(a):
    c,d=map(int, input().split())
    e+=[[c,d]]
e.sort()
a=i=j=0
while i < b:
    a+=(e[j][0]*e[j][1])
    i+=e[j][1]
    j+=1
print(a-((i-b)*e[j-1][0]))
Buggy python submission (verdict: Runtime Error):
x1,y1,x2,y2=map(int,input().split())
print(x2-y2+y1,y2+x2-x1,y2-y1+x1,x2-x1+y1)

Fixed submission:
a=int(input())
print(int(a/2)*int((a+1)/2))
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=[3,5,7,11,13,17,19]
c=d=0
if a<105:a=104
for i in range(103,a):
    for j in b:
        if a%j==0:c+=1
    if c==3:d+=1
    c=0
print(d)

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=[3,5,7,9,11,13,15,17,19]
c=d=0
if a<105:a=105
for i in range(104,a):
    for j in b:
        if a%j==0:c+=1
    if c==3:d+=1
    c=0
print(d)

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
n=-int(input())
a=""
while n:
    a+=str(n%2)
    n//=-2
print(a[::-1] if a else 0)

Fixed submission:
a,b=map(int,input().split())
print("0"if a%b == 0 else "1")
Buggy python submission (verdict: Runtime Error):
a=int(input())
print(["ABC","ARC","AGC"][int(a/2800)+int(a/1200)])

Fixed submission:
a=int(input())
print(["AGC","ARC","ABC"][(a < 2800) + (a < 1200)])
Buggy python submission (verdict: Runtime Error):
N=int(input())
def cou(n,x):
    i=0
    while(n>0):
        i+=n%x
        n//=x
    return i
ans=N
for i in range(N+1):
    ans=min(ans,cou(j,6)+cou(N-j,9))
print(ans)

Fixed submission:
N=int(input())
def cou(n,x):
    i=0
    while(n>0):
        i+=n%x
        n//=x
    return i
ans=N
for j in range(N+1):
    ans=min(ans,cou(j,6)+cou(N-j,9))
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
w=ans=9**9

for i in range(N):
    e=S[:i].count("W")
    w=S[i:].count("E")
    ans=min(ans,e+w)
    if w=0:break
print(ans)


Fixed submission:
a,b=map(int,input().split())
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
w=ans=9**9
for i in range(N):
    e=S[:i].count("W")
    w=S[i:].count("E")
    ans=min(ans,e+w)
    if w==0:break
print(ans)

Fixed submission:
N=int(input())
S=input()
e=0
ans=w=S.count("E")
for i in S:
    if i=="E":w-=1
    else: e+=1
    ans=min(ans,e+w)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
w=ans=9**9
for i in range(N):
    e=S[:i].count("W")
    w=S[i:].count("E")
    ans=min(ans,e+w)
    if w==0:break
print(ans)


Fixed submission:
N=int(input())
S=input()
e=0
ans=w=S.count("E")
for i in S:
    if i=="E":w-=1
    else: e+=1
    ans=min(ans,e+w)
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
w=ans=9**9
for i in range(N):
    e=S[:i].count("W")
    w=S[i:].count("E")
    ans=min(ans,e+w)
    if w=0:break
print(ans)


Fixed submission:
N=int(input())
S=input()
e=0
ans=w=S.count("E")
for i in S:
    if i=="E":w-=1
    else: e+=1
    ans=min(ans,e+w)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=9**9
for i in range(N):
    e=S[:i].count("W")
    w=S[i:].count("E")
    ans=min(ans,e+w)
print(ans)


Fixed submission:
N=int(input())
S=input()
e=0
ans=w=S.count("E")
for i in S:
    if i=="E":w-=1
    else: e+=1
    ans=min(ans,e+w)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
K=int(input())
As=sorted(s)
ans=[]
for A in As:
    if len(ans)>K:break
    for j in range(1,K+1):
        ind=0
        for i in s:
            if i==A:
                if len(s[ind:ind+j])==j and (s[ind:ind+j] not in ans):
                    ans.append(s[ind:ind+j])
            ind+=1
print(sorted(ans)[K-1])


Fixed submission:
s=input()
K=int(input())
As=sorted(set(s))
ans=[]
for A in As:
    ans.append(A)
    if len(ans)>=K:break
    for j in range(2,K+1):
        ind=0
        for i in s:
            if i==A:
                Judge=s[ind:ind+j]
                if len(Judge)==j and (Judge not in ans):
                    ans.append(Judge)
            ind+=1
print(sorted(ans)[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
K=int(input())
As=sorted(s)
ans=[]
for A in As:
    if len(ans)>K:break
    for j in range(1,K+1):
        ind=0
        for i in s:
            if i==A:
                if len(s[ind:ind+j])==j and (s[ind:ind+j] not in ans):
                    ans.append(s[ind:ind+j])
            ind+=1
print(sorted(ans)[K-1])



Fixed submission:
s=input()
K=int(input())
As=sorted(set(s))
ans=[]
for A in As:
    ans.append(A)
    if len(ans)>=K:break
    for j in range(2,K+1):
        ind=0
        for i in s:
            if i==A:
                Judge=s[ind:ind+j]
                if len(Judge)==j and (Judge not in ans):
                    ans.append(Judge)
            ind+=1
print(sorted(ans)[K-1])
Buggy python submission (verdict: Runtime Error):
import itertools as ite
N=int(input())
C=[0]*(N+1)
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
for i,j,k in list(ite.combinations(range(5),3)):
    ans+=C[i]*C[j]*C[k]
print(ans)


Fixed submission:
N=int(input())
C=[0,0,0,0,0,0]
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
ans+=C[0]*C[1]*C[2]
ans+=C[0]*C[1]*C[3]
ans+=C[0]*C[1]*C[4]
ans+=C[0]*C[2]*C[3]
ans+=C[0]*C[2]*C[4]
ans+=C[0]*C[3]*C[4]
ans+=C[1]*C[2]*C[3]
ans+=C[1]*C[2]*C[4]
ans+=C[1]*C[3]*C[4]
ans+=C[2]*C[3]*C[4]
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools as ite
N=int(input())
C=[0]*N
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
for i,j,k in list(ite.combinations(range(5),3)):
    ans+=C[i]*C[j]*C[k]
print(ans)


Fixed submission:
N=int(input())
C=[0,0,0,0,0,0]
J="MARCH"
for i in range(N):
    C[J.find(input()[0])]+=1
ans=0
ans+=C[0]*C[1]*C[2]
ans+=C[0]*C[1]*C[3]
ans+=C[0]*C[1]*C[4]
ans+=C[0]*C[2]*C[3]
ans+=C[0]*C[2]*C[4]
ans+=C[0]*C[3]*C[4]
ans+=C[1]*C[2]*C[3]
ans+=C[1]*C[2]*C[4]
ans+=C[1]*C[3]*C[4]
ans+=C[2]*C[3]*C[4]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
s=set(a)
ans=0
for i in s:
    j=a.count(i)
    if j<i:
        ans+=j
    else:
        ans+=j-i
print(ans)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
a.sort()
C=[0]
s=[a[0]]
for i in a:
    if(s[-1]==i):
        C[-1]+=1
    else:
        C.append(1)
        s.append(i)
ans=0
for i in range(len(s)):
    if C[i]<s[i]:
        ans+=C[i]
    else:
        ans+=C[i]-s[i]
print(ans)

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

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
a.sort()
C=[0]
s=[a[0]]
for i in a:
    if(s[-1]==i):
        C[-1]+=1
    else:
        C.append(1)
        s.append(i)
ans=0
for i in range(len(s)):
    if C[i]<s[i]:
        ans+=C[i]
    else:
        ans+=C[i]-s[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if a==0 or i<k :break
        else: c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)


Fixed submission:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if a==0 or i<k :break
        else: c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)


Fixed submission:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if i<k:break
        else: c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Fixed submission:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if i<k:break
        else: c+=1
    ans+=a*(N-c)
print(ans)

Fixed submission:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
P=[list(map(int,input().split())) for i in range(3)]
ans=0
for i in P[0]:
    for j in P[1]:
        for k in P[2]:
            if i<j<k:ans+=1
print(ans)

Fixed submission:
N=int(input())
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(N):
    if i%2:
        o.append(a[i])
        e.insert(0,a[i])
    else :
        o.insert(0,a[i])
        e.append(a[i])
for i in o if N%2 else e:
    print(i,sep="",end=" ")

Fixed submission:
N=int(input())
a=input().split()
print(*(a[::-2]+a[N%2::2]))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(N):
    if i%2:
        o=o+[a[i]]
        e=[a[i]]+e
    else :
        o=[a[i]]+o
        e=e+[a[i]]
for i in o if N%2 else e:
    print(i,sep="",end=" ")

Fixed submission:
N=int(input())
a=input().split()
print(*(a[::-2]+a[N%2::2]))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[int(input()) for i in range(N)]
ans=0
b=1
while(1):
    ans+=1
    b=a[b-1]
    if b==1:
        ans=-1
        break
    if b==2:break
print(ans)

Fixed submission:
N=int(input())
a=[int(input()) for i in range(N)]
j=[0]*N
ans=0
b=1
while(1):
    ans+=1
    b=a[b-1]
    j[b-1]+=1
    if j[b-1]==2:
        ans=-1
        break
    if b==2:break
print(ans)