peterverebics/CodeNet_Python_118 huggingface dataset:
import collections

n = int(input())
a = list(map(int,input().split()))
d = collections.Counter(a)
s = sum([i*(i-1)//2 for i in d.values()])

for j in a:
    print(s-d[j]+1)
N = int(input())
A = list(map(int,input().split()))
import collections as col
 
num_list = set(A)
ca = col.Counter(A)

num = 0

for i in num_list:
    if ca[i] == 1:
        continue
    else:
        num += (ca[i]*(ca[i]-1))//2
        
for i in A:
    ans = num - (ca[i]-1)
    print(ans)
n=int(input())
ls=list(map(int,input().split()))
dic={}
for i in ls:
    dic.setdefault(i,0)
    dic[i]+=1
org=0
for v in dic.values():
    org += v*(v-1)//2

for i in ls:
    v = dic[i]
    print(org-(v*(v-1)//2)+((v-1)*(v-2)//2))
import collections
# import time
#start = time.time()



x=int(input())
a=list(map(int,input().split()))
 
c=collections.Counter(a)
#print(c)

num=0
for i in c.values():
    num += i*(i-1)/2
    
for i in range(x):
    print(int(num-c[a[i]]+1))
import math

N=int(input())
A = list(map(int,input().split()))
cnt=[0]*(N+1)
for i in range(0,N):
	cnt[A[i]-1]+=1
ans=0
for i in range(0,N+1):
	if cnt[i]==0:
		ans+=0
	else:
		ans+=cnt[i]*(cnt[i]-1)//2

for i in range(0,N):
	point=A[i]
	deff=(cnt[point-1]*(cnt[point-1]-1))//2-((cnt[point-1]-1)*(cnt[point-1]-2))//2
	print(ans-deff)
import collections as cl
import math


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


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

cnt = cl.Counter(A)
cnt_l = [0] * 200000
for a in A:
    cnt_l[a] += 1

ans = 0
for v in cnt_l:
    ans += combinations_count(v, 2)

for a in A:
    print(ans - cnt_l[a] + 1)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
val = list(cnt.values())
s = 0
for i in val:
  s += i*(i-1)//2
for i in A:
  print(s-(cnt[i]-1))
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    C = collections.Counter(A)

    ans = 0
    for v in C.keys():
        ans += C[v] * (C[v] - 1) // 2

    for a in A:
        tmp = ans
        tmp -= C[a] * (C[a] - 1) // 2
        tmp += (C[a] - 1) * (C[a] - 2) // 2
        print(tmp)


if __name__ == '__main__':
    main()
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dict = defaultdict(int)
ans = 0
for k in range(N):
    a = A[k]
    ans += dict[a]
    dict[a] += 1

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

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


kosu = Counter(A)

tempSum = 0
for v in kosu.values():
    tempSum += v * (v - 1) // 2



for a in A:
    print(tempSum - kosu[a]+1)
N = int(input())
l = list(map(int,input().split()))

d = {}


for i in range(N):
    if l[i] in d:
        d[l[i]] += 1
    else:
        d[l[i]] = 1

max_comb = 0
for v in d.values():
    max_comb += v * max(0, (v-1)) /2

def get_n(x):

    return int(max_comb - d[x] +1)


for e in l:
    print(get_n(e))
n = int(input().strip())
A = list(map(int, input().strip().split()))

cnt=[0]*(n+1)
for a in A:
    cnt[a]+=1

total=0
for c in cnt:
    total+=c*(c-1)
total//=2

for k in range(n):
    print(total-cnt[A[k]]+1)
from collections import Counter
N, li = int(input()), list(map(int, input().split()))
cnt_dict, cnt_total = Counter(li), 0
for i in cnt_dict.items():
    cnt_total += i[1] * (i[1]-1) // 2
for k in range(N):
    buf = cnt_dict[li[k]]
    print(cnt_total - buf*(buf-1)//2 + (buf-1)*(buf-2)//2)
n = int(input())
a = list(map(int, input().split()))
data = [0 for _ in range(2*10**5+1)]
for x in a:
    data[x] += 1

ans = 0
for i in range(2*10**5):
    ans += data[i]*(data[i]-1)//2

for x in a:
    print(ans - (data[x]-1))
n = int(input())
b = list(map(int,input().split()))
balls = [0]*(n+1)
for i in range(n):
    balls[b[i]] += 1

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


for i in range(n):
    bb = balls[b[i]]
    print(su - bb+1)
# n choose 2
def binomial_2(n):
    if n < 2:
        return 0
    else:
        return n * (n - 1) // 2

N = int(input())
A = [int(x) for x in input().split()]

dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

tot = 0
for num in dict.values():
    tot += binomial_2(num)

for i in range(N):
    print(tot - dict[A[i]] + 1)
from collections import *
from math import *
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
S = 0

for k,v in C.items():
  S+=comb(v,2)

for a in A:
  print(S-(comb(C[a],2)-comb(C[a]-1,2)))
from collections import defaultdict

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

counter = defaultdict(list)
for i in range(len(nums)):
  counter[nums[i]].append(i)

total = 0
for _,v in counter.items():
  v = len(v)
  total += (v * (v-1)) // 2

for k in range(len(nums)):
  t = len(counter[nums[k]])
  print(total - t*(t-1)//2 + (t-1)*(t-2)//2)
import collections
def I(): return int(input())
def LI(): return list(map(int,input().split()))
##################################################
N = I()
A = LI()
count = collections.Counter(A)
sum = 0
for x in count.values():
    sum += x*(x-1)//2
for x in A:
    print(sum-(count[x]-1))
import collections
n = int(input())
a = list(map(int,input().split()))

aset = set(a)
col = collections.Counter(a)
N = len(aset)
s = 0
for i in range(N):
    k = col[aset.pop()]
    if k>1:
        s += k*(k-1)//2
for i in range(len(a)):
    l = col[a[i]]
    if (l-1)>1:
        c1=l*(l-1)//2
        c2=(l-1)*(l-2)//2
        print(s-c1+c2)
    else:
        c1=l*(l-1)//2        
        print(s-c1)
n = int(input())
a = tuple(map(int,input().split()))
from collections import Counter
c = Counter(a)
ans  = 0
for i in c.values():
    ans += (i*(i-1))//2
for i in a:
    print(ans-c[i]*(c[i]-1)//2+(c[i]-1)*(c[i]-2)//2)
import math
from collections import Counter

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return (a*(a-1))//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
#for i in a:
#    d=mycounter(d,i)
dd=Counter(a)
#print(d)
p=0
for i in dd.values():p+=ABC159D(i)
print('\n'.join(map(str,[p-dd[i]+1 for i in a])))
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = dict(Counter(a))
ans = 0
for v in c.values():
    ans += v*(v-1)//2
for i in range(n):
    print(ans-c[a[i]]+1)
import collections
import math

def c2(x):
  c = math.factorial(x) // (math.factorial(x-2)*2)
  return c

n = int(input())

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

adic = collections.Counter(a)

cnt = 0

for i in adic:
  num = adic[i]
  if num > 1:
    cnt += c2(num)

for i in a:
  num = adic[i]
  if num == 1:
    print(cnt)
  else:
    print(cnt - (num-1))
import copy
n=int(input())
a=list(map(int,input().split()))
ans=0
b=copy.copy(a)
a.sort()
cnt=1
num=[0]*n
for i in range(n-1):
	if a[i]==a[i+1]:
		cnt+=1
	else:
		num[a[i]-1]=cnt
		ans+=cnt*(cnt-1)//2
		cnt=1
ans+=cnt*(cnt-1)//2
num[a[-1]-1]+=cnt
for i in range(n):
	x=num[b[i]-1]
	if x<=1:
		print(ans)
	else:
		e=ans-x*(x-1)//2+(x-1)*(x-2)//2
		print(e)
from collections import Counter 
N = int(input())
A = list(map(int, input().split()))
c_A = Counter(A)
all =sum( [i*(i-1)//2 for i in c_A.values()] )

for i in range(N):
    ans =all -( c_A[A[i]] -1)
    print(ans)
n = int(input())
a = list(map(int, input().split()))
r = [0 for i in range(n+1)]
t = [0 for i in range(n+1)]
for ai in a:
    r[ai] += 1
def c2(n):
    return n * (n-1) // 2
t = list(map(lambda i:c2(i-1), r))
r = list(map(c2, r))
s = sum(r)
for i in range(n):
    l = a[i]
    print(s - r[l] + t[l])
from collections import Counter

N = int(input())
*l, = map(int, input().split())
c = Counter(l)

v = 0
for i in c.values():
    v += i*(i-1)//2

for i in l:
    print(v-(c[i]*(c[i]-1)//2)+((c[i]-1)*(c[i]-2)//2))
n = int(input())
a = list(map(int, input().split()))

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1
s = sum([v * (v - 1) // 2 for _, v in cnt.items()])
dic = { k: s - (v - 1) for k, v in cnt.items() }
ans = "\n".join(map(lambda ai: str(dic[ai]), a))
print(ans)
from math import factorial
n=int(input())
cnt=[0]*(n+1)
lst=list(map(int,input().split()))
for i in lst:
    cnt[i]+=1
ans=0
for i in range(n+1):
    p=cnt[i]
    if p>=2:
        ans+=factorial(p)//factorial(p-2)//2
for i in range(n):
    print(ans-cnt[lst[i]]+1)
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)

ans = 0
for i in C.values():
    ans += int(0.5* i * (i-1))
for j in A:
    print(ans-C[j]+1)
from collections import defaultdict, Counter

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

d = defaultdict(int)
for a in A:
    d[a] += 1

all = 0
for val in d.values():
    all += val * (val - 1) / 2

all = int(all)
val_cnt = Counter(A)
for a in A:
    print(all - (val_cnt[a] - 1))
import collections

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

A_counter= collections.Counter(A)

_sum = 0
for count in A_counter:
    _sum += (A_counter[count]* (A_counter[count]-1)) // 2

for k in range(N):
    l = (A_counter[A[k]]) *  (A_counter[A[k]]-1)//2
    m = (A_counter[A[k]]-1) *  (A_counter[A[k]]-2)//2
    # print(_sum)
    # print(c_a)
    print(_sum -l + m)
N=int(input())
a=[int(x) for x in input().split()]
import collections
c=collections.Counter(a)
d=list(c.keys())
def nc2(x):
    return x*(x-1)//2
ans0=0
for i in d:
    ans0+=nc2(c[i])
for i in range(len(a)):
    print(ans0-(c[a[i]]-1))
from collections import Counter, defaultdict, deque

N, = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]


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


counts = Counter(A)
total = 0
for x, count in counts.items():
    total += choose2(count)

for x in A:
    old = choose2(counts[x])
    new = choose2(counts[x] - 1)

    print(total - old + new)
n=int(input())
t=[int(i) for i in input().split()]
cnt=[0]*(n+1)
for i in t:
	cnt[i]+=1
	
s = 0
for i in cnt:
	s+=i*(i-1)//2

for i in t:
	g = cnt[i]
	ans = s - g*(g-1)//2 + (g-1)*(g-2)//2
	print(ans)
n = int(input())
a = list(map(int, input().split()))

from collections import Counter
count = Counter(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in list(count.values()):
    total += choose2(i)

for i in a:
    s = count[i]
    print(total - choose2(s) + choose2(s-1))
import collections
N = int(input())
arr = list(map(int, input().split()))
count = collections.Counter(arr)
total = 0
for i in count.values():
    total += (i*(i-1)/2)
for i in arr:
    print(int(total- count[i]+1))
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  4 19:37:51 2020

@author: Kanaru Sato
"""

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

for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

count = 0
for nums in dic:
    count += (dic[nums]*(dic[nums]-1))//2

for i in range(n):
    print(count-(dic[a[i]]-1))
from itertools import combinations
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
ans=0
for i in range(N):
    B[A[i]]+=1
for i in range(1,N+1):
    ans+=B[i]*(B[i]-1)//2
for k in range(0,N):
    print(ans-B[A[k]]+1)
n = int(input())
a = list(input().split(" "))
b = [0 for i in range(n+1)]
for i in range(n):
    b[int(a[i])] += 1
sum = 0
for j in range(n+1):
        sum += b[j]*(b[j]-1)/2
for i in range(n):
    print(int(sum)-b[int(a[i])]+1)
import collections
n = int(input())
a = list(map(int,input().split()))
 
u = collections.Counter(a)
 
sume = 0
for i in u.values():
    sume += int(i*(i-1)/2)
 
for k in range(n):
    s = u[a[k]]
    print(sume-s+1)
N = int(input())
A = list(map(int, input().split()))
num_A = [0] * N

for i in A:
    num_A[i-1] += 1

ans = 0
for i in num_A:
    ans += 0.5 * (i - 1) * i
        
for i in range(N):
    print(int(ans - (num_A[A[i]-1] - 1)))
from collections import Counter as C
N = int(input())
A = list(map(int,input().split()))
c = C(A)
s = 0
for i in c.values():
    s += i*(i-1)//2
for j in A:
    print(s-(c[j]-1))
import copy

N = int(input())

As = list(map(lambda i: int(i), input().split()))

ns = [0 for i in range(N)]

for a in As:
    ns[a-1] += 1

def get_comb(arr):
    res = 0
    for a in arr:
        if a == 0:
            continue
        res += a*(a-1)/2
    return int(res)

ba = get_comb(ns)

for a in As:
    print(ba - get_comb([ns[a-1]]) + get_comb([ns[a-1]-1]))
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)
import copy
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
c=[0]*n
d=[0]*n
for i in range(n):
 b[a[i]-1]+=1
for i in range(n):
 c[i]=b[i]*(b[i]-1)//2
 if b[i]==0:
  continue
 else:
  d[i]=(b[i]-1)*(b[i]-2)//2
sumc=sum(c)
for i in range(n):
 print(sumc-c[a[i]-1]+d[a[i]-1])
cnt=0
#print(b,c,d)
from collections import Counter
n = int(input())
*a, = map(int, input().split())
c = Counter(a)
s = sum(i*(i-1)//2 for i in c.values())
for k in range(n):
    print(s-c[a[k]]+1)
#!/usr/bin/env python3
from collections import Counter

_, *a = map(int, open(0).read().split())
c = Counter(a)
s = sum(i * (i - 1) // 2 for i in c.values())
for i in a:
    print(s - c[i] + 1)
N = int(input())
A = list(map(int,input().split()))

import collections
import math

dicA = collections.Counter(A)

total = 0
for x in list(dicA.values()):
  if x != 1:
    total += math.factorial(x) // (math.factorial(x - 2)*2)

for i in range(N):
  print(total - dicA[A[i]] +1)
def cmb(n):
    if n < 2:
        return 0
    else:
        return (n*(n-1)/2)

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

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i])

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])
    tmp = S + S_dif
    print(int(tmp))
from collections import Counter

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

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

from collections import Counter
C=Counter(A)
ANS=0
for i in C.values():
    ANS+=i*(i-1)//2

for a in A:
    k=C[a]

    print(ANS-(k*(k-1)//2)+((k-1)*(k-2)//2))
n = int(input())
a = list(map(int,input().split()))

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

cnt = 0
for i in num_list:
    cnt += i*(i-1)/2

for i in a:
    print(int(cnt +1 -num_list[i]))
import collections

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

c = collections.Counter(A)

total = sum([ c[n]*(c[n] -1) //2 for n in c])

for k in range(N):
    n = A[k]
    print( total - c[n]*(c[n]-1) // 2 + (c[n] - 1)*(c[n] -2) //2)
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))
from collections import Counter

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

# 先にk番目を抜かない場合を求めておく
ans = 0
for n in c.values():
    ans += n*(n-1)//2

# k番目を抜く場合の差分を加える
for k in range(N):
    m = c[A[k]]
    print(ans - (m-1))  # -m*(m-1)//2 + (m-1)*(m-2)//2
from collections import Counter

N = int(input())

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

dic = Counter(A)

res = 0
for i, cnt in dic.items():
    res += cnt*(cnt-1)//2


for i in A:
    temp = dic[i]-1
    print(res-temp)
n = int(input())
A = list(map(int, input().split()))

CNT = [0] * (n + 1)
for a in A:
    CNT[a] += 1

x = sum(cnt * (cnt - 1) // 2 for cnt in CNT if cnt)

for a in A:
    print(x - (CNT[a] - 1))
import collections
n = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = B.copy()
total = 0
for i in B.values():
    total += i*(i-1)//2
for i in A:
    print(total - B[i]+1)
import collections

#Input
n = int(input())
l_a = list(map(int, input().split()))

#Process
d_c = collections.Counter(l_a)
l_c = list(d_c.values())

#N個から選ぶ方法
o = 0
for i in range(len(l_c)):
    if(l_c[i] != 1):
        o += int((l_c[i] - 1) * l_c[i] / 2)

#Output
for i in range(n):
    print(o - d_c[l_a[i]] + 1)
import collections
n = int(input())
a_list = list(map(int,input().split()))
c=collections.Counter(a_list)
result=0

for i in c.values():
    result+=i * (i - 1)//2

for a in a_list:
    minus=-(c[a]) * (c[a]-1)//2
    plus=(c[a]-1) * (c[a]-2)//2
    print(result + minus + plus)
N = int(input())
A = list(map(int,input().split()))
A_set = list(set(A))
l = [0]*(N+2)
ans = [0]*(N+2)
for a in A:
  l[a]+=1
comb = [0]*(N+2)
for i in range(2,N+1):
  comb[i] = i*(i-1)//2
  
for i in range(2,N+1):
  ans[i]=comb[i]-comb[i-1]
  
total = 0
for a in A_set:
  total += comb[l[a]]

for a in A:
  print(int(total-ans[l[a]]))
n = int(input())
a = list(map(int, input().split()))
import collections
c = collections.Counter(a)


al = 0
for v in c.values():
    al += v*(v-1)/2


for aa in a:
    print(int(al - c[aa]+1))
n = int(input())
ai = list(map(int,input().split()))
dic = {}
su = 0
for a in ai:
    dic[a] = 0
for a in ai:
    dic[a] += 1
for i , x in enumerate(dic):
    su += dic[x]*(dic[x]-1)/2
for a in ai:
    print(int(su-dic[a]+1))
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (n + 1)
for i in range(n):
    cnt[a[i]] += 1
conb1, conb2 = [], []
for i in range(n + 1):
    conb1.append(cnt[i] * (cnt[i] - 1) // 2)
    if cnt[i] == 0:
        conb2.append(0)
    else:
        conb2.append((cnt[i] - 2) * (cnt[i] - 1) // 2)
sumall = sum(conb1)
for i in range(n):
    ans = sumall - conb1[a[i]] + conb2[a[i]]
    print(ans)
import collections

N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
C=sum([x*(x-1)//2 for x in B.values()])

for i in A:
  temp=B[i]
  print(C-(temp*(temp-1)//2-(temp-1)*(temp-2)//2))
kazu = dict()
N=input()
A = [int(i) for i in input().split()]
for a in A:
    if a in kazu:
        kazu[a] += 1
    else:
        kazu[a] = 1

tori = 0
for k in kazu.values():
    tori += k*(k-1)//2
for a in A:
    print(tori - kazu[a]+1)
n = int(input()) 
A = [int(x) for x in input().split()]

L = {}
for i in A:
    if i in L:
        L[i] += 1
    else:
        L[i]= 1

L2 = []
for i in L:
    L2.append(L[i]*(L[i]-1)/2)
    
res = sum(L2)
for i in A:
    print(int(res - L[i] + 1))
N = int(input())
S = list(map(int, input().split()))

data = [0]*(N+1)
for num in S:
    data[num] += 1

ans = 0
for num in data:
    if num < 2:
        continue
    ans += num*(num-1)//2

for num in S:
    if data[num] < 2:
        print(ans)
    else:
        print(ans-data[num]+1)
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
H = Counter(A)
K = {}

for k,v in H.items():
    K[k] = v*(v-1)//2
total = sum(K.values())

for i in A:
    print(total - K[i] + (H[i] - 1)*(H[i]-2)//2)
#!/usr/bin/env python3
from collections import Counter

from scipy.special import comb

_, *a = map(int, open(0).read().split())
c = Counter(a)
s = sum(comb(i, 2, exact=True) for i in c.values())
for i in a:
    print(s - c[i] + 1)
n = int(input())
a = list(map(int, input().split()))
num = [0] * n
cnt = 0

for i in a:
    num[i - 1] += 1

for i in num:
    cnt += i * (i - 1)//2

for i in range(n):
    tmp = num[a[i]-1]
    ans = cnt - (tmp-1)
    print(ans)
import sys
from collections import Counter

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

A_count = Counter(A)


allsum = 0

for i in (A_count.values()):
    allsum += (i*(i-1))//2


for j in A:
    counter_num = A_count[j]
    difference = (((counter_num)*(counter_num-1))//2) - (((counter_num-1)*(counter_num-2))//2)
    print(allsum - difference)
import math
from collections import Counter


def comb(x, y):
    if x - y < 0:
        return 0
    return math.factorial(x) // (math.factorial(y) * math.factorial(x - y))


N = int(input())

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


c = Counter()

ints = list()
for a in A:
    ints.append(a)
    c[a] += 1

t = 0
for a in set(ints):
    t += comb(c[a], 2)

for a in ints:
    print(t - (c[a] - 1))
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

n = 0
B = set(A)

C = Counter(A)

for i in C.keys():
    n += C[i] * (C[i]-1) // 2

for i in range(N):
    a = A[i]
    print(n - C[a] + 1)
def n_c_2(n):
    if n < 1:
        return 0
    else:
        return n * (n - 1) // 2

N = int(input())
A = [int(x) for x in input().split()]

n_balls = [0 for _ in A]
for a_i in A:
    n_balls[a_i - 1] += 1

n_combinations = [n_c_2(n) for n in n_balls]
total_combinations = sum(n_combinations)

for i, a_i in enumerate(A):
    diff = n_c_2(n_balls[a_i - 1]) - n_c_2(n_balls[a_i - 1] - 1)
    print(total_combinations - diff)
n = int(input())

def f(x):
    res = x * (x - 1) // 2

    return max(0, res)


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

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

counts = [0] * (n + 1)

for x in a:
    counts[x] += 1

s = sorted(counts)
m1 = s[-1]
m2 = s[-2]


max_result = 0
for k in range(1, n + 1):
    max_result += f(counts[k])

for k in range(1, n + 1):
    kk = a[k - 1]
    print(max_result - f(counts[kk]) + f(counts[kk] - 1))
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for a in A:
  d[a] += 1

keisan = dict()

for key,value in d.items():
  keisan[key] = (value * (value-1)) // 2
res = sum(keisan.values())
# print(d,keisan)
for a in A:
  # 合計から必要なくなった部分を除去する
  val = d[a]
  
  print(res - ((val*(val-1))//2) +(((val-1)*(val-2))//2)  )
import math
N = int(input())
K = list(map(int,input().split()))
hashmap = {}
for k in K:
  if k not in hashmap:
    hashmap[k] = 0
  hashmap[k]+=1
total = 0
for v in hashmap.values():
  if v>=2:
  	total+=math.factorial(v) // (math.factorial(v - 2) * 2)

for k in K:
  print(total-(hashmap[k]-1))
from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]
C = Counter(A)
ans = {}
cal = sum([b*(b-1)//2 for b in C.values()])
for a, b in C.items():
    ans[a] = cal - (b-1)
for a in A:
    print(ans[a])
n=int(input())
arr= list(map(int,input().split(' ')))

count={}
for i in range(len(arr)):
    val=arr[i]
    if val not in count.keys():
        count[val]=1
    else:
        count[val]+=1

big_sum=0
for d in count.keys():
    big_sum+= count[d]*(count[d]-1)/2

for a in arr:
    if a in count.keys():
        if count[a]==1:
            print(int(big_sum))
        else:
            print(int(big_sum-(count[a]-1)))
n=int(input())
l=list(map(int,input().split()))
d={};an=0
for i in l:
  d[i]=d.get(i,0)+1
for i in d.values():
  an+=i*(i-1)//2
for j in l:
  i=d[j];print(an+(i-1)*(i-2)//2-i*(i-1)//2)
n = int(input())
l = list(map(int, input().split()))

from collections import Counter
c = Counter(l)

total = 0
for i in c.values():
    if i != 1:
        total += i*(i-1)//2 # 組み合わせ_重複なしの数の公式を整理

for j in range(n): # 影響する部分のみ再計算(引く→足す)する
    tmp = c[l[j]]
    before = tmp*(tmp-1)//2 
    after = (tmp-1)*(tmp-2)//2
    print(total - before + after)
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
# print(d)
ans = 0
for key in d:
    ans += d[key]*(d[key]-1)//2

for i in range(N):
    print(ans - (d[A[i]] - 1))
import collections
n = int(input())
a = [int(i) for i in input().split()]
c = collections.Counter(a)
ans = 0
for i in c.keys():
    ans += (c[i]) * (c[i] - 1) / 2
for i in a:
    print(int(ans - c[i] + 1))
#python3
from collections import Counter
def C2(x):
    return x*(x-1)//2

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    d = Counter(a) 
    pans = 0
    for v in d.values():
        pans += C2(v)

    for k in range(n):
        p = pans
        val = d[a[k]]
        p = p - C2(val) + C2(val-1)
        print(p)
main()