AtCoder Beginner Contest 159 - Banned K

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-----
5
1 1 2 1 2

-----Sample Output-----
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.

Source: atcoder | Difficulty: MEDIUM


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


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)


from collections import Counter
n = int(input())
al = list(map(int, input().split()))
c = Counter(al)
ans = 0
for (k, v) in c.items():
	ans += v * (v - 1) // 2
for a in al:
	b = c[a]
	print(ans - b * (b - 1) // 2 + (b - 1) * (b - 2) // 2)


n = int(input())
A = list(map(int, input().split()))
import collections
c = collections.Counter(A)
ans = sum([j * (j - 1) // 2 for j in c.values()])
for x in A:
	print(ans - (c[x] - 1))


from collections import Counter
n = int(input())
a_array = list(map(int, input().split()))
a_counter = Counter(a_array)
count_max = max(a_counter.values())

def nC2(n):
	return n * (n - 1) // 2
nc2_array = [0] * (count_max + 1)
sum_comb = 0
for (a, count) in a_counter.items():
	comb = nC2(count)
	sum_comb += comb
	nc2_array[count] = comb
	nc2_array[count - 1] = nC2(count - 1)
for a in a_array:
	a_count = a_counter[a]
	ans = sum_comb - nc2_array[a_count] + nc2_array[a_count - 1]
	print(ans)


n = int(input())
al = list(map(int, input().split()))
ll = [0 for _ in range(n)]
fl = []
tl = []
for a in al:
	ll[a - 1] += 1
for l in ll:
	if l >= 2:
		fl.append(l * (l - 1) // 2)
		tl.append((l - 1) * (l - 2) // 2)
	else:
		fl.append(0)
		tl.append(0)
cnt = sum(fl)
for a in al:
	print(cnt - fl[a - 1] + tl[a - 1])


import collections
N = int(input())
A = list(map(int, input().split()))
l = collections.Counter(A)
al = sum([x * (x - 1) // 2 for x in l.values()])
for i in range(N):
	print(al - (l[A[i]] - 1))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
total = sum([v * (v - 1) // 2 for v in c.values()])
for i in a:
	print(total - (c[i] - 1))


N = int(input())
A = list(map(int, input().split()))
count = [0] * (N + 1)
for i in range(N):
	count[A[i]] += 1
total = 0
for j in range(1, N + 1):
	cj = count[j] * (count[j] - 1) // 2
	total = total + cj
ans = total
for k in range(N):
	ans = total - (count[A[k]] - 1)
	print(ans)


from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
s = 0
for v in cnt.values():
	s += v * (v - 1) // 2
for i in range(n):
	print(s - cnt[a[i]] + 1)


n = int(input())
a = [int(x) for x in input().split()]
cnt = [0] * (n + 1)
for v in a:
	cnt[v] += 1
tmp = 0
for c in cnt:
	tmp += c * (c - 1) // 2
for v in a:
	print(tmp - cnt[v] + 1)


n = int(input())
A = list(map(int, input().split()))
import collections
C = collections.Counter(A)
t = 0
for i in C.values():
	t += i * (i - 1) // 2
for i in A:
	print(t - C[i] + 1)


n = int(input())
l = list(map(int, input().split()))
x = [0] * n
for i in range(n):
	x[l[i] - 1] += 1
d = 0
for i in range(n):
	d = d + x[i] * (x[i] - 1) // 2
for i in range(n):
	b = d - (x[l[i] - 1] - 1)
	print(b)


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


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
sum = 0
for (k, v) in list(cnt.items()):
	sum += v * (v - 1) // 2
for i in range(N):
	num = cnt.get(A[i])
	if num == 1:
		ans = sum
	elif num == 2:
		ans = sum - 1
	else:
		ans = sum - num * (num - 1) // 2 + (num - 1) * (num - 2) // 2
	print(ans)


from collections import defaultdict
import collections
import math
N = int(input())
List = list(map(int, input().split()))
dicList = collections.Counter(List)
total = 0
for key in dicList:
	if dicList[key] >= 2:
		total += dicList[key] * (dicList[key] - 1) // 2
for item in List:
	print(total - dicList[item] + 1)


import collections
n = int(input())
a = list(map(int, input().split()))
d = collections.Counter(a)
s = sum([i * (i - 1) // 2 for i in d.values()])
for j in a:
	print(s - d[j] + 1)


n = int(input())
a = list(map(int, input().split()))
b = {}
for i in a:
	b[i] = b.get(i, 0) + 1
s = sum([i * (i - 1) // 2 for i in b.values()])
for i in a:
	print(s - b[i] + 1)


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


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


import collections
import math

def cmb_factorial(s):
	return math.factorial(s) // (math.factorial(2) * math.factorial(s - 2))
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
f = {}
cmb = 0
for x in c.values():
	f[1] = 0
	f[2] = 1
	if x >= 3:
		f[x] = cmb_factorial(x)
		if x - 1 not in f:
			f[x - 1] = cmb_factorial(x - 1)
	cmb += f.get(x)
for z in a:
	y = c.get(z)
	ans = cmb
	if y >= 2:
		ans = cmb - f.get(y) + f.get(y - 1)
	print(ans)


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = {}
ANS = 0
for (x, y) in Counter(A).items():
	if y >= 2:
		a[x] = [y, y * (y - 1) // 2]
		ANS += y * (y - 1) // 2
for i in range(n):
	ans = ANS
	if A[i] in a:
		x = a[A[i]][0] - 1
		ans -= a[A[i]][1]
		ans += x * (x - 1) // 2
	print(ans)


n = int(input())
a = list(map(int, input().split()))
e = list(set(a))
s = 0
t = [0] * 200000
for i in a:
	t[i] += 1
for j in e:
	k = t[j]
	s += k * (k - 1) // 2
for u in a:
	print(s - t[u] + 1)


n = int(input())
l = [int(x) for x in input().split()]
m = [0] * 200007
for x in l:
	m[x] = m[x] + 1
total = 0
for x in m:
	total += x * (x - 1) // 2
for x in l:
	print(total - m[x] + 1)


n = int(input())
aaa = list(map(int, input().split(' ')))
hoge = [0, 0]
for i in range(2, int(1000000.0) + 1):
	hoge.append(hoge[i - 1] + (i - 1))
d = {}
for a in aaa:
	d[a] = d.get(a, 0) + 1
total = sum([hoge[v] for v in list(d.values())])
for i in range(1, n + 1):
	ct = d[aaa[i - 1]]
	print(total - (hoge[ct] - hoge[ct - 1]))


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


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


N = int(input())
A = list(map(int, input().split()))
di = {}
for a in A:
	if a not in di.keys():
		di[a] = 1
	else:
		di[a] += 1
sum = 0
for (a, b) in di.items():
	sum += int(b * (b - 1) / 2 * 1)
for k in A:
	n = di[k]
	bef = n * (n - 1) / 2
	aft = (n - 1) * (n - 2) / 2
	print(int(sum - bef + aft))


N = int(input())
A = [int(x) for x in input().split()]
d = [0] * N
for a in A:
	d[a - 1] += 1
score = 0
for a in d:
	score += a * (a - 1) // 2
for a in A:
	print(score - d[a - 1] + 1)


import collections
N = int(input())
A = list(map(int, input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
	S += i * (i - 1) // 2
for x in A:
	print(S - CA[x] + 1)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
S = sum((c * (c - 1) // 2 for c in C.values()))
for a in A:
	print(S - C[a] + 1)


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


n = int(input())
a = list(map(int, input().split()))
l = [0] * n
for x in a:
	l[x - 1] += 1
ans = sum([x * (x - 1) // 2 for x in l])
for x in a:
	print(ans - l[x - 1] + 1)


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


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


N = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))
d = [0] * N
for i in A:
	d[i] += 1
s = sum(map(lambda x: x * (x - 1) // 2, d))
for i in A:
	print(s + (1 - d[i]))


n = int(input())
A = list(map(int, input().split()))
X = [0] * (n + 1)
for a in A:
	X[a] += 1
s = 0
for x in X:
	s += x * (x - 1) // 2
for a in A:
	print(s - X[a] + 1)


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


def f():
	n = int(input())
	(*li,) = list(map(int, input().split()))
	from collections import Counter
	c = Counter()
	for i in li:
		c[i] += 1
	ans = 0
	from math import comb
	for i in list(c.values()):
		ans += comb(i, 2)
	for i in li:
		print(ans - comb(c[i], 2) + comb(c[i] - 1, 2))
f()


import numpy as np
n = int(input())
A = list(map(int, input().split()))
c = np.zeros(n + 1, dtype=np.int32)
for a in A:
	c[a] += 1
aa = list(set(A))
allsum = 0
for a in aa:
	allsum += c[a] * (c[a] - 1) // 2
for a in A:
	print(allsum - c[a] + 1)


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


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


N = int(input())
A = [int(i) for i in input().split()]
B = [0] * N
for i in range(N):
	B[A[i] - 1] += 1
s = 0
for i in range(N):
	s += B[i] * (B[i] - 1) // 2
for i in range(N):
	print(s - B[A[i] - 1] + 1)


from collections import Counter
from scipy.special import comb
s = input()
A = list(map(int, input().split()))
d = Counter(A)
sum_c = 0
for v in d.values():
	if v >= 2:
		sum_c += comb(v, 2, exact=True)
for a in A:
	x = sum_c - comb(d[a], 2, exact=True) + comb(d[a] - 1, 2, exact=True)
	print(x)


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


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


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


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


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
dic = dict()
for (k, v) in cnt.items():
	dic[k] = v * (v - 1) // 2
res = sum(dic.values())
for ai in a:
	print(res - dic[ai] + int(dic[ai] * (cnt[ai] - 2) / cnt[ai]))


from collections import defaultdict

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	d = defaultdict(lambda : 0)
	d2 = {}
	for i in a:
		d[i] += 1
	for (i, j) in d.items():
		x = j * (j - 1) // 2
		d2[i] = x
	ans = 0
	ans = sum(d2.values())
	for i in range(n):
		print(ans - d[a[i]] + 1)

def __starting_point():
	main()
__starting_point()


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)


import collections
N = int(input())
A = list(map(int, input().split()))
b = collections.Counter(A)
C = 0
for i in b.values():
	C += i * (i - 1) / 2
for i in range(N):
	print(int(C - b[A[i]] + 1))


N = int(input())
(*A,) = map(int, input().split())
import collections
c = collections.Counter(A)
s = 0
for i in c.values():
	s += i * (i - 1) / 2
for a in A:
	t = c[a]
	print(int(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2))


from collections import Counter
n = int(input())
(*a,) = map(int, input().split())
c = Counter(a)
s = sum((i * (i - 1) // 2 for i in c.values()))
for k in range(n):
	print(s - c[a[k]] + 1)


c = [0] * 8 ** 6
(_, a) = open(0)
(*a,) = map(int, a.split())
for i in a:
	c[i] += 1
s = sum((i * ~-i // 2 for i in c))
print(' '.join((str(s - c[i] + 1) for i in a)))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
import sys
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
N = ni()
A = na()
d = collections.Counter(A)
ct = {}
for (k, v) in list(d.items()):
	ct[k] = max(0, v * (v - 1) // 2)
sum_ = sum(ct.values())
for ai in A:
	print(sum_ - ct[ai] + max((d[ai] - 1) * (d[ai] - 2) // 2, 0))


import collections
N = int(input())
li = list(map(int, input().split()))
cn = collections.Counter(li)
sumC = sum([n * (n - 1) // 2 for n in cn.values()])
for k in range(N):
	print(sumC - (cn[li[k]] - 1))


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))


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


n = int(input())
l = list(map(int, input().split()))
import collections
c = collections.Counter(l)
ans = 0
for v in c.values():
	ans += v * (v - 1) // 2
for x in l:
	print(ans - c[x] + 1)


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


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


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


from collections import Counter
(N, *A) = map(int, open(0).read().split())
C = Counter(A)
full = sum((n * (n - 1) // 2 for n in C.values()))
for a in A:
	print(full - (C[a] - 1))


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))


def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
import math

def choose2(n):
	return n * (n - 1) // 2
N = get_int()
An = get_ints()
uni = [0] * (N + 1)
for i in range(N):
	uni[An[i]] += 1
sumWay = 0
for i in range(N + 1):
	sumWay += choose2(uni[i])
for i in range(N):
	print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]] - 1))


N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
	a[i - 1] += 1
cnt = 0
cnt += sum([i * (i - 1) // 2 for i in a])
for i in A:
	print(cnt - (a[i - 1] - 1))


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
dic = {}
sum = 0
for i in range(n):
	if not a[i] in dic:
		dic[a[i]] = 1
	else:
		dic[a[i]] += 1
		sum += dic[a[i]] - 1
for i in a:
	print(sum - dic[i] + 1)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
from collections import Counter, defaultdict

def main():
	(n, *a) = map(int, read().split())
	aa = Counter(a)
	d1 = defaultdict(int)
	d2 = defaultdict(int)
	for (k, v) in aa.items():
		d1[k] = v * (v - 1) // 2
		v -= 1
		d2[k] = v * (v - 1) // 2
	sumd1 = sum(d1.values())
	for ae in a:
		r = sumd1 - d1[ae] + d2[ae]
		print(r)

def __starting_point():
	main()
__starting_point()


n = int(input())
x = list(map(int, input().split()))
xm = max(x)

def ra(a):
	(ll, l) = ([0] * xm, 1)
	for i in range(len(a) - 1):
		if a[i] == a[i + 1]:
			l += 1
		else:
			ll[a[i]] += l
			l = 1
	ll.append(l)
	return ll
b = ra(sorted(x))
d = 0
for i in b:
	d += i * (i - 1) // 2
for i in range(n):
	print(d - b[x[i]] + 1)


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


n = int(input())
cnt = [0] * (n + 1)
cmb = 0
a = list(map(int, input().split()))
for ai in a:
	cnt[ai] += 1
	cmb += cnt[ai] - 1
for ai in a:
	print(cmb - cnt[ai] + 1)


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)


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)


from collections import Counter
from math import factorial

def nCr(n, r):
	return factorial(n) // (factorial(n - r) * factorial(r))
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
D = dict()
s = 0
for a in set(A):
	c = C[a]
	if c > 1:
		x = nCr(c, 2)
		s += x
		if c > 2:
			D[a] = (x, nCr(c - 1, 2))
		else:
			D[a] = (x, 0)
	else:
		D[a] = (0, 0)
for a in A:
	t = D[a]
	print(s - t[0] + t[1])


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
s = 0
for key in c:
	s += c[key] * (c[key] - 1) // 2
for item in a:
	print(s - c[item] + 1)


import collections as c
n = int(input())
A = list(map(int, input().split()))
D = c.Counter(A)
S = 0
for i in D:
	x = D[i]
	S += x * (x - 1) // 2
for a in A:
	print(S - D[a] + 1)


import collections
N = int(input())
A = list(map(int, input().split()))
S = 0
c = collections.Counter(A)
for v in c.values():
	S = S + v * (v - 1) // 2
for i in range(len(A)):
	print(S - c[A[i]] + 1)


from collections import *
(n, *a) = map(int, open(0).read().split())
b = Counter(a)
ans = sum((v * (v - 1) // 2 for (k, v) in b.items()))
for i in range(n):
	x = b[a[i]]
	print(ans - x * (x - 1) // 2 + (x - 1) * (x - 2) // 2)


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]))


import math

def combination(n, r):
	if n <= 1:
		return 0
	elif n == 2:
		return 1
	else:
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def count_list(lst):
	count_lst = [0] * (max(lst) + 1)
	for i in lst:
		count_lst[i] += 1
	return count_lst

def main():
	n = int(input())
	a_lst = list(map(int, input().split()))
	lst1 = count_list(a_lst)
	lst2 = [0] * len(lst1)
	for i in range(len(lst1)):
		lst2[i] = combination(lst1[i], 2)
	tmp = sum(lst2)
	for i in range(n):
		a = a_lst[i]
		print(tmp - (lst1[a] - 1))

def __starting_point():
	main()
__starting_point()


n = int(input())
a = input().split()
dict = {}
ans = 0
for i in range(n):
	a[i] = int(a[i])
	if not a[i] in dict:
		dict[a[i]] = 1
	else:
		dict[a[i]] += 1
for i in dict:
	ans += dict[i] * (dict[i] - 1) // 2
for i in range(n):
	print(ans - dict[a[i]] + 1)


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


(n, *a) = map(int, open(0).read().split())
m = [0] * n
for i in a:
	m[i - 1] += 1
w = 0
for i in range(n):
	w += m[i] * (m[i] - 1) // 2
for i in a:
	print(w + 1 - m[i - 1])


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


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0
for (key, value) in b.items():
	ans += value * (value - 1) // 2
for i in range(n):
	print(ans - b[a[i]] + 1)


n = int(input())
a = list(map(int, input().split()))
nums = [0] * (n + 1)
for i in a:
	nums[i] += 1
t = 0
for j in nums:
	t += j * (j - 1) // 2
for k in a:
	print(t + 1 - nums[k])


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


N = int(input())
A = list(map(int, input().split()))
L = [0] * (max(A) + 1)
for a in A:
	L[a] += 1
SUM = 0
for l in L:
	SUM += l * (l - 1) // 2
for a in A:
	l = L[a]
	print(SUM - l * (l - 1) // 2 + (l - 1) * (l - 2) // 2)


n = int(input())
a = list(map(int, input().split()))
aset = list(set(a))
ans = 0
al = [0] * 200000
for i in a:
	al[i] += 1
for j in aset:
	k = al[j]
	ans += k * (k - 1) // 2
for u in a:
	print(ans - al[u] + 1)


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


N = int(input())
Alst = list(map(int, input().split()))
Blst = [0] * (N + 1)
num = 0
for i in Alst:
	num = num + Blst[i]
	Blst[i] += 1
for i in Alst:
	k = Blst[i] - 1
	print(num - k)


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
s = 0
for k in d:
	s += d[k] * (d[k] - 1) // 2
for i in range(N):
	t = d[A[i]]
	print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)


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


import collections
n = int(input())
a = list(map(int, input().split()))
dic = collections.Counter(a)
total = 0
for x in list(dic.values()):
	total += x * (x - 1) // 2
for y in range(n):
	b = a[y]
	lost = dic[b] * (dic[b] - 1) // 2 - (dic[b] - 1) * (dic[b] - 2) // 2
	print(total - lost)


n = int(input())
b = list(map(int, input().split()))
l = [0] * n
for i in range(n):
	l[b[i] - 1] += 1
l2 = sum([i * (i - 1) // 2 for i in l])
for i in b:
	print(l2 - (l[i - 1] - 1))


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
s = sum((cnt * ~-cnt // 2 for cnt in cnt.values()))
for k in A:
	print(s - cnt[k] + 1)


n = int(input())
A = list(map(int, input().split()))
CNT = [0] * (n + 1)
for a in A:
	CNT[a] += 1
x = sum((cnt * (cnt - 1) // 2 for cnt in CNT if cnt))
for a in A:
	print(x - (CNT[a] - 1))


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


import collections
N = int(input())
lst = input().split()
s = 0
dic = collections.Counter(lst)
for i in dic.values():
	s += (i * i - i) // 2
for i in lst:
	print(s + 1 - dic[i])


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 x in a:
	print(ans - c[x] + 1)


import collections
_ = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
M = 0
for v in c.values():
	if v > 1:
		M += v * (v - 1) / 2
for k in l:
	print(int(M - c[k] + 1))


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


n = int(input())
a = list(map(int, input().split()))
import collections
c = collections.Counter(a)
al = 0
for v in c.values():
	al += v * (v - 1) / 2
for aa in a:
	print(int(al - c[aa] + 1))


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


N = int(input())
L = list(map(int, input().split()))
c = {}
for i in set(L):
	c[i] = 0
for i in L:
	c[i] += 1
s = sum([i * (i - 1) // 2 for i in c.values()])
for i in L:
	print(s - c[i] + 1)


import collections as cl
N = int(input())
A = list(map(int, input().split()))
cn = cl.Counter(A)
sumC = sum([n * (n - 1) // 2 for n in cn.values()])
for k in range(N):
	print(sumC - cn[A[k]] + 1)


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


N = int(input())
A = list(map(int, input().split()))
li = [0] * (N + 1)
total = 0
for i in A:
	li[i] += 1
for i in li[1:]:
	total += i * (i - 1) // 2
for i in A:
	j = li[i]
	print(total - j * (j - 1) // 2 + (j - 1) * (j - 2) // 2)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
S = sum([n * (n - 1) // 2 for n in c.values()])
for i in range(N):
	print(S - (c[A[i]] - 1))


from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
kw = Counter(A)
ans = sum([x * (x - 1) // 2 for x in kw.values()])
for i in A:
	print(ans - kw[i] + 1)


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)


from collections import Counter
n = int(input())

def kC2(k):
	return k * (k - 1) // 2
A = list(map(int, input().split()))
AC = Counter(A)
total = sum((kC2(v) for v in AC.values()))
print(*[total - kC2(AC[a]) + kC2(AC[a] - 1) for a in A], sep='\n')


N = int(input())
A = list(map(int, input().split()))
s = [0] * (N + 1)
for i in range(N):
	s[A[i]] += 1

def nC2(n):
	return n * (n - 1) // 2
ss = list(map(nC2, s))
sss = sum(ss)
for i in range(N):
	print(sss - s[A[i]] + 1)


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


n = int(input())
l = list(map(int, input().split()))
d = {}
an = 0
for i in l:
	d[i] = d.get(i, 0) + 1
for i in d.values():
	an += i * (i - 1) // 2
for j in l:
	i = d[j]
	print(an + (i - 1) * (i - 2) // 2 - i * (i - 1) // 2)


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


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


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	if d.get(i, -1) == -1:
		d[i] = 0
	d[i] += 1
s = 0
for i in d:
	s += d[i] * (d[i] - 1) // 2
for i in a:
	print(s - d[i] + 1)


N = int(input())
A = [int(x) for x in input().split()]
numdict = dict()
for h in range(N):
	if A[h] in numdict.keys():
		numdict[A[h]] += 1
	else:
		numdict[A[h]] = 1
all_select_two = 0
for i in numdict.keys():
	value = numdict[i]
	all_select_two += value * (value - 1) // 2
ans = 0
for k in range(N):
	j = A[k]
	value = numdict[j]
	ans = all_select_two - value + 1
	print(ans)


import collections
N = int(input())
A = list(map(int, input().split()))
cc = collections.Counter(A)
L = list(cc.values())
total = 0
for i in range(len(L)):
	total += L[i] * (L[i] - 1) // 2
ans = 0
for a in A:
	temp = cc[a] * (cc[a] - 1) // 2
	ttemp = (cc[a] - 1) * (cc[a] - 2) // 2
	ans = total - temp + ttemp
	print(ans)


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


n = int(input())
a = list(map(int, input().split()))
b = {}
for x in a:
	b.setdefault(x, 0)
	b[x] += 1
ans = 0
for x in b.values():
	ans += x * (x - 1) // 2
for x in a:
	print(ans - b[x] + 1)


N = int(input())
A = list(map(int, input().strip().split()))
from collections import Counter
C = Counter(A)
K = set(A)
ans = 0
for i in K:
	ans += C[i] * (C[i] - 1) // 2
for i in A:
	print(ans - (C[i] - 1))


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)


s = int(input())
a = list(map(int, input().split()))
from collections import Counter
b = Counter(a)
total = 0
for i in b.values():
	total += i * (i - 1) // 2
for i in a:
	print(total - b[i] * (b[i] - 1) // 2 + (b[i] - 1) * (b[i] - 2) // 2)


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


N = int(input())
K = list(map(int, input().split()))
C = [0] * (N + 1)
for k in K:
	C[k] += 1
Sc = 0
for c in C:
	Sc += c * (c - 1) // 2
for k in K:
	print(Sc - (C[k] - 1))


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


n = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
d = Counter(A)
sum_ = 0
for i in d.values():
	sum_ += i * (i - 1) // 2
for a in A:
	print(sum_ - (d[a] - 1))


N = int(input())
s = 0
A = list(map(int, input().split()))
li = [0] * (2 * 10 ** 5 + 1)
for i in range(N):
	li[A[i]] += 1
for j in range(N + 1):
	s += li[j] * (li[j] - 1) // 2
for k in range(N):
	print(s - li[A[k]] + 1)


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


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


from collections import Counter
N = int(input())
As = list(map(int, input().split()))
cnt = Counter(As)
num = sum([v * (v - 1) // 2 for v in list(cnt.values())])
anss = []
for A in As:
	v = cnt[A]
	ans = num - v * (v - 1) // 2 + (v - 1) * (v - 2) // 2
	anss.append(ans)
print('\n'.join(map(str, anss)))


from collections import Counter as C
N = int(input())
(*A,) = map(int, input().split())
c = C(A)
s = sum((v * ~-v // 2 for v in c.values()))
for a in A:
	print(s - ~-c[a])


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


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
tot = 0
dif = {}
for (k, v) in cnt.items():
	tot += v * (v - 1) // 2
	dif[k] = v - 1
ans = [tot - dif[a] for a in A]
print('\n'.join(map(str, ans)))


from collections import Counter
N = int(input())
(*A,) = map(int, input().split())
C = Counter(A)
S = 0
for v in C.values():
	S += v * (v - 1) // 2
for a in A:
	print(S - C[a] + 1)


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


from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)
MX = sum((v * (v - 1) for v in C.values())) // 2
for i in range(N):
	print(MX - C[A[i]] + 1)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
x = 0
for i in C:
	x += C[i] * (C[i] - 1) // 2
for a in A:
	print(x - (C[a] - 1))


import math
ini = lambda : int(input())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
gcd = lambda x, y: gcd(y, x % y) if x % y else y

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
		if temp % i == 0:
			cnt = 0
			while temp % i == 0:
				cnt += 1
				temp //= i
			arr.append([i, cnt])
	if temp != 1:
		arr.append([temp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n

	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			(x, y) = (y, x)
		self.parents[x] += self.parents[y]
		self.parents[y] = x

	def size(self, x):
		return -self.parents[self.find(x)]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def members(self, x):
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]

	def roots(self):
		return [i for (i, x) in enumerate(self.parents) if x < 0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()}

	def __str__(self):
		return '\n'.join(('{}: {}'.format(r, self.members(r)) for r in self.roots()))
mod = 10 ** 9 + 7
n = ini()
a = inl()
b = [0] * (n + 1)
for i in a:
	b[i] += 1
c = []
for i in range(n + 1):
	c.append(b[i] * (b[i] - 1) // 2)
ans = sum(c)
for i in a:
	d = b[i] - 1
	print(max(ans - d, 0))


n = int(input())
a = [int(i) for i in input().split()]
dic = {}
for i in range(n):
	dic[i + 1] = 0
for ai in a:
	dic[ai] += 1
cnt = 0
for di in dic:
	cnt += dic[di] * (dic[di] - 1) // 2
for i in range(n):
	print(cnt - dic[a[i]] * (dic[a[i]] - 1) // 2 + (dic[a[i]] - 2) * (dic[a[i]] - 1) // 2)


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print((node, '->', self.adj_list[node]))

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return len(parents)

def dict_sort(ans):
	ans = sorted(list(ans.items()), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def factors(n):
	d = {}
	while n % 2 == 0:
		if 2 in d:
			d[2] += 1
		else:
			d[2] = 1
		n /= 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
			n /= i
	n = int(n)
	if n > 1:
		d[n] = 1
	return d

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(a, b, c):
	chk = b * b - 4 * a * c
	if chk >= 0:
		ans1 = (-b + chk ** 0.5) / (2 * a)
		ans2 = (-b - chk ** 0.5) / (2 * a)
		return [int(ans1), int(ans2)]
	return -1

def permutation(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(n - r + 1, n + 1):
		ans *= i
	return ans

def combination(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(r):
		ans *= n - i
	div = 1
	for i in range(2, r + 1):
		div *= i
	return ans // div

def sumn(n):
	return n * (n + 1) // 2

def arrinp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return list(map(int, input().split()))

def main():
	n = int(input())
	ls = arrinp()
	occur = {}
	for i in ls:
		if i in occur:
			occur[i] += 1
		else:
			occur[i] = 1
	d = {}
	for i in occur:
		d[i] = sumn(occur[i] - 1)
	total = sum(d.values())
	for i in ls:
		print(total - d[i] + sumn(occur[i] - 2))

def __starting_point():
	main()
__starting_point()


N = int(input())
a = list(map(int, input().split()))
b = [0] * N
sum = 0
for i in range(N):
	b[a[i] - 1] += 1
for i in range(N):
	sum += b[i] * (b[i] - 1) // 2
for i in range(N):
	print(sum - b[a[i] - 1] + 1)


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 = 0
for d in D:
	ans += D[d] * (D[d] - 1) // 2
for a in A:
	print(ans - D[a] + 1)


from copy import copy
from collections import Counter
from scipy.special import comb
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
S = 0
for i in range(1, n + 1):
	S += comb(C[i], 2, exact=True)
for k in range(n):
	p = A[k]
	ans = S - comb(C[p], 2, exact=True) + comb(C[p] - 1, 2, exact=True)
	print(ans)


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


N = int(input())
A = [int(s) for s in input().split(' ')]
d = dict()
d2 = dict()
d3 = dict()
d4 = dict()
for a in A:
	d[a] = d.get(a, 0) + 1
for a in list(d.keys()):
	d2[a] = d[a] * (d[a] - 1) // 2
	d3[a] = (d[a] - 1) * (d[a] - 2) // 2
total = sum((d2[a] for a in list(d.keys())))
for a in A:
	print(total - d2[a] + d3[a])


N = int(input())
A = list(map(int, input().split()))
d = dict()
for i in range(N):
	if A[i] not in d:
		d[A[i]] = 0
	d[A[i]] += 1
x = sum((x * (x - 1) // 2 for x in list(d.values())))
for i in range(N):
	y = d[A[i]]
	print(x - y * (y - 1) // 2 + (y - 1) * (y - 2) // 2)


input()
l = list(map(int, input().split()))
from collections import *
c = Counter(l)
t = sum((i * ~-i // 2 for i in c.values()))
for i in l:
	print(t - c[i] + 1)


N = int(input())
A = list(map(int, input().split()))
import collections
a = collections.Counter(A)
from operator import mul
from functools import reduce

def combinations_count(n, r):
	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
ans = 0
for i in a:
	if a[i] > 1:
		ans += combinations_count(a[i], 2)
for i in A:
	n = a[i]
	if n > 2:
		print(ans + combinations_count(n - 1, 2) - combinations_count(n, 2))
	elif n == 2:
		print(ans - 1)
	else:
		print(ans)


n = int(input())
A = input().split()
B = {}
s = 0
for a in A:
	if a not in B:
		B[a] = 0
	B[a] += 1
	s += B[a] - 1
for a in A:
	print(s - (B[a] - 1))


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


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)


N = int(input())
A = list(map(int, input().split()))
from collections import Counter
ctr = Counter(A)
tmp = sum((v * (v - 1) // 2 for v in ctr.values()))
for a in A:
	print(tmp - ctr[a] + 1)


from collections import Counter
import math

def combinations_count(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
com = 0
for i in range(1, n + 1):
	if c[i] <= 1:
		continue
	com += combinations_count(c[i], 2)
for k in range(1, n + 1):
	ans = com
	ans -= c[a[k - 1]] - 1
	print(ans)


n = int(input())
lst = [int(i) for i in input().split()]
visited = {}
for d in lst:
	if d in visited.keys():
		visited[d] += 1
	else:
		visited[d] = 1
count = 0
for d in visited.keys():
	count += int(visited[d] * (visited[d] - 1) / 2)
for d in lst:
	v = visited[d] - 1
	ans = count - v
	print(ans)


N = int(input())
A = list(map(int, input().split()))
ls = [0] * (N + 1)
for a in A:
	ls[a] += 1
C = 0
for i in set(A):
	n = ls[i]
	C += n * (n - 1) // 2
for a in A:
	n = ls[a]
	print(C - (n - 1))


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)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
import collections
d = collections.Counter(a)
p = 0
for (i, v) in list(d.items()):
	if v >= 2:
		p += sum(range(1, v))
for i in a:
	if d[i] >= 2:
		print(p - (d[i] - 1))
	else:
		print(p)


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


from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]
c = Counter(A)
ans = 0
for i in c:
	ans += c[i] * (c[i] - 1) // 2
for i in range(len(A)):
	if c[A[i]] == 1:
		print(ans)
	else:
		tmp = c[A[i]]
		print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)


N = int(input())
A = list(map(int, input().split()))
num = [0] * (2 * 10 ** 5)
ans = 0
for i in A:
	num[i - 1] += 1
for j in range(2 * 10 ** 5):
	ans += num[j] * (num[j] - 1) // 2
for p in A:
	print(ans - num[p - 1] + 1)


import math

def combinations_count(n, r):
	if n < 2:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
aa = [int(i) for i in input().split()]
d = {}
for a in aa:
	d[a] = d.get(a, 0) + 1
kei = 0
for k in d.keys():
	combi = combinations_count(d[k], 2)
	kei += combi
	d[k] = (d[k], combi)
ret = 0
for k in d.keys():
	d[k] = (d[k][0], d[k][1], kei - d[k][0] + 1)
for a in aa:
	print(d[a][2])


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))


import collections
n = int(input())
a = list(map(int, input().split()))
b = collections.Counter(a)
e = 0
for x in b.values():
	e += x * (x - 1)
for x in a:
	t = b[x]
	p = e - t * (t - 1) + (t - 1) * (t - 2)
	print(p // 2)


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


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


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


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


N = int(input())
A = [int(a) - 1 for a in input().split()]
X = [0] * N
for a in A:
	X[a] += 1
s = 0
for x in X:
	s += x * (x - 1) // 2
for a in A:
	print(s - (X[a] - 1))


import collections
N = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
sum = 0
for i in list(B.values()):
	sum += i * (i - 1) / 2
for i in list(A):
	ans = int(sum - (B[i] - 1))
	print(ans)


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


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


n = int(input())
a = [int(a) - 1 for a in input().split()]
cnt = [0] * n
for i in a:
	cnt[i] += 1
total = 0
for i in cnt:
	total += i * (i - 1) // 2
for i in a:
	print(total - (cnt[i] - 1))


import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
cmb = 0
for x in c.values():
	cmb += x * (x - 1) // 2
for z in a:
	y = c.get(z)
	before = y * (y - 1) // 2
	after = (y - 1) * (y - 2) // 2
	ans = cmb - before + after
	print(ans)


N = int(input())
A = list(map(int, input().split()))
l = [0] * (2 * 10 ** 5 + 1)
for i in A:
	l[i] += 1
ans = sum((i * (i - 1) // 2 for i in l))
for i in A:
	print(ans - l[i] + 1)


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


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


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


def main():
	import math
	n = int(input())
	inlis = list(map(int, input().split()))
	indic = dict()
	total = 0
	for num in inlis:
		if num in indic:
			indic[num] += 1
		else:
			indic[num] = 1
	for (k, v) in indic.items():
		total += int(v * (v - 1) / 2)
	for num in inlis:
		print(total - indic[num] + 1)

def __starting_point():
	main()
__starting_point()


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


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


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


def main():
	N = int(input())
	A = [int(a) - 1 for a in input().split(' ')]
	int_cnt = [0] * N
	for a in A:
		int_cnt[a] += 1
	S = sum([combination_2(c) for c in int_cnt])
	for i in range(N):
		x = int_cnt[A[i]]
		print(S - combination_2(x) + combination_2(x - 1))

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


N = int(input())
A = input().split()
num_list = [0] * N

def combination(n):
	C = [0]
	for i in range(2, n + 1):
		C.append(int(i * (i - 1) / 2))
	return C
com = combination(N)
sum_com = 0
for i in range(N):
	num_list[int(A[i]) - 1] += 1
for i in range(N):
	if num_list[i] == 0:
		continue
	else:
		sum_com += com[num_list[i] - 1]
for i in range(N):
	print(sum_com - num_list[int(A[i]) - 1] + 1)


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


from scipy.special import comb
n = int(input())
l = list(map(int, input().split()))
flg = [0 for i in range(2 * 10 ** 5 + 1)]
flg2 = [0 for j in range(2 * 10 ** 5 + 1)]
for i in l:
	flg[i] += 1
s = 0
for i in range(1, n + 1):
	flg2[i] += (flg[i] - 1) * (flg[i] - 2) / 2 - flg[i] * (flg[i] - 1) / 2
	s += flg[i] * (flg[i] - 1) / 2
for i in l:
	print(int(s + flg2[i]))


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


from collections import Counter
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, list(range(n, n - r, -1)))
	under = reduce(mul, list(range(1, r + 1)))
	return over // under
n = int(input())
al = list(map(int, input().split()))
c = Counter(al)
k = 0
for v in list(c.values()):
	if v == 1:
		continue
	else:
		k += cmb(v, 2)
for a in al:
	if c[a] == 1:
		print(k)
	elif c[a] == 2:
		print(k - cmb(c[a], 2))
	else:
		print(k - cmb(c[a], 2) + cmb(c[a] - 1, 2))


n = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
	d[a] = d.get(a, 0) + 1
comb = []
for i in d:
	if d[i] > 1:
		comb.append(d[i] * (d[i] - 1) // 2)
s = sum(comb)
for a in A:
	ans = s - d[a] * (d[a] - 1) // 2 + (d[a] - 1) * (d[a] - 2) // 2
	print(ans)


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

def combinations_count(n, r):
	if n < r:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans = dict()
for a in A:
	if a in ans:
		ans[a] += 1
	else:
		ans[a] = 1
prin = 0
for a in ans:
	prin += combinations_count(ans[a], 2)
for i in range(n):
	print(prin - ans[A[i]] + 1)


n = int(input())
a = list(map(int, input().split()))
from collections import Counter
ca = Counter(a)
ans = sum([v * (v - 1) // 2 for v in ca.values()])
for ai in a:
	print(ans - ca[ai] + 1)


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


N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
	d[a] = d.get(a, 0) + 1
ans = sum([v * (v - 1) // 2 for v in d.values()])
for a in A:
	print(ans - d[a] + 1)


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


n = int(input())
lis = list(map(int, input().split()))
ban = [0] * n
tmp = 0
for i in lis:
	ban[i - 1] += 1
for i in ban:
	tmp += i * (i - 1) // 2
for i in lis:
	print(tmp + (1 - ban[i - 1]))


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


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)


(n, *a) = map(int, open(0).read().split())
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
ans = sum([i * (i - 1) // 2 for i in d.values()])
for i in a:
	print(ans + 1 - d[i])


N = int(input())
A = list(map(int, input().split()))
d = dict([])
ans = 0
for a in A:
	if a in d:
		ans += d[a]
		d[a] += 1
	else:
		d[a] = 1
for a in A:
	print(ans - d[a] + 1)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
s = Counter(a)
sums = 0
for k in s.keys():
	sums += (s[k] - 1) * s[k] // 2
for i in a:
	print(sums - s[i] + 1)


n = int(input())
a = list(map(int, input().split()))
numdict = {}
for n in a:
	if n in numdict.keys():
		numdict[n] += 1
	else:
		numdict[n] = 1
all_sum = 0
for k in numdict.keys():
	v = numdict[k]
	all_sum += v * (v - 1) // 2
for n in a:
	print(all_sum - numdict[n] + 1)


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


n = int(input())
a = list(map(int, input().split()))
l = [0] * 10 ** 6
ans1 = 0
for i in a:
	l[i] += 1
for i in l:
	ans1 += i * (i - 1) / 2
for i in a:
	print(int(ans1 - (l[i] - 1)))


import collections
n = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
s = 0
for (k, i) in B.items():
	s += i * (i - 1) // 2
for a in A:
	print(s - (B[a] - 1))


n = int(input())
al = list(map(int, input().split()))
counter = [0] * (n + 1)
for a in al:
	counter[a] += 1
sum = 0
for c in counter:
	sum += c * (c - 1) // 2
for a in al:
	print(sum - (counter[a] - 1))


from collections import Counter
n = input()
(*l,) = map(int, input().split())
A = Counter(l)
c = 0
for i in A.values():
	c += i * (i - 1) // 2
for j in l:
	print(c - A[j] + 1)


import collections
N = int(input())
a = [int(x) for x in input().split()]
A = collections.Counter(a)
T = sum((A[i] * ~-A[i] for i in A)) // 2
for i in a:
	print(T - ~-A[i])


n = int(input())
a = list(map(int, input().split()))
lst = [0] * (max(a) + 1)
for i in a:
	lst[i] += 1
num_lst = [0] * (max(a) + 1)
for i in range(1, max(a) + 1):
	if not lst[i] in [0, 1]:
		num_lst[i] = lst[i] * (lst[i] - 1) // 2
ans = sum(num_lst)
for i in a:
	if lst[i] in [0, 1]:
		print(ans)
	else:
		print(ans - num_lst[i] + (lst[i] - 1) * (lst[i] - 2) // 2)


import collections
(n, *a) = map(int, open(0).read().split())
c = collections.Counter(a)
ans = sum([val * (val - 1) // 2 for val in c.values()])
for i in range(n):
	print(ans - (c[a[i]] - 1))


N = int(input())
A = list(map(int, input().split()))
from collections import Counter
counter = Counter(A)
from collections import defaultdict
res_dic = defaultdict(int)
base = 0
for (key, n) in list(counter.items()):
	res_dic[key] = (n * (n - 1) // 2, (n - 1) * (n - 2) // 2)
	base += n * (n - 1) // 2
for i in range(N):
	ans = base - res_dic[A[i]][0] + res_dic[A[i]][1]
	print(ans)


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


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


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


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


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


import collections
N = int(input())
lsA = list(map(int, input().split()))
counterA = collections.Counter(lsA)
val = list(counterA.values())
lsans = []
alln = 0
for i in val:
	alln += i * (i - 1) // 2
for i in range(N):
	M = counterA[lsA[i]]
	div = M * (M - 1) // 2 - (M - 1) * (M - 2) // 2
	print(alln - div)


n = int(input())
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
ans0 = sum((cc * (cc - 1) // 2 for cc in c.values()))
for k in range(n):
	m = c[a[k]]
	print(ans0 - m + 1)


n = int(input())
arr = list(map(int, input().split()))
tt = [0] * (n + 7)
total = 0
for a in arr:
	tt[a] += 1
for t in tt:
	total += t * (t - 1) // 2
for i in range(n):
	n = tt[arr[i]]
	d = n * (n - 1) // 2 - (n - 1) * (n - 2) // 2
	print(total - d)


import collections
N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)
ans = 0
for i in C.values():
	ans += int(0.5 * i * (i - 1))
for j in A:
	print(ans - C[j] + 1)


from collections import Counter as f
n = input()
(*l,) = map(int, input().split())
A = f(l)
c = sum([i * (i - 1) // 2 for i in A.values()])
for j in l:
	print(c - A[j] + 1)


import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
ans = sum([x * (x - 1) // 2 for x in c.values()])
for i in range(N):
	print(ans - c[A[i]] + 1)


N = int(input())
A = list(map(int, input().split()))
c = [0] * (N + 1)
for a in A:
	c[a] += 1
total = sum([n * (n - 1) // 2 for n in c])
for a in A:
	print(total - (c[a] - 1))


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


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)))


n = int(input())
A = list(map(int, input().split()))
cnt = [0] * n

def choose2(m):
	return m * (m - 1) / 2
for i in range(n):
	A[i] -= 1
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(int(ans))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
count = Counter(a)
b = sum(((v - 1) * v // 2 for v in count.values()))
for i in a:
	print(b + 1 - count[i])


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


import collections

def resolve():
	n = int(input())
	a = tuple(map(int, input().split()))
	A = collections.Counter(a)
	cnt_0 = 0
	for i in A.values():
		cnt_0 += int(i * (i - 1) / 2)
	for i in a:
		cnt_1 = A[i] - 1
		print(cnt_0 - cnt_1)
resolve()


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	n = i_input()
	a = i_list()
	k = [0]
	for i in range(2 * 10 ** 5):
		k.append(k[i] + (i + 1))
	t = a.copy()
	t.sort()
	s = 0
	m = [0] * n
	for (i, n) in itertools.groupby(t):
		l = len(list(n))
		s += k[l - 1]
		if l > 1:
			m[i - 1] = k[l - 2] - k[l - 1]
	for i in a:
		print(s + m[i - 1])

def __starting_point():
	main()
__starting_point()


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = Counter(A)
select_num = [0] * (10 ** 6 + 1)
for (num, cnt) in Counter(A).items():
	select_num[num] = cnt * (cnt - 1) // 2
sum_select = sum(select_num)
for a in A:
	print(sum_select - select_num[a] + (count[a] - 1) * (count[a] - 2) // 2)


from collections import Counter

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

def __starting_point():
	main()
__starting_point()