peterverebics/CodeNet_Python_118 huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
li = [0] * n
cou = [0] * (n+2)
for i in range(n):
    if li[a[i]-1] != 0:
        cou[li[a[i]-1]+1] += 1
    li[a[i]-1] += 1
y = 0
ma = max(li)
for i in range(ma-1):
    k = cou[ma-i] - cou[ma-i+1]
    y += (ma-i) * (ma-i-1) * k // 2
for i in range(n):
    x = li[a[i]-1]
    if x >= 2:
        print(y-x+1)
    else: print(y)
import math
import collections

N = input()
nums = list(map(int, input().split()))
counter = collections.Counter(nums)
patterns = {}
for k, v in counter.items():
    patterns[k] = math.comb(v, 2)

baseline = sum(v for v in patterns.values())

for n in nums:
    # todo : memo
    print(baseline - patterns[n] + math.comb(counter[n] - 1, 2))
from collections import deque
N = int(input())
A = list(map(int,input().split()))
balls = [[] for _ in range(N+1)]
for i in range(N):
  balls[A[i]].append(i)
  
K = 0  
for i in range(N+1):
  if len(balls[i]) < 2:
    continue
  else:
    u = len(balls[i])
    K += int(u*(u-1)/2)
  
t = 0
q = deque()
for i in range(N):
  s = A[i]
  a = len(balls[s])
  if a >=2:
    d = a-1
  else:
    d = 0
  q.append(K-d)


while q:
  v = q.popleft()
  print(v)
