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):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = {}
for k in cnt.keys():
    ans[k] = (cnt[k] * (cnt[k]-1)) // 2
s = sum(list(ans.values()))
for ai in a:
    if cnt[ai] == 1:
        print(s)
    else:
        print(s - ans[ai] + int((ans[ai] / cnt[ai]) * (cnt[ai] - 2)))

Solution (Python):
import collections

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

  numerator = [n - r + k + 1 for k in range(r)]
  denominator = [k + 1 for k in range(r)]

  for p in range(2,r+1):
    pivot = denominator[p - 1]
    if pivot > 1:
      offset = (n - r) % p
      for k in range(p-1,r,p):
        numerator[k - offset] /= pivot
        denominator[k] /= pivot

  result = 1
  for k in range(r):
    if numerator[k] > 1:
      result *= int(numerator[k])
      

  return result

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

count = collections.Counter(a)

l1 = [0 for _ in range(n)]
l2 = [0 for _ in range(n)]

for i,v in count.items():
	if v != 1:
		l1[i-1] = cmb(v,2)
		l2[i-1] = cmb(v-1,2)

sum_l1 = sum(l1)

for i in range(n):
	
	print(l2[a[i]-1] + sum_l1 - l1[a[i]-1])

Solution (Python):
n=int(input())
inp=list(map(int,input().split()))
hoge=[0 for i in range(n)]
huga=[0 for i in range(n)]
for i in inp:
  huga[i-1]+=1
  hoge[i-1]=(huga[i-1]-1)*huga[i-1]
some=sum(hoge)//2
for i in inp:
  if(huga[i-1]==2):
    print(some-1)
  else:
    print(some-int(huga[i-1]-1))

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

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

Solution (Python):
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count.items():
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)

Solution (Python):
n = int(input())
a_list = list(map(str, input().split()))
nums = {}
for num in a_list:
    if num in nums:
        nums[num][0] += 1
    else:
        nums[num] = [1]
total = 0
for key, value in nums.items():
    subtotal = (value[0] * (value[0] - 1)) // 2
    value.append(subtotal)
    total += subtotal
