peterverebics/CodeNet_Python_118 huggingface dataset:
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):
    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()))

a = list(set(A))
cc = Counter(A)
dup = [x for x in a if cc[x] > 1]
m = len(a)
l = len(A) 
al = sum(cc.values())

for k in A:
    if k in dup:
        print(int(al-cc[k]+1))
    else :
        print(int(al))
from collections import defaultdict
import math

N = int(input())
A = [int(i) for i in input().split()]
d = defaultdict(int)
for a in A:
  d[a] += 1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
num = 0
for i in d.values():
  if i >= 2:
    num += combinations_count(i, 2)
    
for i in range(N):
  a = A[i]
  if d[a] > 2:
    print(num - combinations_count(d[a], 2) + combinations_count(d[a]-1, 2))
  elif d[a] == 2:
    print(num - combinations_count(d[a], 2))
  else:
    print(0)
from collections import OrderedDict
N = int(input())
A = list(map(int, input().split()))
# maybe use a dictionary
ball_values = OrderedDict()
for val in A:
  if val not in ball_values:
    ball_values[val] = 1
  else:
    ball_values[val] += 1
# get total pairs of all balls
total_possible_combos = sum(item[1]*(item[1]-1)//2 for item in ball_values.items())
# for each k, take away the loss of pairs due to removing it
k_outputs = [total_possible_combos-(ball_values[val]-1) for val in A]
print(k_outputs)
import collections
N = int(input())
A = list(map(int,input().split()))
cnt = 0

s = collections.Counter(A)

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

print('\n'.join([str(cnt-A.count(A[i])+1) for i in range(N)]))
n=int(input())
a=list(map(int,input().split()))
c=[0]*n
#a[i]は1以上n以下で、cの要素番号は0~n-1(acは1ずれている。)
all=0
for i in range(n):
  c[a[i]-1]+=1
for i in range(n):
  if c[i]>=2:
    d=c[i]*(c[i]-1)/2
    all+=d
for i in range(n):
  print(all-(c[a[i]-1]-1))
info = input(" ").split()
N = int(info[0])
A = list(map(lambda x : int(x),info[1:]))
for i in range(N):
    count = 0
    n_list = []
    B = A[0:i] + A[i + 1:]
    for j in B :
        c = B.count(j)
        if c != 1 and not j in n_list:
            n_list.append(j)
            count += c*(c-1)/2
    print(int(count))
import collections
def I(): return int(input())
def LI(): return list(map(int,input().split()))
##################################################
N = I()
A = LI()
count = collections.Counter(A)
nC2 = {}
for x in count.values():
    nC2[x] = x*(x-1)//2
sum = sum(nC2.values())
for x in A:
    if x-1 in nC2:
        minus = nC2[x-1]
    else:
        minus = (x-1)*(x-2)//2
        nC2[x-1] = minus
    print(sum-x+minus)
n,*a=map(int,open(0).read().split())
c=[0]*n
for i in range(n):
  c[a[i]-1]+=1
s=sum(c)
for i in range(n):
  print(s-c[a[i]-1])
n = int(input())
l = list(map(int, input().split()))
dic = {}
ans = 0
a = 0

for i in range(n):
  a = l.count(i+1)
  if a == 0 or a == 1:
    if max(l) < i:
      break
    else:
      continue
  else:
    dic[i+1] = a
    x = l.count(i+1)
    ans += int(x*(x-1)/2)
  
for i in range(n):
  if dic.get(l[i]) != None:
    a = dic[l[i]]
    print(ans-a+1)
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
result = 0
for i in balls:
    conbi[i-1] +=1
print(conbi)
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in balls:
    print(result-conbi[k-1]+1, end=" ")
import collections

n = int(input())
a = [int(i) for i in input().split(' ')]
c = collections.Counter(a)
counts = {}
all_sum = 0
for k, v in c.items():
    val = v * (v-1) / 2
    counts[k] = val
    all_sum += val

for i in range(n):
    k = a[i]
    count = c[k] - 1
    val = counts[k]
    print(all_sum - val + count * (count - 1) / 2)
#input
N = int(input())
A = list(map(int, input().split()))

#output
from collections import  Counter
L = Counter(A)

original_answer = 0
for i in range(N):
    if L[i] >= 2:
        original_answer += L[i] * (L[i]-1) // 2

for i in range(N):
    temp = 0
    if L[A[i]] == 1:
        print(original_answer)
    elif L[A[i]] == 2:
        temp -= 1
    elif L[A[i]] > 2:
        temp = temp - L[A[i]]*(L[A[i]]-1)//2 + (L[A[i]]-1)*(L[A[i]]-2)//2 
    print(original_answer + temp)
from math import factorial

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

def combination(n,r):
  if n < 2:
    return 0
  else:
    return factorial(n) / factorial(r) / factorial(n-r)

lens = []
ans = 0
for p in range(N):
  lens.append(An.count(p))
for p in range(N):
  lend = lens.copy()
  if lend[p] == 0:
    continue
  else:
    lend[p] -= 1
  for k in range(N):
    ans += combination(lend[k], 2)

print(int(ans))
import math
from collections import Counter

def cmb(n,r):
    if n < r:
        return 0
    return math.factorial(n)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([cmb(v,2) for v in count.values()])

    for i in range(len(A)):
        remain = A[:i] + A[i+1:]
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
for k in range(N):
	s=0
	for i in range(N):
		for j in range(i+1,N):
			if B[i]==B[j]:
				s=s+1
			else:
				break
	if B[i]==A[k]:
		s=s-1
	print(s)
N=int(input())
A=list(map(int,input().strip().split()))

l=[0 for n in range(N+1)]

for e in A:
    l[e]+=1

count=0
for n in range(N):
    if l[n]>=2:
        count+=l[n]*(l[n]-1)//2
            
for n in range(N):
    print(count-l[A[n]]+1)
N = int(raw_input())
A = map(int, raw_input().split())


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

sumN = long(0)
for i in range(N):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)

