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):
from collections import defaultdict

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

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

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

for i in range(n):
    ai = A[i]
    cnt = d[ai]
    diff = (cnt * (cnt - 1)) // 2 - ((cnt - 1) * (cnt - 2)) // 2
    print(ans - diff)

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

Solution (Python):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = list(map(int,readline().split()))
dic1 = defaultdict(int)

for i in lst1:
    dic1[i] += 1



al = 0
for i in dic1.values():
    if i >= 2:
        al += i*(i-1)//2

for i in lst1:
    res = dic1[i]
    if res >= 2:
        print(al-res*(res-1)//2+(res-1)*(res-2)//2)
    else:
        print(al)

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    conb = [0]*N
    ans = 0
    for i in A:
        conb[i-1] += 1
    for j in conb:
        if j != 0:
            ans += j*(j-1)//2
    for k in range(N):
        print(ans- conb[A[k]-1]+1)



if __name__ == '__main__':
    solve()

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

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

Solution (Python):
from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    cnt = Counter(A)
    cnt_common = cnt.most_common()
    ans = 0
    for i in range(len(cnt_common)):
        num, val = cnt_common[i]
        ans += val * (val - 1) // 2
    for i in A:
        c = cnt[i]
        print(ans - c * (c - 1) // 2 + (c-1) * (c-2) // 2 )

if __name__ == '__main__':
    main()

Solution (Python):

import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))

