peterverebics/CodeNet_Python_118 huggingface dataset:
from operator import mul
from functools import reduce
import collections

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

c = collections.Counter(M)

A = 0

for i in c.values():
    if i >= 2:
        A += cmb(i, 2)
    
for j in M:
    print(A - (c[j]-1))
# D - Banned K
from collections import Counter


def main():
    N, *A = map(int, open(0).read().split())
    counter = Counter(A)
    total = 0
    dif = {}
    for k, v in counter.items():
        total += v * (v - 1) // 2
        dif[k] = v - 1
    ans = [total - dif[a] for a in A]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()
n=int(input())
li=list(map(int,input().split()))
d={}
dif={-1}
ans={}
for i in range(n):
    if li[i] not in dif:
        dif|={li[i]}
    if d.get(li[i])!=None:
        d[li[i]]+=1
    else:
        d[li[i]]=1
dif.remove(-1)
g=0
for i in dif:
    g+=d[i]*(d[i]-1)//2
for i in dif:
    ans[i]=g-(d[i]-1)*d[i]//2+(d[i]-2)*(d[i]-1)//2
for i in li:
    print(ans[i])
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]-1]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]-1]+1)
N = int(input())
arr = list(map(int, input().split()))
cnt = {}
sum_num = 0
for idx in arr:
    if idx in cnt:
        cnt[idx] += 1
    else:
        cnt[idx] = 1

for i in cnt.values():
    sum_num += i * (i - 1) // 2

for idx in arr:
    c = cnt[idx]
    ans = sum_num - c * (c - 1) // 2
    ans = ans + (c - 1) * (c - 2) // 2
    print(ans)
n = int( input() )
a = list( map( int, input().split() ) )

cnt = [ 0 ] + [ 0 ] * n

for a_i in  a:
    cnt[a_i] += 1

all_combi = 0
for m in cnt:
    all_combi += m * ( m - 1 ) // 2

for k in range( 1, n+1 ):
    print( all_combi - ( cnt[a[k-1]] - 1 ) )
n = int(input())
a = [int(i) for i in input().split()]
nC2 = [0 for i in range(n + 1)]
for i in range(2, n + 1):
    nC2[i] = i * (i - 1) // 2
cnt = [0]*n
for i in a:
    cnt[i - 1] += 1
res = 0
for i in cnt:
    res += nC2[i]
for i in a:
    print(res - nC2[cnt[i - 1]] + nC2[cnt[i - 1] - 1])
n=int(input())
a=list(map(int,input().split()))
x=[0]*(n+1)

for i in a:
    x[i]+=1
