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())
balls = list(map(int, input().split()))

counter = {}
for b in balls:
  counter[b] = counter.get(b, 0) + 1

sum = 0
for v in counter.values():
  sum += v * (v-1) // 2
  
for b in balls:
  n_old = counter[b]
  c_old = n_old * (n_old - 1) // 2
  c_new = (n_old - 1) * (n_old - 2) // 2
  
  result = sum - c_old + c_new
  print(result)

Solution (Python):
N = int(input())
K = list(map(int, input().split()))
counter = dict()
for i in range(N):
  if K[i] not in counter:
  	counter[K[i]] = 1
  else:
   	counter[K[i]] += 1

results = 0
remove_counter = dict()
for key, value in counter.items():
  remove_counter[key] = (value * (value - 1) / 2) - ((value - 1) * (value - 2) / 2)
  results += value * (value - 1) / 2
for i in range(N):
  print(int(results - remove_counter[K[i]]))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num_dic = {}
for i in a:
    if i in num_dic:
        num_dic[i]+=1
    else:
        num_dic[i] = 1
pre_ans = 0
for k,v in num_dic.items():
    pre_ans+=v*(v-1)//2
for num in a:
    tmp = num_dic[num]
    ans = pre_ans - (tmp-1)
    print(ans)

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

import collections
A_count = collections.Counter(A)

import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2

for ai in A:
    
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Solution (Python):


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

m = {}
for a in A:
    m[a] = m.get(a, 0) + 1

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

for a in A:
    value = m[a]
    old_value = (value * (value - 1)) // 2
    new_value = ((value - 1) * (value - 2)) // 2
    print(max_value + new_value - old_value)

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

hako = [0 for i in range(N)]
sum = 0

c = collections.Counter(A)

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


for k in range(N):
    print(sum-(c[A[k]] - 1))

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

ans_l=[0]*(n+1)
ans=0
def con(a):
    return int(a*(a-1)*0.5)
for i in l:
    ans_l[i]+=1


for j in ans_l:
    ans+=con(j)

for i in l:
    ans_2=ans
    
    
    ans_2-=con(ans_l[i])
    
    
    
    ans_2+=con(ans_l[i]-1)
    print(ans_2)

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

def main():
    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
    
    ans = 0
    for key, value in dic.items():
        ans += (value * (value-1)) // 2
    
    for a in A:
        print(ans - dic[a] + 1)


if __name__ == "__main__":
    main()

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

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


C = {}
for i in A:
    if i in C:
        C[i] += 1
    else:
        C[i] = 1

ans = 0    
for i in C.keys():
    ans += C[i] * (C[i]-1) // 2
    
for i in A:
    dec =  C[i] * (C[i]-1) // 2 - (C[i]-1) * (C[i]-2) //2
    print(ans - dec)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
c = [0 for _ in range(max(a))]
for k, v in d.items():
    c[k - 1] = v * (v - 1) / 2

ans = sum(c)
for i in range(n):
    p = a[i]
    res = c[p - 1] * (d[p] - 2) / d[p]
    ans -= c[p - 1] - res
    print(int(ans))
    ans += c[p - 1] - res

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

B=Counter(A)

total=0

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

for i in range(N):
    ans=total
    ans-=B[A[i]]-1
    print(ans)

Solution (Python):
d={}
s=[]

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

for a in nums:    
    if not a in d:
        d[a]=1
    else:
        d[a]+=1
    s.append(a)
    
allcount=0

for count in d.values():
    allcount+=int(count*(count-1)/2)

for num in s:
    print(allcount-d[num]+1)

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
from collections import Counter
c = Counter(l)
def motomeru(i):
  return int(c[i]*(c[i]-1)/2)
def herasu(i):
  if c[i] == 0:
    return 0
  else:
    return int((c[i]-1)*(c[i]-2)/2)
zenbu = 0
for i in range(n):
  zenbu = zenbu + motomeru(i+1)
for i in l:
  a = zenbu - motomeru(i) + herasu(i)
  print(a)

Solution (Python):
s = input()
n=int(s[0])
s = input().split()
d={}
dc={}
summ=0
for i in s:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d:
    n = d[i]
    if n>1:
        e=n*(n-1)/2
        summ+=e
        dc[i]=e
    else:
        dc[i]=0
for i in s:
    n = d[i]-1
    e = n*(n-1)/2
    print(int(summ-dc[i]+e))

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
from collections import defaultdict
d = defaultdict(int)
for a in l:
  d[a] += 1
