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=[int(x) for x in input().split()]
num={i:0 for i in range(N)}
for i in A:
    num[i-1]+=1
def set(k):
    if k >= 2:
        return (k)*(k-1)/2
    else:
        return 0
def selfset(k):
    if k >= 2:
        return (k-1)*(k-2)/2
    else:
        return 0

setnum={i:set(num[i]) for i in range(N)}
a=sum(setnum.values())

selfsetnum={i:selfset(num[i]) for i in range(N)}


for i in range(N):
    print(int(a-setnum[A[i]-1]+selfsetnum[A[i]-1]))

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

from collections import Counter


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


C=Counter()
for i in range(n):
    C[a[i]] += 1
xsum=0
for key, value in C.items():
    xsum += value*(value-1)//2


for k in range(n):
    print( xsum - (C[a[k]] - 1) )

Solution (Python):
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

input = sys.stdin.readline

from collections import Counter

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


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


C=Counter()
for i in range(n):
    C[a[i]] += 1
xsum=0
for key, value in C.items():
    xsum += value*(value-1)//2
    

for k in range(n):
    print( xsum - (C[a[k]] - 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

ans = 0

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

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

Solution (Python):
import math


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

dic={}
for i in li:
    if i not in dic:
        dic[i] = 1
    elif dic[i] >= 1:
        dic[i] += 1
        



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

for i in range(n):
    print(math.floor(cnt - dic[li[i]]+1))

Solution (Python):
from collections import Counter
n = int(input())
a=list(map(int,input().split()))
c=Counter(a)
sum = 0
for i in c.values():
    sum += i*(i-1)//2

for i in a:
    if c[i] > 0:
        print(sum-(c[i]-1))

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
num=[0]*n

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

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
from collections import Counter
def comb(n):
    if n==1:
        return 0
    else:
        return n*(n-1)/2
list=Counter(A)
sum=0
for number in list:
    sum=sum+comb(list[number])

for i in A:
    print(int(sum-comb(list[i])+comb(list[i]-1)))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n = II()
    A = LI()

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

    def choose2(a):
        if a == 0: return 0
        return a * (a-1) // 2

    
    ans = 0
    for k, v in memo.items():
        ans = ans + choose2(v)
    

    for a in A:
        print(ans - choose2(memo[a]) + choose2(memo[a] - 1))


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n = II()
    A = LI()

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

    def choose2(a):
        if a == 0: return 0
        return a * (a-1) // 2

    
    ans = 0
    for k, v in memo.items():
        ans = ans + choose2(v)
    

    for a in A:
        print(ans - choose2(memo[a]) + choose2(memo[a] - 1))


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  
def Is(): return map(int, input().split())  
def LI(): return list(map(int, input().split()))  
def TI(): return tuple(map(int, input().split()))  
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  
def LS(): return list(input())  
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n = I()
A = LI()
c = [0]*(n+1)
d = [0]*(n+1)
for a in A:
    c[a-1] += 1

def nc2(num):  
    return int(num*(num-1)/2)
for i in range(n):
    d[i] = nc2(c[i])

dsum = sum(d)
for i in range(n):
    a = A[i] - 1
    print(dsum - nc2(c[a]) + nc2(c[a]-1))

Solution (Python):
import collections

N = int(input())
As = list(map(int,input().split()))
Cs = collections.Counter(As)

s = 0
for key in Cs:
  s = s + Cs[key]*(Cs[key] - 1)//2
  
for i in range(N):
  rlt = s - Cs[As[i]]*(Cs[As[i]] - 1)//2 + (Cs[As[i]] - 1)*(Cs[As[i]] - 2)//2
  print(rlt)

Solution (Python):
from __future__ import print_function

import array
import bisect
import collections
import copy
import fractions
import functools
import heapq
import itertools
import math
import operator
import random
import re
import string
import sys
import time
from collections import Counter, deque
from fractions import Fraction
from functools import reduce
from heapq import heapify, heappop, heappush, heappushpop, heapreplace
from itertools import accumulate
from operator import mul
from queue import PriorityQueue as pq
from queue import Queue

sys.setrecursionlimit(500000)









input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


















def combinations_count(n, r):
    if r>n:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n = int(input().strip())
    a = list(map(int, input().strip().split()))
    C=Counter()
    for i in range(n):
        C[a[i]]+=1
    ans_temp=0
    X=[0 for _ in range(n+1)]
    for key, value in C.items():
        X[key] = combinations_count(value, 2)
        ans_temp += X[key]
    for k in range(n):
        print( ans_temp - X[a[k]] + combinations_count(C[a[k]]-1,2) )


if __name__ == '__main__':
    main()

Solution (Python):

import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()

a = LIST()

occ = defaultdict(int)

for el in a:
    occ[el]+=1

tot = 0

for key in occ:
    tot+=occ[key]*(occ[key] - 1)//2

for el in a:
    print(tot - occ[el] + 1)

Solution (Python):
from collections import Counter
 
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i*(i - 1)//2 for i in b.values()) 

for i in a:

    print(total - (b[i] - 1))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B={}
for i in A:
  if i not in B:
    B[i]=0
  B[i]+=1
c=0
for v in B.values():
    c+=v*(v-1)/2
for i in range(N):
  print(int(c-B[A[i]]+1))

Solution (Python):
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

n = readInt()
a = readInts()

d = defaultdict(int)

ans = 0

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

maxv = 0
for i in d:
	maxv+=comb(d[i],2)

for k in range(0,n):
	b = d[a[k]]
	delta = comb(b,2)-comb(b-1,2)
	ans = maxv-delta
	print(ans)

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

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}
total = 0

for i in a:
    if i not in d:
        d[i] = 1
    else:
        total += d[i]
        d[i] += 1

ans = [total - (d[i] - 1) for i in a]
print("\n".join(map(str,ans)))

Solution (Python):
def ban():
    n = int(input())
    a = list(map(int, input().split()))
    d = {}
    total = 0

    for i in a:
        if i not in d:
            d[i] = 1
        else:
            total += d[i]
            d[i] += 1

    ans = [total - (d[i] - 1) for i in a]
    return "\n".join(map(str, ans))

print(ban())

Solution (Python):
def ban():
    from collections import Counter
    n = int(input())
    a = list(map(int, input().split()))
    b = Counter(a)
    total = sum(i*(i - 1)//2 for i in b.values())

    ans = [(total - (b[i] - 1)) for i in a]
    return "\n".join(map(str, ans))

print(ban())

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
total = sum(i*(i - 1)//2 for i in b.values())

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

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
D = Counter(A)
L = list(D.values())

ans = 0
for x in L:
    ans += x*(x-1)//2

for k in range(n):
    print(ans-(D[A[k]]-1))

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
t = 0
for k,v in d.items():
    t += (v * (v-1)) // 2
for i in range(n):
    v = d[a[i]]
    s = t - (v * (v-1)) // 2 + ((v-1) * (v-2))//2
    print(s)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}
total = 0

for i in a:
    if i not in d:
        d[i] = 1
    else:
        total += d[i]
        d[i] += 1

for i in a:
    ans = total - (d[i] - 1)
    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}
total = 0

for i in a:
    if i not in d:
        d[i] = 1
    else:
        total += d[i]
        d[i] += 1

for i in range(n):
    ans = total - (d[a[i]] - 1)
    print(ans)

Solution (Python):

import sys


def solve_iter(N: int, A: "List[int]"):
    from collections import Counter
    def f(n):
        return n * (n - 1) // 2
    c = Counter(A)
    base = sum(map(f, c.values()))
    for a in A:
        yield base - f(c[a]) + f(c[a]-1)

def solve(N: int, A: "List[int]"):
    return list(solve_iter(N, A))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    print(*solve(N, A), sep='\n')

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
max_two = [0]*(N+1)
one_minus = [0]*(N+1)
A_cnt = Counter(A)
A_cnt = A_cnt.most_common()
for a in A_cnt:
    max_two[a[0]] = (a[1]*(a[1]-1))//2
    one_minus[a[0]] = ((a[1]-1)*(a[1]-2))//2
max_sum = sum(max_two)

for i in range(N):
    print(max_sum-max_two[A[i]]+one_minus[A[i]])

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 list(set(a)):
  ans+=d[i]*(d[i]-1)//2
for i in a:
  kari=ans
  kari-=d[i]*(d[i]-1)//2
  kari+=(d[i]-1)*(d[i]-2)//2
  print(kari)

Solution (Python):
from collections import defaultdict, Counter

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

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

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

all = int(all)
val_cnt = Counter(A)
for a in A:
    print(all - (val_cnt[a] - 1))

Solution (Python):
n = int(input())
alist = list(map(int, input().split(" ")))
blist = [0]*n

for i in range(n):
  blist[alist[i]-1] += 1

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

for i in range(n):
  print(int(total-(blist[alist[i]-1]-1)))

Solution (Python):
from collections import Counter
n = int(input())
m = list(map(int,input().split()))   
ctr = Counter(m)
all = 0
def f(n):
    return n*(n-1)//2

for i in ctr.values():
    all += f(i)

ans = []
for j in m:
    ans.append(all - ctr[j] +1)

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

Solution (Python):
from collections import Counter

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

c = Counter(a)

total = 0
for i in c.items():
    x = i[1]
    total += x*(x-1)//2

for i in a:
    ans = total
    ans -= (c[i] - 1)
    print(ans)

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    assert len(A) == N
    ball = collections.Counter(A)
    total = 0
    for i in ball.values():
        if i >= 2:
            total += combinations_count(i, 2)
    for k in range(N):
        if ball[A[k]] == 2:
            print(total - 1)
        elif ball[A[k]] == 1:
            print(total)
        else:
            print(total - ball[A[k]] + 1)


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


if __name__ == '__main__':
    main()

Solution (Python):


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

box = [0] * (N + 1)
box_2 = [0] * (N + 1)
box_3 = [0] * (N + 1)

for i in range(N):
    box[A_list[i]] += 1

for i in range(N + 1):
    if box[i] > 1:
        box_2[i] = (box[i] * (box[i] - 1)) / 2
        box_3[i] = ((box[i] - 1) * (box[i] - 2)) / 2

ans_base = sum(box_2)

for i in range(N):

    if box[A_list[i]] > 0:
        diff = box_2[A_list[i]] - box_3[A_list[i]]
        print(int(ans_base - diff))
    else:
        print(int(ans_base))

Solution (Python):
from collections import Counter


def main():
    
    
    
    
    
    
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    base_num = sum([n * (n - 1) // 2 for n in counter.values()])
    for k in range(N):
        print(base_num - (counter[A[k]] - 1))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**6) 
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right

from collections import deque 



from collections import Counter

from itertools import accumulate

from heapq import heapify,heappop,heappush


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds




N = int(input())


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


l=[0]*N
ans=0
for a in A:
    ans+=l[a-1]
    l[a-1]+=1


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

Solution (Python):

import math
import collections

def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    counter = 0
    a_c = collections.Counter(A)
    for v in a_c.values():
        counter += combinations_count(v,2)

    for a in A:
        print(counter-a_c[a]+1)

if __name__ == "__main__":
    main()

Solution (Python):

import math
import collections

def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    counter = 0
    a_c = collections.Counter(A)
    for v in a_c.values():
        counter += combinations_count(v,2)

    for a in A:
        print(counter-a_c[a]+1)

if __name__ == "__main__":
    main()

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

total = 0
for key, val in new_a.items():
    if val > 1:
        total += (val * (val - 1) // 2)


for i in a:
    ans = total
    ans -= new_a[i]-1
    print(ans)

Solution (Python):
from collections import Counter


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

ans1 = 0
counter = Counter(a)
items = list(counter.items())
counter_dict = dict(items)

for i in range(len(items)):
    c_i = items[i][1]
    ans1 += c_i * (c_i - 1) // 2

for k in range(n):
    ans2 = counter_dict.get(a[k]) - 1
    print(ans1 - ans2)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [0]*N
for n in range(N):
  B[A[n]-1] +=1
max_val = 0
for m in range(N):
  max_val+= B[m-1]*(B[m-1]-1)//2
result = [max_val]*N
for n in range(N):
  result[n] -= B[A[n]-1]-1
for n in range(N):
  print(result[n])

Solution (Python):
import math

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

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

memo = [0 for i in range(10 ** 6)]
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    if memo[tmp] == 0:
      memo[tmp] = tmp * (tmp - 1) // 2
      ans += memo[tmp]
    else:
      ans += memo[tmp]

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  elif tmp == 2:
    print(ans - 1)
  else:
    print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
ncr1 = {}
ncr2 = {}
d = defaultdict(int)

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

sumA = 0

for key, value in d.items():
    ncr1[key] = value * (value-1) // 2
    ncr2[key] = (value-1)*(value-2) // 2
    sumA += ncr1[key]

for i in range(N):
    a = A[i]
    ans = sumA - ncr1[a] + ncr2[a]
    print(ans)

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

from collections import Counter

cnt = Counter(a)
b = set(a)
c = 0
for i in b:
    c += cnt[i]*(cnt[i]-1)//2

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

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

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

c = collections.Counter(A)
keys = c.keys()
ans_dict = {}
ans_dict2 = {}
for key in keys:
    ans_dict[key] = cmb(c[key]-1,2)
    ans_dict2[key] = cmb(c[key],2)

SUM  = sum(ans_dict2.values())




for key in A:
    print(SUM-ans_dict2[key]+ans_dict[key])

Solution (Python):
N=int(input())
K=list(map(int, input().split()))
from collections import Counter
ans = 0
C = Counter(K)
for k, v in C.items():
    ans += v*(v-1)//2

for a in K:
    e = C[a]
    print(ans-e*(e-1)//2+(e-1)*(e-2)//2)

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

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

Solution (Python):
from collections import Counter


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = read_ints()
    counter = Counter(A)
    total = 0
    for count in counter.values():
        total += count*(count-1)//2
    for a in A:
        if counter[a] > 1:
            print(total-(counter[a]-1))
        else:
            print(total)


if __name__ == '__main__':
    solve()

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

counts = [0] * (N+1)

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

sum_ = 0
for k in range(1, N+1):
    sum_ += counts[k] * (counts[k]-1) // 2

for k in range(1, N+1):
    
    print(sum_ - (counts[A[k-1]] - 1))

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

Solution (Python):
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)


inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)


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



def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


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


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a




def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


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

    nums = defaultdict(int)
    ans = 0
    for i in range(n):
        nums[a[i]] += 1
    for i in nums:
        ans += nums[i] * (nums[i]-1)//2
    """
    for v in a:
        ans += nums[v]
        nums[v] += 1
    """

    for v in a:
        print(ans - (nums[v]-1))


if __name__ == '__main__':
    main()

Solution (Python):
A = int(input())
import collections
total = 0
listN = list(map(int,input().split()))
dic = collections.Counter(listN)
listB = list(dic.values())
for i in listB:
    total += i * (i-1) // 2
dic_keys = list(dic.keys())
dic_values = list(dic.values())
for i in range(len(dic_values)):
    B = dic_values[i]
    dic_values[i] = total-(B-1)
dic = {}
for i in range(len(dic_values)):
    dic[dic_keys[i]] = dic_values[i]
for i in listN:
    print(dic[i])

Solution (Python):
n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in t:
  dn[i] = 0
for i in L:
  dn[i] += 1
for i in t:
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]]-1)*(dn[L[i]]-2)/2))