def resolve():
    N=int(input())
    A=tupin()

    from collections import Counter
    c=Counter(A)
    total=0
    
    for t in c.items():
        ag,b=t
        total+=(b*(b-1))//2
    
    for m in A:
        a=c[m]
        print(total-((a*(a-1))//2)+((a-1)*(a-2))//2)

resolve()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
C = Counter(A)


al = 0
for ball, num in C.items():
    al += num * (num - 1) // 2

for a in A:
    ball = a
    num = C[a]
    ans = al - C[a] * (C[a] - 1) // 2 + (C[a] - 1) * (C[a] - 2) // 2
    print(ans)

Solution (Python):
import collections
N=int(input())
L=list(map(int,input().split()))
S=collections.Counter(L)
K={}
ans=0
for x,y in S.items():
	K[x]=(y*(y-1)//2,(y-1)*(y-2)//2)
	ans+=K[x][0]
for i in range(N):
	print(ans-K[L[i]][0]+K[L[i]][1])

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
c = list(c.items())
num = 0
nc2 = dict()
n_1c2 = dict()
for i in range(len(c)):
    nc2[c[i][0]] = c[i][1] * (c[i][1]-1) // 2
    num += c[i][1] * (c[i][1]-1) // 2
    n_1c2[c[i][0]] = (c[i][1]-1)*(c[i][1]-2) // 2
for i in range(n):
    tar = a[i]
    print(num-nc2[tar]+n_1c2[tar])

Solution (Python):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    dict = {}
    for i in range(n):
        if a[i] in dict:
            dict[a[i]] += 1
        else:
            dict[a[i]] = 1
    dval = list(dict.values())
    total = 0
    for i in range(len(dval)):
        total += (dval[i] * (dval[i]-1))/2
    for i in range(n):
        test = a[i]
        print(int(total-dict[test]+1))
resolve()

Solution (Python):
from collections import Counter

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

ans=0
c=Counter(a)
for v in c.values():
  if v>=2:
    ans+=v*(v-1)//2

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

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

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

for a in A:
    v = c[a]
    add = (v - 1) * (v - 2) // 2
    sub = v * (v - 1) // 2
    print(ans-sub+add)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    ans = 0
    for v in c.values():
        if v > 1:
            ans += v*(v-1)//2
    for k, a in enumerate(A):
        cnt = 0
        add = 0
        if c[a] > 1:
            cnt = c[a]*(c[a]-1)//2
        if c[a] > 2:
            add = (c[a]-1)*(c[a]-2)//2
        print(ans - cnt + add)


if __name__ == '__main__':
    main()

Solution (Python):
import collections
N = int(input())
A = list(map(int, input().split()))
t = collections.defaultdict(int)
for x in A:
    t[x] += 1
ans = 0
for x in t:
    ans += t[x]*(t[x]-1) // 2
for x in A:
    tmp = ans
    tmp -= (t[x]*(t[x] - 1)) // 2
    print(tmp + ((t[x]-1)*(t[x]-2))//2)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  










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

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

Solution (Python):
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    count = {}
    for aa in a:
        if aa in count:
            count[aa] += 1
        else:
            count[aa] = 1
    all_way = 0
    for c in count.values():
        all_way += c * (c - 1) // 2
    for i in range(n):
        if a[i] in count:
            print(all_way - count[a[i]] + 1)
        else:
            print(all_way)


if __name__ == '__main__':
    main()

Solution (Python):
def examA():
    N = I()
    ans = ((N+1)//2)/N
    print(ans)
    return

def examB():
    N, K = LI()
    H = [I()for _ in range(N)]
    H.sort()
    ans = inf
    for i in range(N-K+1):
        cur = H[i+K-1]-H[i]
        if ans>cur:
            ans = cur
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    ans = [0]*N
    C = Counter(A)
    base = 0
    for c in C.values():
        base += c*(c-1)//2
    
    
    for i in range(N):
        ans[i] = base - (C[A[i]]-1)
    for v in ans:
        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
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:ans+=d[i]*(d[i]-1)//2
for i in a:
  m=d[i]*(d[i]-1)//2
  mm=(d[i]-1)*(d[i]-2)//2
  print(ans-m+mm)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

Solution (Python):
import collections
n = int(input())
a = [int(i) for i in input().split()]
c = collections.Counter(a)
ans = 0
for i in c.keys():
    ans += (c[i]) * (c[i] - 1) / 2
for i in a:
    print(int(ans - c[i] + 1))

Solution (Python):
import copy
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
count=dict(Counter(a))
ans=0
dic={}
for j,k in count.items():
    ans=k*(k-1)/2
    dic[j]=ans
s=sum(dic.values())
for i in range(n):
    v=count[a[i]]
    if v==0:
        print(0)
    else:
        print(int(s-v+1))

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

Solution (Python):
N = int(input())
nums = list(map(int,input().split()))
x = [0] * N
ans = 0
for i in range(N):
    x[nums[i] - 1] += 1
for i in range(N):
    ans += (x[i]*(x[i]-1))/2
ans = int(ans)    
for i in range(N):
    if x[nums[i] - 1] == 0 or x[nums[i] - 1] ==1:
        print(ans)
    else:
        print(ans - x[nums[i]-1] + 1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
count = [0]*N
for i in range(N):
    count[A[i]-1] += 1
s = 0
for i in range(N):
    s += count[i] * (count[i]-1) // 2
for i in range(N):
    if count[A[i]-1] == 0 or count[A[i]-1] == 1:
        print(s)
    else:
        print(s - count[A[i]-1] + 1)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
c = [0] * n
for i in a:
    c[i-1] += 1
combinations = [i * (i - 1) // 2 for i in c]
sum = sum(combinations)

for k in range(1,n+1):
    print(sum - combinations[a[k-1]-1] + max(0, c[a[k-1]-1] -1) * max(0, c[a[k-1]-1] - 2) // 2)

Solution (Python):
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])

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

c = Counter(A)
num_combination = [v * (v-1)//2 for v in c.values()]
ans = sum(num_combination)
for x in A:
  print(ans - c[x] + 1)

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

N = int(input())
la = list(map(int,input().split()))
all = 0
c = collections.Counter(la)

for i in range(N+1):
    all += cmb(c[i],2)

for k in range(N):
    print(all-c[la[k]]+1)

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1

total = 0
for v in d.values():
    if v != 1 and v != 0:
        total += int(v * (v - 1) / 2)

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

Solution (Python):
import math
from collections import Counter

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return (a*(a-1))//2

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


dd=Counter(a)

p=0
for i in dd.values():p+=ABC159D(i)
print('\n'.join(map(str,[p-dd[i]+1 for i in a])))

Solution (Python):
import math
from collections import Counter

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

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


dd=Counter(a)

p=0
for i in dd.values():p+=ABC159D(i)
print('\n'.join(map(str,[p-dd[i]+1 for i in a])))

Solution (Python):
import math
from collections import Counter

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

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


dd=Counter(a)

p=0
for i in dd.values():p+=ABC159D(i)
for i in a:
    print(p-dd[i]+1)

Solution (Python):
import math

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
for i in a:
    d=mycounter(d,i)
p=0
for i in d.values():p+=ABC159D(i)
for i in a:
    print(p-d[i]+1)

Solution (Python):
import math

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
for i in a:
    d=mycounter(d,i)
p=sum([ABC159D(i) for i in d.values()])
for i in a:
    print(p-d[i]+1)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
num = [0] * (N+1)
for x in A:
    num[x] += 1
sum = 0
for x in num:
    sum += x * (x - 1) // 2
for x in A:
    print(sum - num[x] * (num[x] - 1) // 2 + (num[x] - 1) * (num[x] - 2) // 2)

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

Solution (Python):
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  


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


n = int(input())
A = list(map(int, input().split()))
B = [0] * (n + 1)
for a in A:
    B[a] += 1
ans = sum(cal(b) for b in B)
for a in A:
    num = ans
    num -= cal(B[a])
    B[a] -= 1
    num += cal(B[a])
    print(num)
    B[a] += 1

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

import collections

c = collections.Counter(a)

s = 0
for i in c:
    j = c[i]

    s += j * (j - 1) // 2

for i in range(n):
    j = c[a[i]]
    s2 = s - j * (j - 1) // 2 + max(0, (j - 1) * (j - 2) // 2)
    print(s2)

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

import collections

c = collections.Counter(a)

s = 0
for i in c:
    j = c[i]

    s += j * (j - 1) // 2

for i in range(n):
    j = c[a[i]]
    s2 = s - j * (j - 1) // 2 + max(0, (j - 1) * (j - 2) // 2)
    print(s2)

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

index=[0]*(n+1)

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

ans=0
for i in index:
    ans+=i*(i-1)/2

for a in A:
    print(str(int(ans-index[a]+1)))

Solution (Python):
n=int(input())
k= list(map(int, input().split()))
z=[0]*n
cnt=0
for  i in range(n):
   z[k[i]-1]+=1
for m in range(n):
    cnt+=z[m]*(z[m]-1)//2
for j in range(n):
    a=k[j]-1
    print(cnt-z[a]+1)

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

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

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

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

for i in range(N):
    k=(cnt[a[i]-1])*(cnt[a[i]-1]-1) //2
    l=(cnt[a[i]-1]-1)*(cnt[a[i]-1]-2) //2
    d=k-l
    print(c_sum-d)

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

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

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

for i in range(N):
    k=(cnt[a[i]-1])*(cnt[a[i]-1]-1) //2
    l=(cnt[a[i]-1]-1)*(cnt[a[i]-1]-2) //2
    d=k-l
    print(c_sum-d)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import mul
from functools import reduce
def cmb1(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    A_c=Counter(A)

    combi=0
    for ac in A_c.items():
        if ac[1]>=2:
            combi+=cmb1(ac[1],2)
    for i in range(n):
        print(combi-(A_c[A[i]]-1))



if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter,defaultdict
from operator import mul
from functools import reduce
def cmb1(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    A_c=Counter(A)

    combi=0
    for ac in A_c.items():
        if ac[1]>=2:
            combi+=cmb1(ac[1],2)
    for i in range(n):
        print(combi-(A_c[A[i]]-1))

if __name__=='__main__':
    main()

Solution (Python):
from collections import Counter

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


Freq = Counter(A)


ans_max = 0
for kv in Freq.items():
  ans_max += kv[1] * (kv[1] - 1) // 2

for a in A:
  
  if Freq.get(a) == 1:
    print(ans_max)
    continue

  
  x = Freq.get(a)
  diff = (x * (x-1) // 2) - ((x-1) * (x-2) // 2)

  
  ans = ans_max - diff
  print(ans)

Solution (Python):
from collections import Counter

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


Freq = dict(sorted(Counter(A).items(), key=lambda x: x[1], reverse=True))


ans_max = 0
for kv in Freq.items():
  ans_max += kv[1] * (kv[1] - 1) // 2

for a in A:
  
  if Freq.get(a) == 1:
    print(ans_max)
    continue

  
  x = Freq.get(a)
  diff = (x * (x-1) // 2) - ((x-1) * (x-2) // 2)

  
  ans = ans_max - diff
  print(ans)

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

b = [0 for _ in range(max(a))]
for i in a:
    b[i - 1] += 1
ans = 0
for i in b:
    ans += int(i * (i-1) / 2)

for i in a:
    print(ans - (b[i - 1] - 1))

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
dic={}
for e in ls:
  if (e in dic):
    dic[e]+=1
  else:
    dic[e]=1
Sum=0
for key,value in dic.items():
  Sum+=value*(value-1)//2

for i in range(N):
  print(Sum-dic[ls[i]]+1)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
dif = [0] * (n + 1)
sum_c = 0
c = Counter(a)
for i, v in c.items():
    if v < 2:
        continue
    val = v * (v - 1) / 2
    dif[i] = v - 1
    sum_c += val
print('\n'.join([str(int(sum_c - dif[i])) for i in a]))

Solution (Python):
from collections import Counter





def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n
    if n <= 1:
        return 0

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


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

countMost = count.most_common()

lis = [0] * (2 * 10 ** 5)
combination = [0] * (2 * 10 ** 5)
tot = 0
for i, v in countMost:
    
    lis[i - 1] = v
    val = cmb(v, 2)
    tot += val
    combination[i - 1] = val


for i, v in enumerate(data):
    num = lis[v - 1]
    if (num == 2):
        
        ans = tot - 1
    else:
        ans = tot - combination[v-1] + cmb(num-1, 2)

    print(ans)
'''
dataSort = data.sort()
print(countMost)
print(len(countMost))
'''

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(A)
C = {key:(B[key]*(B[key]-1)//2) for key in B}
ans = sum(C.values())


for i in A:
    if C[i] < 1:
        print(ans)
    else:
        print(ans - C[i] + (B[i]-1)*(B[i]-2)//2)

Solution (Python):
def main():
    import collections
    import math
    n=int(input())
    a=list(map(int, input().split()))
    c=collections.Counter(a)
    cnt=list(c.items())
    ans=0
    comb=[]
    for i in range(len(cnt)): 
        buf=(cnt[i][1]**2-cnt[i][1])//2
        comb.append(buf)
        ans+=buf
    for ai in a:
        print(ans-c[ai]+1)

if __name__=='__main__':
    main()

Solution (Python):
from operator import mul
from functools import reduce

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

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


lista = [0] * (n + 1)
sum = 0
for j in range(n):
    lista[a[j]] += 1
for i in lista:
    if i >= 2:
        sum += cmb(i, 2)
for i in a:
    print(sum - lista[i] + 1)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
number=[0]*(N+1)
all_sum=0
for i in A:
    number[i]+=1
for i in number:
    all_sum+=i*(i-1)/2
for i in range(N):
    print(int(all_sum-(number[A[i]]-1)))

Solution (Python):
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*(n+1)
for i in range(n):
    coun[a[i]]+=1
for i in range(n+1):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)

Solution (Python):
import numpy as np
from collections import Counter
from scipy.misc import comb
N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1), dtype=np.int64)
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")

Solution (Python):
from collections import Counter
from scipy.misc import comb
import numpy as np
N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")

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

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

for i in A:
    B[i] += 1
sum_original = sum([j*(j-1)//2 for j in B])
for k in range(N):
    print(sum_original - B[A[k]] + 1)

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

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

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

seisu = [0 for i in range(N+1)]

for i in A:
  seisu[i] += 1
  
ans = 0
for i in seisu:
  ans += int(i*(i-1)/2)

for i in range(N):
  ans2 = ans - seisu[A[i]] + 1
  print(ans2)

Solution (Python):
from collections import defaultdict
n=int(input())
dd = defaultdict(int)
A=[int(i) for i in input().split()]
for i in A:
    dd[i]+=1
memo = [0]*(n+1)
for i in dd:
    memo[i]=(dd[i]*(dd[i]-1))//2
ans = sum(memo)
done = [-1]*(n+1)
for i in range(n):
  print(int(ans-memo[A[i]]+(memo[A[i]])*((dd[A[i]]-2)/dd[A[i]])))

Solution (Python):
from collections import defaultdict
n=int(input())
dd = defaultdict(int)
A=[int(i) for i in input().split()]
for i in A:
    dd[i]+=1
memo = [0]*(n+1)
for i in dd:
    memo[i]=(dd[i]*(dd[i]-1))//2
ans = sum(memo)
done = [-1]*(n+1)
for i in range(n):
    if done[A[i]]==-1:
        done[A[i]]=(int(ans-memo[A[i]]+(memo[A[i]])*((dd[A[i]]-2)/dd[A[i]])))
        print(done[A[i]])

    else:
        print(done[A[i]])

Solution (Python):
import collections 
import math

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 i in a:
    print(cnt- c[i]*(c[i]-1)//2 + (c[i]-1)*(c[i]-2)//2)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
counts = [0] * (N + 1)
for a in As:
    counts[a] += 1
tot = 0
for count in counts:
    tot += (count * count - count) // 2
for a in As:
    print(tot - counts[a] + 1)

Solution (Python):
from collections import Counter

def main():

    N = int(input(""))
    A = list(map(int,input().split()))
    X = 0
     
    A_e = list(set(A))
     
    x = Counter(A)
     
    for i in A_e:
        if x[i] >= 2:
            xc2 = x[i]*(x[i]-1)/2
            X = X + xc2
     
    for k in A:
        print(int(X-x[k]+1))

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l=[0]*(max(a)+1)
l2=[0]*(max(a)+1)
for i in range(n):
     l[a[i]]+=1
for i in range(len(l)):
    l2[i]=max(0,(l[i]*(l[i]-1))//2)
sum=sum(l2)
for k in range(n):
    ans1=sum-l2[a[k]]
    ans2=max(0,((l[a[k]]-1)*(l[a[k]]-2))//2)
    print(ans1+ans2)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter, defaultdict
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


n, *a = map(int, read().split())
counter = list(Counter(a).items())
cnt = defaultdict(int)
memo = defaultdict(int)
for k, v in counter:
    if v > 1:
        cnt[k] = cmb(v, 2)
        if v > 2:
            memo[k] = cmb(v - 1, 2)
        else:
            memo[k] = 0
    else:
        cnt[k] = 0
        memo[k] = 0
ans = sum(cnt.values())
for aa in a:
    print(ans - cnt[aa] + memo[aa])

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
a = []
b = 0
for m in range(n):
    a.append(0)
for m in range(n):
    a[l[m]-1] += 1
for m in range(n):
    b += int(a[m]*(a[m]-1)/2)
for m in range(n):
    print(b-a[l[m]-1]+1)

Solution (Python):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N



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


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

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

from collections import Counter

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

k_ttl = 0
for i in range(n):
    print(ttl - (cnt[a[i]] - 1))

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

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

for i in range(n):
    ans = amount + 1 - cnt[a[i]]
    print(ans)

Solution (Python):
from collections import Counter

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