for i in range(n):
    val = a_list[i]
    subtotal = ((nums[val][0]-1)*(nums[val][0]-2))//2
    res = total - nums[val][1] + subtotal
    print(res)

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split()))
A = sorted(a)
s = [0]*(n+1)
b = [0]*(n+1)
c = []
for i in range(1, n+1):
    x = a[i-1]
    s[i] = bisect.bisect_right(A, x) - bisect.bisect_left(A, x)
    if b[a[i-1]] == 0:
        c.append(s[i]*(s[i]-1)//2)
        b[a[i-1]] = 1
S = sum(c)

for i in range(1, n+1):
    print(S - s[i] + 1)

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

a_count=collections.Counter(a)

nctwo=[0,0,1]

def nc2(i):
    if(len(nctwo)>i):
        return nctwo[i]
    else:
        while(len(nctwo)<=i):
            nctwo.append(nctwo[-1] * len(nctwo) / (len(nctwo)-2))
        return nctwo[i]

allsum=0
for v in a_count.values():
    allsum+=nc2(v)

for i in range(n):
    ai_count=a_count[a[i]]
    print(int(allsum-(nc2(ai_count) - nc2(ai_count-1))))

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

import collections

numcount=collections.Counter(numlist)


sum = 0
for i in numcount.values():
    sum += int(i * (i - 1) / 2)

for i in numlist:
    print(sum - numcount[i] + 1)

Solution (Python):
import collections

n = int(input())
list1 = list(map(int,input().split()))
list2 = collections.Counter(list1)

kei1=0

for j in list2.values():
    kei1 += j * (j-1) // 2

for x in list1:
    print(kei1 - (list2[x] -1))

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

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

from collections import Counter
cnt_A = Counter(A)

All = 0
cnt = 0
for a in B:
    cnt = cnt_A[a]
    All +=  cnt*(cnt-1)//2

for k in range(N):
    ans_k = 0
    cnt = cnt_A[A[k]]
    ans_k = cnt - 1
    Ans = All - ans_k
    print(Ans)

Solution (Python):
from collections import Counter
import sys

def input():
    return sys.stdin.readline().strip()
def combi(num):
    return num * (num - 1) // 2
def main():
    N = int(input())
    A = list(map(int,input().split()))
    counterdic = Counter(A)
    ma = 0
    for value in counterdic.values():
        ma += combi(value)
    for i in A:
        print(ma-combi(counterdic[i])+combi(counterdic[i]-1))
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    from collections import Counter
    n = int(input())
    As = list(map(int,input().split(" ")))

    cnts = Counter(As)
    ns = [cnts.get(i,0)*(cnts.get(i,0)-1)/2 for i in range(1,n+1)]
    sumn = sum(ns)
    for i in As:
        k = cnts.get(i,0)
        ct = sumn - k*(k-1)/2 + (k-1)*(k-2)/2
        print(int(ct))
main()

Solution (Python):
n = raw_input()
a = map(int, raw_input().split(' '))
import collections
q = 0
cc = collections.Counter(a)
for k in cc:
	q += cc[k] * (cc[k]-1) /2


for e in a:
	print q - cc[e] * (cc[e]-1) /2 + (cc[e]-1)*(cc[e]-2)/2

Solution (Python):
n = raw_input()
a = map(int, raw_input().split(' '))
import collections
q = 0
cc = collections.Counter(a)
for k in cc:
	q += cc[k] * (cc[k]-1) /2


for e in a:
	q -= cc[e] * (cc[e]-1) /2
	cc[e]-=1 
	q += cc[e] * (cc[e]-1) /2
	print q
	q -= cc[e] * (cc[e]-1) /2
	cc[e]+=1 
	q += cc[e] * (cc[e]-1) /2

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
sum=0
list=[0]*N
list2=[0]*N

for a in A:
  list[a-1] +=1
  

for n in range(N):
  sum += list[n]*(list[n]-1)//2
  

for n in range(N):
  if list[n]>0:
  	list2[n]=sum-list[n]*(list[n]-1)//2+(list[n]-1)*(list[n]-2)//2
  
for a in A:
  print(list2[a-1])

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    arr = [int(x) for x in input().split()]
    freq = {}
    for elem in arr:
        if elem not in freq:
            freq[elem] = 0
        freq[elem] += 1
    total = 0
    for elem, f in freq.items():
        total += (f * (f - 1)) / 2
    for elem in arr:
        print(int(total - freq[elem] + 1))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
import math
def cmb(n,r):
    f = math.factorial
    return int(f(n) // f(r) // f(n-r))
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b
e={}
dd=0
for i,j in d.items():
    dd+=combination(j, 2)
    e[i]=combination(j-1, 1)

for i in a:
    print(dd-e[i])

Solution (Python):
def resolve():
    import collections

    N = int(input())
    A_list = [int(item) for item in input().split()]
    origin_dict = collections.Counter(A_list)

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

    for j in range(N):
        deff = origin_dict[A_list[j]] -1

        print(twopair_in_N - deff)
    

if __name__ == "__main__":
    resolve()

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

c=collections.Counter(a)
s=0
for i in c.values():
    s+=i*(i-1)//2

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

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

Solution (Python):
from collections import defaultdict


def main():
    d = defaultdict(int)
    nums = []
    _ = input()
    nums = list(map(int, input().split()))
    for n in nums:
        d[n] += 1
    
    total_combs = 0
    for k in d.keys():
        total_combs += int((d[k]*(d[k]-1))/2)
    
    for n in nums:
        print(total_combs - (d[n] - 1))
        
 
if __name__ == "__main__":
    main()

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):
from math import factorial


def c(n):
    if n < 2:
        return 0
    return factorial(n) // (factorial(n-2) * factorial(2))


def main():
    N = int(input())  
    a = list(map(int, input().split()))  
    for i in range(N):
        a[i] -= 1

    nums = [0 for _ in range(N)]

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

    b = [c(nums[i]) for i in range(N)]
    sum_b = sum(b)

    b_alt = [c(nums[i]-1) for i in range(N)]

    for i in range(N):
        print(sum_b - b[a[i]] + b_alt[a[i]])


if __name__ == '__main__':
    main()

Solution (Python):
def combi(n):
    if n > 1: return n*(n-1)//2
    else:return 0

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

sum = [0]*(max(A)+1)
for a in A:sum[a] += 1
total = 0
for s in sum:total += combi(s)
for a in A:
    print(total - combi(sum[a]) + combi(sum[a]-1))

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

data = [0]*(N+1)
for num in S:
    data[num] += 1

ans = 0
for num in data:
    if num < 2:
        continue
    ans += num*(num-1)//2

for num in S:
    if data[num] < 2:
        print(ans)
    else:
        print(ans-data[num]+1)

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

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        

max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)