Solution (Python):
M=int(input())
N=list(input().split())
check=[0]*M
for i in range(M):
    check[int(N[i])-1]+=1
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    
    print(num-(check[int(N[i])-1]-1))

Solution (Python):
M=int(input())
N=list(input().split())
check=[0]*M
for i in range(M):
    check[int(N[i])-1]+=1
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    if check[int(N[i])-1]!=2:
        print(num-(check[int(N[i])-1]-1))
    else:
        print(num-1)

Solution (Python):
M=int(input()) 
N=list(input().split()) 
check=[0]*M           
for i in range(M):    
    check[int(N[i])-1]+=1   
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    if check[int(N[i])-1]!=2:
        print(num-(check[int(N[i])-1]-1))
    else:
        print(num-1)

Solution (Python):
import copy
from scipy.misc import comb
n = int(input())


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

ac2 = []
ac2_diff = []
for i in range(n):
    ac2.append(comb(an[i], 2, exact=True))
    ac2_diff.append(ac2[i]-comb(an[i]-1, 2, exact=True))
sum = sum(ac2)
for i in range(n):
    print(sum - ac2_diff[a[i]-1])

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

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

for i,j in c.items():
    a += j *(j-1) //2

for k in range(n):
    nn = c[A[k]]
    ans = a -(nn-1)
    print(ans)