def main():
    from collections import Counter
    import sys

    input()
    a = list(map(int, sys.stdin.readline().split()))

    d = Counter(a)

    base = sum(v * (v - 1) // 2 for v in d.values())
    e = [str(base - (d[v] - 1)) for v in a]
    print('\n'.join(e))


if __name__ == '__main__':
    main()
def main():
	import collections
	s = int(input())
	a = list(map(int,input().split()))
	ac = collections.Counter(a)
	ans = 0
	for i in set(ac):
		at = ac[i]
		ans += (at * (at-1))/2
	for t in a:
		ans_print = ans -((ac[t] * (ac[t] -1))/2) + (((ac[t]-1) * ((ac[t]-1)-1))/2)
		print(int(ans_print))
if __name__ == '__main__':
	main()
n = int(input())
nums = list(map(int, input().split()))

num_count = {}
for num in nums:
    num_count[num] = num_count.get(num, 0) + 1

total = 0
for num, ele in num_count.items():
    total += (ele * (ele - 1)) // 2

ans = []

for num in nums:
    ans.append(total - num_count[num] + 1)
print("\n".join(list(map(str, ans))))
def main():
    from collections import Counter
    n=int(input())
    a=list(map(int,input().split()))

    q = Counter(a)
    a_cn = sum(x * (x - 1) // 2 for x in q.values())

    ans = []
    for x in a:
        ans.append(a_cn - q[x] + 1)

    print(*ans, sep='\n')


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

N, *A = map(int, open(0).read().split())

C = Counter(A)

full = sum(n * (n - 1) // 2 for n in C.values())
for a in A:
    print(full - (C[a] - 1))
def f(x):
	return x * (x-1) // 2

n = int(input())
a = list(map(int, input().split()))
b = [0] * n
c = [0] * n
d = [0] * n
e = [0] * n
s = 0
for aa in a:
	b[aa-1] += 1
for i in range(n):
	c[i] = f(b[i])
	d[i] = f(b[i] - 1)
	s += c[i]
for i in range(n):
	e[i] = s - c[i] + d[i]
# print(b,c,d,e)
for i in range(n):
	print(e[a[i]-1])
from collections import Counter
N, = list(map(int,input().split()))
A  = list(map(int,input().split()))
c = Counter(A)
p = sum([(c[k]*(c[k]-1)//2) for k in c.keys()])
for ai in A:
    print(p - c[ai] + 1)
n=int(input())
l=[int(x) for x in input().split()]
m=[0]*(200007)
for x in l:
    m[x]=m[x]+1

total=0
for x in m:
    total+=(x*(x-1))//2

for x in l:
    print(total-m[x]+1)
n = int(input())
A = input().split()

B = {}
for a in A:
    if a not in B:
        B[a] = 0
    B[a] += 1

sum = 0
for b in B:
    sum += B[b] * (B[b] - 1) // 2

for a in A:
    print(sum - (B[a] - 1))
def main():
  import sys
  input = sys.stdin.readline
  n = int(input())
  a = [int(i) for i in input().split()]
  Ss = set(a)
  s = list(Ss)
  import collections
  c = collections.Counter(a)
  j = 0
  #print(c[a[0]])
  for i in range(len(s)):
    j += int(c[s[i]]*(c[s[i]]-1)/2)
  #print(j)
  for i in range(n):
      print(int(j-(c[a[i]]-1)))
if __name__ == '__main__':
    main()
import collections


def solve(n, balls):
    counts = collections.Counter(balls)

    totalWays = 0

    for count in counts.values():
        totalWays += count*(count-1)//2

    results = []

    for ball in balls:
        waysWithoutBall = totalWays - (counts[ball]*(counts[ball]-1)//2)

        results.append(waysWithoutBall +
                       ((counts[ball]-1)*(counts[ball]-2)//2))

    return results


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

results = solve(n, balls)

for result in results:
    print(result)
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(1,N+1):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
        
for A_k in A:
    d=C[A_k]
    if d<2:
        ans=ans1
    else:
        ans=ans1-(d-1)
    print(int(ans))
#!/usr/bin/python3
import sys
from collections import Counter
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = [int(x) for x in input().split()]
c = Counter(a)
def c2(n):
    return n * (n - 1) // 2

ans = sum(c2(v) for v in c.values())

def add(x):
    global ans
    ans -= c2(c[x])
    c[x] += 1
    ans += c2(c[x])

def remove(x):
    global ans
    ans -= c2(c[x])
    c[x] -= 1
    ans += c2(c[x])

for x in a:
    remove(x)
    print(ans)
    add(x)
n = int(input())
a = [int(i) for i in input().split()]

d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

ans = 0
for i in d:
    ans += d[i]*(d[i]-1)//2
for i in a:
    print(ans - d[i]*(d[i]-1)//2 + (d[i]-2)*(d[i]-1)//2)
import collections as c

n = int(input())

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

x = c.Counter(a)

cnt = {}

for k,v in x.items():
    cnt[k] = v*(v-1)//2
    
s = sum(cnt.values())
    
mcnt = {}

for k,v in x.items():
    mcnt[k] = cnt[k]-(v-2)*(v-1)//2
    
for i in a:
    print(s-mcnt[i])
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]
def compute(x):
	if x>=2:
		return (x*(x-1)//2)
	else:
		return 0

n = int(input())
a = list(map(int,input().split()))
d = {}
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
s = 0
for j in d:
	s += compute(d[j])

for i in a:
	temp = s - compute(d[i])
	temp = temp + compute(d[i]-1)
	print(temp)
import bisect, collections
 
 
 
def solution():
    d = collections.defaultdict(int)
    n = int(input().strip())
    a = [int(x) for x in input().strip().split(" ")]
    for x in a:
        d[x] += 1
    total = 0
    for _, v in d.items():
        total += v*(v-1)//2
    for x in a:
        print(total-d[x]*(d[x]-1)//2+(d[x]-1)*(d[x]-2)//2)
    

def main():    
    # T = int(input().strip())
    for _ in range(1):
        solution()

if __name__ == "__main__":
    main()
n = int(input())
a = list(map(int, input().split()))
m = [0] * n
for i in a:
    m[i - 1] += 1
ans = 0
for i in m:
    if i >= 2:
        ans += i * (i - 1) // 2
for i in a:
    if m[i - 1] >= 2:
        print(ans - m[i - 1] * (m[i - 1] - 1) // 2 + (m[i - 1] - 1) * (m[i - 1] - 2) // 2)
    else:
        print(ans)
import math
import collections


f = math.factorial


def comb(n, r, memo):
    if (n, r) in memo:
        return memo[n, r]
    elif n < r:
        memo[n, r] = 0
        return 0
    else:
        res = memo[n, r] = f(n) // f(r) // f(n - r)
        return res


N = int(input())
A = list(map(int, input().split()))
memo = {}
counts = collections.Counter(A)
total = sum(comb(count, 2, memo) for count in counts.values())
for a in A:
    count = counts[a] - 1
    diff = count * (counts[a] - count + 1) // 2
    print(total - diff)
N=int(input())
A=list(map(int,input().split()))
from collections import Counter
c=Counter(A)
x=sum([v*(v-1)//2 for v in c.values()])
for a in A:
    print(x-c[a]+1)
import collections

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

c=collections.Counter(a)
num=0
for i in c.values():
    num+=i*(i-1)/2
    
for i in range(x):
    print(int(num-c[a[i]]+1))
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
  b[a[i]-1]+=1
c = sum([i*(i-1)//2 for i in b])
for i in a :
  print(c-(b[i-1]-1))
N=int(input())
A=list(map(int,input().split()))
from collections import Counter
def comb(n):
    if n==1:
        return 0
    else:
        return n*(n-1)/2
list=Counter(A)
sum=0
for number in list:
    sum=sum+comb(list[number])

for i in A:
    print(int(sum-comb(list[i])+comb(list[i]-1)))
from collections import Counter
N=int(input())
A=[int(item)for item in input().split()]
c=Counter(A)
full = {i: c[i] * (c[i] - 1) / 2 for i in c.keys()}
#full = [full[item-1] for item in A]
#print(full)
#ichiheri = [c[i]-1 * (c[i]-1) / 2 for i in range(1,1+len(c))]
sumA = sum(full.values())
val = {i:int(sumA-full[i]+(c[i]-2) * (c[i]-1) / 2 )for i in c.keys()}
#print(ichiheri)



for a in A:
    print(val[a])
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1
# print(x)
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))
for i in range(n):
    if x[a[i]-1]>=2:
        print(count-x[a[i]-1]+1)
    else:
        print(count)
from collections import Counter

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

d = Counter(A)
l = list(d.values())
X = 0
for i in l:
  X += i*(i-1)/2
for i in A:
  x = X
  a = d[i]
  if a != 1:
    x -= a*(a-1)/2
  if a > 1:
    x += (a-1)*(a-2)/2  
  print(int(x))
n = int(input())
a = [int(e) for e in input().split()]
c= [0]*(n+1)
def nc2(n):
    return n*(n-1)//2
for i in range(0,n):
    c[a[i]] += 1
sum = 0
for i in range(1,n+1):
    sum += nc2(c[i])
for i in range(0,n):
    print(sum - nc2(c[a[i]])+nc2(c[a[i]]-1))
N = int(input())
A = list(map(int,input().split()))

from collections import Counter
counter = Counter(A)

from collections import defaultdict
res_dic = defaultdict(int)

base = 0
for key,n in counter.items():
  res_dic[key] = (n * (n - 1) // 2, (n - 1) * (n - 2) // 2)
  base += n * (n - 1) // 2
  
for i in range(N):
  ans = base - res_dic[A[i]][0] + res_dic[A[i]][1]
  print(ans)
N = int(input())
A = list(map(int,input().split(sep=" ")))
S = [0 for i in range(0,N+1,1)]
for i in range(0,N,1):
    S[A[i]] += 1
Sum = 0
for i in range(1,N+1,1):
    Sum += S[i]*(S[i]-1)//2
for k in range(0, N ,1):
    print(Sum - S[A[k]] +1)
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
sum = 0

kn = [0 for i in range(n+1)]
for i in range(n):
    kn[a[i]] += 1
for i in range(n+1):
    sum += kn[i]*(kn[i]-1)//2

for i in range(n):
    x = kn[a[i]]
    print(sum-x+1)
import collections
n = int(input())
a = list(map(str,input().split()))
c = collections.Counter(a)
all_answer = 0
for _,b in c.items():
	all_answer += b*(b-1)//2
for i in a:
	b = c[i]
	print(all_answer-b*(b-1)//2+(b-1)*(b-2)//2)
def nc2(n):
  if n > 1:
    val = n * (n - 1) // 2
  else:
    val = 0
  return val

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

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

all_sum = 0
for num, count in num_dict.items():
  all_sum += nc2(count)
  
for a in A:
  org_count = num_dict[a]
  print(all_sum - (nc2(org_count) - nc2(org_count - 1)))
n=int(input(""))
lista=input("").split(" ")
lisa=[]
listn=[]
for i in range(n+1):
    listn+=[0]
for i in lista:
    lisa+=[int(i)]
    listn[int(i)]+=1
s=0
for i in listn:
    if(i<2):
        continue
    else:
        s+=i*(i-1)/2
for i in lisa:
    print(int(s-listn[i]+1))
from collections import defaultdict
from copy import copy
n = int(input())
a = [int(i) for i in input().split()]
count_a = defaultdict(int)
diff_a = [0] * n
for ai in a:
        count_a[ai] += 1

for i in range(n):
    diff_a[i] = (count_a[a[i]] - 1)

count = 0    
for v in count_a.values():
    count += v*(v - 1) // 2
for i in range(n):
    count_copy = copy(count)
    print(count_copy - diff_a[i])
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
c=0
for i in range(n):
    b[a[i]-1]+=1
for i in range(n):
    c+=b[i]*(b[i]-1)//2
for i in range(n):
    print(c-b[a[i]-1]+1)
import collections
import math

n = int(input())
a = [int(i) for i in input().split()]

def com(n, r):
    if n > 1:
        ann = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        ann = 0
    return ann

b = collections.Counter(a)
ans = []
for i in b:
    ans.append(com(b[i],2))
anss = sum(ans)

for i in range(n):
    t = b[a[i]]
    print(anss - (t-1))
import itertools
import functools
import math
from collections import Counter
from itertools import combinations

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

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

C=Counter(A)

C1=[0]*(N+1)
C2=[0]*(N+1)

sum = 0
for i in range(0,2*10**5):
    if C[i] > 1:
        n = C[i]
        r = 2
        sum += combinations_count(n,r)

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

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


for n in A :
  num_list[n-1] += 1
  
calc_list = list(map(lambda x : max(0, int(x*(x-1)/2)), num_list))
s = sum(calc_list)

for k in range(N) :
  print(s - num_list[A[k]-1] + 1)
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
a = list(set(A))
cc = Counter(A)
dup = set([x for x in a if cc[x] > 1])
c_l = [(cc[i]-1)*(cc[i])/2 for i in a]
al = sum(c_l)

for k in A:
    if k in dup:
        print(int(al-cc[k]+1))
    else :
        print(int(al))
n = int(input())
d = {}
astr = list(map(int, input().split()))
for i in astr:
    d[i] = d.get(i, 0) + 1

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

s = sum(f(i)  for i in d.values())


for i in astr:
    t = d[i]
    print(s - f(t) + f(t-1))
N = int(input())
A = list(map(int, input().split()))


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


counts = [0] * (N + 1)
for a in A:
    counts[a] += 1
total = sum(map(lambda n: comb2(n), filter(lambda n: n > 1, counts)))

for a in A:
    print(total - (counts[a] - 1))
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
ans = 0

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

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

for i in range(n):
    print(ans - b[a[i] -1] + 1)
n=int(input())
arr=list(map(int,input().strip().split()))[:n]
dict1={}
for i in arr:
	if i in dict1:
		dict1[i]+=1
	else:
		dict1[i]=1
sum1=0
for i in dict1:
	sum1+=((dict1[i]*(dict1[i]-1))//2)
for i in arr:
	k=sum1
	n1=dict1[i]
	k-=((n1*(n1-1))//2)
	k+=((n1-1)*(n1-1-1)//2)
	print(k)
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:
    print(result - c[a] + 1)
n = int(input())
A = list(map(int, input().split()))

value = [0]*n

for i in range(n):
  value[A[i]-1]+=1
 
sum = 0
for i in range(n):
  sum += value[i]*(value[i]-1)//2

for i in A:
  print(sum - value[i-1]+1)
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(max(a)+1)]
for x in a:
    b[x] += 1
c = sum([x*(x-1)//2 for x in b])
for i in range(n):
    print(c-b[a[i]]+1)
N = int(input())
A = input().split()

from collections import Counter
B=Counter(A)

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

for k in range(N):
    e=B[A[k]]
    ans_k=ans-e*(e-1)//2+(e-1)*(e-2)//2
    print(ans_k)
import collections
N = int(input())
li = list(map(int, input().split()))
cn = collections.Counter(li)
sumC = sum([n*(n-1)//2 for n in cn.values()])
for k in range(N):
    print(sumC - (cn[li[k]]-1))
import collections
import math

def func(n):
    ans = math.factorial(n)//((math.factorial(n-2))*math.factorial(2))
    return ans

N = int(input())
a = input().split()
ans = dict(collections.Counter(a))
sums = 0
for i in ans.values():
        if i < 2:
            continue
        else:
            sums += func(i)
            
for j in range(N):  
    print(sums-(ans[a[j]]-1))
def comb(n):
    if (n <= 1):
        return 0
    return (n - 1) * n / 2

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

cnt = [0 for i in range(N + 1)]
for a in A:
    cnt[a] += 1
comb1 = [comb(cnt[a]) for a in A]
comb2 = [comb(cnt[a] - 1) for a in A]

Sum = sum([comb(c) for c in cnt])

for i in range(len(A)):
    print(int(Sum - comb1[i] + comb2[i]))
from collections import Counter

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

c = Counter(a)
dic = {}

for x in a:
    if x not in dic:
        ex = (c[x] - 1) * (c[x] - 2) / 2
        no = (c[x]) * (c[x] - 1) / 2
        dic[x] = (int(no), int(ex))

su = sum([int(x[0]) for x in dic.values()])

for i,x in enumerate(a):
    print(su - (dic[x][0] - dic[x][1]))
import collections

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

# 数値Aの頻度
ndic = collections.Counter(A)

mem = {}
tcmb = 0
for j in ndic:
    if ndic[j] == 1:
        continue
    
    if ndic[j] in mem:
        tcmb += mem[ndic[j]]
    else:
        mem[ndic[j]] = int((ndic[j] * (ndic[j] -1)) / 2)
        tcmb += mem[ndic[j]]
        
for i in A:
    cmb  = tcmb - (ndic[i] - 1)
    print(cmb)
from collections import Counter


n = int(input())

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

c = Counter(a)


res = []

for i in range(1, n+1):
    m  = c.get(i, 0)
    res.append(m * (m-1) // 2)

s = sum(res)


for i in range(1, n+1):
    x = a[i-1]
    l = c.get(x, 0)


    print(s - res[x-1] + (l-1) * (l-2) // 2)
from collections import Counter

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

#table = set(a)
con = Counter(a)
dic = {}
#for i in table:
#    con[i] = a.count(i)
#    dic[i] = -1

for x in a:
    if x not in dic:
        ex = (con[x] - 1) * (con[x] - 2) / 2
        no = (con[x]) * (con[x] - 1) / 2
        dic[x] = (int(no), int(ex))

su = sum([int(x[0]) for x in dic.values()])

for i,x in enumerate(a):
    print(su - (dic[x][0] - dic[x][1]))
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline

N, *A = map(int, read().split())
a = Counter(A)
s = sum(i * (i - 1) // 2 for i in a.values())

for i in A:
    v = a[i]
    answer = s - v * (v - 1) // 2 + (v - 1) * (v - 2) // 2
    print(answer)
import collections
_ = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
M=0
for v in c.values():
    if v>1:
        M +=  v*(v-1)/2

for k in l:
    print(int(M-c[k]+1))
N=int(input())
lst=list(map(int, input().split()))

import collections

dct=collections.Counter(lst)


#for i in range(N):
Sum=0
for v in dct.values():
        Sum+=v*(v-1)//2


for i in range(N):
    print(Sum-dct[lst[i]]+1)
def main():

    from collections import Counter
    import sys

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

    d = Counter(a)

    base = sum(v * (v - 1) // 2 for v in d.values())
    e = {k: base - (v >= 2) * (v - 1) for k, v in d.items()}
    p = [str(e[x]) for x in a]
    q = '\n'.join(p)
    print(q)


if __name__ == '__main__':
    main()
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
Ca = {k:v for k, v in Counter(A).items() if v>=2}
ans = {}
al = 0
for k, v in Ca.items():
    al += v*(v-1)//2
for k, v in Ca.items():
    ans[k] = al - v*(v-1)//2 + (v-1)*(v-2)//2
for a in A:
    if a in ans:
        print(ans[a])
    else:
        print(al)
from collections import Counter

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

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

for i in A:
    b = ans
    b -= c[i]*(c[i]-1)//2
    b += (c[i]-1)*(c[i]-2)//2
    print(b)
from collections import Counter

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

cnt = Counter(a)

cnt_items = list(cnt.items())

cnt_values = [i[1] for i in cnt_items]

sum = sum([j*(j-1)//2 for j in cnt_values])

for k in a:
    p = cnt[k]
    print(sum- p*(p-1)//2 + (p-1)*(p-2)//2)
N = int(input())
A = list(map(int,input().split()))

ls = [0]*N
for i in range(N):
    ls[A[i]-1] += 1
s = 0
for i in range(N):
    s += ls[i]*(ls[i]-1)//2
ans = [0]*N
for i in range(N):
    ans[i] = s-ls[A[i]-1] + 1

print(*ans,sep='\n')
n = int(input())
a = list(map(int, input().split()))
nums = [0 for i in range(n)]
sum = 0
for i in range(n):
    nums[a[i]-1] += 1
for i in range(n):
    t = nums[i]
    sum += t*(t-1)//2
for i in range(n):
    t = nums[a[i]-1]
    print(sum - t*(t-1)//2 + (t-1)*(t-2)//2)
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

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

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

for k in range(N):
  ans = total - s[A[k]-1]*(s[A[k]-1]-1)//2 + (s[A[k]-1]-1)*((s[A[k]-1]-1)-1) // 2
  print(ans)
import numpy as np

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

counter = np.bincount(A)

total = (counter * (counter - 1)).sum() // 2
diff = counter -1
ans = total - diff[A]

print(*ans, sep="\n")
n=int(input())
a=list(map(int, input().split()))
b=[0]*n
ans=0

for i in range(n):
    b[a[i]-1]+=1
for i in range(n):
    ans+=(b[i]*(b[i]-1))//2
for i in range(n):
    print(ans-b[a[i]-1]+1)
N = int(input()) #N: ボールの個数

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

from collections import defaultdict

d = defaultdict(int)
for i in A:
    d[i] += 1
max = sum([d[i]*(d[i]-1)//2 for i in range(1,N+1)])
ans = [max - d[i] + 1 for i in A]

for x in ans:
    print(x)
n = int(input())
a = [int(x) for x in input().split()]
sum = 0

d = {}
d_sum = {}
dd_sum = {}

for aa in a:
    if aa not in d:
        d[aa] = 0
    d[aa] += 1

for dd in d.keys():
    sum += d[dd] * (d[dd]-1) // 2
    d_sum[dd] = d[dd] * (d[dd]-1) // 2

for i in range(len(a)):
    buf = a[i]
    tmp = sum
    tmp -= d_sum[buf]
    tmp += (d[buf] - 1) * (d[buf] - 2) // 2
    print(tmp)
import numpy as np
N = int(input())
A = np.array(input().split(),np.int64)

bincnt = np.bincount(A)

total = (bincnt * (bincnt - 1)).sum() // 2
ans = (total - (bincnt-1))[A].astype(str)

print('\n'.join(ans))
N = int(input())
A = list(map(int, input().split()))

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

cntd = {}
for i in range(N):
    if A[i] in cntd:
        cntd[A[i]] += 1
    else:
        cntd[A[i]] = 1

sum_comb = 0
for k, v in cntd.items():
    sum_comb += comb2(v)

#print(cntd)
#print(sum_comb)
for i in range(N):
    k = A[i]
    ans = sum_comb - comb2(cntd[k]) + comb2(cntd[k]-1)
    print(ans)
import collections


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

for i in a:
  j = c[i] - 1
  b = j * (j - 1) // 2
  y = (j + 1) * j // 2
  d = y - b
  print(int(s - d))
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
cnt_list = Counter(A)

total = sum([cnt*(cnt-1)//2 if cnt > 1 else 0 for cnt in cnt_list.values()])
print(*[total-cnt_list[a]+1 for a in A], sep='\n')
N = int(input())
A = list(map(int, input().split()))
b = {}
p = 0

for a in A:
  if not a in b:
    b[a] = 1
  else:
    b[a] += 1
    
for v in b.values():
  p += v * (v - 1) // 2
  
for a in A:
  d = b[a]
  ans = p - (d * (d - 1) // 2) + ((d - 1) * (d - 2) // 2)
  print(ans)
from collections import Counter

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

n = int(input())
balls = [int(i) for i in input().split()]

c = Counter(balls)
total = 0
for k, v in c.items():
    total += nC2(v)

for i in range(n):
    ball = balls[i]
    num = c.get(ball)
    ans = total - nC2(num) + nC2(num - 1)
    print(ans)
def comb(n,r):
    if (n<r): return 0
    a,b=1,1
    r = min(r,n-r)
    for i in range(r):
        a = a*(n-i)
        b = b*(r-i)
    return a // b

from collections import Counter

n=int(input())
a=list(map(int,input().split()))
count_a = Counter(a)
ans = 0
for x,y in count_a.items():
    ans += comb(y,2)

for i in a:
    print(ans-count_a[i]+1)
n=int(input())
a=[int(i) for i in input().split()]
m=max(a)
l=[0]*(m+1)
c=[0]*(m+1)
for i in a:
  l[i]+=1
for i in set(a):
  c[i]=l[i]*(l[i]-1)/2
s=sum(c)
for i in range(n):
  print(int(s-c[a[i]]+(l[a[i]]-1)*(l[a[i]]-2)/2))
n=int(input())
a=list(map(int,input().split()))
ct=[0 for i in range(n+1)]
for i in range(n):
  ct[a[i]]+=1
ans=0
for i in range(n+1):
  ans+=(ct[i]*(ct[i]-1))//2
for i in range(n):
  print(ans-ct[a[i]]+1)