peterverebics/CodeNet_Python_118 huggingface dataset:
import math
import collections

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

C = collections.Counter(A)
csum = 0

for c in C.values():
    if c > 1:
        csum += combinations_count(c, 2)

for a in A:
    print(csum - (C[a]-1))
from collections import Counter

n = int(input())
a = [int(x) for x in input().split()]
s = 0
c = Counter(a)
# print(c)
for i in c.values():
    s += i*(i-1)// 2
    
# print(s)
for j in range(n):
    t = c[a[j]]
    print(s-t+1)
def cmb(n,r):#r==2固定
    return n*(n-1)//2

def main():
    import sys
    from collections import defaultdict

    N=int(sys.stdin.readline())
    AL=list(map(int,sys.stdin.readline().split()))
    dic=defaultdict(int)
    for a in AL:
        dic[a]+=1


    K=[cmb(v,2) for k,v in dic.items()]
    total=sum(K)

    for i in range(N):
        a=dic[AL[i]]
        print(total-cmb(a,2)+cmb(a-1,2))

main()
# 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(map(str, answer)))
import sys
import collections
ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n = ri()
a = rl()
c = collections.Counter(a)
t = 0
for v in c.values():
    t += v*(v-1)//2

for i in a:
    print(t-c[i]+1)
N = int(input())
d = {}
for i in range(1,N+1):
    d[i] = 0
A = list(map(int,input().split()))
for i in range(N):
    a = A[i]
    d[a] += 1
s = 0
for i in range(1,N+1):
    x = d[a]
    s += (x*(x-1))//2
for i in range(N):
    y = A[i]
    z = s + 1 - d[y]
    print(z)
n = int(input())
a = list(map(int,input().split()))
count = [0 for i in range(n+1)]
ans = 0
for i in range(n):
    count[a[i]] += 1
for i in range(n):
    ans += count[i]*(count[i]-1)//2
for i in range(n):
    num = count[a[i]]

    print(ans-(num*(num-1)//2)+(num-1)*(num-2)//2)
n = int(input())
a =list(map(int,input().split()))
d = [0]*(n+1)
answer = 0
for i in range(n):
  d[a[i]]+=1
for j in range(n):
  answer+= int((d[j]*(d[j]-1))/2)
for k in range(n):
  print(answer+1-(d[a[k]]))
n=int(input())
array=list(map(int,input().split()))
tot=0
x=0
count=[0]*10000000
for c in range(n):
  count[array[c]]+=1
for c in range(n):
  if x<array[c]:
    x=array[c]
    t=count[array[c]]
    tot+=int(t*(t-1)/2)
for i in range(n):
  ans=tot
  l=count[array[i]]
  ans-=int(l*(l-1)/2)
  ans+=int((l-1)*(l-2)/2)
  print(ans)
N=int(input())
A=list(map(int,input().split()))
total=0
A_li=[0]*(1+2*10**5)
for i in range(N):
    A_li[A[i]]+=1
for i in range(1+2*10**5):
    total+=A_li[i]*(A_li[i]-1)//2
for i in range(1,N+1):
    if A_li[A[i-1]]>1:
        print(total-(A_li[A[i-1]]-1))
    else:
        print(0)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)

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

for k in range(N):
    print(tmp-B[A[k]]+1)
from collections import Counter
from copy import deepcopy

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

for i in range(n):
    tmp_c = deepcopy(c)
    ans = 0
    tmp_c[a[i]] -= 1
    for v in tmp_c.values():
        ans += v*(v-1)/2
    print(ans)
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    print(A.count(A[i])-1)
N = int(input())
a = (input().split())
a_str = ''.join(a)
a_str2 = a_str
sum = 0
l_dict = {}
while len(a_str)>0:
    n = a.count(a_str[0])
    sum += int(n*(n-1)/2)
    l_dict[a_str[0]] = n
    a_str = a_str.replace(a_str[0],'')
for k in range(N):
    print(sum-l_dict[a_str2[k]]+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):
    data[i] = num[i] * (num[i] - 1) // 2

x = sum(data)

for i in ball:
    print(x - num[i] + 1)
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5))
for i in range(N):
    li[A[i]]+=1