for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Solution (Python):
import collections

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

Solution (Python):
n=int(input())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
c=[0 for i in range(n)]
r=0
count=0
for i in input().split():
  a[int(i)-1]+=1
  b[count]=int(i)
  count+=1
for i in range(n):
  m=a[b[i]-1]
  c[i]=2*m-2
for i in range(n):
  r+=a[i]*(a[i]-1)
for i in range(n):
  print((r-c[i])//2)

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

C = {}
for a in A:
    if not(a in C):
        C[a] = 0

    C[a] += 1

s = sum(c*(c-1)//2 for c in C.values())

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

Solution (Python):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
sum_A = 0
dict = defaultdict(int)
for i in A:
    dict[i] += 1

for v in dict.values():
    sum_A += v * (v - 1) // 2

for i in A:
    print(sum_A - (dict[i] - 1))

Solution (Python):
import collections as cl
import math


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


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

cnt = cl.Counter(A)
cnt_l = [0] * 200000
for a in A:
    cnt_l[a] += 1

ans = 0
for v in cnt_l:
    ans += combinations_count(v, 2)

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

Solution (Python):
import collections as cl
import math


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


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

cnt = cl.Counter(A)
ans = 0
for v in cnt.values():
    ans += combinations_count(v, 2)

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

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

A_count = collections.Counter(A)

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

for i in range(N):
    count = A_count[A[i]]
    ans = sum - count + 1
    print(ans)

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

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

import collections

D = collections.Counter(L)
sum=0
for i in D.values():
	sum+=i*(i-1)//2

for i in range(n):
	m = D[L[i]]
	ans = sum-(m-1)
	print(ans)

Solution (Python):
from collections import defaultdict

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

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

S = sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2])

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

Solution (Python):
def q4():
    import collections
    N = int(input())
    A = [int(i) for i in input().split()]

    def n_C_2(n):
        """ n個から2個選ぶ組み合わせ総数を計算 """
        ret = 0 if n < 2 else n * (n - 1) / 2
        return ret

    all_sum = 0  
    counter = collections.Counter(A)
    
    for v in counter.values():
        all_sum += n_C_2(v)

    for i in range(N):
        cnt = counter[A[i]]  
        ans = all_sum - n_C_2(cnt) + n_C_2(cnt - 1)
        print(int(ans))


if __name__ == '__main__':
    q4()

Solution (Python):
import math
from collections import Counter

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

def combinations_count(n, r):
    if n==1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c = Counter(Balls)
d={}
ALL_SUM=0
for i,j in c.most_common():
    d[i]=j
    ALL_SUM+=combinations_count(j,2)
for k in Balls:
    print(ALL_SUM-(d[k] - 1))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A_ball = [0 for i in range(N)]

for i in A:
    A_ball[i-1] += 1

max_pattern = 0
for ball in A_ball:
    max_pattern += ball * (ball - 1) /2

for num in A:
    print(int(max_pattern - (A_ball[num-1]-1)))

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

num_list = [0]* (len(a)+1)

for i in range(len(a)):

    num_list[a[i]] += 1

total = 0

