peterverebics/CodeNet_Python_118 huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
d=dict()
for i in range(n):
  if a[i] not in d:
    d[a[i]]=1
  else:
    d[a[i]]+=1
s=0
l=list(d.items())
for i in range(len(l)):
  if l[i][1]>=2:
    s+=l[i][1]*(l[i][1]-1)//2
for i in range(n):
  if d[a[i]]<2:
    print(s)
  else:
    print(s-(d[a[i]]-1))
from math import factorial

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


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


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

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

s = [0]*(n+1)
for x in a:
    s[x] += 1
    

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

for i in range(n):
    ans = p - s[a[i]]*(s[a[i]]-1)//2 + (s[a[i]]-2)*(s[a[i]]-1)//2
    print(ans)
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

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

for i in a:
    print(ans-cnt[i]+1)
from math import factorial
def comb(n):
    if n == 1 or n == 0:
        return 0
    return int(n * (n-1) / 2 )

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

count = {}
ans = 0

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

for v in count.values():
    ans += comb(v)


for i in range(n):
    v = count[a[i]]
    print(ans - comb(v) + comb(v-1))
N=int(input())
A=list(map(int,input().split()))
d={}
for a in A:
    if a not in d:
        d[a]=1
    else:
        d[a]+=1
ans=0
for k in d.keys():
    e=d[k]
    ans+=e*(e-1)//2
for a in A:
    keep=ans
    e=d[a]
    temp=e*(e-1)//2
    ans-=temp
    ans+=(e-1)*(e-2)//2
    print(ans)
    ans=keep
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))
n=int(input())
a=list(map(int,input().split()))

import collections
C = collections.Counter(a)

#logging.debug(C)

sum=0
for v in list(C.values()):
	sum+=v*(v-1)//2
 