Solution (Python):
import sys





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

n = int(input())

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

bunpu = [0]*(n+1)

for i in range(len(a)):
    bunpu[a[i]]+=1


sum = 0
for i in bunpu:
    sum+=choose(i)
i = 0
for i in a:
    print(int(sum-choose(bunpu[i])+choose(bunpu[i]-1)))

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

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

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

ans_all = 0
ans_list = {}
for k, v in d.items():
    if v == 1:
        ans_list[k] = 0
        continue
    if v == 2:
        ans_all += 1
        ans_list[k] = 1
        continue
    ans_all += v*(v-1)/2
    ans_list[k] = v*(v-1)/2 - (v-1)*(v-2)/2

for a in A:
    print(int(ans_all-ans_list[a]))

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

data = [0]*(n+1)

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

allans = 0
for d in data:
  if d >= 2:
    allans += (d*(d-1))//2
    
for aa in a:
  if data[aa] == 2:
    print(allans - (data[aa]*(data[aa]-1))//2)
  elif data[aa] > 2:
    print(allans - (data[aa]-1))
  else:
    print(allans)

Solution (Python):
N = int(input())
src = list(map(int,input().split()))
dic = {}
for n in range(N):
  if dic.get(src[n]) == None:
    dic[src[n]] = 1
  else:
    dic[src[n]] += 1
a = 0
for key, value in dic.items():
  a += value*(value-1)//2
ans = []
for s in src:
  ans.append(a - dic[s]*(dic[s]-1)//2 + (dic[s]-1)*(dic[s]-2)//2)
for b in ans:
  print(b)

Solution (Python):
N = int(input())
Alist=list(map(int, input().split()))
numdic = {}
for i in Alist:
    if i in numdic:
        numdic[i] += 1
    else:
        numdic[i] = 1
Apple = 0
for i in numdic.values():
    Apple += i*(i-1)//2
for i in Alist:
    tmp = Apple
    tmp -= (numdic[i]-1)
    print(tmp)

Solution (Python):
n=int(input())
li=list(map(int,input().split()))
d={}
dif={-1}
ans={}
for i in range(n):
    if li[i] not in dif:
        dif|={li[i]}
    if d.get(li[i])!=None:
        d[li[i]]+=1
    else:
        d[li[i]]=1
dif.remove(-1)
g=0
for i in dif:
    g+=d[i]*(d[i]-1)//2
for i in dif:
    ans[i]=g-(d[i]-1)*d[i]//2+(d[i]-2)*(d[i]-1)//2
for i in li:
    print(ans[i])

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

b = []
total = 0

for i in range(n):
    b.append(0)

for i in range(n):
    b[a[i]-1] += 1
for i in range(n):
    if b[i] >= 2:   
        total += b[i]*(b[i]-1)//2



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

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

l1sum=sum(l1)
for i in range(n):
    if l[a[i]-1]-1>=2:print(l1sum-l1[a[i]-1]+ (l[a[i]-1]-1)*(l[a[i]-1]-2)//2)
    else:print(l1sum-l1[a[i]-1])