Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(1,N+1):
    print(A.index(i)+1,end=" ")

Fixed submission:
N=int(input())
A={i:a for (i, a) in enumerate(list(map(int, input().split())),1)}
B=sorted(A.items(), key=lambda A:A[1])
for i in range(N):
    print(B[i][0],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(1,N+1):
    B.append(A.index(i)+1)
print(*B)

Fixed submission:
N=int(input())
A={i:a for (i, a) in enumerate(list(map(int, input().split())),1)}
B=sorted(A.items(), key=lambda A:A[1])
for i in range(N):
    print(B[i][0],end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q=map(int,input().split())
P=[K]*N
for i in range(Q):
    a=int(input())
    for n in range(N):
        if n!=a-1:P[n]-=1
for i in range(N):
    if P[i]>0:print("Yes")
    else:print("No")

Fixed submission:
N,K,Q=map(int,input().split())
P=[K-Q]*N
for i in range(Q):
    a=int(input())
    P[a-1]+=1
for i in range(N):
    if P[i]>0:print("Yes")
    else:print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
ans=0
for i in range(N):
    ans+=i
print(ans)

Fixed submission:
N=int(input())
ans=(N-1)*N//2
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from math import factorial
def combinations(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
N=int(input())
S=["".join(sorted(input())) for i in range(N)]
s=Counter(S)
ans=0
for key,value in s.items():
    ans+=combinations(value,2)
print(ans)

Fixed submission:
from collections import Counter
from math import factorial
def combinations(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
N=int(input())
S=["".join(sorted(input())) for i in range(N)]
s=Counter(S)
ans=0
for key,value in s.items():
    if value>=2:
        ans+=combinations(value,2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
H=list(map(int,input().split()))
a=0
for i in range(1,N):
    a=max(H[:i])
    if H[i]<a-1:
        print("No")
        break
else:
    print("Yes")

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
a=H[0]
for i in range(1,N):
    if H[i]<a-1:
        print("No")
        break
    a=max(a,H[i])
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(input()) for i in range(N)]
for i in range(N):
    print(max(A[:i]+A[i+1:]))

Fixed submission:
N=int(input())
A=[int(input()) for i in range(N)]
maximum=max(A)
maximum2=sorted(A)[-2]
for a in A:
    if a!=maximum:
        print(maximum)
    else:
        print(maximum2)
Buggy python submission (verdict: Time Limit Exceeded):
L,R=map(int,input().split())
ans=2018
if R-L>=2019**2:
    R=L+2019**2
for i in range(L,R):
    for j in range(i+1,R+1):
        ans=min(ans,(i*j)%2019)
        if ans==0:
            break
print(ans)

Fixed submission:
L,R=map(int,input().split())
ans=2018
if R-L>=2019**2:
    R=L+2019**2
for i in range(L,R):
    for j in range(i+1,R+1):
        ans=min(ans,(i*j)%2019)
        if ans==0:
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D=map(int,input().split())
count=0
for i in range(A,B+1):
    if i%C!=0 and i%D!=0:
        count+=1
print(count)

Fixed submission:
from fractions import gcd
A,B,C,D=map(int,input().split())
A-=1
lcm=C*D//gcd(C,D)
print(B-B//C-B//D+B//lcm-(A-A//C-A//D+A//lcm))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
B=[0]*N
for i in range(M):
    l,r=map(int,input().split())
    for j in range(l-1,r):
        B[j]+=1
print(B.count(M))

Fixed submission:
N,M=map(int,input().split())
ml=0
mh=N
for i in range(M):
    l,r=map(int,input().split())
    ml=max(ml,l)
    mh=min(mh,r)
print(max(0,mh-ml+1))

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=set(i for i in range(1,N+1))
for i in range(M):
    l,r=map(int,input().split())
    A=set(j for j in range(l,r+1) if j in A)
print(len(A))

Fixed submission:
N,M=map(int,input().split())
ml=0
mh=N
for i in range(M):
    l,r=map(int,input().split())
    ml=max(ml,l)
    mh=min(mh,r)
print(max(0,mh-ml+1))

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
count=0
A=[i for i in range(1,N+1)]
for i in range(M):
    l,r=map(int,input().split())
    A=[j for j in range(l,r+1) if j in A]
print(len(A))

Fixed submission:
N,M=map(int,input().split())
ml=0
mh=N
for i in range(M):
    l,r=map(int,input().split())
    ml=max(ml,l)
    mh=min(mh,r)
print(max(0,mh-ml+1))
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,n=map(int,input().split())
count=0
for r in range(n+1):
    for g in range(n+1):
            if n>=r*R+g*G and (n-r*R-g*G)%B==0:
                count+=1
print(count)

Fixed submission:
R,G,B,n=map(int,input().split())
count=0
for r in range(n+1):
    for g in range(n+1):
            if n>=r*R+g*G and (n-r*R-g*G)%B==0:
                count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
k=int(input())
for i in range(n):
    if s[i] == s[k]:
        print(s[i],end="")
    else:
        print("*",end="")

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

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

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

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input(),split())
h,w=map(int,input(),split())
print(H*W-h*W-w*(H-h))

Fixed submission:
H,W=map(int,input().split())
h,w=map(int,input().split())
print(H*W-h*W-w*(H-h))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
X=sorted(list(map(int,input().split())))
Y=[]
for i in range(M-1):
    y=X[i+1]-X[i]
    Y.append(y)
y=sorted(Y)[::-1]
print(sum(y[N-1]))

Fixed submission:
N,M=map(int,input().split())
X=sorted(list(map(int,input().split())))
Y=[]
for i in range(M-1):
    y=X[i+1]-X[i]
    Y.append(y)
y=sorted(Y)[::-1]
print(sum(y[N-1:]))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
SA=sum(A)
SB=sum(B)
S=SA-SB
cnt=0
if SB>SA:
    print(-1)
    exit()
for a,b in zip(A,B):
    if a>b:
        C.append(a-b)
    elif a==b:
        cnt+=1
for c in sorted(set(C)):
    if S>=C.count(c)*c:
        cnt+=C.count(c)
        S-=C.count(c)*c
    else:
        cnt+=S//c
        S=0
    if S==0:
        break
print(N-cnt)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
SA=sum(A)
SB=sum(B)
S=SA-SB
cnt=0
ns=0
if SB>SA:
    print(-1)
    exit()
for a,b in zip(A,B):
    if a>b:
        C.append(a-b)
    elif a<b:
        ns+=b-a
        cnt+=1
C.sort(reverse=True)
for i in range(len(C)):
    if ns>0:
        cnt+=1
        ns-=C[i]
    else:break
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
SA=sum(A)
SB=sum(B)
S=SA-SB
cnt=0
if SB>SA:
    print(-1)
    exit()
for a,b in zip(A,B):
    if a>b:
        C.append(a-b)
    elif a==b:
        cnt+=1
for c in sorted(set(C)):
    if S>=C.count(c)*c:
        cnt+=C.count(c)
        S-=C.count(c)*c
    else:
        cnt+=S//c
        S=0
    if S==0:
        break
print(N-cnt)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
SA=sum(A)
SB=sum(B)
S=SA-SB
cnt=0
ns=0
if SB>SA:
    print(-1)
    exit()
for a,b in zip(A,B):
    if a>b:
        C.append(a-b)
    elif a<b:
        ns+=b-a
        cnt+=1
C.sort(reverse=True)
for i in range(len(C)):
    if ns>0:
        cnt+=1
        ns-=C[i]
    else:break
print(cnt)
Buggy python submission (verdict: Runtime Error):
N,P=map(int,input().split())
i=2
ans=1
while P!=1 or i<int(N**.5)+1:
    I=i**N
    if P%I==0:
        ans*=I
        P//=I
    elif P%i==0:
        P//=i
    else:
        i+=1
print(ans)

Fixed submission:
n,p = map(int,input().split())
 
def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf
 
ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,P=map(int,input().split())
i=2
ans=1
while P!=1:
    if P%(i**N)==0:
        ans*=i
        P//=i**N
    elif P%i==0:
        P//=i
    else:
        i+=1
print(ans)

Fixed submission:
n,p = map(int,input().split())
 
def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf
 
ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N,P=map(int,input().split())
A=defaultdict(int)
i=2
ans=1
while P!=1:
    if P%i==0:
        A[i]+=1
        P//=i
    else:
        i+=1
for key,value in A.items():
    if value>=N:
        ans*=key**(value//N)
print(ans)

Fixed submission:
n,p = map(int,input().split())
 
def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf
 
ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N,P=map(int,input().split())
A=[]
i=2
ans=1
while P!=1:
    if P%i==0:
        A.append(i)
        P//=i
    else:
        i+=1
A=Counter(A)
for key,value in A.items():
    if value>=N:
        ans*=key**(value//N)
print(ans)

Fixed submission:
n,p = map(int,input().split())
 
def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf
 
ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N,P=map(int,input().split())
A=[]
i=2
ans=1
while P!=1:
    if P%i==0:
        A.append(i)
        P//=i
    else:
        i+=1
A=Counter(A)
for key,value in A.items():
    if value>=N:
        ans*=key**(value//N)
print(ans)

Fixed submission:
n,p = map(int,input().split())
 
def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf
 
ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
count=0
for i in range(len(S)):
    if S[i]=="W":
        count+=S[:i].count("B")
print(count)

Fixed submission:
S=input()
count=0
ans=0
for i in range(len(S)):
    if S[i]=="W":
        ans+=count
    else:
        count+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
count=0
a=2*10**5+1
while count!=a:
    a=count
    for i in range(len(S)-1):
        if S[i]=="B" and S[i+1]=="W":
            S[i]="W"
            S[i+1]="B"
            count+=1

print(count)

Fixed submission:
S=input()
count=0
ans=0
for i in range(len(S)):
    if S[i]=="W":
        ans+=count
    else:
        count+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
def lcm(a,b):
    return (a*b)//gcd(a,b)

def lcm_list(numbers):
    return reduce(lcm,numbers,1)

n=int(input())
a=list(map(int,input().split()))
b=lcm_list(a)
y=0
for x in a:
    y+=x-1
print(y)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
y=0
for x in a:
    y+=x-1
print(y)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=n
for i in range(n):
    ans=min(s[:i].count("W")+s[i+1:].count("E"),ans)
print(ans)

Fixed submission:
n=int(input())
S=input()
a=S.count("E")
m=a
for s in S:
    if s=="E":
        a-=1
    m=min(m,a)
    if s=="W":
        a+=1
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k=map(int,input().split())
if a==b==c:
    print(0)
    exit()
for i in range(k):
    A=c+b;B=a+c;C=a+b
    a=A;b=B;c=C
if abs(a-b)>10**18:
    print("Unfair")
else:
    print(a-b)

Fixed submission:
a,b,c,k=map(int,input().split())
if a==b==c:
    print(0)
    exit()
elif abs(a-b)>10**18:
    print("Unfair")
elif k%2==1:
    print(b-a)
else:
    print(a-b)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=["."*W]+["."+input()+"." for i in range(H)]+["."*W]
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=="#":
            if S[i+1][j]=="." and S[i-1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                print("No")
                exit()
print("Yes")

Fixed submission:
H,W=map(int,input().split())
S=["."*(W+2)]+["."+input()+"." for i in range(H)]+["."*(W+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=="#":
            if S[i+1][j]=="." and S[i-1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                print("No")
                exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
mport collections
 
n = int(input())
ln = list(map(int, input().split()))
m = int(input())
lm = list(map(int, input().split()))
 
c1 = collections.Counter(lm)
c2 = collections.Counter(ln)
 
for i in c1.keys():
    if c2[i] < c1[i]:
        print("NO")
        exit()
 
print("YES")

Fixed submission:
import collections
 
n = int(input())
ln = list(map(int, input().split()))
m = int(input())
lm = list(map(int, input().split()))
 
c1 = collections.Counter(lm)
c2 = collections.Counter(ln)
 
for i in c1.keys():
    if c2[i] < c1[i]:
        print("NO")
        exit()
 
print("YES")
Buggy python submission (verdict: Runtime Error):
n=int(input())
b=0
for i in range(7):
    if 2**i=<n:
        b=2**i
print(b)


Fixed submission:
n=int(input())
b=0
for i in range(7):
    if 2**i<=n:
        b=2**i
print(b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
print(*A[::-2],*A[n%2::2])

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
if N%2==0:
    B=A[::-2]+A[::2]
else:
    B=A[::-2]+A[1::2]
print(*B)

Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
print(*A[::-2],*A[n%2::2])

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
if N%2==0:
    B=A[::-2]+A[::2]
else:
    B=A[::-2]+A[1::2]
print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
B=[]
for a in A:
    B.append(a)
    B=B[::-1]
print(*B)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
if N%2==0:
    B=A[::-2]+A[::2]
else:
    B=A[::-2]+A[1::2]
print(*B)
Buggy python submission (verdict: Runtime Error):
a.b = map(int, input().split())
print(a+b if a+b<10 else "error")

Fixed submission:
a,b = map(int, input().split())
print(a+b if a+b<10 else "error")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for j in range(M)]
for i in range(N):
    for j in range(N-M+1):
        if A[i][j:j+M]==B[0]:
            if all(A[i+k][j:j+M]==B[k] for k in range(1,M)):
                print("Yes")
                exit()
print("No")

Fixed submission:
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for j in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M]==B[0]:
            if all(A[i+k][j:j+M]==B[k] for k in range(1,M)):
                print("Yes")
                exit()
print("No")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for j in range(M)]
for i in range(N):
    for j in range(N-M):
        if A[i][j:j+M]==B[0]:
            if all(A[i+k][j:j+M]==B[k] for k in range(1,M)):
                print("Yes")
                exit()
print("No")

Fixed submission:
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for j in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M]==B[0]:
            if all(A[i+k][j:j+M]==B[k] for k in range(1,M)):
                print("Yes")
                exit()
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
ans=0
for i in range(len(S)):
    if S[i]=="A":
        for j in range(i+1,len(S)):
            if S[j]=="Z":
                ans=max(ans,j-i+1)
print(ans)

Fixed submission:
S=input()
start=0
end=len(S)+1
for s in S:
    start+=1
    if s=="A":
        break
for s in S[::-1]:
    end-=1
    if s=="Z":
        break
print(end-start+1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)][::-1]
plus=0
for j in range(N):
    AB[j][0]+=plus
    while AB[j][0]%AB[j][1]!=0:
        AB[j][0]+=1
        plus+=1
print(plus)

Fixed submission:
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)][::-1]
plus=0
for j in range(N):
    AB[j][0]+=plus
    if AB[j][0]%AB[j][1]!=0:
        a=AB[j][1]-(AB[j][0]%AB[j][1])
        AB[j][0]+=a
        plus+=a
print(plus)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
x==c-a
y==d-b
print("U"*y+"R"*x+"D"*y+"L"*x+"L"+"U"*(y+1)*"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U")

Fixed submission:
a,b,c,d=map(int,input().split())
x=c-a
y=d-b
print("U"*y+"R"*x+"D"*y+"L"*x+"L"+"U"*(y+1)+"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U")

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
x=c-a
y=d-b
print("U"*y+"R"*x+"D"*y+"L"*x+"L"+"U"*(y+1)*"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U")

Fixed submission:
a,b,c,d=map(int,input().split())
x=c-a
y=d-b
print("U"*y+"R"*x+"D"*y+"L"*x+"L"+"U"*(y+1)+"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U")
Buggy python submission (verdict: Runtime Error):
    print(sum(T[:P-1])+X+sum(T[P:]))

Fixed submission:
N=int(input())
T=list(map(int,input().split()))
M=int(input())
for i in range(M):
    P,X=map(int,input().split())
    print(sum(T[:P-1])+X+sum(T[P:]),end="\n")
Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=0
A=[]
for i in range(1,N+1):
    if ans+i==N:
        A.append(i)
        break
    if N-(ans+i)>=i+1:
        A.append(i)
        ans+=i
    else:
        del A[-1]
        ans-=i-1
        if (N-ans)%2==0:
            A.append((N-ans)//2-1)
            A.append((N-ans)//2+1)
        else:
            A.append((N-ans)//2)
            A.append((N-ans)//2+1)
        break
print(*A,sep="\n")


Fixed submission:
N=int(input())
ans=0
reject=0
A=[]
for i in range(1,N+1):
    ans+=i
    if ans>=N:
        reject=ans-N
        for j in range(1,i+1):
            if j!=reject:
                print(j)
        break
Buggy python submission (verdict: Runtime Error):
ans = None
for r in range(100):
    for i in [-r, r]:
        if (X + i) not in p:
            ans = X+i
            break

    if ans is not None:
        break


print(ans)

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

ans = None
for r in range(100):
    for i in [-r, r]:
        if (X + i) not in p:
            ans = X+i
            break

    if ans is not None:
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.fromstring(input(), np.uint64, sep=" ")

uniq, counts = np.unique(A, return_counts=True)

p = lambda n: n * (n - 1) // 2

n = p(counts)
m = p(counts-1)

ans = n.sum() - n + m

mapping = dict(zip(uniq, ans))

for a in A:
    print(mapping[a])


Fixed submission:
from collections import defaultdict
import numpy as np

N = int(input())
A = np.fromstring(input(), np.int, sep=" ")

uniq_count = defaultdict(int)
for a in A:
    uniq_count[a] += 1
uniq = np.fromiter((uniq_count.keys()), np.int)
counts = np.fromiter(uniq_count.values(), np.int)

p = lambda n: n * (n - 1) // 2

n = p(counts)
m = p(counts - 1)

ans = n.sum() - n + m

mapping = dict(zip(uniq, ans))

for a in A:
    print(mapping[a])
Buggy python submission (verdict: Time Limit Exceeded):
a = list(input())
res = ''
for i in a:
  if i == '?':
    res += 'D'
  else:
    res += i
    
print(res)


Fixed submission:
a = input()
a = a.replace('?', 'D')
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
reverse = False
for _ in range(Q):
    tmp = input().split()
    if len(tmp) == 1:
        reverse = not reverse
    else:
        F = int(tmp[1])
        C = tmp[2]
        if F == 1:
            if reverse:
                S.append(C)
            else:
                S.insert(0, C)
        else:
            if reverse:
                S.insert(0, C)
            else:
                S.append(C)

if reverse:
    S.reverse()
print(''.join(S))

Fixed submission:
S = list(input())
Q = int(input())
reverse = False
flont = []
for _ in range(Q):
    tmp = input().split()
    if len(tmp) == 1:
        reverse = not reverse
    else:
        F = int(tmp[1])
        C = tmp[2]
        if F == 1:
            if reverse:
                S.append(C)
            else:
                flont.append(C)
        else:
            if reverse:
                flont.append(C)
            else:
                S.append(C)
flont.reverse()
flont.extend(S)
if reverse:
    flont.reverse()
print(''.join(flont))