#print answer
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)
from collections import Counter

def nCk(n, k, m=10**9+7):
    a = b = 1
    for i in range(k):
        a = (a * (n-i)) % m
        b = (b * (i+1)) % m
    return (a * pow(b, m-2, m)) % m

n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
c = {}
d = {}
for k, v in b.items():
    c[k] = nCk(v, 2)
    d[k] = nCk(v-1, 2)
total = sum(c.values())
for i in range(n):
    ans = total - c[a[i]] + d[a[i]]
    print(ans)
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():
  if i>1:
    ans+=i*(i-1)/2
for i in range(n):
  bk=dic[a[i]]
  print(int(ans-bk+1) if bk>1 else ans)
n = int(input())
aList = list(map(int, input().split()))
acount = []
for i in aList:
    acount.append(aList.count(i)-1)
sums = sum(acount)
for i in acount:
    print((sums)//2 - i for i in acount)
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b0=list(a[1:])
c0=Counter(b0)
d0=0
for i in c0:
    d0+=(c0[i])*(c0[i]-1)/2
print(d0)
for j in range(1,n-1):
    b=list(a[0:j])+list(a[j+1:])
    c=Counter(b)
    d=0
    for j in c:
        d+=(c[j])*(c[j]-1)/2
    print(d)
b2=list(a[:-1])
c2=Counter(b2)
d2=0
for k in c2:
    d2+=(c2[k])*(c2[k]-1)/2
print(d2)
M=int(input())
N=list(input().split())
print(N)
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):
    print(num-(check[int(N[i])-1]-1))