for j in range(len(num_list)):
    total += (num_list[j]* (num_list[j]-1))/2



for k in range(len(a)):

    print(int(total-(num_list[a[k]])+1))
"""
import math

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

cnt = flaot(0.0)

for i in range(1, len(a)+1):
    b = a[0:i-1]+a[i:len(a)]
    
    cnt = 0.0
    for j in range (1, len(a)):
        cnt += b.count(j)*(b.count(j)-1)/2
    print(int(cnt))
"""

Solution (Python):
N=int(input())
m=list(map(int,input().split()))
t=[]
for i in range(N):
  t.append(0)
for i in range(N):
  t[m[i]-1]+=1
total=0
for i in range(N):
  total+=(t[i]*(t[i]-1))//2
for i in range(N):
  if t[m[i]-1]<2:
    print(total)
  else:
    print(total-(t[m[i]-1]-1))

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

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

from collections import Counter

count_dic = Counter(a)


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

for k in a:
    print(int(all_count - (count_dic[k] - 1)))

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

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

for i in range(n):
    try:
        l[d[a[i]]]+=1
    except:
        d[a[i]]=ind
        l.append(1)
        ind+=1

for i in range(len(l)):
    total+=comb(l[i])

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
count_list = [0]*(n+1)
comb_list = [0]*(n+1)
for i in range(len(a)):
  count_list[a[i]] += 1

for i in range(len(a)):
  comb_list[i+1] = count_list[i+1]*(count_list[i+1]-1)//2

wa = sum(comb_list)

for i in range(n):
  print(wa-(count_list[a[i]]-1))

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

Solution (Python):
def combi(x):
    return x * (x-1) //2

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



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



cnt = [0] * n

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



total = 0

for i in cnt:
    total += combi(i)

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

Solution (Python):
def combi(x):
    return x * (x-1) //2

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



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



cnt = [0] * n

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



total = 0

for i in cnt:
    total += combi(i)

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

