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.

Difficulty: interview

Starter code:

Solutions:
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n+1)
l2=[0]*(n+1)
for i in a:
    l[i]+=1

for i in range(1,n+1):
    l2[i]=l[i]*(l[i]-1)//2
sum_l=sum(l2)
for i in range(1,n+1):
    print((sum_l-(l[a[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()))
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)


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


""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return n*(n-1)//2
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく
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=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))


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

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

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)


import math
import sys
##### graph implementation with adjacancy list#####
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=[]):
        #print(v,end=" ")
        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)
        
#####sorting a dictionary by the values#####
def dict_sort(ans):
    ans=sorted(list(ans.items()),reverse=True,key=lambda kv:(kv[1]))
    
##### naive method for testing prime or not O(n^.5)#####
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

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

#####Primes till Nth O(n)#####
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

#####all the prime factors of a number#####
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

#####greatest common divisor of two numbers#####
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

#####least common multiplyer of two numbers#####
def lcm(a,b):
    return (a*b)//gcd(a,b)

#####function that return all the letters#####
def alphabates():
    return "abcdefghijklmnopqrstuvwxyz"

#####binary search O(logN)#####
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

#####quadratic roots#####
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
#####permutations#####
def permutation(n,r):
    if n<r:
        return 0
    ans=1
    for i in range(n-r+1,n+1):
        ans*=i
    return ans

#####combinations#####
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

#####sum till nth#####
def sumn(n):
    return (n*(n+1))//2
        
#####taking an array/list as input#####
def arrinp():
    ls=list(map(int,input().split()))
    return ls

#####taking multiple inputs#####
def mult_inp():
    return list(map(int,input().split()))

#####Main function starts from here#####
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()

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

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)

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)

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)

""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return math.floor(n*(n-1)/2)

# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく ここのindex=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())
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)

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

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)

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] += comb(flg[i]-1, 2) - comb(flg[i], 2)
#     s += comb(flg[i], 2)
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]))

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

# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 22:04:16 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]
d = [0]*N

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


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


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 = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
#print(d)
s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2
#print("s=",s)
for i in range(N):
    t = d[A[i]]
    #print("t=",t)
    print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)

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

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)

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)

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

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


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


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

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()))
di = {}

for a in A:
  if a not in di.keys(): # diに何もなかった場合
    #print("add")
    di[a] = 1
  else:
    #print("sum")
    di[a] += 1

# 全体量計算
sum = 0
for a, b in di.items():
  #print(a,b)
  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))

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())
aaa = list(map(int, input().split(' ')))
# 1,1,1,2,2, -> 3c2 + 2c2 = 4 + 1 = 4
# 1つ抜くときの数は一発で求まるので。。。
# 1c2=0
# 2c2=1
# 3c2=3
# 4c2=6
# 5c2=10
# 6c2=15
# 7c2=21
# hoge[i] = hoge[i-1] + (i-1)
hoge = [0,0]
for i in range(2, int(1e6)+1):
    hoge.append(hoge[i-1] + (i-1))


# 1,1,1,2,2, -> 3c2 + 2c2 = 4 + 1 = 4
d = {}
for a in aaa:
    d[a] = d.get(a, 0) + 1
total = sum([hoge[v] for v in list(d.values())])

# 1つ抜く
for i in range(1, n+1):
    ct = d[aaa[i-1]]
    print((total - (hoge[ct] - hoge[ct-1])))


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)

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)

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)

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)

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

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


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)


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

count = [0]*(N+1)

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

#print(count)

total = 0
for j in range(1,N+1):
  cj = count[j]*(count[j]-1)//2
  #print(cj)
  total = total + cj

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

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

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)


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)


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

cnt = Counter(As)

num = sum([v*(v-1)//2 for v in list(cnt.values())])
#print('# num:', num)

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


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


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

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


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)

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



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

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

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:
    #print(i,S[i])
    a=total-S[i]+1
    print(a)

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

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().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シグマk = n(n-1)/2 ......   

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


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

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

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))
# x * x-1 // 2


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

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

for a in A:
  if a not in di.keys(): # diに何もなかった場合
    #print("add")
    di[a] = 1
  else:
    #print("sum")
    di[a] += 1

# 全体量計算
sum = 0
for a, b in di.items():
  #print(a,b)
  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))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
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()  # ignore trailing spaces

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


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)

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

# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 22:04:16 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]
d = [0]*N

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

""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return n*(n-1)//2
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
con = [0] * (N+1)	#con[i] := iC2
for i in range(N+1):
  con[i] = choose2(i)
# 各数値の2通りの選択通り数を足していく
"""
for i in range(N + 1):
    sumWay += con(uni[i])
"""
#↑を書きかえてみた
for i in uni:
  sumWay += con[i]
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
    print((sumWay - con[uni[An[i]]] + con[uni[An[i]]-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)

from collections import *
from math import *
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
S = 0

for k,v in C.items():
  S+=comb(v,2)

for a in A:
  print(S-(comb(C[a],2)-comb(C[a]-1,2)))

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)

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

#--maincode----------------

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

# coding: utf-8
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()

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)

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

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





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)

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


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

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)

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

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)

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)