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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
C = [0]*N
D = [0]*N
for i in range(N):
    B[A[i]-1]+=1
for i in range(N):
    C[i] = int(B[i]*(B[i]-1)/2)
    D[i] = int((B[i]-1)*(B[i]-2)/2)
S = sum(C)
for i in A:
    print(S-C[i-1]+D[i-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_base = 0
for v in D.values():
    ans_base += v * (v - 1) // 2

for a in A:
    if D[a] > 1:
        print(ans_base - (D[a] * (D[a] - 1) // 2) + ((D[a] - 1) * (D[a] - 2) // 2))
    else:
        print(ans_base)

Solution (Python):
import copy
n=int(input())
a=list(map(int,input().split()))
ans=0
b=copy.copy(a)
a.sort()
cnt=1
num=[0]*n
for i in range(n-1):
	if a[i]==a[i+1]:
		cnt+=1
	else:
		num[a[i]-1]=cnt
		ans+=cnt*(cnt-1)//2
		cnt=1
ans+=cnt*(cnt-1)//2
num[a[-1]-1]+=cnt
for i in range(n):
	x=num[b[i]-1]
	if x<=1:
		print(ans)
	else:
		e=ans-x*(x-1)//2+(x-1)*(x-2)//2
		print(e)

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


def comb2(n):
    if n == 0:
        return 1
    else:
        return (n-1)*(n-2) // 2


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

count = [0] * N
Comb = 0
for a in A:
    count[a-1] += 1
for i,c in enumerate(count):
    Comb += comb(c)

for a in A:
    c = count[a-1]
    ans = Comb - comb(c) + comb2(c)
    print(ans)

Solution (Python):
from collections import Counter

N, *A = map(int, open(0).read().split())
ctr = Counter(A)
total = sum(v * (v - 1) // 2 for v in ctr.values())
for v in A:
    c = ctr[v]
    print(total - (c * (c - 1) // 2) + max(0, (c - 1) * (c - 2) // 2))

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    c = Counter(A)
    ans = []
    D = {}
    T = 0
    for k, v in c.items():
        D[k] = (((v-1) * (v-2)) // 2, ((v) * (v-1)) // 2)
        T += ((v) * (v-1)) // 2
    for a in A:
        ans.append(T-D[a][1] + D[a][0])
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print('\n'.join(map(str, slv(N, A))))


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
ans = 0
for k, v in c.items():
    if v > 1:
        ans += v * (v - 1) // 2

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

Solution (Python):
from sys import exit, setrecursionlimit
setrecursionlimit(10**6)

def array2D(row, col ,val=0):
    return [[val]*col for i in range(row)]


def comb2(x):
    if x>=2:
        return x*(x-1)//2
    else:
        return 0

n = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1

ans_t = 0
for i in d:
    ans_t += comb2(d[i])

for a in A:
    print(ans_t - comb2(d[a]) + comb2(d[a]-1))

Solution (Python):
"""
NTC here
"""
import sys
inp = sys.stdin.readline


def input(): return inp().strip()


flush = sys.stdout.flush





def iin(): return int(input())


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





def main():
    def fn(n):
        if n<0:return 0
        return (n*(n+1))//2
    n = iin()
    a = lin()
    dc = {}
    for i in a:
        try:
            dc[i]+=1
        except:
            dc[i] = 1
    sm = 0
    for i in dc:
        sm+= fn(dc[i]-1)
    for i in a:
        x = dc[i]
        ch = sm - fn(x-1) + fn(x-2)
        print(ch)

main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num = [0 for _ in range(n)]
c = [0 for _ in range(n)]
for i in a:
    num[i - 1] += 1

for i in range(n):
    if num[i] == 0:
        continue
    c[i] = num[i] * (num[i] - 1) // 2

ans = sum(c)

for i in a:
    tmp = (num[i - 1] - 2) * (num[i - 1] - 1) // 2 - num[i - 1] * (num[i - 1] - 1) // 2
    print(ans + tmp, )

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

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

for i in range(1,N+1):
    preans[i] = (data[i]*(data[i]-1))//2

s = sum(preans)

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
balls = {}
for a in A:
  if a in balls:
    balls[a]+=1
  else:
    balls[a] = 1
ans = 0
for a in balls:
  ans += balls[a]*(balls[a]-1)//2

for i in range(n):
  ball = A[i]
  count = balls[ball]
  print(ans - count*(count-1)//2 + (count-1)*(count-2)//2)

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class v:
    def __init__(self, f):
        self.f = f
        self.v = None
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    N = int(input())
    A = read_list()
    D = {}
    for a in A:
        D[a] = D.setdefault(a, 0) + 1
    
    S = sum(i * (i - 1) for i in D.values()) // 2
    for k in range(N):
        print(S - (D[A[k]] - 1))


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=[0]*(n+1)

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


for i in range(n):
    k=a[i]
    p=x[k]*(x[k]-1)//2
    q=(x[k]-1)*(x[k]-2)//2
    print(s-p+q)

Solution (Python):
from collections import Counter


def cmb(a):
    return a * (a - 1) // 2


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    s = sum([cmb(x) for x in c.values()])
    for i in a:
        print(s - c[i] + 1)


if __name__ == '__main__':
    resolve()

Solution (Python):
def inputs(): return [int(x) for x in input().split()]
from collections import defaultdict
n= int(input())
a = inputs()

ans = 0
l = defaultdict(list)
l1 = defaultdict(int)
for i in range(n):
    l1[a[i]]+=1
for i in l1.keys():
    ans+=(l1[i]*(l1[i]-1))//2
    if 1<l1[i]:
        l[i].append([(l1[i]*(l1[i]-1))//2,((l1[i]-2)*(l1[i]-1))//2])
    else:
        l[i].append([(l1[i]*(l1[i]-1))//2,0])
for i in a:
    
    f,s = l[i][0]
    print(ans-f+s)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count = [0] * 200005
for a in A:
    count[a] += 1

s = 0
for c in count:
    s += c * (c - 1) // 2

for a in A:
    c = count[a]
    x = c * (c - 1) // 2
    c -= 1
    y = c * (c - 1) // 2

    print(s - x + y)

Solution (Python):
def comb(n,r):
    if (n<r): return 0
    a,b=1,1
    r = min(r,n-r)
    for i in range(r):
        a = a*(n-i)
        b = b*(r-i)
    return a // b

from collections import Counter

n=int(input())
a=list(map(int,input().split()))
count_a = Counter(a)
ans = 0
for x,y in count_a.items():
    ans += comb(y,2)

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

Solution (Python):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
AC=Counter(A)
goukei=0
for i, e in AC.items():
    goukei+=(e*(e-1))//2
for a in A:
    p=AC[a]
    print(goukei - (p*(p-1))//2 + ((p-1)*(p-2))//2)

Solution (Python):


import sys
stdin = sys.stdin
from collections import Counter

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

def main():
    n = ni()
    a = na()
    c = Counter(a)
    s = 0
    for m in c.values():
        s += m*(m-1)//2
    for ai in a:
        print(s-(c[ai]-1))


if __name__ == "__main__":
    main()

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

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

s = sum([f(c) for c in C])
for i in range(N):
	a = A[i]
	c = C[a]
	print(s - f(c) + f(c - 1))

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

Solution (Python):
def main():

    N = int(input())
    A = list(map(int, input().split()))
    count = dict()
    for v in A:
        count[v] = count.get(v, 0) + 1
    tot = 0
    for v in count:
        tot += count[v] * (count[v] - 1) // 2

    for k in range(N):
        v = A[k]
        u = tot - count[v] * (count[v] -1) // 2
        u += (count[v]-1) * (count[v] - 2) // 2
        print(u)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def examA():
    N, M = LI()
    ans = N*(N-1)//2 + M*(M-1)//2
    print(ans)
    return

def examB():
    def judge(A):
        
        n = len(A)
        for i in range(n//2):
            if A[i]!=A[n-i-1]:
                return False
        return True
    S = SI()
    N = len(S)
    if not judge(S):
        print("No")
        return
    if judge(S[:(N-1)//2]) and judge(S[(N+1)//2:]):
        print("Yes")
    else:
        print("No")
    return

def examC():
    L = I()
    ans = (L/3)**3
    print(ans)
    return

def examD():
    N = I()
    A = LI()
    D = defaultdict(bool)
    C = Counter(A)
    M = 0
    for key,c in C.items():
        M += c*(c-1)//2
    
    
    ans = [0]*N
    for i in range(N):
        a = A[i]
        c = C[a]
        ans[i] = M -(c*(c-1)//2) + ((c-1)*(c-2)//2)
    for v in ans:
        print(v)
    return

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

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

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

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examD()

"""

"""

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


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

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

total = 0
for i in range(1,n+1):
    if b[i]>=2:
        total += combinations_count(b[i],2)

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

Solution (Python):
from collections import Counter

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

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

for i in range(N):
    print(s - max(0,C[A[i]]-1))

Solution (Python):
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    C = collections.Counter(A)

    ans = 0
    for v in C.keys():
        ans += C[v] * (C[v] - 1) // 2

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


if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9 +7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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 lcm(a, b):
    return a * b // gcd (a, b)





N = inputI()
l = inputIL()

count = [0]*(N+1)

for i in l:
  count[i] += 1

res = 0
for i in count:
  res += i*(i-1)//2

for i in l:
  print(res-(count[i]-1))

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    aDict = dict()
    for i, a in enumerate(A):
        if a in aDict: aDict[a] += 1
        else: aDict[a] = 1
    indivisual = dict()
    total = 0
    for key in aDict:
        n = aDict[key]
        total += n * (n - 1) // 2
        indivisual[key] = n * (n - 1) // 2
    for i, a in enumerate(A):
        ans = total - indivisual[a]
        n = aDict[a]
        ans += (n-1) * (n-2) // 2
        print(ans)


    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split(" ")]
ma = max(a)
b = [0 for i in range(ma)]
for i in a:
    b[i-1] += 1
c = [i*(i-1)//2 for i in b]
s = sum(c)
for i in a:
    if c[i-1] != 0:
        print(s-(b[i-1]-1))
    else:
        print(s)

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

ac = Counter(a)
al = 0
for k in ac:
    al+=ac[k]*(ac[k]-1)//2
for i in range(n):
    ack = ac[a[i]]
    al2 = al-ack*(ack-1)//2
    al2 += (ack-2)*(ack-1)//2
    print(al2)

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


main()

Solution (Python):
from collections import Counter

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

C = Counter(A)
tmp = 0
for key in C.keys():
    if C[key] >= 2:
        tmp += (C[key] * (C[key]-1))//2

for a in A:
    if C[a] <= 1:
        print(tmp)
    else:
        print(tmp - (C[a] * (C[a]-1))//2 + ((C[a]-1) * (C[a]-2))//2)

Solution (Python):
def main():
    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
    rt = 0
    for i in d:
        rt += (d[i] * (d[i]-1))//2
    for i in A:
        if d[i] == 1:
            print(rt)
        else:
            print(rt - ((d[i] * (d[i]-1))//2) + (((d[i]-1) * (d[i]-2))//2))
main()

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
com = {}
ans = 0
for k, v in c.items():
  ans += v*(v-1)//2 

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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()

    ex_comb =  defaultdict(int)
    all_comb = 0
    cnt = defaultdict(int)
    for a in A:
        cnt[a] += 1
    for a,c in cnt.items():
        val = c*(c-1)//2
        all_comb += val
        ex_comb[a] = val
    for a in A:
        whole = all_comb - ex_comb[a]
        whole += (cnt[a]-2)*(cnt[a]-1)//2
        print(whole)


if __name__ == '__main__':
    main()

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

for i in range(N):
  nums[A[i]]+=1
  
tmp=0
for i in range(1, N+1):
  tmp+=nums[i]*(nums[i]-1)//2
  
for i in range(N):
  print(tmp-max(0, nums[A[i]]-1))

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

lst = [0] *(N + 1)
for a in A:
    lst[a] += 1

ans = 0
for tmp in lst:
    ans += (tmp * (tmp - 1)) // 2


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

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

Solution (Python):
import collections

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

c = collections.Counter(a)

ans = 0

for x in c.values():
    ans += x * (x-1) // 2

for x in a:
    if c[x] == 1:
        print(ans)
    else:
        z = c[x]
        print(ans - z*(z-1)//2 + (z-1)*(z-2)//2)

Solution (Python):
from collections import Counter

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

cnt = Counter(As)
B = sum([k*(k-1)//2 for k in cnt.values()])


anss = []
for A in As:
    x = cnt[A]
    ans = B - x*(x-1)//2 + (x-1)*(x-2)//2
    anss.append(ans)

print('\n'.join(map(str, anss)))

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

mydict = {}

for num in nums:
    if not num in mydict:
        mydict[num] = 1
    else:
        mydict[num] += 1



all_sum = 0
for key, value in mydict.items():
    all_sum += value * (value - 1)// 2

for num in nums:
    print(all_sum - (mydict[num] - 1))

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

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

cnt = [0 for _ in range(n+1)]

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

ans = 0

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

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

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

count = [0] * (n+1)
for x in a:
    count[x] += 1

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

s = 0
for x in count:
    s += comb(x)

for x in a:
    print(s - comb(count[x]) + comb(count[x] - 1))

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

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

for a in A:
  n = D[a]
  print(S - n*(n-1)//2 +(n-1)*(n-2)//2)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
num=[0]*n
for i in a_list:
    num[i-1]+=1
c=0
for i in num:
    c+=i*(i-1)//2
for i in range(n):
    x=a_list[i]
    ans=c-num[x-1]+1
    print(ans)

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(N):
  if a[i] not in dic.keys():
    dic[a[i]]=1
  else:
    dic[a[i]]+=1
tmp=1
for v in dic.keys():
  cnt=dic[v]
  if cnt>=2:
    tmp+=(cnt*(cnt-1)//2)
for i in range(N):
  print(tmp-dic[a[i]])

Solution (Python):
def main():
    n = int(input())
    balls = list(map(int,input().split()))
    vals = {}
    for i in balls:
        if i not in vals.keys():
            vals[i] = 0

        vals[i] += 1

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

        
    for i in balls:
        val = vals[i]
        total -= val*(val-1)//2
        val -= 1
        val = max(val,0)
        total += val*(val-1)//2
        print(total)
        total -= val*(val-1)//2
        val += 1
        total += val*(val-1)//2


main()

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


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    k = min(k, n - k)
    ans = 1
    for i in range(1, k + 1):
        ans *= n - i + 1
        ans //= i
    return ans


d = defaultdict(int)
comb_list = [0] * n
for ai in a:
    d[ai] += 1

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

for i in range(n):
    ans_i = ans_sum - comb(d[a[i]], 2) + comb(d[a[i]] - 1, 2)
    print(ans_i)

Solution (Python):
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    from collections import Counter

    n = int(input())
    aa = list(map(int, input().split()))
    c = Counter(aa)

    all_sum = 0
    for value in c.values():
        all_sum += int(value*(value-1)/2)

    for a in aa:
        print(all_sum-c[a]+1)

Solution (Python):
from collections import Counter
def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    t = sum(v * (v - 1) // 2 for v in C.values())
    for a in A:
        print(t - (C[a] - 1))

main()

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B=[0]*n
for i in range(n):
    B[A[i]-1]+=1
C=[0]*n
D=[0]*n
for i in range(n):
    b=B[i]
    C[i]=b*(b-1)//2
    if b==0:
        D[i]=0
    else:
        D[i]=(b-1)*(b-2)//2
ans=sum(C)
for i in range(n):
    a=A[i]-1
    ans_=ans-C[a]+D[a]
    print(ans_)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

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

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

Solution (Python):
n=int(input())
lists=list(map(int,input().split()))
cnt=0
from collections import Counter
d=dict(Counter(lists))
for value in d.values():
    cnt+=value*(value-1)//2

for i in range(n):
    x=lists[i]
    ans=0
    ans+=cnt
    now=d[x]
    ans-=now*(now-1)//2
    ans+=(now-1)*(now-2)//2
    print(ans)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
cnt = [0]*n
for i in range(n):
    cnt[a[i]-1] += 1

tmp = [0]*n
for i in range(n):
    tmp[i] = (cnt[i]*(cnt[i]-1))//2
s = sum(tmp)
for i in range(n):
    print(s - cnt[a[i]-1]+1)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    count = {}
    for aa in a:
        if aa in count:
            count[aa] += 1
        else:
            count[aa] = 1
    balls = list(count.items())
    all = 0
    for b in balls:
        all += b[1] * (b[1] - 1) // 2
    for aa in a:
        print(all - count[aa] + 1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
counter = Counter(A)
total = sum(x*(x-1)//2 for x in counter.values())
for a in A:
    x = counter[a]
    temp = total
    temp -= x * (x-1) // 2
    if x > 2:
        temp += (x-1) * (x-2) // 2
    print(temp)

Solution (Python):
from collections import Counter
n,*a=map(int,open(0).read().split())
C=Counter(a)
s=sum(x*(x-1)//2 for x in C.values())
ans=[]
for x in a:
	c=C[x]
	t=s-c*(c-1)//2+(c-1)*(c-2)//2
	ans.append(t)
print(*ans,sep="\n")

Solution (Python):
from collections import Counter
def main():
    N = int( input())
    A = list( map( int, input().split()))
    C = Counter(A)
    ans = 0
    ANS = []
    for t in C:
        ans += C[t]*(C[t]-1)//2
    for a in A:
        if C[a] == 1:
            ANS.append(ans)
            continue
        ANS.append( ans - C[a]*(C[a]-1)//2 + (C[a]-1)*(C[a]-2)//2)
    print("\n".join( map( str, ANS)))
if __name__ == '__main__':
    main()

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

cnt = {}
for a in arr:
    if a not in cnt:
        cnt[a] = 1
    else:
        cnt[a] += 1

comb = {}

sums = 0
for key in cnt.keys():
    t1 = cnt[key]*(cnt[key]-1)
    t2 = (cnt[key]-2)*(cnt[key]-1)
    comb[key] = [t1//2,t1//2-t2//2]
    sums += t1//2

for i in range(n):
    print(sums-comb[arr[i]][1])

Solution (Python):
from collections import Counter
N = int(input())
Alist = list(map(int, input().split()))
Ac = Counter(Alist)
kaz_d = {}
for k, v in Ac.items():
    kaz_d[k] = (v * (v-1))//2
s = sum(kaz_d.values())
for a in Alist:
    v = Ac[a]
    print(s - ((v*(v-1)//2)) + (((v-1)*(v-2))//2))

Solution (Python):
from collections import Counter

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

C = Counter(A)

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

for i in range(N):
    d = C[A[i]]
    res = tmp - d * (d - 1) // 2 + (d - 1) * (d - 2) // 2
    print(res)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
table = [0] * (N + 1)
for i in range(N):
  table[a[i]] += 1

ttable = [0] * (N + 1)
for i in range(N + 1): ttable[i] = table[i] * (table[i] - 1) // 2
cs = [0] * (N + 2)
for i in range(N + 1): cs[i + 1] = cs[i] + ttable[i]



for x in a:
  t = cs[x] + (cs[-1] - cs[x + 1])
  print(t + (table[x] - 1) * (table[x] - 2) // 2)

Solution (Python):
from collections import defaultdict as dd

dic = dd(int)
N = int(input())
a = list(map(int,input().split()))
for i in range(N):
    dic[str(a[i])] += 1

res = 0

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

res2 = [0]*N
for i in range(N):
    tmp = dic[str(a[i])]
    print(res-(tmp-1))

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

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

    num = [0] * (N+1)
    for a in A:
        num[a] += 1
    S = 0
    for i in range(1, N+1):
        S += (num[i] * (num[i]-1)) // 2
    ans = [0] * (N+1)
    for i in range(1, N+1):
        if num[i]:
            ans[i] = S - (num[i] * (num[i]-1)) // 2 + ((num[i]-2) * (num[i]-1)) // 2
        else:
            ans[i] = S
    for i in range(N):
        print(ans[A[i]])


if __name__ == '__main__':
    main()