def motomeru(i):
  return int(d[i]*(d[i]-1)/2)
def herasu(i):
  if d[i] == 0:
    return 0
  else:
    return int((d[i]-1)*(d[i]-2)/2)
zenbu = 0
for i in range(n):
  zenbu = zenbu + motomeru(i+1)
for i in l:
  a = zenbu - motomeru(i) + herasu(i)
  print(a)

Solution (Python):
from collections import Counter 

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans_list = [0] * n
    cnt_list = Counter(num_list)
    for k, v in cnt_list.items():
        if v == 1:
            ans_list[k-1] = 0
            continue
        ans_list[k-1] = v * (v-1) // 2
        
    sum_num = sum(ans_list)

    ans = sum_num

    for i in range(n):
        ans -= ans_list[num_list[i]-1]
        if cnt_list[num_list[i]]-1 != 1:
            ans += (cnt_list[num_list[i]]-1) * (cnt_list[num_list[i]]-2) // 2
        print(ans)
        ans = sum_num

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())

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

num=[0]*(N+1) 

cnb=[-1]*(N+1) 

for i in range(len(ball)):
  num[ball[i]]+=1


allcnb=0
for i in num:
  if i>=2:
    allcnb+=int(i*(i-1)/2)

for i in ball:
  cnb=0

  if num[i]>=2:
    cnb=num[i]-1

  print(allcnb-cnb)

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

ans_l=[0]*(n+1)
ans=0
def con(a):
    return int(a*(a-1)*0.5)
for i in range(n):
    ans_l[l[i]]+=1


for j in ans_l:
    ans+=con(j)

for i in range(n):
    ans_2=ans
    
    
    ans_2-=con(ans_l[l[i]])
    
    
    
    ans_2+=con(ans_l[l[i]]-1)
    print(ans_2)

Solution (Python):
import collections
N=int(input())
A=[int(x) for x in input().rstrip().split()]
A_c=collections.Counter(A)
cnt=0

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


for i in A:
  x=A_c[i]
  if x==1:
    print(cnt)
  else:
    print(cnt-x+1)

Solution (Python):
from sys import stdin

N = int(stdin.readline())
a_dict = {}
A = list(map(int, stdin.readline().split()))
for a in A:
    if a in a_dict:
        a_dict[a] += 1
    else:
        a_dict[a] = 1

sum_comb = 0
B = set(A)
for b in B:
    n = a_dict[b]
    sum_comb += n * (n - 1) // 2

for a in A:
    ans = sum_comb
    n = a_dict[a]
    ans -= n * (n - 1) // 2
    ans += (n - 1) * (n - 2) // 2
    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = 0
ans = 0
dic = {}
for i in a:
    if i not in dic.keys():
        dic[i] = 1
    else:
        dic[i] += 1
for i in dic.values():
    ans += i*(i-1)//2
for i in a:
    print(ans - (dic[i] - 1))

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

total = 0

for i in C.keys():
   if C[i]>1:
        total += (C[i]*(C[i]-1))//2

for i in A:
    print(total-(C[i]-1))

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

count_dict = {}
result_dict = {}

for a in a_list:
    if a not in count_dict:
        count_dict[a] = 1
    else:
        count_dict[a] += 1


count = 0
for k,v in count_dict.items():
    if v >= 2:
        count += v*(v-1)//2