for j in range(N):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-(li[A[k]]*(li[A[k]]-1))//2+((li[A[k]]-1)*(li[A[k]]-2))//2)
n=int(input())
a=[int(s) for s in input().split()]
for i in range(0,n):
    print(a.count(a[i])-1)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += v * (v - 1) // 2


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = A[i] * (A[i] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)
import collections
n = int(input())
a = list(map(int,input().split()))

c = collections.Counter(a)

comon = c.most_common()
ans = 0
for i in comon:
  if i[1] != 1:
  	ans += (i[1]*(i[1]-1)//2)
  
for i in a:
    for j in comon:
      if i == j[0]:
        co = j[1]
        break
    if co == 1:
      print(0)
    else:
      print(ans-(co*(co-1)//2)+((co-1)*(co-2)//2))
import math

num = int(input())
a_i = list(map(int, input().split()))
anslist = [0] * (num + 1)
for x in range(num):
    val = x + 1
    cnt = a_i.count(val)
    if cnt <= 1: anslist[val] = 0
    else: anslist[val] = math.factorial(cnt - 1)

ans = sum(anslist)
for x in range(num):
    val = a_i[x]
    cnt = a_i.count(val)
    if cnt <= 2: print(ans)
    else: 
        sa = anslist[val] - math.factorial(cnt - 2)
        print(ans - sa)
N = int(input())
A = list(map(int, input().split()))
uA = list(set(A))
c = {u:A.count(u) for u in uA}

la = {}
lb = {}

for a in uA:
  la[a] = int(c[a]*(c[a]-1)/2)
  lb[a] = int((c[a]-1)*(c[a]-2)/2)
  
for a in A:
  ks = list(la.values())
  b = lb[a] + sum([k for k in ks if k !=a])
  print(b)
import collections
n = int(input())
num_list = list(map(int, input().split()))
all = 0

c = collections.Counter(num_list)
value_list = list(c.values())

for i in range(len(value_list)):
    if not value_list[i] == 1:
        all += value_list[i]*value_list[i-1]//2

for k in range(n):
    print(all - c[num_list[k]]-1)
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()

from scipy.misc import comb
def combi(n):
    if n<=1:
        return 0
    if n==2:
        return 1
    return comb(n,2)

c=[a.count(i) for i in range(1,n+1)]
d=[combi(m) for m in c]
s=sum(d)

for i in range(n):
    print(s-d[a[i]-1]+combi(c[a[i]-1]-1))
n = int(input())
aList = list(map(int, input().split()))
acount = [aList.count(i)-1 for i in aList]
sums = sum(acount)
for i in acount:
    print((sums)//2 - i for i in acount)
N= int(input())
A = list(map(int,input().split()))
B = []
C = []

for i in range(1,N+1):
    n = A.count(i)
    B.append(n*(n-1)//2)
    C.append((n-1)*(n-2)//2 if n >1 else 0)

B_sum = sum(B)
print(B)
print(C)

for i in range(N):
    a = A[i]-1
    print(B_sum-B[a]+C[a])
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)

for k in range(N):
  print(num - (c[k]-1))
import copy

def n_sum(n):
  x = 1
  ans_sum = 0
  while x <= n:
    ans_sum += x
    x += 1

  return ans_sum

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


new_a = list(set(a))
dummy_a = copy.deepcopy(new_a)

for i in range(len(new_a)):
  dummy_a[i] = a.count(new_a[i])

print(dummy_a)
for i in a:
  dummy_b = copy.deepcopy(dummy_a)
  dummy_b[new_a.index(i)] -= 1
  ans = 0
  for j in dummy_b:
    ans += n_sum(j - 1)
  print(ans)
import collections
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n+1)
ans=0
for i in range(n):
    l[a[i]]+=1
for j in range(n):
    if l[j]>1:
        ans+=(l[j])*(l[j]-1)//2
for k in range(n):
    s=l[a[k]]
    if s<2:
        print(ans)
    else:
        print(ans-(s+1)*s//2+s*(s-1)//2)
N = int(input())
An = [int(x) for x in input().split()]  
 
# ボールを全部使えるときの合計を求める
s = 0
for i in range(1,N+1):
    b = An.count(i)
    if b > 1:
        s += b*(b-1) / 2

for k in range(N):
    print(s - (An.count(An[k])-1))
import itertools
import copy

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

N_all = list(itertools.combinations(N_list, len(N_list)-1))
for N_rem in N_all:
    count = 0
    num_list = list(itertools.combinations(N_rem,2))
    for i, j in num_list:
        if i==j:
            count+=1
    print(count)
import numpy as np

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

b=np.zeros(N)

for i in range(N):
  b=np.zeros(N)
  b[i]=A.count(i+1)
  tmp=0
  for j in range(N):
    if(i==j):
      tmp=tmp+(b[j]-1)*(b[j]-2)/2
    else:
      tmp=tmp+b[j]*(b[j]-1)/2
  print(int(tmp))
n = int(input())
num_list =  list(map(int,input().split()))
num_list2 = [0]*n
num_list3 = [0]*n
for i in num_list:
    num_list2[i-1] += 1
for i in range(n):
    num_list3[i-1] = n*(n-1) // 2

for i in num_list:
    ans = n*(n-1) // 2
    print(ans-num_list3[i-1]+sum(num_list3))
  #  elif size == 1:
        #ans = 0
   # else :
    #    ans = 0 
    #num_list5[num_list2[i]-1] = ans
import itertools
import copy

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

for i in range(len(a)):
  aa = copy.copy(a)
  del aa[i]
  for av in aa:
    if av in matches:
      matches[av] += 1
    else:
      matches[av] = 1
  combi_cnt = 0
  for v in matches:
    combi_cnt += len(list(itertools.combinations(range(v), 2)))
  print(combi_cnt)
from collections import Counter
n = int(input())
res = list(map(int,input().split()))
a = Counter(res)
k = 0
for i in a.keys():
    a[i] -= 1
    sums = 0
    for j in a.values():
        sums += j * (j - 1) // 2
    a[i] += 1
    res = [sums if x == i else x for x in res]
for k in res:
    print(k)
n=int(input())
a = list(map(int, input().split()))
a2=list(set(a))
a3=sorted(a2)
for i in a:
    p=0
    for j in a3:
        s=a.count(j)
        if j==i:
            s-=1
        p+=(s*(s-1))/2
    print(p)
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
B = [0] * (n+1)
for i in range(n):
    B[A[i]] += 1

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

su = sum(C)

for i in range(n):
    print(su - C[A[i]] + (B[A[i]]-1)*(B[A[i]]-2)//2)
n = int(input())
a = list(map(int, input().split()))

li = [0] * (n+1)
tmp = 0

for i in range(n):
    li[a[i]] += 1
    
for i in range(n):
    tmp += sum(int(i) for i in range(li[i]))
    
for i in range(n):
    ans = tmp - li[a[i]] + 1
    print(ans)
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2
    for k in range(N):
        if 2 <= c[A[k]]:
            print(ans - (c[A[k]] - 1))
        else:
            print(0)


if __name__ == '__main__':
    main()
N = int(input())
A = list(input().split())
for i in range(len(A)-1):
  count=0
  j=i+2
  for j in range(len(A)-1):
    if A[i+1]==A[j]:
      count=count+1
  print(count)
from collections import Counter
N=int(input())
A = list(map(int,input().split()))
ans = [0] * N
B = Counter(A)
for i in range(N):
    ans[i] = B[A[i]]-1

total=sum(ans)
C=[]
for i in range(N):
    c = (total-ans[i])//2
    C.append(c)

for num in C:
    print(num)
from collections import Counter
from scipy.misc import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0
for k, v in counter.items():
    if 2 <= v:
        ans += v * (v - 1) // 2
for a in A:
    if a in counter and 2 <= counter[a]:
        v = counter[a]
        diff = v * (v - 1) // 2 - ((v- 1) * (v - 2) // 2)
        print(ans - diff)
    else:
        print(0)
import math

def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = (int)(input())
a = list(map(int, input().split(" ")))
temp = [0 for i in range(n + 1)]
aaa = sorted(a)
count = 0
for i in range(n - 1):
  if aaa[i] == aaa[i + 1]:
    count+= 1
  else:
    temp[aaa[i]] = count + 1
    count = 0
else:
  if len(a) == 1:
    temp[aaa[0]] = 1
  else:
    temp[aaa[-1]] = count + 1
ans = 0
#print(temp)#各数字の出現回数
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5)+1)
for i in range(N):
    li[A[i]]+=1
for j in range(N):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-(li[A[k]]*(li[A[k]]-1))//2+((li[A[k]]-1)*(li[A[k]]-2))//2)
N = int(input())
K = list(map(int,input().split()))
A = [0]*N
print(A)
for i in range(N):
    A[K[i]-1] += 1
r = 0
for k in range(N):
    r += 0.5*(A[k]*(A[k]-1))
An =[]
for j in range(N):
    D = A[K[j]-1]-1
    An.append(int(r-(0.5*(D+1)*(D))+(0.5*D*(D-1))))
for i in range(len(An)):
    print(An[i])
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n)
l1=[0]*(n)
for i in range(n):
    l[a[i]-1]+=1
    
for i in range(n):
    if l[i]>=2:
        l1[i]+=(l[i]*(l[i]-1))//2

l1sum=sum(l1)
for i in range(n):
    if l[a[i]-1]-1>=2:print(l1sum-l1[a[i]-1]+(l[i]*(l[i]-1))//2)
    else:print(l1sum-l1[a[i]-1])
import bisect

n = int(input())
a = list(map(int, input().split()))
A = sorted(a)
s = [0]*(n+1)
b = [0]*(n+1)
c = []
for i in range(1, n+1):
    x = a[i-1]
    s[i] = bisect.bisect_right(A, x) - bisect.bisect_left(A, x)
    if b[a[i-1]] == 0:
        c.append(s[i]*(s[i]-1)//2)
        b[a[i-1]] = 1
S = sum(c)
print(c)
for i in range(1, n+1):
    print(S - s[i] + 1)
N_ = int(input())

A_ = list(map(int,input().split()))
#A_.remove(1)
#print(A_)
def xC(num):
    return (num * (num - 1)) //2

def Re_(reA,t):
    Dup = []
    num = 0
    #print(reA)
    for i in range(len(reA)):
        if Dup.count(reA[i]) == 0:
            Dup.append(reA[i])
        else:
            pass
    for i in range(len(Dup)):
        num += xC(reA.count(Dup[i]))
    return num
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-(tmp-2)) * (tmp-1) // 2)
    ans += ((tmp-2) * (tmp-1) // 2)
    print(ans)
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())
print(ans)

for i in s:
    x = counted[i]
    print(int(ans - x + 1))
N = int(input())
A = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for value in A:
    C[value - 1] += 1
print(C)
ways_all = 0
for i in range(N):
    ways_all += (C[i] * (C[i] - 1)) // 2
print(ways_all)
for value in A:
    print(ways_all - C[value - 1] + 1)
from collections import Counter
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += c * c-1 // 2
for a in An:
    print(cnt - (counter[a] - 1))
from collections import Counter
from scipy.misc import comb
N = int(input())
A = [int(x) for x in input().split()]
C = Counter(A)
def banned_count(seq):
    for i in range(N):
        count = 0
        C[A[i]] -= 1
        for j in C.values():
            if j >= 2:
                count += comb(j, 2)
        print(int(count))
        C[A[i]] += 1
banned_count(A)
n = int(input())

a = input().split(" ")
ab = a
for k in range(n):
    count = 0
    if not k == 0:
        a.insert(k-1, a[k-1])
    ab.pop(k)
    for i in range(n-1):
        for j in range(i):
            if a[i] == a[j] and not i == j:
                count = count + 1
    print(count)
def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ans = 0
    lim = max(a)
    amount = [0]*lim
    for i in range(lim):
        amount[0] = a.count(i+1)
        ans += amount[i]*(amount[i]-1)//2
    #print(ans)
    for j in range(n):
        ansout = ans
        #print(amount[a[j]-1])
        ansout -= amount[a[j]-1] -1
        print(ansout)

if __name__ == '__main__':
    main()
N = int(input())
A = list(map(int, input().split()))
count = [0] * 200005
for a in A:
    count[a] += 1

s = 0
for c in count:
    s += c * (c - 1) // 2
print(s)

for a in A:
    c = count[a]
    x = c * (c - 1) // 2
    c -= 1
    y = c * (c - 1) // 2

    print(s - x + y)
N=int(input())
A=[int(x) for x in input().split()]
num={i:0 for i in range(N)}
for i in A:
    num[i-1]+=1
def set(k):
    if k >= 2:
        return (k)*(k-1)/2
    else:
        return 0
def selfset(k):
    if k >= 2:
        return (k-1)*(k-2)/2
    else:
        return 0

setnum={i:set(num[i]) for i in range(N)}
a=sum(setnum.values())
print(setnum,A)

selfsetnum={i:selfset(num[i]) for i in range(N)}


for i in range(N):
    print(int(a-setnum[A[i]-1]+selfsetnum[A[i]-1]))
import collections
import copy

def f(l):
    return l*(l-1)


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

for x in a:
    c=copy.deepcopy(b)
    c[x]-=1
    d=c.values()
    e=0
    for y in d:
        e+=f(y)
    print(e//2)
import collections

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

ct = collections.Counter(A)

ret = []
total = 0
for k,count in ct.items():
    if count > 1:
        total += count * (count-1) // 2

for i,v in enumerate(A):
    if ct[v] > 1:
        count = ct[v]
        adjust = (count-1) * (count-2) // 2 - (count-1) * count // 2
        val = total + adjust
    else:
        val = 0
    print(val)
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(N)]
ans = []
for i in A:
    num[i-1]+=1
sums = 0
print(num)
for i in A:
    num[i-1]-=1
    for j in range(N):
        if num[j] > 1:
            sums += 1/2*num[j]*(num[j]-1)
    ans.append(int(sums))
    sums = 0
    num[i-1]+=1

print(ans)
N = int(input())
A = [int(i) for i in input().split()]
print(A)
a = 0
for i in range(N):
    tmp = A[:i]
    tmp.extend(A[i+1:])
    for j in range(N-2):
        for k in range(N-1-j):
            if tmp[j] == tmp[k]:
                a += 1
print(a)
N = int(input())
A = list(map(int, input().split()))
l = [0] * 10000001
for i in A:
    l[i] += 1
s = 0
for i in range(N):
    s += l[i] * (l[i] - 1) / 2
for a in A:
    print(int(s - (l[a] * (l[a] - 1)) / 2 + (l[a] - 1) * (l[a] - 2) / 2))
N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (N+1)
ans = 0
for i in range(N):
  cnt[A[i]] += 1
for i in range(N):
  ans += cnt[i] * (cnt[i] - 1) // 2
for i in range(N):
  print(ans - cnt[A[i]] + 1)
N=int(input())
A=list(map(int,input().split()))
S=[0 for j in range(N+1)]
count=0
for i in range(N):
  S[A[i]]+=1
for i in range(N):
  count+=S[i]*(S[i]-1)//2
for i in range(N):
  print(count-(S[A[i]]-1))
N = int(input())
data = input().split(" ")
visit = [0 for i in range(N)]
ans = 0
for i in range(N):
  for j in range(N):
    if (data[j] == data[i])and(visit[i]==0)and(visit[j]==0):
      visit[i] = 1
      visit[j] = 1
      ans += 1
      
  print(ans)
n=int(input())
a=list(map(int, input().split()))
k=len(a)
for i in range(k):
  del a[i]
  ans=0
  for j in range(n):
    ac=a.count(j)
    ans+=ac*(ac-1)//2
  print(ans)
  a.insert(k, 'k')
n=int(input())
a=list(map(int,input().split()))
d={}
ua=list(set(a))
total=0
print('hoge')
for x in ua:
    y=a.count(x)
    d[x]=y
    total+=(y-1)*y//2
for x in a:
    print(total-d[x]+1)
import collections 
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
c=defaultdict(int)
for s in a:
    c[s]+=1
print(c)

a1=list(set(a))
print(a1)

total=0
for j in range(len(a1)):
    x=c[a[j]]
    print(x)
    total+=x*(x-1)/2
    print('total=',total)

for i in range(n):
    ans=total-c[a[i]]+1
    print(int(ans))
import math

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

C = list(set(A))
M = len(C)
t = []
anst = 0
for i in range(M):
  t.append(A.count(C[i]))
  temp = A.count(C[i])
  if temp >=2:
    anst += math.factorial(temp)/(math.factorial(temp-2)*2)

#print(t)
#print(anst)
#print(jisyo[1])
for i in range(N):
  print(t[C.index(A[i])])
  print(int(anst-t[C.index(A[i])]+1))
n = int(input())
a = list(map(int, input().split()))

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

for i in range(1, n+1):
    print(sumx - x[a[i-1]] * (x[a[i-1]]-1) // 2 + (x[a[i-1]]-1) * (x[a[i-1]]-2) // 2)
n = int(input())
a = list(map(int,input().split()))
answer = 0
answer1 = 0

for i in range(max(a)):
  answer += a.count(i + 1) * (a.count(i + 1) -1) // 2

for k in range(n):
  if a.count(a[k]) > 2:
    answer1 = answer - (a.count(a[k]) - 1)
  print(answer1)
n = 8
a = list(map(int, '1 2 1 4 2 1 4 1'.split()))
count_dict = {}
total_sum = 0
for i in a:
    if i not in count_dict:
        count_dict[i] = a.count(i)
        total_sum += (a.count(i))*(a.count(i)-1)//2
for i in a:
    print(total_sum - (a.count(i)*(a.count(i)-1)//2) + (a.count(i)-1)*(a.count(i)-2)//2)
import itertools

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

gr=itertools.groupby(sorted(A))
s=0
dic={}
for x,group in gr:
  l=len(list(group))
  if l >= 2:
    s+=l*(l-1)/2
  dic[x]=l

for k in range(N):
  l=dic[A[k]]
  if l >= 2:
    print(int(s-l*(l-1)/2+(l-1)*(l-2)/2))
  else:
    print(s)
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
  n = int(input())
  a = list(map(int, input().split()))
  c = collections.Counter(a)
  s = 0
  for i in list(c.values()):
    s += i*(i-1)//2
  print(c)
  for i in a:
    print(s-(c[i]-1))
  return 0
 
if __name__ == "__main__":
  solve()
import collections
N=int(input())
a=0
list1 = list(map(int, input().split()))
c = collections.Counter(list1)
for i in range(N):
    a+=int(c[i+1]*(c[i+1]-1)/2)
for i in range(N):
    print(a-c[list1[i]]*2+3)
import copy
N = int(input())
A = list(map(int, input().split()))

a_types = set(A)
count_dict = [0] * N
for each in a_types:
    count_dict[each - 1] = A.count(each)

for each in A:
    count_dict[each - 1] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a - 1] + 1)
def nC2(n):
    return n*(n-1)/2

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

cnt = [0]*(n+1)
total = 0
ans = 0

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

for i in range(n):
    total += nC2(cnt[i])

for i in range(n):
    print(total - nC2(cnt[a[i]]) + nC2(cnt[a[i]] - 1))
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
    for j in range(n):
        if i!=j:
            for k in range(j+1,n):
                if a[j]==a[k]:
                    ans[i]+=1
for i in ans:
    print(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

for i in range(n):
    f = a[i]
    t = a_2[f-1] - 1
    #print(int(sum(al)-(al[f-1]-t*(t-1)/2)))
n = int(input())
a = [int(i) for i in input().split()]
c = [0 for i in range(n+1)]
b = sorted(a)
cnt = 1
for i in range(n-1):
  if b[i]==b[i+1]:
    cnt += 1
  else:
    c[b[i]] = cnt
    cnt = 1
  if i==n-2:
    c[b[n-1]] = cnt
ans = 0
for i in range(n):
  ans += int(c[i]*(c[i]-1)/2)
for i in range(n):
  print(ans-(c[a[i]]-1))
import collections
import functools
import math

n = int(input())
l = list(map(int, input().split(" ")))
c = collections.Counter(l)

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

total = functools.reduce(lambda x, y : x + f(y, 2), c.values())

for i in l:
    print(total - f(c.get(i, 0), 2) + f(c.get(i, 0) - 1 , 2))