Problem:
 Score : 400 points    Problem Statement  We have N balls. The i -th ball has an integer A_i written on it. For each k=1, 2, ..., N , solve the following problem and print the answer.   Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k -th ball so that the integers written on them are equal.       Constraints   3 \leq N \leq 2 \times 10^5  1 \leq A_i \leq N  All values in input are integers.         Input  Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output  For each k=1,2,...,N , print a line containing the answer.        Sample Input 1 5
1 1 2 1 2      Sample Output 1 2
2
3
2
3  Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2 . From these balls, there are two ways to choose two distinct balls so that the integers written on them are equal. Thus, the answer for k=1 is 2 .       Sample Input 2 4
1 2 3 4      Sample Output 2 0
0
0
0  No two balls have equal numbers written on them.       Sample Input 3 5
3 3 3 3 3      Sample Output 3 6
6
6
6
6  Any two balls have equal numbers written on them.       Sample Input 4 8
1 2 1 4 2 1 4 1      Sample Output 4 5
7
5
7
7
5
7
5

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

import collections
import math

dicA = collections.Counter(A)

total = 0
for x in list(dicA.values()):
  if x != 1:
    total += math.factorial(x) // (math.factorial(x - 2)*2)

for i in range(N):
  print(total - dicA[A[i]] +1)

Solution (Python):
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 - d[a] + 1)

Solution (Python):
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 - d[a] + 1)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    m = {}

    for i in a:
        if i not in m:
            m[i] = 1
        else:
            m[i] += 1
    
    ans = 0

    for key in m:
        if m[key] >= 2:
            ans += m[key] * (m[key] - 1) // 2
    
    for i in range(n):
        if m[a[i]] >= 2:
            print(ans - (m[a[i]] * (m[a[i]] - 1) // 2 - (m[a[i]] - 1) * (m[a[i]] - 2) // 2))
        else:
            print(ans)

Solution (Python):
def possibleCombos(num):
    num2 = num - 1
    return (num2*num2 + num2)//2
N = int(input())
A = [int(i) for i in input().split()]
data = [0] * (N+1)
total = 0
for i in A:

    data[i] +=1

for i in data:
    total += possibleCombos(i)
for i in A:
    result = total - possibleCombos(data[i]) + possibleCombos(data[i]-1)
    print(result)

Solution (Python):
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)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
m = {}
for a in A:
    m.setdefault(a, 0)
    m[a] += 1

all_combination = 0
for v in m.values():
    if v > 1:
        all_combination += int(v * (v - 1) / 2)
for a in A:
    ans = all_combination - (m[a] - 1)
    print(ans)

Solution (Python):
N = int(input())
Alist = list(int(x) for x in input().split())

nball = [0] * (N+1)
for i in range(N):
    nball[Alist[i]]+=1

sum=0
for i in range(N):
    sum+=nball[i+1]*(nball[i+1]-1)/2
    
for i in range(N):
    if(nball[Alist[i]] > 2):
        print(int(sum-( ((nball[Alist[i]]-1)*2) /2 )))
    elif(nball[Alist[i]] == 2):
        print(int(sum-1))
    else:
        print(int(sum))

Solution (Python):
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 = c[A[i]] * (c[A[i]] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))

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

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

for k in range(0, N):
    ak = A[k]
    print(counts - d[ak] + 1)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
total = 0
for k, v in c.items():
  total += v* (v-1)/2
for a in A:
  print(int(total - c[a]+1))

Solution (Python):
import sys
input = sys.stdin.readline


'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
import collections