for a in a_list:
    num = count_dict[a]
    if num >= 3:
        print(count-num*(num-1)//2+(num-1)*(num-2)//2)
    elif num == 2:
        print(count-1)
    else:
        print(count)

Solution (Python):
import collections

n = int(input())
a_list = [int(num) for num in input().split(" ")]
c_dict = collections.Counter(a_list)

total_comb = 0
for i in c_dict:
    i_count = c_dict[i]
    total_comb += int(i_count*(i_count-1)/2)
for k in range(n):
    except_num = a_list[k]
    print(total_comb - (c_dict[except_num]-1))

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
d=collections.Counter(a)
total=sum([(v-1)*v//2 for v in d.values()])
for x in a:
    print(total-d[x]+1)

Solution (Python):
from collections import *

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

c = Counter(A)
t = {key : (value*(value-1)//2) for key, value in c.items()}
s = sum(t.values())
ans = {a : s-t[a] + ((c[a]-1)*(c[a]-2)//2) for a in A }

for a in A: print(ans[a])

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
d=collections.Counter(a)
total=0
for v in d.values():
    total+=(v-1)*v//2
for x in a:
    print(total-d[x]+1)

Solution (Python):
from collections import defaultdict
 
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
for a in A:
    D[a] += 1
 
memo = defaultdict(lambda: -1)
conv_D = defaultdict(int)
SUM = 0
for d in D:
    conv_D[d] = D[d] * (D[d] - 1) // 2
    SUM += conv_D[d]
 
for i in range(N):
    if memo[A[i]] == -1:
        tmp = SUM - conv_D[A[i]] + (D[A[i]] - 1)*(D[A[i]] - 2)//2
        print(tmp)
        memo[A[i]] = tmp
    else:
        print(memo[A[i]])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d={}
for x in a:
    if d.get(x) is None:
        d[x]=1
        continue
    d[x]+=1
total=0
for v in d.values():
    total+=(v-1)*v//2
for x in a:
    print(total-d[x]+1)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
cnt = 0
c = collections.Counter(a)
for i in c.values():
    cnt += i*(i-1) // 2
for j in range(n):
    print(cnt - c[a[j]] + 1)

Solution (Python):
from collections import defaultdict, Counter

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

sum = 0
for v in dic.values():
    sum += v * (v - 1) / 2
    
for i in range(n):
    print(int(sum - (dic[a[i]] - 1)))

Solution (Python):
from collections import Counter
_, *a = map(int, open(0).read().split())
c = Counter(a)
s = sum(c*~-c // 2 for c in c.values())
for k in a:
    print(s - c[k] + 1)

Solution (Python):
import itertools
import math 
def C(n,r): return n*(n-1)//r

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
cc = {}
for key, val in d.items():
    temp = C(val,2)
    c += temp
    if cc.get(key) is None:
        cc[key] = temp - C(val-1,2)
for i in a:
    print(c - cc[i])

Solution (Python):

from collections import Counter

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

count = 0

for i, j in c.items():
    count += C(j)

for i in a:
    m = c[i]
    print(count - m + 1)

Solution (Python):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    comb = 0
    for i in c.values():
        if i >= 2:
            comb += i*(i-1)//2
    for i in range(N):
        print(comb - (c[A[i]] - 1))

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math 
def C(n,r):
    if n-r < 0:
        return 0 
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
cc = {}
for key, val in d.items():
    temp = C(val,2)
    c += temp
    if cc.get(key) is None:
        cc[key] = temp - C(val-1,2)
for i in a:
    print(c - cc[i])

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

dic = {}
ans = 0







for a in A:
    tmp = dic.get(a)
    if tmp == None:
        dic[a] = 1
    else:
        dic[a] = tmp + 1

for key in list(dic.keys()):
    tmp = dic.get(key)
    ans += tmp * (tmp - 1) // 2
    

for a in A:
    val = dic.get(a)
    print(ans-val+1)

Solution (Python):
n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for j in numdic:
    nsum += numdic[j] * (numdic[j] - 1) // 2

for k in range(n):
    ans = nsum
    if numdic[numlist[k]] >= 2:
        ans -= (numdic[numlist[k]]-1)
    print(ans)

Solution (Python):
n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for k in numdic:
    nsum += numdic[k] * (numdic[k] - 1) // 2

for j in range(n):
    ans = nsum
    cal = numdic[numlist[j]]
    if cal >= 2:
        ans = ans - (cal-1)
    print(ans)

Solution (Python):
import sys
from collections import defaultdict
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
ans = 0
cum = defaultdict(int)
def couple_combination(n):
    if n >= 2:
        return int(n * (n - 1) / 2)
    else:
        return 0
for v in A:
    cum[v] += 1
for v in cum.values():
    ans += couple_combination(v)
for v in A:
    print(max(0,ans - cum[v] + 1))

Solution (Python):
n=int(input())

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


dic={}

for a in al:
    dic[a]=dic.get(a,0)+1
total=0
for k in dic.keys():
    total+=dic[k]*(dic[k]-1)//2

for k in range(n):
    count=dic[al[k]]
    ans=total-count*(count-1)//2+(count-1)*(count-2)//2
    print(ans)

Solution (Python):
import collections


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

    counters = collections.Counter(A)
    ans = 0
    for _, c in counters.items():
        ans += c*(c-1)//2

    for K in range(N):
        if A[K] in counters:
            c = counters[A[K]]
            if counters[A[K]] > 2:
                print(ans - (c*(c-1)//2) + ((c-1)*(c-2)//2))
            else:
                print(ans - (c*(c-1)//2))
        else:
            print(ans)



if __name__ == "__main__":
    solve()

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

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

n = int(input())
A = list(map(int, input().split()))
A = [a-1 for a in A]
  
Cnt = [0]*n
for i in range(n):
  Cnt[A[i]] += 1
    
tot = 0
for i in range(n):
    tot += choose2(Cnt[i])

for i in range(n):
    ans = tot
    ans -= choose2(Cnt[A[i]])
    ans += choose2(Cnt[A[i]]-1)
    print(ans)

Solution (Python):
n = int(input())
balls = list(map(int, input().split()))
counts = {}
for ball in balls:
    if ball in counts:
        counts[ball] = counts[ball] + 1
    else:
        counts[ball] = 1

total = 0
used = set([])
for ball in balls:
    if not ball in used:
        total += counts[ball] * (counts[ball] - 1) // 2
        used.add(ball)

for ball in balls:
    removed = counts[ball] * (counts[ball] - 1) // 2
    added = (counts[ball] - 2) * (counts[ball] - 1) // 2
    print(total - removed + added)

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

for k in range(n):
  num_ak = hist_a[a[k]-1]
  sum_val = tmp_sum - num_ak * ( num_ak - 1 ) // 2 + ( num_ak - 1 ) * ( num_ak - 2 ) // 2
  print(sum_val)

Solution (Python):
from collections import Counter
n = int(input())
num_list = list(map(int,input().split()))
a = Counter(num_list)
count = 0
for i in a.values():
  count += (i*(i-1))//2
for j in num_list:
  print(count-(a[j]-1))

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
from collections import Counter
LL = Counter(L)
cnt = 0
sum1 = 0
for v in LL.values():
    a = v*(v-1)//2
    sum1 +=a

li = []
for i in range(n):
    li.append((L[i],LL[L[i]]))

for i in range(n):
    c = li[i][1]
    c = c*(c-1)//2
    b = li[i][1]-1
    b = b*(b-1)//2
    print(sum1-(c-b))

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for i in range(n):
  d[a[i]]+=1
tmp=0
for v in d.values():
  tmp+=v*(v-1)//2

for v in a:
  if d[v]>1:
  	print(tmp-d[v]+1)
  else:
    print(tmp)

Solution (Python):
from collections import Counter
N, li = int(input()), list(map(int, input().split()))
cnt_dict, cnt_total = Counter(li), 0
cnt_total =sum([i[1] * (i[1]-1) // 2 for i in cnt_dict.items()])
for k in range(N):
    print(cnt_total - cnt_dict[li[k]]*(cnt_dict[li[k]]-1)//2 + (cnt_dict[li[k]]-1)*(cnt_dict[li[k]]-2)//2)

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

Solution (Python):
from collections import Counter
N, li = int(input()), list(map(int, input().split()))
cnt_dict, cnt_total = Counter(li), 0
for i in cnt_dict.items():
    cnt_total += i[1] * (i[1]-1) // 2
for k in range(N):
    buf = cnt_dict[li[k]]
    print(cnt_total - buf*(buf-1)//2 + (buf-1)*(buf-2)//2)

Solution (Python):
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[A[i]-1] * (B[A[i]-1] - 1)) // 2
	if B[A[i]-1] >= 1:
		res += ((B[A[i]-1] - 1) * (B[A[i]-1] - 2)) // 2
	print(res)

Solution (Python):
n = int(input())
an= list(map(int, input().split()))
 
datas = [0] * (n+1)
for a in an:
    datas[a] += 1
 
ans = 0
for i in range(1,n+1):
    if datas[i] > 1:
        ans += datas[i] * (datas[i]-1)/2
ans = int(ans)
 
for k in range(0,n):
    if datas[an[k]] > 1:
        print(int(ans - datas[an[k]] * (datas[an[k]]-1)/2 + (datas[an[k]]-1) * (datas[an[k]]-2)/2))
    else:
        print(ans)

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
n=int(input())
a=list(map(int,input().split()))
c=collections.Counter(a)
res=sum([v*(v-1)//2 for v in c.values()])
for x in a:
 print(res-c[x]+1)

Solution (Python):
N=int(input())
A=list(map(int,input().split() ))
from collections import Counter
d=dict(Counter(A))

cnt=0
for item in d:
    cnt += (d[item])*(d[item]-1)//2


   
for num in A:
    new = max(0, (d[num]-1)*(d[num]-2)//2)
    print(cnt- d[num]*(d[num]-1)//2 + new)

Solution (Python):
from collections import Counter


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


c = Counter(A)
ans = []




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

ans = []
for a in A:
    
    tmp = c[a]-1
    ans.append(total - tmp)

for i in range(N):
    print(ans[i])

Solution (Python):


import sys
stdin = sys.stdin

import numpy as np

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = np.array(na())
    counter = np.bincount(a)
    total = np.sum(counter*(counter-1))//2
    answer = (total - (counter-1))[a]
    print(*answer, sep="\n")

if __name__ == "__main__":
    main()

Solution (Python):
'''
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split(' '))))
num_sum = 0
remove_array = np.array([], int)
for i in range(N):
    c1 = np.count_nonzero(A == i + 1)
    c2 = np.count_nonzero(A == A[i])
    if c2 <= 1:
        remove_array = np.append(remove_array, 0) ←　appendがネックになってる？
    else:
        remove_array = np.append(remove_array, c2 - 1)
    num_sum += int(c1 * (c1 - 1) / 2)
print(*(num_sum - remove_array), sep='\n')
'''
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 range(N):
    tmp = total
    print(tmp - (cnt[A[i]] - 1))

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

Solution (Python):
from collections import Counter
n=int(input())
a=[int(A) for A in input().split()]

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

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

Solution (Python):
'''
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split(' '))))
num_sum = 0
remove_array = np.array([], int)
for i in range(N):
    c1 = np.count_nonzero(A == i + 1)
    c2 = np.count_nonzero(A == A[i])
    if c2 <= 1:
        remove_array = np.append(remove_array, 0)
    else:
        remove_array = np.append(remove_array, c2 - 1)
    num_sum += int(c1 * (c1 - 1) / 2)
print(*(num_sum - remove_array), sep='\n')
'''
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 range(N):
    tmp = total
    tmp -= cnt[A[i]] * (cnt[A[i]] - 1) // 2
    tmp += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) // 2
    print(tmp)

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

Solution (Python):
import collections
import math
def calculateProb(counts):
    ways = 0
    for key in counts.keys():
        if counts[key] < 2:
            continue
        else:
            val = counts[key]
            ret = val*(val-1)/2
            ways += ret
    return ways

def getfact(val):
    if val < 2:
        return 0
    return val*(val-1)/2


n = int(input())

values = list(map(int, input().split(' ')))
counts = collections.Counter(values)

ways = calculateProb(counts)
for k in range(n):
    curVal = values[k]
    count = counts[curVal]
    temp = ways
    ways = ways - getfact(count)  + getfact(count - 1)
    print(int(ways))
    ways = temp

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
a = Counter(A)
b = list(a.keys())
B = [0]*(N+1)
for i in b:
  B[i] = int(a[i]*(a[i]-1)/2)
total = sum(B)

for i in range(N):
  k = A[i]
  change = (a[k]-1)*(a[k]-2)/2
  print(int(total-B[k]+change))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
dic1 = {}
dic2 = {}
for i in range(N):
  if A[i] in dic1:
    dic1[A[i]] += 1
  else:
    dic1[A[i]] = 1
ans = 0
for v in dic1.values():
  ans += (v*(v-1))//2
for j in range(N):
  w = dic1[A[j]]
  v = w-1
  comb = ans -(w*(w-1))//2 + (v*(v-1))//2
  print(comb)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
d=dict()

for i in range(len(l)):
  d.setdefault(l[i],0)
  d[l[i]] += 1

result=0

for key,value in d.items():
    num=(value*(value-1))/2
    result += num

for i in range(len(l)):
    r1=int((d[l[i]]*(d[l[i]]-1))/2)
    r2=int(((d[l[i]]-1)*(d[l[i]]-2))/2)
    output=int(result-r1+r2)
    print(output)

Solution (Python):
def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
ans=0
B=set(A)
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
for i in B:
    ans+=Comb(L[i-1],2)
for i in range(N):
    pri=ans
    pri=ans-L[A[i]-1]+1
    print(pri)

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

dic = {}

for i in A:
    if i in dic:
        dic[i] = dic[i] + 1
    else:
        dic[i] = 1


dic2 = {}


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

diff_dic = {}

for key,value in dic.items():
    diff_dic[key] = int((value*(value-1)/2) - ((value-1)*(value-2)/2))


for i in A:
    print(ans-diff_dic[i])

Solution (Python):
from collections import Counter
n = int(input())
l = [int(i) for i in input().split()]

c = Counter(l)

total = sum([v * (v-1) // 2 for v in c.values()])
for i in l:
    print(total - c[i] + 1)

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]

from collections import Counter
c = Counter(l)
x = list(c.values())

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

y = 0
for i in range(len(x)):
    if x[i] != 1:
        y += combinations_count(x[i], 2)

for j in range(n):
    print(y - (c[l[j]] - 1))

Solution (Python):
from collections import Counter

n = int(input())
al = list(map(int, input().split()))
al_cnt = Counter(al)
ans = sum([i * (i - 1) // 2 for i in al_cnt.values()])
for j in al:
    print(ans - al_cnt[j] + 1)

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
count = {}

for i in B:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1
    
total = 0
for i in count:
  total += count[i]*(count[i]-1)/2
  
for i in range(N):
  k = count[B[i]]
  print(int(total-k+1))

Solution (Python):
from collections import Counter

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

d = Counter(A)
k = d.keys()




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


total = 0
for kk in k:
    total += nC2(d[kk])



for a in A:
    res = total
    res -= d[a] - 1
    print(res)

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

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

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

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

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

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

Solution (Python):
from collections import Counter

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


def comb(x):
    if x == 0:
        return 0
    if x == 1:
        return 0
    return x * (x - 1) // 2


d = Counter(A)

k = d.keys()


total = 0

for kk in k:
    total += comb(d[kk])



for a in A:
    res = total
    res -= comb(d[a])
    res += comb(d[a] - 1)
    print(res)

Solution (Python):
from collections import Counter as cnt
n =  int(input())
A = list(map(int, input().split()))
dic = cnt(A)
total = 0
for num in dic.values():
  if num >= 2:
    total += num * (num - 1) // 2
    
for num in A:
  target = dic[num]
  ans = total
  if target >= 2:
    ans -= target * (target - 1) // 2
    ans += (target - 1) * (target - 2) // 2
  print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from bisect import bisect_left

def calc(d, i, dsum, m):
    return comb(d, i) + dsum[i] + dsum[m] - dsum[i+1]

def comb(d, i):
    return d[i][1] * max(0, d[i][1] - 1) // 2

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = [[k, v] for k, v in sorted(dict(Counter(v)).items())]
    keys = [q[0] for q in d]
    m = len(d)
    dsum = [0] * (n+1)
    for i in range(1, m+1):
        dsum[i] = dsum[i-1] + comb(d, i-1)
    for i in range(n):
        j = bisect_left(keys, v[i])
        d[j][1] -= 1
        print(calc(d, j, dsum, m))
        d[j][1] += 1

if __name__ == '__main__':
    main()

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

datas = [0] * (n+1)
for a in an:
    datas[a] += 1

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

for k in range(0,n):
    if datas[an[k]] > 1:
        print(int(ans - datas[an[k]] * (datas[an[k]]-1)/2 + (datas[an[k]]-1) * (datas[an[k]]-2)/2))
    else:
        print(ans)

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

Solution (Python):
from collections import Counter

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

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

ans = []
for a in A:
    ans.append(S - (cntA[a] - 1))

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
c = {}
for k in range(N):
    if c.get(A[k]) is None:
        c[A[k]] = 1
    else:
        c[A[k]] += 1

x = 0
for i in c:
    x += c[i]*(c[i]-1)//2
for i in range(N):
    print(x+1-c[A[i]])

Solution (Python):
n = int(input())
num_list =  list(map(int,input().split()))
num_list2 = [0]*n
num_list3 = [0]*n
for i in num_list:
    num_list2[i-1] += 1
for i in range(n):
    ans = num_list2[i]*(num_list2[i]-1)//2
    num_list3[i] = ans
sum_V = sum(num_list3)
for i in num_list:
    ans = (num_list2[i-1]-1)*(num_list2[i-1]-2)//2
    print(ans-num_list3[i-1]+sum_V)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for i in a:
    cnt[i-1] += 1
total = [0] * n
for i in range(n):
    total[i] = cnt[i] * (cnt[i] - 1) // 2
total_sum = sum(total)
for i in a:
    ans = total_sum
    ans -= total[i-1]
    ans += (cnt[i-1] - 1) * (cnt[i-1] - 2) // 2
    print(ans)