peterverebics/CodeNet_Python_118 huggingface dataset:
from collections import Counter

def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    Da = Counter(A)
    cnt = 0
    for v in Da.values():
        cnt += v*(v - 1)//2

    for i in range(n):
        print(cnt - (Da[A[i]] - 1))

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

N = int(input())
A = list(map(int,input().split()))
a = collections.Counter(A)
v = a.values()
l_v = list(v)

#合計
s = 0
for i in range(len(l_v)):
    n = l_v[i]-1
    s += n*(n+1)//2
#カウント
for i in range(N):
    print(s-(a[A[i]]-1))
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 20:55:58 2020

@author: naoki
"""

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

aC2 = [0] * (N+1)

for i in range(2,N+1):
    aC2[i] = int(i*(i-1)/2)

count = [0 for i in range(N+1)]

for i in range(N):
    count[A[i]] += 1

all_count = 0
for i in range(N+1):
    all_count += aC2[count[i]]

for i in range(N):
    print(all_count - aC2[count[A[i]]] + aC2[count[A[i]]-1])
n=int(input())
A=list(map(int,input().split()))

D={}
for i in A:
    if i in D:
        D[i]+=1
    else:
        D[i]=1
T=0
for i in D:
    T+=D[i]*(D[i]-1)//2

for i in range(n):
    print(T-(D[A[i]]-1))
import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
def cmb(n):
    if n == 1:
        return 0
    else:
        return n * (n-1) /2
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
s = 0
for i in mydict.values():
	s += cmb(i)
for i in range(N):
    a = A[i]
    x = mydict[a] - 1
    print(int(s-x))
import collections


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

    counter = collections.Counter(A)
    ans = 0

    for i in counter.values():
        ans += i * (i - 1) // 2

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


resolve()
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

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

from collections import Counter
c=Counter(a)
# print(c)
d={i:comb(j) for i,j in c.items()}
# print(d)
s=sum(d.values())
# print(s)

for i in a:
    print(s-d[i]+comb(c[i]-1))
n = int(input())
A = list(map(int, input().split()))
cnt = [0]*n
for a in A:
    cnt[a-1] += 1
ans = 0
for i in range(n):
    ans += cnt[i] * (cnt[i]-1) // 2
for a in A:
    print(ans-cnt[a-1]+1)
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
Acount = Counter(A)

total = 0
for key in Acount.keys():
    total += Acount[key] * (Acount[key] - 1) // 2

for i in range(n):
    tmp = total
    tmp -= Acount[A[i]]*(Acount[A[i]]-1) // 2
    tmp += (Acount[A[i]]-1)*(Acount[A[i]]-2) // 2
    print(tmp)
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return int(j * (j-1) / 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))
N = int(input())
nums = list(map(int, input().split()))
al = 0
part = {}
for i in range(N):
    if nums[i] in part:
        al += part[nums[i]]
        part[nums[i]] += 1
    else:
        part[nums[i]] = 1

for i in range(N):
    print(al - part[nums[i]] + 1)
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
  
s = 0
for k,v in d.items():
  s += v * (v-1) // 2
for x in a:
  c = d[x] - 1
  print(s - c)
import math

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

count = [0]*N
for i in range(N):
    count[A[i] - 1] += 1

sum = 0
for i in range(N):
    t = count[i]
    if t >= 2:
        sum += math.factorial(t) // (math.factorial(t - 2) * 2)

for i in range(N):
    t = count[A[i] - 1]
    if t > 1:
        print(sum - t + 1)
    else:
        print(sum)
from collections import Counter
import math

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

ctr = Counter(aa)

cmb2 = [0] * 200001
for n in range(2, 200001):
    r = 2
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

x = 0
for k, v in ctr.items():
    x += cmb2[v]

for a in aa:
    k = ctr[a] - 1
    print(x - k)
N=int(input())
A=list(map(int,input().split()))
ls=[0 for _ in range(N)]
for i in range(N):
  ls[A[i]-1]+=1
s=0
for i in range(len(ls)):
    m=ls[i]*(ls[i]-1)//2
    s+=m
for j in range(N):
  print(s-(ls[A[j]-1]-1))
N = int(input())
A = list(map(int, input().split()))

import collections

c = collections.Counter(A)

sum_all = sum([v * max(v - 1, 0) // 2 for k, v in c.items()])

ans = []
for a in A:
  b = c[a]
  ans_a = sum_all - (b * max(b - 1, 0) // 2) + (max(b - 1, 0) * max(b - 2, 0) // 2)
  ans.append(ans_a)
print(*ans, sep='\n')
a=int(input())
l=list(map(int,input().split()))
List=[0]*(a+1)
for i in l:
  List[i]+=1
s=0
for i in List:
  s+=int(i*(i-1)/2)
for i in l:
  print(s-List[i]+1)
s = input()
n=int(s[0])
s = input().split()
d={}
dc={}
summ=0
for i in s:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d:
    n = d[i]
    if n>1:
        e=n*(n-1)/2
        summ+=e
        dc[i]=e
    else:
        dc[i]=0
for i in s:
    n = d[i]-1
    e = n*(n-1)/2
    print(int(summ-dc[i]+e))
import collections

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

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

import collections as cl
c_A = cl.Counter(A)
sum_c_A=0
for i in c_A.keys():
	if c_A[i]>1:
		sum_c_A += c_A[i]*(c_A[i]-1)/2

for j in A:
	print(int(sum_c_A-c_A[j]+1))
from collections import Counter
N = int(input())
As = list(map(int, input().split()))

ct = Counter(As)
ans = 0
for k, v in ct.items():
    ans += (v * (v-1)) // 2

for a in As:
    c = ct[a]
    if c >= 2:
        print(ans - ((c * (c-1)) // 2) + (((c-1) * (c-2)) // 2))
    else:
        print(ans)
import collections

N = int(input())
A = list(map(int,input().split()))
c = [0]*N
p = 0


c = collections.Counter(A)

for i in range(N):
  p += (c[i+1])*(c[i+1]-1)//2

for i in range(N):
  print(p-c[A[i]]+1)
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
C=0
for i in A:
    B[i-1]+=1
for i in B:
    if i>=2:
        C+=i*(i-1)//2
for i in A:
    print(C-B[i-1]+1)
from collections import Counter

N = int(input())
A_array = list(map(int, input().split()))
Ai_dict = Counter(A_array)


def calc_comb(dct):
    num = 0
    for k,v in dct.items():
        num += v*(v-1)/2
    return int(num)


res_dict = dict([])
TotalComb = calc_comb(Ai_dict)

for n in A_array:
    if not n in res_dict.keys():
        res_dict[n] = TotalComb - Ai_dict[n]+1
    print(res_dict[n])
import collections
N = int(input())
A = list(map(int, input().split()))
wlists = collections.Counter(A)
sum_num = 0
for i in wlists:
  sum_num += wlists[i] * (wlists[i] - 1) // 2
for i in range(N):
  num = sum_num - wlists[A[i]] * (wlists[A[i]] - 1) // 2
  if wlists[A[i]] > 1:
    num += (wlists[A[i]] - 1) * (wlists[A[i]] - 2) // 2
  print(num)
if __name__ == '__main__':
    N = int(input())
    arr = [int(x) for x in input().split()]
    freq = {}
    for elem in arr:
        if elem not in freq:
            freq[elem] = 0
        freq[elem] += 1
    total = 0
    for elem, f in freq.items():
        total += (f * (f - 1)) / 2
    for elem in arr:
        print(int(total - freq[elem] + 1))
n = int(input())
a = list(map(int, input().split()))

d = [0]*n
for i in a:
    d[i-1] += 1

s = 0
for i in range(n):
    s += int(d[i]*(d[i]-1)/2)

for i in range(n):
    print(s-(d[a[i]-1]-1))
n = int(input())
ball = list(map(int,input().split()))

num = [0] * (n + 1)
data = [0] * (n + 1)

for i in ball:
    num[i] += 1

for i in range(n+1):
    data[i] = num[i] * (num[i] - 1) // 2

x = sum(data)

for i in ball:
    print(x - num[i] + 1)
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for i in a:
    cnt[i-1] += 1
total = [0] * n
for i in range(n):
    total[i] = cnt[i] * (cnt[i] - 1) // 2
total_sum = sum(total)
for i in a:
    ans = total_sum
    ans -= total[i-1]
    ans += (cnt[i-1] - 1) * (cnt[i-1] - 2) // 2
    print(ans)
import collections

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

ans=0
dic=collections.Counter(A)
keys=list(dic.keys())
values=list(dic.values())


for i in values:
    
    ans+=(i*(i-1))//2

for j in A:
    ANS=ans
    num=dic[j]
    ANS=ANS-(num-1)
    print(ANS)
from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = Counter(A)
    cnt_common = cnt.most_common()
    ans = 0
    for i in range(len(cnt_common)):
        num, val = cnt_common[i]
        ans += val * (val - 1) // 2
    for i in A:
        c = cnt[i]
        print(ans - c * (c - 1) // 2 + (c-1) * (c-2) // 2 )

if __name__ == '__main__':
    main()
n = int(input())
a = list(map(int,input().split()))
l = [0 for i in range(n+1)]
ans = 0
for i in range(n):
    l[a[i]] += 1
for i in range(n+1):
    ans += (l[i]*(l[i]-1))//2
al = []
for i in range(n):
    a0 = ans - (l[a[i]]*(l[a[i]]-1))//2 + ((l[a[i]]-1)*(l[a[i]]-2)//2)
    al.append(a0)
for i in al:
    print(i)
from collections import Counter

n = int(input())
integer = list(map(int, input().split()))
length = len(integer)
counter = Counter(integer)
keys = counter.keys()
total = 0
for key in keys:
  total += counter[key] * ( counter[key] -1 ) / 2
total = int(total)

for i in integer:
  tmp = total
  tmp -= counter[i] - 1
  print(tmp)
import sys

input = sys.stdin.readline

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

cnt = [0] * N

for a in A:
    cnt[a - 1] += 1

combination = [0] * N

for a in A:
    combination[a - 1] = cnt[a - 1] * (cnt[a - 1] - 1) // 2

total = sum(combination)

for a in A:
    c = combination[a - 1]
    b = cnt[a - 1]
    ans = total - c + c * (b - 2) // b
    print(ans)
n=int(input())
a=list(map(int,input().split()))

cnt=[0]*(n+1)
s=0

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

for i in range(1,n+1):
    if cnt[i]>=2:
        s+=cnt[i]*(cnt[i]-1)//2

for k in range(1,n+1):
    if cnt[a[k-1]]>=2:
        print(s-cnt[a[k-1]]+1)
    else:
        print(s)
n = int(input().rstrip())
line = input().rstrip().split(' ')

a = []
d = [0] * n
for i in range(n):
    num = int(line[i])
    a.append(num)
    d[num - 1] += 1

ans_list = [0] * n
for i in range(n):
    ans_list[i] = int(d[i] * (d[i] - 1) / 2)

total = 0
for i in range(n):
    total += ans_list[i]

for i in range(n):
    ans = total

    ans -= ans_list[a[i] - 1]
    num = d[a[i] - 1] - 1
    ans += num * (num - 1) / 2

    print(int(ans))
import sys
from collections import Counter
input = sys.stdin.readline

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

count = Counter(A)
sm = {}
sm2 = {}
for key, value in count.items():
    sm[key] = value*(value-1)//2
    sm2[key] = (value-1)*(value-2)//2
total = sum(sm.values())

for num in A:
    print(total - sm[num] + sm2[num])
N = int(input())
A = list(map(int,input().split()))
B = [0]*(N+1)
for a in A:
    B[a]+=1
C = [0]*(N+1)
for i in range(N+1):
    C[i] = (B[i]-1)*B[i]//2
S = sum(C)
for k in range(N):
    s = A[k]
    ans = S-C[s]
    b = B[s]-1
    print(ans+(b-1)*b//2)
from collections import Counter

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

cnt = Counter(A)

cmb = 0
for a, c in cnt.items():
    if c >= 2:
        cmb += c * (c - 1) // 2

for a in A:
    minus = 0 if cnt[a] < 2 else cnt[a] * (cnt[a]-1) // 2
    c = cnt[a] - 1
    plus = 0 if c < 2 else c * (c-1) // 2
    ans = cmb - minus + plus
    print(ans)
n = int(input())
a = [int(x) for x in input().split()]

deta = [0] * (n+1)

for i in a:
    deta[i] += 1

ans = [0] * (n+1)

for j in range(n+1):
    if deta[j] > 1:
        ans[j] = deta[j]*(deta[j]-1)/2
    else :
        ans[j] = 0

add = sum(ans)

for k in a:
    print(int(add - deta[k]*(deta[k]-1)/2 + (deta[k]-1)*(deta[k]-2)/2))
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
ans=0
for i in dic.values():
  ans+=i*(i-1)/2
for i in range(n):
  bk=dic[a[i]]
  print(int(ans-bk+1 if bk>1 else ans))
from collections import Counter
from scipy.misc import comb

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

num = 0
for v in c.values():
  if v > 1:
      num += comb(v, 2,exact=True)
for k in range(N):
  print(int(num - (c[A[k]]-1)))
# sys.stdin.readline()
import sys
input = sys.stdin.readline
import collections

N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
cnt=[]
for k in c:
    cnt.append(c[k]*(c[k]-1)//2)

s=sum(cnt)
for i in range(N):
    print(s-c[A[i]]+1)
import collections
c = {0: 0, 1: 0, 2: 1}
n = int(input())
sum = 0
for i in range(3, n + 1):
    c[i] = c[i - 1] * i // (i - 2)
cc = collections.defaultdict(int)
a = list(map(int, input().split()))
for i in a:
    cc[i] += 1
for k, v in cc.items():
    sum += c[v]
# print (c)
# print (cc)
# print (sum)
for i in range(n):
    v = cc[a[i]]
    # print (v)
    # print(c[v], c[v - 1])
    print (sum - c[v] + c[v - 1])
import sys
readline=sys.stdin.readline

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

from collections import defaultdict
dic=defaultdict(int)

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

for i in range(n):
    d = c[a[i]]
    x = (d*(d-1))//2 if d > 1 else 0
    y = ((d-1)*(d-2))//2 if d > 2 else 0
    print(s-x+y)
N = int(input())
A = list(map(int, input().split()))

B = [0]*(N+1)

for i in range (0, N):
	B[A[i]]+=1
    
C = 0
import math

for i in range (1, N+1):
	C+=math.comb(B[i],2)
    
for i in range (0, N):
	print(C+math.comb(B[A[i]]-1,2)-math.comb(B[A[i]],2))
from collections import Counter
# from scipy.special import comb
from scipy.misc import comb
n = int(input())
a = [int(x) for x in input().split()]
aa = Counter(a)
cnt = []
for i in range(1, n + 1):
    cnt.append(comb(aa[i], 2, exact=True))
s = sum(cnt)
for i in range(n):
    print(s - comb(aa[a[i]], 2, exact=True) + comb(aa[a[i]] - 1, 2, exact=True))
from collections import Counter

n = int(input())
lst = list(map(int,input().split()))
c = Counter(lst)
res = 0
for k,v in c.items():
    if v >= 2:
        res += v*(v-1)//2
for x in lst:
    if c[x]<2:
        print(res)
    else:
        print(res - (c[x] - 1))
A = int(input())
import collections
total = 0
listN = list(map(int,input().split()))
dic = collections.Counter(listN)
listB = list(dic.values())
for i in listB:
    total += i * (i-1) // 2
dic_keys = list(dic.keys())
dic_values = list(dic.values())
for i in range(len(dic_values)):
    B = dic_values[i]
    dic_values[i] = total-(B-1)
dic = {}
for i in range(len(dic_values)):
    dic[dic_keys[i]] = dic_values[i]
for i in listN:
    print(dic[i])
N = int(input())
A = list(map(int, input().split()))
dic1 = {}
dic2 = {}
for i in range(N):
  if A[i] in dic1:
    dic1[A[i]] += 1
  else:
    dic1[A[i]] = 1
ans = 0
for v in dic1.values():
  ans += (v*(v-1))//2
for j in range(N):
  w = dic1[A[j]]
  v = w-1
  comb = ans -(w*(w-1))//2 + (v*(v-1))//2
  print(comb)
import math
from collections import Counter

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

def cmb(r,k):
  if r < k: return 0
  return math.factorial(r) // math.factorial(r-k) // math.factorial(k)

c = Counter()
for a in A:
  c[a] += 1
al = 0
for v in c.values():
  al += cmb(v,2)

for k in range(N):
  print(al - (c[A[k]]-1))
n = int(input())
a = list(map(int,input().split()))
raw = [0 for _ in range(3*10**5)]
for x in a:
  raw[x] += 1
ans = 0
for y in raw:
  ans += y * (y-1) // 2
for x in a:
  tmp = int(ans)
  tmp -= raw[x] - 1
  print(tmp)
import collections
n=int(input())
a=list(map(int, input().split(' ')))
c = collections.Counter(a)

def n_c_2(val):
  ret = 0
  if val > 1:
    ret = (val)*(val-1)//2
  return ret

org_nc2 = {}
org_minus1_nc2 = {}
sumall = 0
for k in list(c.keys()):
  org_nc2[k] = n_c_2(c[k])
  org_minus1_nc2[k] = n_c_2(c[k] - 1)
  sumall += org_nc2[k]
for d in a:
  ans = sumall - org_nc2[d] + org_minus1_nc2[d]
  print (ans)
N=int(input())
L=list(map(int,input().split()))
S=sorted(L)
D={}
c=1
t=0
for i in range(N-1):
  if S[i]==S[i+1]:
    c+=1
  else:
    D[S[i]]=c
    c=1
D[S[N-1]]=c

for i in D.values():
   t+=i*(i-1)//2 
for i in range(N):
  print(t-(D[L[i]]-1))
from collections import Counter

n = int(input())
*arr, = map(int, input().split())


cnt = Counter(arr)

ans = 0

total = 0

for k, v in cnt.items():
    if v > 1:
        total += v * (v - 1) // 2


for v in arr:
    print(total - cnt.get(v, 1) + 1)
def main():
  N = int(input())
  A = list(map(int, input().split()))

  counts = [0] * N

  for v in A:
    counts[v-1] += 1

  total = 0

  for v in counts:
    if(v > 1):
      total += v * (v - 1) // 2

  for v in A:
    n = counts[v-1]

    diff = n * (n - 1) // 2 - (n-1) * (n-2) // 2

    print(total - diff)


if __name__ == "__main__":
  main()
# from collections import deque
from collections import Counter
# from scipy.misc import comb
# from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
S = 0
"""
for key in C:
    S += comb(C[key], 2, exact=True)