for k in range(n):
	x = C[a[k]]
	print(sum-(x*(x-1)//2)+((x-1)*(x-2)//2))
import collections
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

d = defaultdict(list)

for number in c.keys():
    count = c[number]
    d[number] = total - (count-1)

for i in a:
    print(d[i])
import math
def combinations_count(n, r):
    return math.factorial(n)//(math.factorial(n-r) * math.factorial(r))


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

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

total = 0
for i in range(1,n+1):
    if b[i]>=2:
        total += combinations_count(b[i],2)

for i in range(n):
    print(total-b[a[i]]+1)
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from collections import deque

def main():
	n=II()
	A=LI()
	B=[0]*(n+1)
	for i in A:
		B[i]+=1

	ans=0
	for i in B:
		ans+=i*(i-1)//2
	#print(ans)
	for i in A:
		print(ans-B[i]+1)









if __name__ == "__main__":
	main()
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
  if a[i] in dic.keys():
    dic[a[i]] += 1
  else:
    dic[a[i]] = 1
total = 0
loss = [0]*(n+1)
for k in dic.keys():
  res = dic[k]*(dic[k]-1)//2
  total += res
  loss[k] = res-(dic[k]-1)*(dic[k]-2)//2
for i in range(n):
  print(total-loss[a[i]])
n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = {}
for item in a:
    if item in dic.keys():
        dic[item] += 1
    else:
        dic[item] = 1

all_ans = sum([item * (item - 1) // 2 for item in dic.values()])

for i in range(n):
    print(all_ans - dic[a[i]] + 1)
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+1):
    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])
import numpy as np
import collections
n=int(input())
a=list(np.fromstring(input(),int,sep=' '))
dic=collections.Counter(a)
ans=0

for i in dic.values():
    ans+=i*(i-1)//2
    
for i in range(n):
    print(ans-(dic[a[i]]-1))
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
sum_A = 0
dict = defaultdict(int)
for i in A:
    dict[i] += 1

for v in dict.values():
    sum_A += v * (v - 1) // 2

for i in A:
    print(sum_A - (dict[i] - 1))
n = int(input())
lis = list(map(int,input().split()))
num = [0 for i in range(n+1)]
for nn in lis:
  num[nn] += 1
ans = 0
for nnn in num:
  ans += (nnn*(nnn-1))//2
for i in range(n):
  print(ans-(num[lis[i]]*(num[lis[i]]-1))//2+((num[lis[i]]-1)*(num[lis[i]]-2))//2)
n = int(input())
a = list(map(int,input().split()))
d = {}
ans = 0
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1

for i in d.items():
    ans += (i[1]*(i[1]-1)//2)

for i in a:
    print(ans - ((d[i]-1)*(d[i]-d[i]+2))//2)
N=int(input())
A=list(map(int,input().split()))

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


C = collections.Counter(A)

d = {}

total = 0
for k, v in C.items():
    d[k] = (v*(v-1)//2, (v-1)*(v-2)//2)
    total += d[k][0]


for i in range(N):
    minus = d[A[i]][0]
    plus = d[A[i]][1]
    print(total - minus + plus)
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
ans_dict = {}

l1 = list(c.values())
l2 = [(i*(i-1))/2 if i >= 2 else 0 for i in l1]
sum_l2 = sum(l2)

for i in l:
    b = c[str(i)]
    if b < 2:
        print(int(sum_l2))
    elif b == 2:
        print(int(sum_l2 - 1))
    elif b > 2:
        print(int(sum_l2 - ((b*(b-1))/2) + (((b-1) *(b-2))/2)))
N = int(input())
A = list(map(int, input().split()))

Li = [0] * max(A)
for a in A:
    Li[a-1] += 1

ans = sum(a*(a-1)//2 for a in Li)

for a in A:
    print(ans - (Li[a-1]-1))
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

T = 0
for k in a.keys():
    c = a[k]
    T += (c * (c-1)) // 2

for i in A:
    t = 0
    c = a[i]
    t = T
    t -= (c * (c-1)) // 2
    c -= 1
    t += (c * (c-1)) // 2
    print(t)
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
ans_dict = {}

hoge = list(c.values())
full_fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
full_ans = sum(full_fuga)

for i in l:
    v = c[str(i)]
    if v < 2:
        print(int(full_ans))
    elif v == 2:
        print(int(full_ans - 1))
    elif v > 2:
        print(int(full_ans - ((v*(v-1))/2) + (((v-1) *(v-2))/2)))
from collections import Counter

n = int(input())
k_list = [int(w) for w in input().split()]
c = Counter(k_list)


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

for i in k_list:
    cnt = c[i]
    tmp = max_pat

    if cnt >= 2:
        tmp -= (cnt * (cnt - 1)) // 2
        tmp += ((cnt - 1) * (cnt - 2)) // 2

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

nums = [0]*N

for val in A:
    nums[val-1] += 1

choices = 0
for num in nums:
    choices += int(num * (num - 1) / 2)

for val in A:
    print(choices - nums[val - 1] + 1)
def nC2 (n):
    return n*(n-1)//2 

N = int(input())
A = tuple(map(int,input().split()))
cnt = [0]*200005
tot = 0
for i in A:
    cnt[i] += 1
for i in cnt:
    tot += nC2(i)
for i in range(N):
    ans = tot - nC2(cnt[A[i]]) + nC2(cnt[A[i]]-1)
    print(ans)
from collections import Counter
n = int(input())
nums = list(map(int,input().split(" ")))

c = Counter(nums)
a = 0
for k,v in c.items():
    if v >=2:
        a+=(v-1)*v//2

for num in nums:
    curr = -1
    if c[num] >= 2:
        curr = a - (c[num]-1)
    else:
        curr = a
    print(curr)
N = int(input())
A = [int(i) for i in input().split()]

ball = [0 for _ in range(N)]

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

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


#print("ball", ball)
for k in range(N):
    ans = all
    ball_new = ball[A[k] - 1] - 1
    #ball_new[A[k] - 1] -= 1

    ans -= ball[A[k] - 1]*(ball[A[k] - 1] - 1)//2
    ans += ball_new*(ball_new - 1)//2

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

from collections import Counter
cnt = Counter(A)

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

c = Counter(a)
key = c.keys()
comb = 0
for i in key:
    comb += (c[i]) * (c[i]-1) // 2

for i in a:
    ans = comb - (c[i]-1)
    print(ans)
import collections
input = raw_input
n = int(input())
nums = map(int, input().split(" "))

counter = collections.Counter(nums)
values = counter.keys()
all_out = 0
for val, num in counter.items():
    if num == 1:
        continue
    else:
        all_out += num * (num-1) // 2

outs = {}
for val, num in counter.items():
    if num == 1:
        outs[val] = all_out
    else:
        outs[val] = all_out - (num-1)

for num in nums:
    print(outs[num])
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
ans=0
for i in list(set(a)):
  ans+=d[i]*(d[i]-1)//2
for i in a:
  kari=ans
  kari-=d[i]*(d[i]-1)//2
  kari+=(d[i]-1)*(d[i]-2)//2
  print(kari)
N=int(input())
A=list(map(int,input().split()))

L=0
C=[0]*N

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

for i in range(N):
    L+=int(C[i]*(C[i]-1)/2)
    
for i in A:
    print(L-C[i-1]+1)
import collections
N = int(input())
A = [int(i) for i in input().split()]

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

for a in A:
    print(ans-C[a]+1)
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):
    if c[list1[i]]!=0:
        print(a-c[list1[i]]+1)
    else:
        print(a)
from math import factorial
from collections import defaultdict


def cmb(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


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

dA = defaultdict(int)
for i in A:
    dA[i] += 1

sm = 0

for i in dA.values():
    if i >= 2:
        sm += cmb(i, 2)
    else:
        sm += 0

for j in A:
    print(sm - (dA[j] - 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

ans = 0
for i in d.values(): ans += i*(i-1)//2
  
for i in a:
  print(ans - (d[i]-1))
n = int(input())
A = list(map(int, input().split()))

import collections
c = collections.Counter(A)
a = 0

for i,j in c.items():
    a += j *(j-1) //2
#print('===', a)
for k in range(n):
    nn = c[A[k]]
    ans = a -(nn-1)
    print(ans)
N=int(input())
A=list(map(int,input().split()))
C=[0]*N
for i in range(N):
    C[A[i]-1]+=1
K=0
for i in range(N):
    if(C[i]!=0):
        K+=int(C[i]*(C[i]-1)/2)

for i in range(N):
    ans=K-(C[A[i]-1]-1)
    print(ans)
N = int(input())
A = list(map(int, input().split()))
 
import collections
import copy

tot = 0
c = collections.Counter(copy.copy(A))
for v in c.values():
  tot += (v*(v-1)/2)

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

count = [0] * (N+1)
for aa in a:
    count[aa] += 1

su = 0
for ct in count:
    su += ct*(ct-1)/2
    
for aa in a:
    print(int(su-count[aa]+1))
from collections import defaultdict
n = int(input())
dic=defaultdict(int)
A = list(map(int, input().split()))
for i in range(n):
    dic[A[i]]+=1

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

for k in range(n):
    x=dic[A[k]]
    if x>=2:
        ans=tmp-(x*(x-1)//2)+((x-1)*(x-2)//2)
    else: ans=tmp
    print(ans)
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
A = Counter(a)

X = 0
for x, y in A.items():
    X += y * (y-1) // 2

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

count = [0]*(N+1)

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

#print(count)

total = 0
for j in range(1,N+1):
  cj = count[j]*(count[j]-1)//2
  #print(cj)
  total = total + cj

ans = total
for k in range(N):
  ans = total - (count[A[k]] - 1)
  print(ans)
N = int(input())
A = [int(s) for s in input().split()]
B = [0 for i in range(N)]
def nC2(n):
  return n*(n-1)//2
for i in range(N):
  B[A[i]-1] += 1
Ctot = 0
for i in range(N):
  Ctot += nC2(B[i])
for i in range(N):
  current_idx = A[i]-1
  if B[current_idx] == 1:
    count = Ctot
  else:
    count = Ctot + nC2(B[current_idx]-1) - nC2(B[current_idx])
  print(count)
import math
 


def nC2(i):
    if i<=1:
        return 0
    return i*(i-1)//2

def compute(count):
    total = 0
    for i in count:
        total += nC2(i)
    return total


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

count = [0] * (N+1)

for value in data:
    count[value] += 1
    
    
total = compute(count)    

for value in data:
    remove = nC2(count[value])
    add = nC2(count[value]-1)

    print(total-remove+add)
# bin/env/pypy3
import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_e = {}
s = sum(v*(v-1)//2 for v in c.values() if v > 1)
for e in a:
    if not e in memo_e:
        #c[e] -= 1
        if 1 < c[e]:
            memo_e[e] = s - (c[e]*(c[e]-1)//2 - (c[e]-1)*(c[e]-2)//2)
        else:
            memo_e[e] = s
    print(memo_e[e])
n = int(input())
a = map(int, input().split())
a = list(a)

c = {}
for k in a:
    if c.get(k) is None:
        c[k] = 1
    else:
        c[k] += 1


def nc2(x):
    return (x*(x-1)) // 2


ans = 0
for cn in c.values():
    ans += nc2(cn)

for k in a:
    print(ans - (nc2(c[k]) - nc2(c[k]-1)))
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
t = 0
for e in C:
    t += C[e]*(C[e]-1)//2

for e in A:
    print(t-C[e]+1)
N = int(input())
A = list(map(int, input().split())) 
size = [0] * N
ans = 0
for i in range(N):
    size[A[i]-1] += 1

for i in range(N):
    if(size[i] >= 2):
        ans += int(size[i] * (size[i]-1) / 2)

for k in range(N):
    if(size[A[k]-1] <= 1):
        print(ans)
    else:
        print(ans - (size[A[k]-1]-1))
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())

cache = {}
for n in nums:
    if n in cache:
        print(cache[n])
    else:
        val = baseline - patterns[n] + math.comb(counter[n] - 1, 2)
        cache[n] = val
        print(val)
import collections

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

c = collections.Counter(a)

r = 0
for j in c:
    if c[j] > 1:
        r = int(r + (c[j] * (c[j] - 1) / 2))

tmp = r 
for i in range(n):
    r = int(r - ((c[a[i]] * (c[a[i]] - 1) / 2)) + (((c[a[i]] - 1) * (c[a[i]] - 2) / 2)))
    print(r)
    r = tmp
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+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)
 
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)
n=int(input())
a=[int(x) for x in input().split()]
num=[0]*n

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

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

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

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
cs = {k: v*(v-1)//2 for k, v in c.items() if v!=1}
s = sum(cs.values())

for v in a:
    if v in cs:
        print(s-(c[v]-1))
    else:
        print(s)
from collections import Counter

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

if len(a) == len(set(a)):
    for i in range(n):
        print(0)
else:
    kw = Counter(a)
    ans = sum([x * (x - 1) // 2 for x in kw.values()])

    for i in range(n):
        print(ans - kw[a[i]] + 1)
N = int(input())
A = list(map(int, input().split()))
ans = [0]*N
for i in range(N):
  ans[A[i]-1]+=1
b = 0
for i in range(len(ans)):
  b += ans[i]*(ans[i]-1)//2
for i in range(N):
  print(b-ans[A[i]-1]+1)
N = int(input())
A = list(map(int, input().split()))
cnt = [0 for _ in range(N)]
for i in range(N):
    cnt[A[i]-1] += 1
S = 0
for i in range(N):
    S += cnt[i]*(cnt[i]-1)/2
for i in range(N):
    if cnt[A[i]-1] == 1:
        print(int(S))
    else:
        print(int(S+(3-2*cnt[A[i]-1])/2))
from collections import Counter

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

cnt = Counter(A)
mem = dict()
for k, v in cnt.items() :
  mem[k] = v * (v - 1) // 2

s = sum(mem.values())
for i in range(N) :
  ret = s - mem[A[i]] + (cnt[A[i]] - 1) * (cnt[A[i]] - 2) // 2
  print(ret)
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inpl(): return list(map(int, sys.stdin.readline().split()))


def inpl_str(): return list(sys.stdin.readline().split())


N = inp()
aa = inpl()

cnts = [0]*(N+10)

for a in aa:
    cnts[a] += 1

S = 0
for a in aa:
    S += cnts[a]-1

S //= 2

for a in aa:
    print(S - cnts[a] + 1)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = Counter(A)
total = 0

for c in list(count.values()):
    total += c*(c-1)/2

for a in A:
    n = count[a]
    before = n*(n-1)/2
    after = (n-1)*(n-2)/2
    ans = total + after - before
    print(int(ans))
N = int(input())
A = list(map(int, input().split()))

from collections import defaultdict
dict = defaultdict(int)
for a in A:
    dict[a] += 1

ans = 0
for key, value in list(dict.items()):
    ans += value*(value-1) // 2

for a in A:
    tmp = ans - dict[a]*(dict[a]-1)//2 + (dict[a]-1)*(dict[a]-2)//2
    print(tmp)
n = int(input())
a = list(map(int, input().split()))
ball = [0] * (n+1)
for i in a:
  ball[i] += 1
base = 0
for i in ball:
  base += i * (i-1) // 2
for i in a:
  b = ball[i]
  ans = base - (b-1) * 2 // 2
  print(ans)
import math
import sys

n = int(sys.stdin.readline().rstrip())
a = list(map(int, sys.stdin.readline().rstrip().split()))
num = [0] * n
for ai in a:
    num[ai - 1] += 1

c = 0
for n in num:
    c += n * (n - 1) // 2

for ai in a:
    print(c - num[ai-1] + 1)
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(int(s))
def combi(n):
    if n > 1: return n*(n-1)//2
    else:return 0

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

sum = [0]*(max(A)+1)
for a in A:sum[a] += 1
total = 0
for s in sum:total += combi(s)
for a in A:
    print(total - combi(sum[a]) + combi(sum[a]-1))
N = int(input())

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

balls = [0] * (N + 1)

for a in A_list:
	balls[a] += 1

counts = [0] * (N + 1)
total = 0

for i in range(1, N + 1):
	ball = balls[i]
	count = ball * (ball - 1) // 2
	total += count
	counts[i] = count

for i in range(N):
	a = A_list[i]
	ball = balls[a] - 1
	count = ball * (ball - 1) // 2
	print(total - counts[a] + count)
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    C = Counter(A)

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

    ans = [0] * N
    for i, a in enumerate(A):
        ans[i] = total - C[a] + 1

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()
import collections as col
n = int(input())
a = list(map(int,input().split()))
cnt = col.Counter(a)

ans = 0
for key,val in cnt.items(): ans += val*(val-1)//2

for i in range(n):
    print(ans - cnt[a[i]] + 1)
def comb2(num):
    return num * (num - 1) // 2


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

# create hash table
table = {}
for i in range(n):
    if a[i] not in table:
        table[a[i]] = 1
    else:
        table[a[i]] += 1

total = 0
for idx in table:
    total += comb2(table[idx])

for i in range(n):
    sub = comb2(table[a[i]])
    add = comb2(table[a[i]] - 1)
    print(total - sub + add)
n = int(input())
a = list(map(int,input().split()))

import collections

e = collections.Counter(a)

count = 0
for i in e.keys():
    m = e[i]
    count += m*(m-1)//2

for k in range(n):
    b = a[k]
    c = e[b] - 1
    ans = count - c
    print(ans)
import collections

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

c = collections.Counter(A_list)
c_value_list = list(c.values())
#print(c_value_list)

ans = 0

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

for k in range(N):
    ans_temp = ans - c[A_list[k]] + 1
    print(ans_temp)
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    cnt = dict()
    ans = dict()
    for i in a:
        cnt[i] = cnt.get(i, 0) + 1

    for (idx, v) in cnt.items():
        ans[idx] = v * (v - 1) // 2

    sum_ = sum(ans.values())

    for k in range(len(a)):
        res = sum_ - (cnt[a[k]] - 1)
        print(res)
from collections import Counter

N=int(input())
L=list(map(int,input().split()))
M=Counter(L)
Z={}
#print(M)
pft=0
for i,j in M.items():
	Z[i]=(j*(j-1)//2,((j-2)*(j-1)//2))
	pft+=Z[i][0]
#print(Z)
for i in range(N):
	print(pft-Z[L[i]][0]+Z[L[i]][1])
n = int(input())
A = list(map(int,input().split()))

S={}
for i in range(n):
    a = A[i]
    if a in S :
        S[a]+=1
    else:
        S[a]=1

V=list(S.values())
c = sum([v*(v-1)//2 for v in V])

cdiff=0
K=[]
for i in range(n):
    cdiff=0
    a = A[i]
    s=S[a]
    if s>=2 :
        cdiff=(s*(s-1)-(s-1)*(s-2))//2
    print(c-cdiff)
import collections
n=int(input())
a=list(map(int,input().split()))

d=collections.Counter(a)
#print(d)
ans=0
for v in d.values():
    ans+=v*(v-1)//2
#print(ans)

for i in range(n):
    ans2=ans
    v=d[a[i]]
    ans2-=v*(v-1)//2
    v-=1
    ans2+=v*(v-1)//2
    print(ans2)
N = int(input())
Alist=list(map(int, input().split()))
numdic = {}
for i in Alist:
    if i in numdic:
        numdic[i] += 1
    else:
        numdic[i] = 1
Apple = 0
for i in numdic.values():
    Apple += i*(i-1)//2
for i in Alist:
    tmp = Apple
    tmp -= (numdic[i]-1)
    print(tmp)
from collections import Counter

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

counter = Counter(A)

all_num = 0
for value in counter.values():
    all_num += value * (value - 1) // 2


for a in A:
    value = counter[a]
    before = value * (value - 1) // 2
    after = (value - 1) * (value -2) // 2
    print(all_num + after - before)