n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(n):
        print((n*(n-1)//2)-n+1)
else:
    d = {}
    for i in l:
        if i in d:
            d[i]+=1
        else:
            d[i] = 1
    for i in l:
        d[i] -= 1
        print(sum(set(d.values())))
        d[i] += 1
n=int(input())
S=list(map(int,input().split()))
set_S=list(set(S))
ans_stock={}
number={}
for i in set_S:
  number[i] = S.count(i)
comb = 0
for i in set_S:
  comb += number[i]*(number[i]-1)/2

for i in S:
  if i in list(ans_stock.keys()):
    print(ans_stock[i])
  else:
    ans = comb -  number[i]*(number[i]-1)/2 +  (number[i]-1)*(number[i]-2)/2
    print(ans)
    ans_stock[i]=ans
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(0)
N = int(input())
A = list(map(int, input().split()))

B = [0] * N

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

ans = 0

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

for i in range(N):
	res = ans
	res -= B[i] * (B[i] - 1) // 2
	if B[i] >= 1:
		res += (B[i] - 1) * (B[i] - 2) // 2
	print(res)
n = int(input())
a = list(map(int, input().split()))

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

from scipy.misc import comb

c = [0]*(n+1)
for i in range(n+1):
    c[i] = int(comb(arr[i],2))

d = [0]*(n+1)
for i in range(n+1):
    d[i] = int(comb(arr[i]-1,2))


for k in range(n):
    ans = sum(c[:a[k]]) + sum(c[a[k]+1:]) + d[a[k]]
    print(ans)
import sys
import math
from collections import Counter
from collections import defaultdict

n = int(sys.stdin.readline())
a = ''.join(sys.stdin.readline().split())
c = Counter(a)

total_comb_num = sum(map(lambda v: max(v*(v-1)//2, 0), c.values()))
for num in a:
    x = c[num]
    print(total_comb_num + max((x-1)*(x-2)//2, 0) - max((x*(x-1)//2, 0)))
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

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

count=Counter(A)
ans=0
for i in range(len(count)):
	ans+=ch_2(count[i])
for j in range(N):
	print(ans-ch_2(count[A[j]]-1))
n=int(input())
arr=list(map(int,input().split()))
tt=[0]*(n+7)

total=0

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

for t in tt:
  total += (t*(t-1)//2)

for i in range(n):
  n = tt[arr[0]]
  d = (n*(n-1)//2) - ((n-1)*(n-2)//2)
  print(total-d)
# x * x-1 // 2
N=int(input())
A=list(map(int,input().strip().split()))

l=[0 for n in range(N+1)]

for e in A:
    l[e]+=1

count=0
for n in range(N):
    if l[n]>=2:
        count+=l[n]*(l[n]-1)//2
            
for n in range(1,N+1):
    if count==0:
        print(0)
    else:
        print(count-l[A[n-1]]+1)
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):
        v = c[A[k]]
        diff = -v*(v-1)//2 + (v-1)*(v-2)//2
        print(ans + diff if v != 1 else 0)


if __name__ == '__main__':
    main()
import copy
n = int(input())
ball_number_list = list(map(int, input().split()))
print(ball_number_list)
def choose2(p):
    return (p*(p-1))/2
def findfind(list1, k):
    c = 0
    list2 = copy.copy(list1)
    del list2[k]
    kinds = list(set(list2))
    for i in kinds:
        c += choose2(list2.count(i))
    return int(c)

for k in range(n):
    print(findfind(ball_number_list,k))
n = int(input())
l = [int(i) for i in input().split()]


ans = 0
for i in range(n):
    j = l.count(i)
    ans += int(j * (j - 1) / 2)
n = int(input())
a = list(map(int, input().split()))
anslist = []

for i in range(1, n+1):
  p = a.pop(-i)
  ans = len(a) - a.count(p)
  anslist.append(ans)
  a.append(p)

for j in reversed(anslist):
  print(j)
n=int(input())
a=list(map(int, input().split()))

import numpy as np

base = 0
for i in range(len(a)):
    base = 0
    a_del = np.delete(a, int(i), 0)
    set_ = a_del.tolist()
    set_1 = list(set(set_))
    for j in range(len(set_1)):
        cnt = set_.count(set_1[j])
        print(cnt)
        if 2 <= cnt:
            base = base + cnt*(cnt-1)/2
    print(base)
import numpy as np
N = int(input())
a = np.array(list(map(int,input().split())))
for i in range(N):
    print(len(a[a == a[i]])-1)
n = int(input())
a_list = input().split()
a_set = set(a_list)
a_dict = {}
sum_ans = 0
for a in a_set:
    a_count = a_list.count(a)
    a_dict[a] = a_count
    if a_count > 1:
        sum_ans += a_count*(a_count-1)//2
    
for a in a_list:
    a_num = a_dict[a]
    if a_num == 1:
        print(sum_ans)
    elif a_num == 2:
        print(sum_ans-1)
    else:
        ans = sum_ans - a_dict[a] + (a_num-2)*(a_num-1)//2
        print(ans)
from collections import Counter

N = int(input())
al = list(map(int, input().split()))
C = Counter(al)
# print(C)
# print(C.values())
ans = 0
for i in C.values():
    ans += i * (i - 1) / 2

for a in al:
    k = C[a]
    print(ans - (k * (k - 1) / 2) + (k - 1) * (k - 2) / 2)
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 - 1 + d[a])
import numpy as np

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

q = np.zeros((n+1),dtype=np.int64)
q[2] = 1
q[3] = 3
q[4] = 6
for i in range(5,n+1):
    q[i] = q[i-1] * i

c = np.zeros((n+1),dtype=np.int64)
for a in A:
    c[a] += 1

s = 0
dex = np.where(c>0)
for i in dex[0]:
    s += q[c[i]]
for i in range(n):
    #print(A[i],q[c[A[i]]],q[c[A[i]]-1])
    print(s - q[c[A[i]]] + q[c[A[i]]-1])
n = int(input())

a = input().split(" ")
ab = a
for k in range(n):
    count = 0
    if not k == 0:
        ab.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)
import collections
n=int(input())
a=list(map(int,input().split()))
k=0
c=collections.Counter(a)
for i in range(a[-1]):
  v=c[i+1]
  k+=v*(v-1)//2
for i in a:
  ans=k-a.count(i)+1
  print(ans)
n = int(input())
A = list(map(int,input().split()))
B = [0]*n

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

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

C = [0]*n
for i,b in enumerate(B):
    if b == 2:
        C[i] = total - 1
    elif b > 2:
         C[i] = total + (b-1)*(b-2)//2 - (b)*(b-1)//2 

for a in A:
    print(C[a-1])
import collections
from sys import stdin
n = int(stdin.readline().rstrip())
ass = list(map(int, stdin.readline().rstrip().split()))

c = collections.Counter(ass)

cnum =[0]*len(c)
keys = c.keys()

cs = {}
for i in keys:
    key = c[i]
    combi = key *(key-1) / 2
    cs[i] = combi

sum = sum(cs.values())

for i in range(n):
    add = c[ass[i]]-1
    adds = add *(add-1) / 2
    ans = sum - cs[ass[i]] + adds
    print(ans)
#N = int(raw_input())
#A = map(int, raw_input().split())

N = 200000
A = [200000]*N

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

sumN = long(0)
for i in range(N+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)

#print answer
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)
# coding: utf-8
N = int(input())
A = input().split()

# total count
dict = set(A)
total_count = 0
for val in dict:
  tmp = A.count(val)
  tmp = int(tmp*(tmp-1)/2)
  total_count += tmp

# substracted count
for k in range(N):
  tmp = A.count(A[k])
  sub_count = int(tmp*(tmp-1)/2)
  print('{}'.format(total_count - sub_count))
import collections


def resolve():
    N = int(input())
    A = sorted(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()
l = int(input())
A = input().split(" ")

unique = set(A)

def combination(number):
  if number == 0 or number == 1:
    return 0
  else:
    return int(number * (number - 1) / 2)

def caluculate(string):
  if memo[string] == 0:
    return(0)
  if memo[string] == 1:
    return(1)
  else:
    return(memo[string] - 1) 
  
total = 0
memo = {}
for i in unique:
  times = A.count(i)
  memo[i] = times
  total += combination(times)

# print(memo)
# print(memo.keys())
# print(total)

for i in A:
  #  print(caluculate(i))
  print(total - caluculate(i))
N=int(input())
list1=list(map(int,input().split()))
list2=[0]*N

for i in range(N):
    list2[i]=list1.count(i+1)

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

total=0
for i in list2:
    total+=choose2(i)


for i in list1:
    ans=total-(list2[i-1]-1)
    print(ans)
N=int(input())
A=list(map(int,input().split()))


dict_A={}
B=list(set(A))
sum=0


for b in B:
    a=A.count(b)
    sum+=a*(a-1)//2

for a in A:
    print(sum-a+1)
N = int(input())
A = [int(c) for c in input().split()]

#全部のパターン数計算→その数のときのパターン数消す
S = set(A)
print(S)
S_cnt = {}
ma = 0
for i in S:
    #S_cnt[i] = A.count(i)
    cnt = A.count(i)
    S_cnt[i] = cnt
    ma += cnt*(cnt-1)//2

for i in A:
    cnt = S_cnt[i]
    print(ma-cnt+1)
N = int(input())
A = list(map(int,input().split()))
B = [A.count(i) for i in range (N + 1)]
print(B)
C = 0
for i in range(N + 1):
  C += int(B[i] * (B[i] - 1) / 2)
for j in A:
  print(0 if B[j] < 2 else C + 1 - B[j])
N = int(input())
A = list(map(int, input().split()))
lis = [0 for _  in range(N+1)]
lis1 = [0 for _ in range(N+1)]
lis2 = [0 for _ in range(N+1)]
for i in range(N):
    lis[A[i]] += 1

for i in range(N):
    num = lis[i]
    if num != 0:
        lis1[i] = int(num*(num-1)/2)
        lis2[i] = int((num-1)*(num-2)/2) - lis1[i]

total = sum(lis1)

for i in range(N):
    val = A[i]
    print(total + lis2[val])
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[a[i]-1]-1 * l[a[i]-1]-2)//2)
    else:print(l1sum-l1[a[i]-1])
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
result = 0
for i in balls:
    conbi[i-1] +=1
print(conbi)
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in range(n):
    print(result-conbi[balls[k]-1]+1)
import collections

N = input()
L = input().split()
C = collections.Counter(L)
I = list(C.keys())
V = list(C.values())

for l in L:
    sum = 0
    for i in range(len(I)):
        if l == I[i]:
            sum += (V[i] - 1) * (V[i] - 2) / 2
        else:
            sum += V[i] * (V[i] - 1) / 2
    print(sum)
import math
N, *A = map(int,input().split())

for e in A:
    d = dict((i, A.count(i)) for i in set(A))
    d[e]-=1
    
    ans = 0
    for i in list(d):
        if d[i] < 2:
            continue
        ans += d[i]*(d[i]-1)/2
    print(int(ans))
n = int(input())
a = list(map(int, input().split()))
x = [0]*(n+1)
tmp = [0]*(n+1)
for i in a:
    x[i] += 1
ans = 0
for i in range(1, n):
    tmp[i] = (x[i] * (x[i]-1))//2
    ans += tmp[i]
for i in range(1, n+1):
    print(ans - tmp[a[i-1]] + (x[a[i-1]]-1)*(x[a[i-1]]-2)//2)
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
ans = np.zeros(N)
total = 0
for i in range(N):
  ans[A[i] - 1] += 1
for i in range(N):
  total += ans[i] * (ans[i] - 1) // 2
for i in range(N):
  print(total - max(ans[A[i]-1]-1,0))
n = int(input())

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

count = [a.count(i) for i in range(1,n+1)]

for j in range(n):
    print((count[j]-1)*(count[j]-2))
from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

if all_count == 0:
    all_count = 1

for i in a_list:
    print(all_count - c[i] + 1)
import math
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = []
for i in range(N):
  a = A[i]
  A[i] = 0
  B = Counter(A)
  for v in B.values():
    if v != 1:
      C.append(math.factorial(v)//2)
  print(sum(C))
  C.clear()
  A[i] = a
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(ans)
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1


for i in range(1,n+1):
    x[a[i-1]-1]-=1
    count = 0
    x_ = [(k*k-1)/2 for k in x if k>=2]
    count = sum(x_)
    # for j in x:
    #     if j>=2:
    #         count += int((j*(j-1)/2))
    x[a[i-1]-1]+=1
    print(count)
from collections import Counter


def tri(num):
    if num < 0:
        return 0
    return int(num*(num+1)/2)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    for i in range(n):
        print(sum([tri(j-1) for j in c.values()]))


if __name__ == "__main__":
    main()
import collections
n = int(input())
a_list = list(map(int,input().split()))
c=collections.Counter(a_list)
result=0
print(c)

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

for a in a_list:
    print(result - c[a] + 1)
def comb2(a):
  if a < 2: return 0
  return int(a * (a - 1) / 2)

N = int(input())
A = list(map(int, input().split()))
dp = [[0, 0] for i in range(N+1)]
for i in range(N):
  dp[A[i]][0] += 1
x = 0
for i in range(N):
  dp[i][1] = comb2(dp[i][0])
  x += dp[i][1]
for i in range(N):
  y = comb2(dp[A[i]][0]-1)
  print(int(x - dp[A[i]][1] + y))
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]

for i, a in enumerate(A):
	num = A.count(a)
	B[i] = num * (num-1) // 2

total_pair = sum(B)
for i in range(N):
	print(total_pair - B[i])
import copy
import itertools

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

for i in range(N):
    tmp = copy.deepcopy(A)
    tmp.pop(i)

    res = 0
    for j in list(set(tmp)):
        l = tmp.count(j)
        if(l<2):
            break
        res += len(list(itertools.combinations(list(range(l)),2)))

    print(res)
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)
import itertools
import collections

N = int(input())
AList = input().split(" ")

for k in range(1, N + 1):
    count = 0
    tempList = collections.Counter([element for index, element in enumerate(AList) if k != index + 1])
    
    if len(tempList.keys()) == 1:
        print(len(list(itertools.combinations(range(len(tempList)), 2))))
        continue

    else:
        for c in tempList.values():
            count += len(list(itertools.combinations(range(c), 2)))
            
        print(count)
import itertools 
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):
    c_a = (A_counter[A[k]]-1) *  (A_counter[A[k]]-2)//2
    print(sum - c_a -1)
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N+1)

ans1=0
s=0

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

for j in range(N):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
        
for k in range(N):
    b=A[k]
    d=C[b]
    if d<2:
        ans=ans1
    else:
        ans=ans1-(d-1)
    print(int(ans))
from collections import Counter

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

s = Counter(c)
t = list(s.items())

nag = len(t)
x = 0
rt = [0 for i in range(nag)]
print(s)

for i in range(nag):
    x += (t[i][1]*(t[i][1]-1))//2
for f in range(nag):
    rt[f] = x - (t[f][1] -1)
  
for j in range(n):
    for k in range(nag):
        if c[j] == t[k][0]:
            print(rt[k])
            break
from collections import*
d={}
n,*a=map(int,open(0).read().split())
b=Counter(a)
for i in range(n):
    c=(b-Counter([a[i]]))
    if a[i]not in d:
        ans=sum([v*(v-1)//2 for k,v in c.items()if v>=2])
        d[a[i]]=ans
    else:
        print(d[a[i]])