Solution (Python):
from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
total = 0
for k, v in counter.items():
  x = ncr(v, 2)
  res[k] = (x, (x * (v-2) // (v)))
  total += x
for a in As:
  v1, v2 = res[a]
  print(total - v1 + v2)

Solution (Python):
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
A = Counter(L)
C = {0:0}

for i in range(1, max(A.values())+1):
    C[i] = C[i-1]+(i-1)
ans = 0
for a in A.keys():
    key = A[a]
    ans += C[key]

for l in L:
    key = A[l]-1
    tmp = ans - C[A[l]]
    print(tmp+C[key])

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

u = collections.Counter(a)

sume = 0
for i in u.values():
    sume += int(i*(i-1)/2)

for k in range(n):
    s = u[a[k]]
    print(sume-s+1)

Solution (Python):
import collections
import copy
N = int(input())
A = list(map(int,input().split()))
AA = collections.Counter(A)
ans = sum([i*(i-1)//2 for i in AA.values()])

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

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

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
s = sum(x * (x - 1) // 2 for x in counter.values())


print('\n'.join(str(s + 1 - counter[x]) for x in A))

Solution (Python):



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

    nums_dict = dict()
    for a in As:
        if a in nums_dict:
            nums_dict[a] += 1
        else:
            nums_dict[a] = 1

    combs = dict()
    total = 0
    for key, value in nums_dict.items():
        comb = (value * (value-1)) // 2
        combs[key] = comb
        total += comb

    for a in As:
        v = nums_dict[a]
        if v > 1:
            c = (v-1) * (v-2) // 2
            print(total - combs[a] + c)
        else:
            print(total)


if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    A = [int(_) for _ in input().split()]
    B = Counter(A)
    cc = 0
    for i in B.keys():
        cc += B[i] * (B[i]-1) // 2
    for a in A:
        print(cc + 1 - B[a])
    return

if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
Adic = [0]*N
for i in range(N):
    Adic[A[i]-1] += 1
counter = 0
for i in range(N):
    num = Adic[i]
    counter += num*(num-1)/2
    
for k in range(N):
    num = Adic[A[k]-1]
    plusminus = (num-1)*(num-2)/2-num*(num-1)/2
    print(int(counter+plusminus))

Solution (Python):
import math
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
m = len(set(a))
nans = 0
tbl = list(Counter(a).values())
tbl2 = Counter(a)
for i in range(m):
    if tbl[i] >= 2:
        nans += math.factorial(tbl[i])//(math.factorial(tbl[i]-2)*math.factorial(2))
for i in range(n):
    num = a[i]
    numcnt = tbl2[num]
    print(nans-(numcnt-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):
    t = d[A[i]]
    print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
import copy
from operator import mul
from functools import reduce

def cmb(n,r):
    if 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
    else:
        return 0


s = [0 for i in range(N)]
for i in range(N):
    s[A[i]-1] += 1
    
s1 = copy.copy(s)
for i in range(N):
    if s[i] == 0:
        s1[i] = 0
    else:
        s1[i] -= 1

amount = 0
for i in range(N):
    a = cmb(s[i],2)
    amount += a

for i in range(N):
    print(amount-s1[A[i]-1])

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

dic = dict(Counter(a_list))

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

for j in a_list:
    n = dic[j]
    if n == 1:
        print(ret)
    else:
        print(ret - (n * (n - 1) // 2) + ((n - 1) * (n - 2) // 2))

Solution (Python):
from collections import Counter

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

cnt = Counter(a)

cnt_items = list(cnt.items())

cnt_values = [i[1] for i in cnt_items]

sum = sum([j*(j-1)//2 for j in cnt_values])

for k in a:
    p = cnt[k]
    print(sum- p*(p-1)//2 + (p-1)*(p-2)//2)

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

if __name__ == "__main__":
    main()

Solution (Python):
class Combination:
    def __init__(self):
        self.fact = [0 for _ in range(100001)]
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,100001):
            self.fact[i] = self.fact[i-1] * i
            print(self.fact[i])

    def calc(self,n,k):
        return int(self.fact[n] / (self.fact[k] * self.fact[n-k]))

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
ans = 0

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A_num:
    if i < 2:
         continue
    else:
        ans += i * (i - 1) // 2

for i in A:
    x = A_num[i]
    ans_tmp = ans - (x * (x - 1) // 2 )
    if (A_num[i] - 1) < 2:
        print(int(ans_tmp))
        continue
    else:
        ans_tmp += ((x - 1) * (x - 2) // 2 )
        print(int(ans_tmp))
        continue

    print(int(ans))
    A_num[i] += 1

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

    q = Counter(a)
    a_cn = sum(x * (x - 1) // 2 for x in q.values())

    ans = []
    for x in a:
        ans.append(a_cn - q[x] + 1)

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


if __name__ == '__main__':
    main()

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

    ctr = Counter(a)
    frm_n = sum(x * (x - 1) // 2 for x in ctr.values())

    ans = []
    for x in a:
        ans.append(frm_n - ctr[x] + 1)

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from collections import Counter
    N = int(input())
    *a, = map(int, input().split())

    ctr = Counter(a)
    frm_n = sum(x * (x - 1) // 2 for x in ctr.values())

    ans = []
    for x in a:
        ans.append(frm_n - ctr[x] + 1)

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


if __name__ == '__main__':
    main()

Solution (Python):
import math
import collections

n = int(input())
a = list(map(int, input().split()))
num_list = []
ans_total = 0

c = collections.Counter(a)

for d in c:
    if not c[d] == 1:
        ans_total += int(math.factorial(c[d])/(2*math.factorial(c[d]-2)))

for i in range(n):
    print(ans_total-c[a[i]]+1)

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

d=collections.Counter(A)
e=0
f=list(d.values())

for i in range(len(f)):
  e+=(f[i]*(f[i]-1))/2

for j in range(N):
  if d[A[j]]==1:
    print(int(e))
  else:
    print(int(e-d[A[j]]+1))

Solution (Python):
from collections import Counter

def myAnswer(N:int,A:list)-> None:
   dic = Counter(A)
   total =0
   for value in dic.values():
      total += value * (value -1) //2
   for a in A:
      print(total - (dic[a]-1))


def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   myAnswer(N,A[:])
if __name__ == '__main__':
   main()

Solution (Python):
import collections
def myAnswer(N:int,A:list)-> None:
   dic = collections.Counter(A)
   total =0
   for value in dic.values():
      total += value * (value -1) //2
   for a in A:
      print(total - (dic[a]-1))


def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   myAnswer(N,A[:])
if __name__ == '__main__':
   main()

Solution (Python):
from collections import Counter

N = int(input())
lst = [int(x) for x in input().split()]
dic = dict(Counter(lst))

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


for x in lst:
    n = dic[x]
    if n == 1:
        print(ret)
    else:
        print(ret - (n * (n - 1) // 2) + ((n - 1) * (n - 2) // 2))

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int , input().split()))
bb = dict(Counter(A))
pattern_ = 0
for i in bb.values():
    pattern_ += ((i*(i-1))//2)
for j in A:
    print(pattern_ - ((bb[j]-1)))

Solution (Python):
from collections import Counter

n = int(input())
a = [int(x) for x in input().split()]
s = 0
c = Counter(a)

for i in c.values():
    s += i*(i-1)// 2
    

for j in range(n):
    t = c[a[j]]
    print(s-t+1)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ls=[0 for _ in range(N)]
for i in range(N):
  ls[A[i]-1]+=1
s=0
for i in range(len(ls)):
    m=ls[i]*(ls[i]-1)//2
    s+=m
for j in range(N):
  print(s-(ls[A[j]-1]-1))

Solution (Python):
n = int(input())
ai = list(map(int,input().split()))
dic = {}
su = 0
for a in ai:
    dic[a] = 0
for a in ai:
    dic[a] += 1
for i , x in enumerate(dic):
    su += dic[x]*(dic[x]-1)/2
for a in ai:
    print(int(su-dic[a]+1))

Solution (Python):


n = int(input())
a = input().split()

list_n = [0 for i in range(n)]
basic = 0

for i in a:
    aa = int(i)
    count = list_n[aa - 1]
    basic += count
    list_n[aa - 1] += 1

ans = 0
for i in range(n):
    ans = 0
    a1 = int(a[i])
    ans = basic - list_n[a1 - 1] + 1
    print("{}".format(int(ans)))

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


dic = {}
su = 0
m = 0
for a in An:
  dic[a] = 0
for a in An:
  dic[a] += 1 
for d,i in enumerate(dic):
  su += dic[i] * (dic[i]-1) / 2
for a in An:
  print(int(su - dic[a] + 1))

Solution (Python):

import sys
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, A: "List[int]"):
    c = Counter(A)
    each = [c[key]*(c[key]-1)//2 for key in c]
    
    
    tot = sum(each)

    for i in range(N):
        print(tot - (c[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):
N = int(input())
Alist = list(map(int,input().split()))
p = [0 for i in range(N)]
for i in range(len(Alist)):
    p[Alist[i]-1] = p[Alist[i]-1] + 1
q = 0
for i in range(len(p)):
    q = q + p[i]*(p[i]-1)/2
for i in range(N):
    print(int(q-p[Alist[i]-1]+1))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
point = 0
for j,k in dic.items():
    point += k*(k-1)//2

for i in a:
    j = point
    j -= dic[i]*(dic[i]-1)//2
    j += (dic[i]-1)*(dic[i]-2)//2
    print(j)

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

SUM=0
for l in L:
  SUM+=l*(l-1)//2
  
for a in A:
  l=L[a]
  print(SUM-l*(l-1)//2+(l-1)*(l-2)//2)

Solution (Python):
import collections
N = int(input())
A_list = list(map(int, input().split()))
A_collection=collections.Counter(A_list)
total=0
for i in A_collection.values():
    total+=i*(i-1)//2
for k in A_list:
    print(total-(A_collection[k]-1))

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

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