n = int(input())
a = list(map(int, input().split()))
alis = collections.Counter(a)
ss = []
for i in range(1, n+1):
    ss.append(alis[i]*(alis[i]-1)//2)


chinpo=sum(ss)

for i in range(n):
    
    print(chinpo-ss[a[i]-1]+(alis[a[i]]-1)*(alis[a[i]]-2)//2)

Solution (Python):
from collections import defaultdict
import math

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

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

for x in A:
    d[x]+=1
s=0
for v in d.values():
    if v>1:
        s+=comb(v,2)

for j in range(N):
    num=A[j]
    z=d[num]-1
    print(s-z)

Solution (Python):
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+1):
  ans += int(c[i]*(c[i]-1)/2)
for i in range(n):
  print(ans-(c[a[i]]-1))

Solution (Python):
def z(z_dic, v: int):
    if v in z_dic:
        return z_dic[v]
    z = 0
    if v == 2:
        z = 1
    elif v > 2:
        z = int(v*(v-1)/2)
    z_dic.setdefault(v, z)
    return z


def main():
    n = int(input())

    ar = [0] * (n+1)
    ls = []

    for x in map(int, input().split()):
        ls.append(x)
        ar[x] += 1

    zls = []
    zls2 = []

    z_dic = {}

    for i in range(1, n+1):
        v = ar[i]
        zls.append(z(z_dic, v))
        zls2.append(z(z_dic, v-1))
    ss = sum(zls)

    for i in range(1, n+1):
        aa = ls[i-1]
        print(ss - zls[aa-1] + zls2[aa-1])


main()

Solution (Python):
def z(z_dic, v: int):
    if v in z_dic:
        return z_dic[v]
    z = 0
    if v == 2:
        z = 1
    elif v > 2:
        z = int(v*(v-1)/2)
    z_dic.setdefault(v, z)
    return z


def main():
    n = int(input())

    ar = [0] * (n+1)
    ls = []

    for x in map(int, input().split()):
        ls.append(x)
        ar[x] += 1

    zls = []
    zls2 = []

    z_dic = {}

    for i in range(1, n+1):
        v = ar[i]
        zls.append(z(z_dic, v))
        zls2.append(z(z_dic, v-1))
    ss = sum(zls)

    for i in range(1, n+1):
        aa = ls[i-1]
        print(ss - zls[aa-1] + zls2[aa-1])
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


main()

Solution (Python):
import numpy as np
def main():
    from collections import Counter
    n = int(input())
    a = tuple(map(int, input().split()))
    ans = 0
    c = Counter(a)
    for i in range(n):
        ans += c[i+1]*(c[i+1]-1)//2
    for j in range(n):
        print(ans - c[a[j]] + 1)
if __name__ == '__main__':
    main()

Solution (Python):
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(total)

Solution (Python):
N = int(input())
K = list(map(int,input().split()))
A = [0]*N
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])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
l = [0] * n
for i in a:
    l[i-1] += 1
    
al = 0
for i in l:
    al += i*(i-1)//2

for k in range(n):
    print(al - (l[a[k]-1] - 1))

Solution (Python):
import math

n=int(input())
a=list(map(int,input().split()))
table={}
fact_table={}
total=0
for i in a:
    if i in table:
        table[i]+=1
    else:
        table[i]=1
for key in table:
    if table[key]>=2:
        fact_table[key]=math.factorial(table[key])//(math.factorial(2)*math.factorial(table[key]-2))
        total+=fact_table[key]
    else:
        fact_table[key]=0
for i in a:
    ans=total-fact_table[i]+((table[i]-2)*fact_table[i])//table[i]
    print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in a_count.items():
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])

Solution (Python):
from collections import Counter
def comb(x):
    return x*(x-1)//2
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
b = 0
for i in c.values():
    b+=comb(i)
for k in range(n):
    print(b-c[a[k]]+1)

Solution (Python):
from collections import Counter

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

