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()))
d = {}
for a in A:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
total = 0
for k in d.keys():
    total += (d[k] * (d[k]-1)) // 2

for i in range(N):
    v = total
    t = A[i]
    v -= ((d[t]) * (d[t]-1)) // 2
    v += ((d[t]-1) * (d[t]-2)) // 2
    print(v)

Solution (Python):
import sys
from collections import Counter

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

n, *a = map(int, sys.stdin.read().split())

def main():
    c = Counter(a)
    res = 0
    for v in c.values():
        res += comb(v)

    for i in a:
        yield res - comb(c[i]) + comb(c[i]-1)
        
if __name__ == "__main__":
    ans = main()
    print(*ans, sep='\n')

Solution (Python):
N = int(input())
L = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for i in L:
    C[i-1] += 1
res = 0

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

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

Solution (Python):
import collections


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

    counter = collections.Counter(A)
    ans = 0

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

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


resolve()

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



Ad = {}
for i in A:
  if not i in Ad:
    Ad[i]=0
  Ad[i] += 1

score_sum = sum([x*(x-1)/2 for x in list(Ad.values())])

for a in A:
    print(int(score_sum - (Ad[a] - 1)))

Solution (Python):

import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)

memo_e = {}
s = sum(v*(v-1)//2 for v in c.values() if v > 1)
for e in a:
    if not e in memo_e:
        
        if 1 < c[e]:
            memo_e[e] = s - (c[e]*(c[e]-1)//2 - (c[e]-1)*(c[e]-2)//2)
        else:
            memo_e[e] = s
    print(memo_e[e])

Solution (Python):
from math import factorial

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

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

nums = [0] * (N + 1)
for i, v in enumerate(A):
    nums[v] += 1
combs = list(map(lambda n: comb(n, 2), nums))
total = sum(combs)

for k, val in enumerate(A):
    print(total - (nums[val] - 1))

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

parent=dict()
An=set(A)
parecou=0
aaa=Counter(A)
for i in aaa.values():
    parecou+=int((i*(i-1)/2))
"""
for i in An:
    f=A.count(i)
    parent[i]=f
    parecou+=int((f*(f-1)/2))
"""



for i in range(N):
    anko=aaa[A[i]]
    print(parecou-int((anko*(anko-1)/2))+int(((anko-2)*(anko-1)/2)))

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cnt = [0] * (N + 1)
total = 0
for i in range(N):
    total += cnt[A[i]]
    cnt[A[i]] += 1
for i in range(N):
    ans = total - (cnt[A[i]] - 1)
    print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for value in A:
    C[value - 1] += 1
ways_all = 0
for i in range(N):
    ways_all += (C[i] * (C[i] - 1)) // 2
for value in A:
    print(ways_all - C[value - 1] + 1)

Solution (Python):
import numpy as np
import collections

n = int(input())
A = list(map(int, input().strip().split()))
C = collections.Counter(A)

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


for i in range(n):
    print(s - C[A[i]] + 1)

Solution (Python):
import numpy as np

n = int(input())

a = np.array(list(map(int, input().split())))
d = [0] * (n+1)
s = {}

for i in a:
  d[i] += 1
  
sum = 0
for k in d:
  if k>1:
    sum += (k*(k-1))//2

for i in range(n):
  nd = d[a[i]]
  ans = sum-(nd*(nd-1))//2
  nd -= 1
  if nd>1:
    ans += (nd*(nd-1))//2
  print(ans)

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

from collections import Counter
C=Counter(A)
ANS=0
for i in C.values():
    ANS+=i*(i-1)//2

for a in A:
    k=C[a]

    print(ANS-(k*(k-1)//2)+((k-1)*(k-2)//2))

Solution (Python):
import collections

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

cnt = collections.Counter(As)
sm = 0 


for k in cnt:
  sm += cnt[k]*(cnt[k]-1)//2
  
for i in range(N):
  print(sm -(cnt[As[i]]-1))

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

Solution (Python):
import sys
import itertools
from collections import Counter
sys.setrecursionlimit(10**8)
if __name__ == "__main__":
    N = int(input())
    A = input().split()
    counter = Counter(A)
    result = 0
    for c in counter.values():
        result += c*(c-1)//2
    for a in A:
        k = counter[a]
        print(result - k*(k-1)//2 + (k-1)*(k-2)//2)

Solution (Python):
import numpy as np

n = int(input())

a = np.array(list(map(int, input().split())))
d = [0] * (n+1)
s = {}

for i in a:
  d[i] += 1
  
sum = 0
for k in d:
  if k>1:
    sum += (k*(k-1))//2

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

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

from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_c = Counter(a)
    a_c_sum = 0
    for c in a_c:
        if a_c[c] >= 2:
            a_c_sum += cmb(a_c[c], 2)

    for ea in a:
        if a_c[ea] <= 1:
            sa = 0
        elif a_c[ea] == 2:
            sa = 1
        else:
            sa = cmb(a_c[ea], 2) - cmb(a_c[ea] - 1, 2)
        print(a_c_sum - sa)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
import collections as cs

def solve(N: int, A: "List[int]"):
    if len(set(A))==len(A):
        for i in range(N):
            print(0)
        exit()
    q=0
    p=cs.Counter(A)
    for o in p.values():
        q+=o*(o-1)//2
    for i in range(N):
        print(q-p[A[i]]+1)
    return



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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
from collections import defaultdict


def num_combinations(_n):
    return _n * (_n - 1) // 2


if __name__ == '__main__':
    n = int(input())
    xs = [int(s) for s in input().split()]
    freq = defaultdict(int)

    for n in xs:
        freq[n] += 1

    total = sum([num_combinations(n) for n in freq.values()])
    for x in xs:
        print(total - (freq[x] - 1))

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

n = int(input())
a = [[] for i in range(n)]

a = [int(i) for i in input().split()]
b = [0]*(n+1)

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

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

def ans(N):
    if N >= 2:
        return(cmb(N,2))
    else: return(0)

cnt=0
for j in b: cnt += ans(j)
for i in a:
    temp = cnt
    temp = temp - (ans(b[i])- ans(b[i]-1))
    print(temp)

Solution (Python):
import math
 
N = int(input())
A = list(map(int, input().split()))
ans = 0

dct = {}
for i in A:
  if not i in dct:
    dct[i]=0
  dct[i] += 1

anst=0
for (i,cnt) in dct.items():
  if cnt >= 2:
    anst += cnt * (cnt-1)/2

for i in A:
  print(int(anst-dct[i]+1))

Solution (Python):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([v*(v-1)/2 for v in count.values()])

    for i in range(len(A)):
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()

Solution (Python):
import collections
from collections import deque
import numpy as np

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

ca = collections.Counter(A)
cakeys = list(ca.keys())
cavalues = np.array(list(ca.values()))




cavaluesmax = cavalues*(cavalues-1)//2
valuesum = np.sum(cavaluesmax)



for a in A:
    
    v = ca[a]
    ans = valuesum - v + 1
    
    print(ans)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
D={}
x=0
for a in A:
	try:
		D[a]=D[a]+((D[a]*2)**0.5//1)+1
	except:
		D[a]=0

y=sum(D.values())
for i in range(len(A)):
	x=0
	z=((D[A[i]]*2)**0.5)//1
	x=y-z
	print(int(x))

Solution (Python):

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

    
    
    d = {i:0 for i in range(1,N+1)}
    d2 = {}
    d3 = {}
    
    


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

    
    sum = 0
    for i in range(1,N+1):
        d2[i] = int(d[i] * (d[i]-1) / 2)
        sum += d2[i]

    

    for i in range(1, N+1):
        if d[i] == 0: d3[i] = 0
        else: d3[i] = int((d[i]-1) * (d[i]-2) / 2)

    


    for i in A:
        print(sum - d2[i] + d3[i])

if __name__ == '__main__':
    main()

Solution (Python):



import math

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























aaa = dict()
for a in aa:
    if a not in aaa:
        aaa[a] = 1
    else:
        aaa[a] += 1

sum = 0
for k in aaa:
    sum += int(aaa[k] * (aaa[k] - 1) / 2)

for a in aa:
    print(sum - (aaa[a] - 1))

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

a = list(set(A))
a_c = {}
for v in A:
  if v in a_c:
    a_c[v] += 1
  else:
    a_c[v] = 1

def cmb(n):
  if n < 2: return 0
  else:
    return n * (n-1)//2

S = 0
for k in a_c:
  S += cmb(a_c[k])

for i in range(N):
  print(S - cmb(a_c[A[i]]) + cmb(a_c[A[i]]-1))

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

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

s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2

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

Solution (Python):

import sys
import collections as cs

def solve(N: int, A: "List[int]"):
    if len(set(A))==len(A):
        for i in range(N):
            print(0)
        exit()
    q=0
    p=cs.Counter(A)
    for o in p.values():
        q+=o*(o-1)//2
    for i in range(N):
        print(q-p[A[i]]+1)
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin,setrecursionlimit
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = [0]*(n+1)
for i in li:
    lin[i] += 1
liv = [0]*(n+1)
point = 0
for j,k in enumerate(lin):
    point += k*(k-1)//2
    liv[j] += k*(k-1)//2
for i in li:
    print(point-liv[i]+(lin[i]-1)*(lin[i]-2)//2)

Solution (Python):

import sys
import collections
import copy


def solve(N: int, A: "List[int]"):
    C = collections.Counter(A)
    S = sum([int(i * (i-1)) / 2 for i in C.values()])
    for k in range(len(A)):
        c = C[A[k]]
        print(int(S - (c * (c-1) / 2) + ((c-1) * (c-2) / 2)))
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
import math

N = int(input())
Al = list(map(int, input().split()))
d_di = {}

counter = Counter(Al)
As_l = list(set(Al))
for n in As_l:
    cnt = int(counter[n])
    if cnt > 1:
        d_di[n] = (math.factorial(cnt) // (2 * math.factorial(cnt - 2)))
    else:
        pass






total = sum(v for v in d_di.values())
for k in Al:
    ans = total - (counter[k]-1)
    if ans < 0:
        ans = 0
    else:
        pass
    print(ans)

Solution (Python):


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

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

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import collections
import math

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


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


ans = sum([comb(v, 2) for v in c.values()])
for ai in A:
    print(ans - c[ai] + 1)

Solution (Python):
import collections
def resolve():
    N = int(input())
    A = tuple(map(int, input().split()))
    C = collections.Counter(A)
    ans = 0
    for i in C.values():
        ans += i * (i-1) // 2

    for a in A:
        print(ans - (C[a] - 1))

if __name__ == '__main__':
    resolve()

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())
 
count = [0]*(N+1)
for i in range(N):
    id = A[i]
    count[id] = count[id]+1
 
sumN = long(0)
for i in range(N+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)
 
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)

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

ct = [0 for i in range(N)]
for i in range(N):
    A[i] -= 1
    ct[A[i]]+= 1

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

for i in range(N):
    print(allct - ct[A[i]] + 1)

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())
 
count = [0]*(N+2)
for i in range(N):
    id = A[i]
    count[id] = count[id]+1
 
sumN = long(0)
for i in range(N+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)
 
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
数え=[0]*N
for i in A:
  数え[i-1]+=1
前者=0
for i in 数え:
  前者+=i*(i-1)//2
for i in A:
  後者=数え[i-1]-1
  print(前者-後者)

Solution (Python):
import collections

N = int(input())
num_list = list(map(int,input().split()))
memo = [0]*(N+1)
memo_flg = [False]*(N+1)
counter = [0] * (N+1)
counter_ans = [0] * (N+1)

for i in num_list:
    counter[i] += 1
for i in range(N+1):
    counter_ans[i] = (counter[i]*(counter[i]-1))//2

all_sum = sum(counter_ans)
def calc(k):
    num = num_list[k]
    
    if(memo_flg[num] is True):
        return memo[num]
    ans = 0
    
    wrong = counter_ans[num]
    c = counter[num]-1
    right = (c*(c-1))//2
    
    ans = all_sum - wrong + right
    memo[num] = ans
    memo_flg[num] = True
    return ans

[print(calc(i)) for i in range(N)]

Solution (Python):
import collections
import math


n = int(input())
aa = list(map(int, input().split()))
ls = [0] * (n+1)

c = collections.Counter(aa)

for i, j in c.items():
    ls[i] = j*(j-1)//2

total = sum(ls)

for i in aa:
    before = (c[i]-1)*(c[i]-2) // 2
    print(total - ls[i] + before)

Solution (Python):
from collections import Counter

def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
C=Counter()
C.update(A)
ans=0
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
Most=C.most_common()

for i in range(len(C)):
    ans+=Comb(Most[i][1],2)
for i in range(N):
    pri=ans
    pri=ans-L[A[i]-1]+1
    print(pri)

Solution (Python):
import collections
import math

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


N=input()
a = list(map(int, input().split()))
c = collections.Counter(a)

ans = sum([comb(v, 2) for v in c.values()])
for ai in a:
    print(ans - c[ai] + 1)

Solution (Python):
from operator import mul
from functools import reduce
import collections
import sys
input = sys.stdin.readline
 
def combinations(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
 
N = int(input())
 
AList = list(map(int, input().split()))

NumberList = set(AList)
CountList = collections.Counter(AList)

result = 0
for i in NumberList:
    if CountList[i] >= 2:
        result += combinations(CountList[i], 2)


for i in AList:
    print(result - (CountList[i] - 1))

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

Solution (Python):
from collections import Counter

N = int(input())
l = list(map(int, input().split()))
set_l = set(l)

dictionary = Counter(l)
ll_dict = {}

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

for n in range(N):
  print(cnt-(dictionary[l[n]]-1))

Solution (Python):
import collections

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

u = collections.Counter(A)
sum = 0
for j, c in u.items():
    sum += int(c * (c - 1) / 2)

s = ""
for k in A:
    s += str(sum - u[k] + 1) + "\n"
print(s)

Solution (Python):
import collections

def solve(N, A):
    c_dict = collections.Counter(A)
    originals = [0 for i in range(N + 1)]
    minus = [0 for i in range(N + 1)]
    
    for (k, v) in c_dict.items():
        originals[k] = v * (v - 1) // 2
        minus[k] = ((v * (v - 1)) - (v - 1) * (v - 2)) // 2
        
    total = sum(originals)
    
    ans = []
    for a in A:
        ans.append(str(total - minus[a]))
    return '\n'.join(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

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

Solution (Python):

import math
import itertools
import statistics
import collections

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

l = collections.Counter(a)


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


s = ""
for i in range(n):
    s = l[a[i]]
    ans = total-s+1
    print(ans)

Solution (Python):
import sys
from collections import Counter


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


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

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


main()

Solution (Python):
from collections import Counter

def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
C=Counter()
C.update(A)
ans=0
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
Most=C.most_common()
for i in range(len(C)):
    ans+=Comb(Most[i][1],2)
for i in range(N):
    pri=ans
    pri=ans-Comb(L[A[i]-1],2)+Comb(L[A[i]-1]-1,2)
    print(pri)

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

Solution (Python):
import collections
import math


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


input()
a = list(map(int, input().split()))
c = collections.Counter(a)

summ = sum([comb(v, 2) for v in c.values()])
for ai in a:
    print(summ - c[ai] + 1)

Solution (Python):
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] 
res_list = {} 


A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return int(j * (j-1) / 2) if j >= 2 else 0


combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
cnt=[0 for _ in range(N+1)]
for i in range(N):
    cnt[A[i]]+=1
cmb=[cnt[k]*(cnt[k]-1)//2 for k in range(N+1)]
SUM=sum(cmb)
for j in range(N):
    n=A[j]
    v=cnt[A[j]]
    print(SUM-cmb[n]+(v-1)*(v-2)//2)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(lambda: 0)
for i in range(len(A)):
    d[A[i]] += 1
total = 0
for k,v in d.items():
    total += v*(v-1)//2
for a in A:
    print(total - (d[a]-1))

Solution (Python):

from scipy.misc import comb

def main():
     n = int(input())
     a = list(map(int, input().split()))
     num_a = dict()
     com_a = dict()

     for i in a:
          if not i in num_a.keys():
               num_a[i] = 1
          else:
               num_a[i] += 1

     for i in num_a.keys():
          value = num_a[i]
          com_a[i] = com(value)

     
     

     pre_ans = sum(com_a.values())
     

     for i in range(n):
          k = a[i]
          ans = pre_ans - com_a[k] + com(num_a[k] - 1)
          print(ans)

def com(n):
     return comb(n, 2, exact=True)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = [int(s) for s in input().split()]
B = [0 for i in range(N)]
def nC2(n):
  return n*(n-1)//2
for i in range(N):
  B[A[i]-1] += 1
Ctot = 0
for i in range(N):
  Ctot += nC2(B[i])
for i in range(N):
  current_idx = A[i]-1
  if B[current_idx] == 1:
    count = Ctot
  else:
    count = Ctot + nC2(B[current_idx]-1) - nC2(B[current_idx])
  print(count)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]



all = {}
for a in A:
  if a not in all:
    all[a] = 0
  all[a] +=1


total = 0
for key, v in all.items():
  total += int(v*(v-1)/2)

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

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
D={}
x=0
lis=[]
for a in A:
	try:
		D[a]=D[a]+((D[a]*2)**0.5//1)+1
	except:
		D[a]=0

z=sum(D.values())
for i in range(len(A)):
	x=0
	y=((D[A[i]]*2)**0.5)//1
	x=x+z-y
	print(int(x))

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

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

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
dp = [0]*n
for i in range(n):
    dp[A[i]-1] += 1
sub = 0
for i in range(n):
    if dp[i] != 0:
        sub += dp[i]*(dp[i]-1)//2
for i in range(n):
    ans = sub
    k = A[i]
    ans -= dp[k-1]*(dp[k-1]-1)//2
    if dp[k-1] == 1:
        print(ans)
    else:
        print(ans+(dp[k-1]-1)*(dp[k-1]-2)//2)

Solution (Python):
from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

for i in a_list:
    print(all_count - c[i] + 1)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7




n = I()
L = LI()
cnt = Counter(L)
ret = 0

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

for i in cnt.values():
    if i >= 2:
        ret += comb(i)

for l in L:
    if cnt[l] < 2:
        print(ret)
    else:
        print(ret - comb(cnt[l]) + comb(cnt[l] - 1))

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

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

for k in a:
    print(all_ans-((c[k]*(c[k]-1))//2)+(((c[k]-1)*(c[k]-2))//2))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A1=sorted(A)
cnt=[0 for _ in range(N+1)] 

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

cmb=[cnt[k]*(cnt[k]-1)//2 for k in range(N+1)]
SUM=sum(cmb)

for j in range(N):
    n=A[j]
    v=cnt[A[j]]
    print(SUM-cmb[n]+(v-1)*(v-2)//2)

Solution (Python):
def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  v = list(d.values())
  base = sum(list(map(func, v)))
  
  for k,v in d.items():
    if v<=1:
      e[k] = base - 0
    else:
      e[k] = base - ( v*(v-1)//2 - (v-1)*(v-2)//2 )
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()

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


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

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

Solution (Python):
from collections import Counter


from operator import mul
from functools import reduce


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


N = int(input())
A = list(map(int, input().split()))
c = [0]*(N+1)

for A_i in A:
    c[A_i] += 1

gsum = 0
for i in range(1, N + 1):
    if (c[i] != 0):
        gsum += cmbf(c[i], 2)

for i in A:
    print(gsum-(c[i]-1))

Solution (Python):

import collections

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

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

for k_ball in A:
    cnt = c[k_ball]
    print(total - (cnt * (cnt - 1) // 2) + ((cnt - 1) * (cnt - 2) // 2))

Solution (Python):
def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  v = list(d.values())
  base = sum(list(map(func, v)))
  
  for k,v in d.items():
    if v<=1:
      e[k] = base - 0
    else:
      e[k] = base - ( v*(v-1)//2 - (v-1)*(v-2)//2 )
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()

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

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

for a in a_list:
  print(result - c[a] + 1)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    s = 0
    for i,j in d.items():
        s += j*(j-1)>>1
    for i in a:
        j = d[i]
        print(s-(j*(j-1)>>1)+((j-1)*(j-2)>>1))
    return


if __name__ == "__main__":
    solve()