s=sum([x[i]*(x[i]-1)//2 for i in range(1,n+1)])


for i in range(n):
    k=a[i]
    p=x[k]*(x[k]-1)//2
    q=(x[k]-1)*(x[k]-2)//2
    print(s-p+q)
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
A = list(map(int, input().split()))

counter = Counter(A)
ans = sum(i * (i - 1) // 2 for i in counter.values())

for a in A:
    c = counter[a]
    print(ans - c * (c - 1) // 2 + (c - 1) * (c - 2) // 2)
n = int(input())
a= list(map(int, input().split()))
from collections import Counter
c=Counter(a)
dic={}
for k,v in c.items():
    dic[k]=v*(v-1)//2
su=0
for k in dic.values():
    su+=k
for i in a:
    print(su-dic[i]+(c[i]-1)*(c[i]-2)//2)
N=int(input())
A = list(map(int, input().split()))

dic={}
for i in A:
    if i in dic.keys():
        dic[i]+=1
    else:
        dic.setdefault(i,1)

hoge=0
for i in dic.values():
    hoge+=i*(i-1)
hoge =int(hoge/2)

for k in A:
    print(hoge-(dic[k]-1))
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N=int(input())
    A=tupin()

    from collections import Counter
    c=Counter(A)
    total=0
    
    for t in c.items():
        ag,b=t
        total+=(b*(b-1))//2
    #print(total)
    for m in A:
        a=c[m]
        print(total-((a*(a-1))//2)+((a-1)*(a-2))//2)
#%%submit!
resolve()
from collections import Counter


def combinations_count(n):
    return n*(n-1)//2


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    t = 0
    for i in c:
        t += combinations_count(c[i])

    for i in range(n):
        print(t-c[a[i]]+1)
import collections
from collections import defaultdict

n = int(input())
l = list(map(int, input().split()))

dict = defaultdict(int)
for i in l:
    dict[i]+=1

ans = 0
for v in dict.values():
    ans += int((v*(v-1)) // 2)

for k in l:
    print(ans - (dict[k] - 1))
import sys
n=int(sys.stdin.readline())
arr=list(map(int,sys.stdin.readline().split()))
from collections import defaultdict
s=0
dic=defaultdict(int)
for i in range(n):
    dic[arr[i]]+=1
for i in dic:
    s+=(dic[i]*(dic[i]-1))//2
#print(s,'s')
for i in range(n):
    a=arr[i]
    ans=s
    
    ans-=dic[a]*(dic[a]-1)//2
    if dic[a]-2>=0:
        ans+=(dic[a]-1)*(dic[a]-2)//2
    print(ans)
def MI():return map(int,input().split())
def LI():return list(MI())

from collections import Counter

n=int(input())
a=LI()
c=Counter(a)

# print(c)
M=0
for i,j in c.items():
    M+=(j)*(j-1)//2
# print(M)
for i in a:
    t=c[i]
    d=(t-1)
    print(M-d)
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

c=Counter(a)
s=0
for key in c:
    s+=c[key]*(c[key]-1)//2
for item in a:
    print(s-c[item]+1)
N = int(input())
A = list(map(int, input().split()))
B = [[] for i in range(N)]
ans = [0]*N
for k, a in enumerate(A):
    a = a - 1
    B[a].append(k)


S = 0
for b in B:
    lenb = len(b)
    if lenb >= 1:
        S += lenb * (lenb-1) / 2

for i, b in enumerate(B):
    for j, k in enumerate(b):
        ans[k] = int(S - (len(b) - 1))
for i in ans:
    print(i)
from collections import Counter as cnt
n =  int(input())
A = list(map(int, input().split()))
dic = cnt(A)
total = 0
for num in dic.values():
  if num >= 2:
    total += num * (num - 1) // 2
    
for num in A:
  target = dic[num]
  ans = total
  if target >= 2:
    ans -= target * (target - 1) // 2
    ans += (target - 1) * (target - 2) // 2
  print(ans)
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
for i in a:
    l[i]+=1

ans=0
for i in range(n+1):
    ans+=l[i]*(l[i]-1)//2

for i in a:
    print(ans-l[i]*(l[i]-1)//2+(l[i]-1)*(l[i]-2)//2)
import collections
a=int(input())
b=list(map(int,input().split()))

c=collections.Counter(b)

n,m=zip(*c.most_common())
n,m=list(n),list(m)
result=0
for i in range(len(m)):
    result+=(m[i]*(m[i]-1))//2

for i in b:
    print(result-c[i]+1)
N = int(input())
A = list(map(int,input().split()))
box = [0]*(N+1)
for i in range(N) :
    box[A[i]] += 1

x = list(map(lambda x: x*(x-1)//2 , box))
ans = sum(x)
for j in range(N) :
    print(ans-(box[A[j]] - 1))
import collections
N=int(input())
lst=input().split()
s=0
dic=collections.Counter(lst)
for i in dic.values():
    s+=(i*i-i)//2
for i in lst:
    print(s+1-dic[i])
n = int(input())
a = list(map(int,input().split()))

a_2 = [0 for i in range(n)]
for i in range(n):
    a_2[a[i]-1] += 1

al = [0 for i in range(n)]
c = 0
for i in a_2:
    if i > 1:
        al[c] += i * (i-1) / 2
    c += 1

sine = sum(al)
for i in range(n):
    f = a[i]
    t = a_2[f-1] - 1
    print(int(sine-(al[f-1]-t*(t-1)/2)))
def parm(a):
    return(int(a*(a-1)/2))

n=int(input())
a=list(input().split())
dic={}
ans=[0]*n
sumans=0
for i in range(n):
    if a[i] in dic.keys():
        dic[a[i]]+=1
    else:
        dic[a[i]]=1
for i in dic.values():
    sumans+=parm(i)
for i in range(n):
    print(sumans-parm(dic[a[i]])+parm(dic[a[i]]-1))
from collections import Counter

N = int(input())
As = [int(n) for n in input().split()]

C = Counter(As)

ans = sum(v * (v - 1) // 2 for k, v in C.items())
M = [C[a] - 1 for a in As]

for m in M:
    print(ans - m)
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr(), dtype=np.int32)
counter = np.bincount(A)
case = (counter * (counter-1) // 2).sum()
answer = case - (counter[A] - 1)
print('\n'.join(answer.astype(str)))
n = int(input())
a = [int(v) for v in input().split()]

field = {}
for v in a:
    if not v in field:
        field[v] = 1
    else:
        field[v] += 1

all_ans = 0
for k,v in field.items():
    all_ans += ((v*(v-1))/2)


for i in a:
    ans = all_ans
    if i in field:
        n = field[i]
        ans -= (n*(n-1))/2
        n = n - 1
        ans += (n*(n-1))/2
    
    print(int(ans))
def main():
    N = int(input())
    A = [int(v) for v in input().split()]
    C = [0] * (N + 1)

    for i in A:
        C[i] += 1

    b = 0
    
    for cnt in C:
        b += ((cnt * (cnt - 1)) // 2)

    for i in range(N):
        p = ((C[A[i]] - 1) * (C[A[i]] - 2)) >> 1
        m = (C[A[i]] * (C[A[i]] - 1)) >> 1
        print(b - m + p)


if __name__ == '__main__':
    main()
N=int(input())
*A,=map(int,input().split())
from collections import*
C=Counter(A)
S=sum(v*(v-1)//2 for v in C.values())
for a in A:
    print(S-C[a]+1)
from collections import Counter

N=int(input())
a=list(map(int,input().split()))

A=Counter(a)
B=list(A.keys())
C=list(A.values())

ans=sum(c*(c-1)//2 for c in C)

for k in range(1,N+1):
    print(ans-A[a[k-1]]+1)
from collections import Counter

def Get_nC2(n):
    return int(n*(n-1) / 2)


N = int(input())
A_i = list(map(int, input().split()))

c = Counter(A_i)


total = sum(list(map(Get_nC2, c.values())))

for a_i in A_i:
    result =  total - Get_nC2(c[a_i]) + Get_nC2(c[a_i]-1)
    print(result)
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
C = defaultdict(int)
for a in A:
    C[a] += 1

sum = 0
for i, c in C.items():
    sum += (c * (c-1)) // 2

for a in A:
    print(sum - (C[a]*(C[a]-1))//2 + ((C[a]-1)*(C[a]-2))//2)
N=int(input())
A=list(map(int,input().split(' ')))
import math
import collections
import operator as op
from functools import reduce
def nCr(n,r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom if n>1 else 0
counter=collections.Counter(A)
penult=0
for i in range(1,N+1):
    penult=penult+nCr(counter[i],2)
for i in range(0,N):
    print(int(penult-(counter[A[i]]-1)))
N = int(input())
A = list(map(int, input().split()))

def comb(x):
    if x > 1:
        return int(x*(x-1)/2)
    return 0

M = [0 for _ in range(N+1)]
C = [0 for _ in range(N+1)]
_C = [0 for _ in range(N+1)]

for i in range(N):
    M[A[i]] += 1
for i in range(N):
    cnt = M[A[i]]
    C[A[i]] = comb(cnt)
    _C[A[i]] = comb(cnt-1)

S = sum(C)
for i in range(N):
    print(S - C[A[i]] + _C[A[i]])
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
import collections
D=collections.defaultdict(int)
for a in A:
  D[a]+=1
tot=0
for d in D.keys():
  if D[d]>=2:
    tot+=D[d]*(D[d]-1)//2
for a in A:
  ans=tot-D[a]*(D[a]-1)//2+(D[a]-1)*(D[a]-2)//2
  print(ans)
import collections
def C(n):
    return n * (n-1) // 2
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k,v in c.most_common():
    d[k] = v
    sm += C(v)
for a in A:
    print (sm - d[a] + 1)
M=int(input())
N=list(input().split())
check=[0]*M
for i in range(M):
    check[int(N[i])-1]+=1
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    if check[int(N[i])-1]!=2:
        print(num-(check[int(N[i])-1]-1))
    else:
        print(num-1)
# collections.counter 使い方
import collections

n=int(input())
a= list(map(int, input().split()))
c = collections.Counter(a)
d = c.most_common()
ans=0

for i in range(len(d)):
    ans+=(d[i][1]*(d[i][1]-1)//2)


for i in range(n):
    if c[a[i]]>=2:
        print(ans-c[a[i]]+1)
    else:
        print(ans)
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)# ()にカウンターの対象のリストの変数名
    cnt=0
    for i in c.values():
        if i>=2:
            cnt+=i*(i-1)//2
    for j in l:
        x=(c[j]-1)*(c[j]-2)//2-c[j]*(c[j]-1)//2
        print(cnt+x)
resolve()
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
t = (n - 1) * (n - 2) // 2
for k, v in c.items():
    ans += v * (v - 1) // 2
for y in a:
    x = c[y]
    print(ans - x * (x - 1) // 2 + (x - 1) * (x - 2) // 2)
from collections import Counter

N = int(input())
An = list(map(int, input().split()))

c = Counter(An)

res = 0
for k,v in c.items():
    res += v*(v-1)//2

for a in An:
    print(res - (c[a]-1))
N = int(input())
A = list(map(int, input().split()))

from collections import defaultdict
c = defaultdict(int)
cm = set()
c2 = list()
num = 0
for i in range(N):
  c[A[i]] += 1
  cm.add(A[i])
for i in list(cm):
  num += c[i]*(c[i]-1)//2
for i in range(N):
  ans = num - c[A[i]] + 1
  c2.append(ans)

for cs in c2:
  print(cs)
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count.items():
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)
import math
import collections


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))


n = int(input())
a = list(map(int, input().split()))

cnt = collections.Counter(a)
each_ans = {}
for key, value in cnt.items():
    t = nc2(value)
    each_ans[key] = (t, t-value+1)
all_sum = sum(value[0] for _, value in each_ans.items())
ans = {}
for key in cnt.keys():
    ans[key] = all_sum - each_ans[key][0] + each_ans[key][1]
for i in a:
    print(ans[i])
n = int(input())
a = list(map(int, input().split()))
x = [0] * max(a)
for i in a:
    x[i - 1] += 1
all = 0


def nc2(n):
    return int(n * (n - 1) / 2)


for j in x:
    if j >= 2:
        all += nc2(j)

for i in range(n):
    if x[a[i]-1] >= 2:
        print(all-x[a[i]-1]+1)
    else:
        print(all)
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))

    dic = {}
    for a in A:
        if a in dic:
            dic[a] += 1
        else:
            dic[a] = 1
    
    ans = 0
    for key, value in dic.items():
        ans += (value * (value-1)) // 2
    
    for a in A:
        print(ans - dic[a] + 1)


if __name__ == "__main__":
    main()
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
base = 0
for i in c.values():
    base += i*(i-1)//2

ans = []
for ai in a:
    k = c[ai]
    tmp = base - k*(k-1)//2 + (k-1)*(k-2)//2
    ans.append(tmp)

print(*ans, sep="\n")
import collections

n = int(input())

a = list(map(int, input().split()))

c = collections.Counter(a)
total = 0
for i in c:
    total += c[i]*(c[i]-1)//2


for i in range(n):
    target = c[a[i]]
    print(total - target*(target-1)//2 + (target-1)*(target-2)//2)
N = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))
C = [0] * N
for a in A:
    C[a] += 1


def comb(n):
    if n <= 1:
        return 0
    else:
        return n * (n - 1) // 2


t = sum(list(map(comb, C)))
for a in A:
    print(t - comb(C[a]) + comb(C[a] - 1))
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

c=Counter(a)
ans=0
for i in c.keys():
  ans+=(c[i]*(c[i]-1))//2

for i in a:
  print(ans-c[i]+1)
import itertools
import math 
def C(n,r):
    if n-r < 0:
        return 0 
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
cc = {}
for key, val in d.items():
    temp = C(val,2)
    c += temp
    if cc.get(key) is None:
        cc[key] = temp - C(val-1,2)
for i in a:
    print(c - cc[i])
from collections import defaultdict

N = int(input())
balls = input()
balls = balls.split()
balls = list(map(int, balls))

count = defaultdict(int)
for i in balls:
  count[i] += 1

def cmb(M):
  return M*(M-1)//2

sum = 0
for i in count:
   sum += cmb(count[i])
#sum = defaultdict(int)
#for i in count:
#  for j in count:
#    if i==j:
#      sum[i] += cmb(count[j]-1)
#    else:
#      sum[i] += cmb(count[j])
#      
for i in balls:
  print(sum - (count[i]-1))
# A = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
# B = [int(input()) for _ in range(n)]
A = list(map(int, input().split()))
# a, b = map(int, input().split())
# S = input()


def choose2(n):
    return n*(n-1)//2


cnt = [0 for _ in range(n+1)]
for i in range(n):
    cnt[A[i]-1] += 1
total = 0
for i in range(n):
    total += choose2(cnt[i])
for i in range(n):
    ans = total
    ans -= choose2(cnt[A[i]-1])
    ans += choose2(cnt[A[i]-1]-1)
    print(ans)
N = int(input())
myList = list(map(int, input().split()))

sortedList = sorted(myList)

myDict = {sortedList[0]:1}
for myIndx1 in range(1,N):
    if sortedList[myIndx1] == sortedList[myIndx1-1]:
        myDict[sortedList[myIndx1-1]] = myDict[sortedList[myIndx1-1]] + 1
    else:
        myDict[sortedList[myIndx1]] = 1

total = 0
for myVal in myDict.values():
    total = total + int((myVal*(myVal-1))/2)

for item in myList:
    print(total - (myDict[item]-1))
import sys
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
 
N = II()
A = LI()
 
from collections import Counter
S = Counter(A)
result = sum(list(map(lambda x: int(x*(x-1)/2), S.values())))
 
for a in A:
 n = S[a]
 print(result-n+1)
N = int(input())
s = list(map(int,input().split()))
M = max(s)
count = [0] * (M+1)
for i in range(1,N):
    count[s[i]] += 1
ans = 0

for j in count:
    if j == 0:
        continue
    ans += int(j*(j-1)/2)
print(ans)
for i in range(1,N):
    ans += count[s[i-1]]
    count[s[i-1]] += 1
    count[s[i]] -= 1
    ans -= count[s[i]]
    print(ans)
from collections import Counter
def f(n):
    if n<2:
        return 0
    return n*(n-1)//2
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = 0
for c in cnt.values():
    ans += f(c)

for a in A:
    print(ans-cnt[a]+1)
#!/usr/bin/env python
from collections import Counter
import sys

input = sys.stdin.readline

def main():
    n = int(input().rstrip())
    l = list(input().rstrip().split())

    c = Counter(l)
    total = 0
    for key in c:
        total += c[key] * (c[key] -1) // 2
    for item in l:
        print(total - (c[item] -1))
    
if __name__ == '__main__':
    main()
import collections
n = int(input())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
total = 0
for key in cnt.keys():
    total += cnt[key]*(cnt[key]-1) // 2
for i in a:
    ans = total
    ans -= cnt[i] * (cnt[i]-1) / 2
    ans += (cnt[i]-1) * (cnt[i]-2) / 2
    print(int(ans))
N=int(input())
A=list(map(int,input().split()))
dic={}
for a in A:
  if a in dic.keys():
    dic[a]+=1
  else:
    dic[a]=1
r=0
for a in dic.keys():
  c=dic[a]
  r+=c*(c-1)//2
for i in range(N):
  c=dic[A[i]]
  print(r - c*(c-1)//2 + (c-1)*(c-2)//2 )
N=int(input())
a=list(map(int, input().split()))
cnt=[0]*N

for i in range(N):
    cnt[a[i]-1]+=1

c_sum=0
for i in range(N):
    c_sum+=(cnt[i]*(cnt[i]-1))//2

for i in range(N):
    k=(cnt[a[i]-1])*(cnt[a[i]-1]-1) //2
    l=(cnt[a[i]-1]-1)*(cnt[a[i]-1]-2) //2
    d=k-l
    print(c_sum-d)
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for i in range(1, n + 1):
    ans += c[i] * (c[i] - 1) // 2
for i in range(n):
    print(ans - c[a[i]] + 1)
N = int(input())
As = [int(s) - 1 for s in input().split()]

Cs = [0 for _ in range(N)]
for A in As:
    Cs[A] += 1

a = [C * (C - 1) // 2 for C in Cs]
b = [(C - 1) * (C - 2) // 2 for C in Cs]

S = sum(a)

for A in As:
    print(S - a[A] + b[A])
import math
import collections

n = int(input())
A = list(map(int, input().split()))

equal = 0
elements = collections.Counter(A)
equal = sum([v * (v - 1) // 2 for v in elements.values()])

for i in range(n):
    equal_i = elements[A[i]] - 1
    print(equal - equal_i)
import sys
import time
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------

N = int(input())
A = inpl()

s = set(A)
table = [0] * (N+1)
for i in A:
    table[i] += 1

comb = 0
for i in s:
    comb += table[i] * (table[i]-1) // 2

for i in A:
    print(comb - (table[i]-1))


# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
n = int(input())
numlist = list(map(int, input().split(" ")))

import collections

numcount=collections.Counter(numlist)


sum = 0
for i in numcount.values():
    sum += int(i * (i - 1) / 2)

for i in numlist:
    print(sum - numcount[i] + 1)
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]

A = Counter(a)

total = sum([A[i] * (A[i] - 1) //2 for i in A.keys()])

for i in range(n):
    tmp = a[i]
    print(total - A[tmp] +1)
import collections

N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
keys = c.keys()
comb = 0
for i in keys:
    comb += (c[i] * (c[i]-1)) //2

for i in A:
    ans = comb - (c[i]-1)
    print(ans)
N=int(input())
A=list(map(int,input().split()))
import collections as col

sa=set(A)
ca=col.Counter(A)
num=0
for i in sa:
    if ca[i]==1:
        continue
    else:
        num += (ca[i]*(ca[i]-1))//2
for i in A:
    ans = num - (ca[i]-1)
    print(ans)
import collections
import math
def C(n):
    return n * (n-1) // 2
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k,v in c.most_common():
    d[k] = v
    sm += C(v)
for a in A:
    print (sm - C(d[a]) + C(d[a]-1))
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))

    c = Counter(A)
    vals = c.keys()
    cnts = c.values()

    subs = {}
    a_sum = 0
    for v, c in zip(vals, cnts):
        subs[v] = c - 1
        a_sum += (c * (c-1)) // 2
    
    for a in A:
        print(a_sum - subs[a])


if __name__ == '__main__':
    main()
import collections

N = int(input())
A = input().split()

c = collections.Counter(A)
cou = list(c.values())

ans = 0
for j in range(len(cou)):
	m = cou[j]
	k = m*(m-1)/2
	ans += int(k)


for i in range(N):
	x = c[A[i]]
	print(ans - x + 1)
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
b = Counter(a)

ans = 0
for i in b:
    ans += b[i] * (b[i]-1) // 2
    
for i in a:
    if b[i] < 2:
        sa = 0
    else:
        sa = b[i] - 1
    print(ans - sa)
def f():
  n = int(input())
  *li,=map(int, input().split())
  from collections import Counter
  c = Counter()
  for i in li:
    c[i] += 1
  ans=0
  from math import comb
  for i in c.values():
    ans += comb(i, 2)
  for i in li:
    print(ans - comb(c[i], 2) + comb(c[i]-1, 2))
f()
def main():
    n = int(input())
    a = list(map(int,input().split()))
    d = {}
    for i in range(n):
        if d.get(a[i]) == None:
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    ans = 0
    for k in d.keys():
        ans += d[k] * (d[k]-1) //2
    for i in range(n):
        print(ans - ((d[a[i]]*(d[a[i]]-1))//2 - (d[a[i]]-1) * (d[a[i]]-2)//2))

if __name__ == "__main__":
    main()
n = int(input())
inp = list(map(int,input().split()))
d = {}
for x in inp:
    d[x] = d.get(x, 0) + 1
v = [0 for _ in range(n+1)]
for x, y in d.items():
    v[x] = (y)*(y-1)//2
tot = sum(v)
for i in range(n):
    print(tot-v[inp[i]]+((d[inp[i]]-1)*(d[inp[i]]-2)//2))
from collections import defaultdict
import math

def combinations_count(n, r):
    if n == 1 or n == 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
A= [int(i.strip()) for i in input().split(' ')]

D =defaultdict(int)

for i in A:
    D[i] += 1

S = 0
for i in D.values():
    S += combinations_count(i,2)

result_dic ={}
for i in A:
    a = D[i] - 1
    print(S - a)
from collections import Counter
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
A_set = np.unique(A)
count_dict= Counter(A)
count_sum = np.sum([count_dict[i]*(count_dict[i]-1)/2 for i in A_set])

out = [int(count_sum-count_dict[i]+1) for i in A]
for i in out:
    print(i)