l = Counter(A)
ans = sum([v*(v-1)//2 for v in l.values()])

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

Solution (Python):
import collections


def permutations_count(n, r):
    return n*(n-1)//2

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

cnt = collections.Counter(A)
per_cnt = {k:permutations_count(v, 2) for k,v in cnt.items()}
pre_total = sum(per_cnt.values())

for a in A:
    print(pre_total-per_cnt[a]+permutations_count(cnt[a]-1, 2))

Solution (Python):
N=int(input())
kazu=[0 for i in range(N)]
A=[int(x) for x in input().rstrip().split()]

for i in A:
  kazu[i-1]+=1

cnt=0
ans=[]
for i in kazu:
  ans.append((i*(i-1))//2)

cnt=sum(ans)
for i in range(N):
  now=kazu[A[i]-1]-1
  print(cnt-ans[A[i]-1]+(now*(now-1))//2)

Solution (Python):


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

d = {}
for i in a:
    if i not in d.keys():
        d[i] = 1 
    else:
        d[i] += 1

org = 0 
for i in d.keys():
    org += d[i]*(d[i]-1)//2

for i in a:
    ans = org - d[i]*(d[i]-1)//2 + (d[i]-1)*(d[i]-2)//2
    print(ans)

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

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

cnt = {}
for a in A:
    if a not in cnt:
        cnt[a] = 1
    else:
        cnt[a] += 1
res = 0
for k, v in cnt.items():
    if v >= 2:
        res += combi2(v)

ans = []
for a in A:
    v = cnt[a]
    if v >= 2:
        ans.append(res-combi2(v)+combi2(v-1))
    else:
        ans.append(res)
for a in ans:
    print(a)

Solution (Python):
from collections import defaultdict


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


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

h = defaultdict(int)
for a in A:
    h[a] += 1

total = 0
for k, v in h.items():
    total += nC2(v)

for k in range(N):
    t = A[k]
    print(total - h[t] + 1)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

from collections import defaultdict 



N = ii()
A = li()
d = defaultdict(int)

for num in A:
    d[num] += 1

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

for num in A:
    if d[num] == 1:
        print(sum_a)
    elif d[num] == 2:
        print(sum_a-1)
    else:
        print(sum_a-d[num]+1)

Solution (Python):


from collections import Counter

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

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

for i in range(N):
    print(total - (counter[A[i]] - 1))

Solution (Python):
from collections import Counter

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

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

for a in A:
    print(s - (cnt[a]-1))

Solution (Python):







def c(n):
    return max(0 , (n * (n - 1)) // 2)

def main():
    from collections import Counter
    n = int(input())
    a = list(map(int , input().split()))
    C = Counter(a)
    ans = 0
    for i in C:
        ans += c(C[i])
    
    for i in a:
        pans = ans - c(C[i]) + c(C[i] - 1)
        print(pans)
    return

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
s = list(map(int,input().split()))

import collections

cnt = collections.Counter(s)
ans = sum([(v * (v-1)) // 2 for k, v in cnt.items()])

for i in range(len(s)):
  print(ans - cnt[s[i]] + 1)

Solution (Python):
import collections

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

C = collections.Counter(A)
C2 = {}
total = 0
for v in C:
  c = C[v]
  c2 = c*(c-1)//2
  total += c2
  C2[v]=(c2-(c-1)*(c-2)//2)
  
for a in A:
  print(total-C2[a])

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

n = inp()
a = inpl()
dic = collections.defaultdict(int)
origin=0
for i in a:
    origin+=dic[i]
    dic[i] += 1

for i in a:
    print(origin-dic[i]+1)

Solution (Python):
import collections

if __name__ == '__main__':

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

    c = collections.Counter(a)

    all = 0

    for item in c.items():
        all += item[1] * (item[1] - 1) //2

    for i in range(n):
        item = c[a[i]]
        after = item * (item-1) // 2
        before = (item-1) * (item-2) // 2
        
        ans = all - after + before
        print(ans)

Solution (Python):
import math
import collections

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

equal = 0
elements = collections.Counter(A)
equal = sum([v * (v - 1) // 2 for v in elements.values()])

for i in range(n):
    equal_i = elements[A[i]] - 1
    print(equal - equal_i)

Solution (Python):
a=int(input())
l=list(map(int,input().split()))
List=[0]*(a+1)
for i in l:
  List[i]+=1
s=0
for i in List:
  s+=int(i*(i-1)/2)
for i in l:
  print(s-List[i]+1)

Solution (Python):
a=int(input())
l=list(map(int,input().split()))
List=[0]*(a+1)
for i in l:
  List[i]+=1
s=0
for i in List:
  s+=int(i*(i-1)/2)
for i in l:
  print(s-List[i]+1)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
cnt = [0]*N
for k,v in c.items():
    cnt[k-1] = v*(v-1)//2
num = sum(cnt)
ans = 0
for a in A:
   print(num-c[a]+1)

Solution (Python):
import collections
import functools
import math

n = int(input())
l = list(map(int, input().split(" ")))
c = collections.Counter(l)
m ={}
def f(n , r):
    if (n, r) in m:
        return m[(n,r)]
    if (n < r):
        return 0
    tmp = math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
    m[(n, r)] = tmp
    return tmp


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

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

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))
count_list = [0]*N

for i in range(N):
    count_list[arr[i-1]-1] +=1

sum = 0
for i in range(N):
    if count_list[i] != 0:
        sum += int(count_list[i]*(count_list[i]-1)/2)

for i in range(N):
    print(sum+1-count_list[arr[i]-1])

Solution (Python):
N = int( input())
A = list( map( int, input().split()))
L = [0] * N

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

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

for i in range( N ):
  print( s - ( L[ A[ i ] - 1 ] - 1 ))

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

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

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

for k in range(N):
    n = b[A[k]]
    ans = int(total - n*(n-1)/2 + (n-1)*(n-2)/2)
    print(ans)

Solution (Python):

import collections as cl
from math import factorial

def comb(n, r):
    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)


npair = 0
for (k, v) in clc.items():
    npair += comb(v, 2)


for a_ in a:
    print(npair - (clc[a_] - 1))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
c = [0] * n
res = 0

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

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

for i in a:
    print(res - c[i-1] + 1)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

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


c = collections.Counter(a)
maxa = 0
item = [0 for i in range(max(a))]
for key,value in c.items():
    item[key-1] = value
    maxa += (value)*(value-1)//2
for i in range(len(a)):
    d = (item[a[i]-1])*(item[a[i]-1]-1)//2-(item[a[i]-1]-1)*(item[a[i]-1]-2)//2
    print(maxa-d)

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

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

m=0
for i in di:
    m+=di[i]*(di[i]-1) // 2

for i in a:
    print(m-di[i]+1)

Solution (Python):
from collections import *
n,*a=map(int,open(0).read().split())
s=set(a)
c=Counter(a)
sm=0
for i in s:
  sm+=c[i]*(c[i]-1)//2
for i in a:
  print(sm-(c[i]*(c[i]-1)//2)+((c[i]-1)*(c[i]-2)//2))

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)

from bisect import bisect_left

N = I()
A = LI()
dic = {}
total_pair = 0
for i in range(N):
    dic[A[i]]  = dic.get(A[i],0) + 1
for value in dic.values():
    total_pair += int(value*(value-1)/2)
for num in A:
    print(total_pair-dic[num]+1)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
s = sum([i*(i-1)//2 for i in c.values()])

for k in range(n):
  print(s-c[a[k]] + 1)

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

nums = [0]*(n+1)
for i in a:
  nums[i] += 1
  
t = 0
for j in nums:
  t += j*(j-1)//2

for k in a:
  print(t+1-nums[k])

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
val = list(cnt.values())
s = 0
for i in val:
  s += i*(i-1)//2
for i in A:
  print(s-(cnt[i]-1))

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools







INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    d = na()
    c = collections.Counter(d)

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

    for i in range(n):
        v = c[d[i]]

        print(int(total - v + 1))


if __name__ == '__main__':
    main()

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

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

m=0
for i in adict:
  m+=adict[i]*(adict[i]-1)//2

for i in a:
  print(m-adict[i]+1)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

sum = 0

for key, value in dic.items():
    sum += value * (value - 1) // 2

for a in A:
    val = dic[a]
    pre_sum = sum - val * (val - 1) // 2
    ans = pre_sum + (val - 1) * (val - 2) //2
    print(ans)

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
C = [0 for i in range(N + 1)]

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

sum_comb = sum([c * (c-1) // 2 for c in C])
for a in A:
    print(sum_comb - (C[a] - 1))

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

dp = [0] * (N+1)

for i_A in A_list:
    dp[i_A] += 1

total = 0
for i_dp in dp:
    total += (i_dp*(i_dp-1)) // 2

for i_A in A_list:
    diff = (dp[i_A]*(dp[i_A]-1))//2 - ((dp[i_A]-1)*(dp[i_A]-2))//2
    print(total - diff)

Solution (Python):
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)

Solution (Python):
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]*(n+1)
c = [0]*(n+1)
su = 0

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

for y in range(len(b)):
    if b[y] >=2:
        c[y]=combinations_count(b[y], 2)
    else:
        c[y]=0
    su += c[y]

for z in range(n):
    if c[a[z]] > 0:
        ans = su - (b[a[z]] - 1)
    else:
        ans = su

    print(str(ans))

Solution (Python):
n = int(input())
a_l = list(map(int,input().split()))

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

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

for num in a_l:
    ans = comb_tot - (a_dict[num]-1)
    print(ans)

Solution (Python):
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))

Solution (Python):
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))

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

count={}
for ak in a:
    if ak not in count:
        count[ak] = 0
    count[ak] += 1

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

for ak in a:
    print(sum-(count[ak]-1))

Solution (Python):
from collections import Counter

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

c=Counter(a)
s=0
for key in c:
    s+=c[key]*(c[key]-1)//2
for item in a:
    print(s-c[item]+1)

Solution (Python):
import math
from collections import Counter

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

c=Counter(a)
s=0
for key in c:
    s+=c[key]*(c[key]-1)//2
for item in a:
    print(s-c[item]+1)

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

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

x, y = [0]*(n+1), [0]*(n+1)
for i in range(n+1):
    x[i] = ct[i]*(ct[i]-1)//2
    y[i] = (ct[i]-1)*(ct[i]-2)//2
s = sum(x)

for i in a:
    print(s-x[i]+y[i])

Solution (Python):

"""
Created on Thu May  7 01:30:29 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

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

B = collections.Counter(A)

W = 0
for i in B.values():
    W += conbination(i)

for i in A:
    print(W-B[i]+1)

Solution (Python):
import copy



N=int(input())
A=list(map(int,input().split()))
counter=[0 for i in range(N+1)]
ans2=[0 for i in range(N+1)]
B=[]
for i in A:
    counter[i]+=1
ans=[0 for i in range(N+1)]
for i,value in enumerate(counter):
    if value>0:
        ans[i]=(value*(value-1)//2)
        ans2[i]=((value-1)*(value-2)//2)
total=sum(ans)
for i in A:
    temp=total
    temp-=ans[i]
    temp+=ans2[i]
    print(temp)

Solution (Python):
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Solution (Python):
import collections

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

C = collections.Counter(A)
count = 0
for i in C.values():
    count += i * (i-1) // 2

for i in A:
    n = C[i]
    if n >= 2:
        print(count - n  + 1)
    else:
        print(count)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
dic={}
for a in A:
  if a in dic:
    dic[a]+=1
  else:
    dic[a]=1
   

c=0
for i in dic.values():
  c+=i*(i-1)/2
for j in range(1,N+1):
  d=c-dic[A[j-1]]+1
  print(int(d))

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

tmp = [0]*(n+1)
for i in a:
    tmp[i] += 1
ans = 0
for i in tmp:
    ans += i*(i-1)//2

for k in range(n):
    num = a[k]
    if tmp[num] == 0:
        print(ans)
        continue
    num = tmp[num]
    print(ans - num*(num-1)//2 + (num-1)*(num-2)//2)

Solution (Python):
n=int(input())
al=[int(a) for a in input().split()]
cnt = {}
total=0

for a in al:
	if a not in cnt:
		cnt[a] = 0
	cnt[a]+=1


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

for a in al:
	print(total - (cnt[a]-1))

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)

nc=[-1]*(n+1)
def nConb(n):
  if nc[n] != -1:
    return nc[n]
  nc[n]=n*(n-1)//2
  return nc[n]

temp=0
for k,v in c.items():
  temp+=nConb(v)

for i in range(n):
  if c[a[i]] == 1:
    print(temp)
  else:
    print(temp-(c[a[i]]-1))

Solution (Python):
n = int(input())
A = input().split()

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

for a in A:
    print(s - (B[a] - 1))

Solution (Python):
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))

Solution (Python):
n=int(input())
alist=list(map(int,input().split()))
adic={}

for a in alist:
    if a in adic:
        adic[a]=adic[a]+1
    else:
        adic[a]=1

kumisum=0
for tmp in adic.values():
    kumisum += int(tmp*(tmp-1)/2)

for i in range(n):
    print(kumisum-(adic[alist[i]]-1))

Solution (Python):
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]-1)*(d[i]-2)//2))

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())

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

cnt = {}

for ball in balls:
    if ball not in cnt:
        cnt[ball] = 0
    cnt[ball] += 1

def combination(nxt, num = 0):
    return (cnt[nxt]-num) * (cnt[nxt]-1- num) // 2

total = 0
for nxt in cnt:
    total += combination(nxt)


for ball in balls:
    ans = total -  combination(ball) + combination(ball,1)
    print(ans)

Solution (Python):
import copy
N = int(input())
A = list(map(int, input().split()))

a_types = set(A)

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

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





for a in A:
    print(all_types - count_dict[a - 1] + 1)

Solution (Python):
import copy
N = int(input())
A = list(map(int, input().split()))

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

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





for a in A:
    print(all_types - count_dict[a - 1] + 1)

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

c = [0]*n

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

for i in range(n):
    print(total - c[a[i]-1] + 1)

Solution (Python):
from collections import defaultdict
num = defaultdict(lambda : 0)
n = int(input())
a = [int(i) for i in input().split()]
for i in a:
    num[i] += 1
memo = {i: 0 for i in num.keys()}
total = 0

for i, j in num.items():
    x = int(j * (j - 1) / 2 )
    memo[i] = x
    total += x

for i, j in enumerate(a):
    y = num[j]
    z = memo[j]

    if y == 1:
        print(total)
    else:
        print(total - z + int((y - 1) * (y - 2) / 2))

Solution (Python):

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

Solution (Python):
N = int(input())
As = list(map(int,input().split(' ')))

dic = {}

for A in As:
	if A not in dic.keys():
		dic[A] = 1
	else:
		dic[A] = dic[A] + 1

cnt = 0

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

for A in As:
	print(cnt - (dic[A]-1) )

Solution (Python):
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)

Solution (Python):
import copy
from collections import Counter

l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
c = Counter

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

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

count = 0
C = Counter(A)
for num in C.values():
    count += num*(num-1)//2


for a in A:
    print(count - (C[a] - 1))

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

dic = dict()
for i in a:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

cnt = 0
dic_v = list(dic.values())
for i in range(len(dic_v)):
    x = dic_v[i]
    cnt += int(x*(x-1)/2)
    
for k in range(n):
    print(cnt - (dic[a[k]]-1))

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

c = [0]*n

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

for i in range(n):
    print(total - c[a[i]-1] + 1)