"""
for i in C.keys():
    S += C[i]*(C[i]-1)//2

for k in range(n):
    A = a[k]
    print(S - C[A] + 1)
def f(m):
    return 0 if m < 2 else m * (m-1) // 2

def solve(n, a):
    D = {}
    for x in a:
        if not x in D:
            D[x] = 0
        D[x] += 1
    total = 0
    for x, num in D.items():
        total += f(num)
    for x in a:
        num = D[x]
        print(total - f(num) + f(num-1))

n = int(input())
a = list(map(int, input().split()))
solve(n, a)
from collections import Counter
n = int(input())
s = [int(i) for i in input().split()]

s_set = set(s)

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

for i in s:
    x = counted[i]
    print(int(ans - x + 1))
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

s = 0
d = defaultdict(int)
for e in A:
    d[e] += 1
k = len(set(d))

for v in d.values():
    s += v*(v-1)//2

for e in A:
    if d[e] > 1:
        res = s - (d[e]-1)
        print(res)
    else:
        print(s)
import collections
n = int(input())
a = list(map(int,input().split()))
aa  = collections.Counter(a)
aakey = list(aa.keys())     
aavalue = list(aa.values())     
ans = 0
for i in range(len(aavalue)):
         ans += (aavalue[i] * (aavalue[i] - 1))//2
for i in range(n):
         val = aa[a[i]]
         print(ans-(val-1))
from collections import Counter


def choose(n, r):
    x, y = 1, 1
    for i in range(r):
        x *= n - i
        y *= i + 1
    return x // y


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

ctr = Counter(a)

b = 0
for cnt in ctr.values():
    b += choose(cnt, 2)

ret = []
for x in a:
    cnt = ctr[x]
    res = b - choose(cnt, 2) + choose(cnt - 1, 2)
    ret.append(res)

print(*ret, sep='\n')
n=int(input())
l=list(map(int,input().split()))
d={}
ans=0
for i in l:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d.keys():
    x=d[i]*(d[i]-1)//2
    ans+=x
for i in l:
    if d[i]>2:
        print(ans-(d[i]*(d[i]-1)//2)+((d[i]-1)*(d[i]-2)//2))
    elif d[i]==2:
        print(ans-1)
    else:
        print(ans)
N = int(input())
A = tuple(map(int, input().split()))

d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

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

for k in range(0, N):
    ak = A[k]
    print(counts - d[ak] + 1)
import collections
N=int(input())
A=list(map(int,input().split()))

cc=collections.Counter(A)
L=list(cc.values())

total=0
for i in range(len(L)):
    total+=L[i]*(L[i]-1)//2

ans=0
for a in A:
    temp=cc[a]*(cc[a]-1)//2
    ttemp=(cc[a]-1)*(cc[a]-2)//2
    ans=total-temp+ttemp
    print(ans)
N = int(input())
A = list(map(int, input().split()))

di = {}
B = set(A)
for b in B:
  di[b] = 0
total = 0
for a in A:
  di[a]+=1
for v in di.values():
  total += v*(v-1)//2
#print(di.values(),total)
ans = []
for a in A:
  ans.append(total-di[a]+1)
print(*ans,sep='\n')
n = int(input())
A = list(map(int, input().split()))
C = {}
for a in A:
    if a in C:
        C[a] += 1
    else:
        C[a] = 1

s = int(sum(c * (c - 1) / 2 for c in C.values()))
for a in A:
    print(int(s - C[a] + 1))
import sys,math,copy,queue,itertools
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
N = int(input())
A = LI()

CA = [0 for _ in range(N+1)]
for i in range(N):
    CA[A[i]] += 1

tc = 0
for i in range(1,N+1):
    tc += CA[i] * (CA[i]-1) // 2

for i in range(N):
    ans = tc
    cnt = CA[A[i]]
    if cnt > 1:
        ans -= cnt * (cnt - 1) // 2 - (cnt - 1) * (cnt - 2) // 2
    print (ans)
input()
from collections import Counter
aa = list(map(int, input().split()))
dic = Counter(aa)

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

for a in aa:
    print(int(total - dic[a] + 1))
n = int(input())
a_l = list(map(int,input().split()))

a_dict = {}
for num in a_l:
    if num in a_dict:
        a_dict[num] += 1
    else:
        a_dict[num] = 1

comb_dict = {}
comb_tot = 0
for num in a_dict:
    comb_dict[num] = a_dict[num]*(a_dict[num]-1)//2
    comb_tot += comb_dict[num]

for num in a_l:
    ans = comb_tot - (a_dict[num]-1)
    print(ans)
N = int(input())
A = list(map(int, input().split()))

B = [0]*(N+1)
for l in range(N):
    B[A[l]] += 1
ans = 0
for i in range(N+1):
    ans += int(B[i] * (B[i]-1) / 2)
for k in range(N):
        print(ans - B[A[k]] + 1)
from collections import Counter

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

MX = sum(v*(v-1) for v in C.values())//2
for i in range(N):
    print(MX-C[A[i]]+1)
import collections
import numpy as np

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

c=collections.Counter(A)
kazu=list(c.values())
a=np.array(kazu)
sn=a*(a-1)/2
s=sum(sn)
for k in range(N):
    sub=c[A[k]]-1
    print(int(s-sub))
import collections
n = int(input())
a = list(map(int, input().split()))

c = dict(collections.Counter(a))

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

for i in a:
    temp = c[i] - 1
    ans = (temp * (temp - 1)) // 2
    ans += sum
    ans -= (c[i] * (c[i] - 1)) // 2
    print(ans)
n = int(input())
a = list(map(int,input().split()))
d = {}
ans = 0
for i in a:
    d[i] = d.get(i,0) + 1
for key in d:
    ans += d[key]*(d[key]-1)//2
for i in a:
    print(ans + 1 - d[i])
n = int(input())
l = list(map(int,input().split()))
d = {}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1
cp = 0
for i in d.values():
    cp+= i*(i-1)//2
for i in l:
    print(cp-d[i]+1)
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
cnt_A = Counter(A)
ans = sum([k * (k - 1) // 2 for k in cnt_A.values()])

for i in range(N):
    print(ans - (cnt_A[A[i]] - 1))
import collections

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

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

counter = collections.Counter(A)

for val in counter.values():
    all_comb += combinations_count_two(val)

for i in A:
    ans = all_comb - combinations_count_two(counter[i]) + combinations_count_two(counter[i] - 1)
    print(ans)