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


def C(n, r):
    if n < 2:
        return 0
    else:
        return n*(n-1)//r


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
dic = {}
total = 0
for key, value in c.items():
    C_val = C(value, 2)
    dic[key] = C_val
    total += C_val
for i in range(N):
    print(total - dic.get(A[i]) + C(c[A[i]]-1, 2))

Solution (Python):
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
input=lambda :sys.stdin.readline().rstrip()

N=int(input())
A=list(map(int,input().split()))
C=Counter(A)
num=sum([C[i]*(C[i]-1)//2 for i in C])
for a in A:
    c=num-C[a]*(C[a]-1)//2
    n=C[a]-1
    if n>=2:
        c+=n*(n-1)//2
    print(c)

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

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

import collections

dct=collections.Counter(lst)



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


for i in range(N):
    print(Sum-dct[lst[i]]+1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
import collections as col
 
num_list = set(A)
ca = col.Counter(A)

num = 0

for i in num_list:
    if ca[i] == 1:
        continue
    else:
        num += (ca[i]*(ca[i]-1))//2
        
for i in A:
    ans = num - (ca[i]-1)
    print(ans)

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

cont = {i : 0 for i in range(max(A) + 1)}
for a in A:
  cont[a] += 1


all_pair = 0
for key in cont:
  all_pair += (cont[key] * (cont[key] - 1)) // 2
  
for a in A:
  print(all_pair - (cont[a] - 1))

Solution (Python):



def main():
    from collections import Counter
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    b = Counter(a)
    diff = dict()
    total = 0

    
    for key, value in b.items():
        comb1 = value * (value - 1) // 2
        comb2 = (value - 1) * (value - 2) // 2
        total += comb1
        diff[key] = max(0, comb1 - comb2)

    ans = [0 for _ in range(n)]

    for index, ai in enumerate(a):
        ans[index] = total - diff[ai]

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


if __name__ == '__main__':
    main()

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

M = max(A) + 1
B = [0] * M
for a in A:
    B[a] += 1
l = [0] * M
for i in range(M):
    l[i] = B[i] * (B[i] - 1) // 2
ans = sum(l)
for a in A:
    if a == 0:
        print(ans)
    else:
        print(ans - l[a] + ((B[a] - 1) * (B[a] - 2) // 2))

Solution (Python):
import numpy as np

num = input()
num = int(num)

str = input()
list_in = list(map(int, str.split()))

count_arr = [0]*num

for item in list_in:
    count_arr[item-1] += 1

sum = 0
for i in range(num):
    tmp = count_arr[i-1]
    tmp = (tmp * (tmp -1))//2
    sum += tmp

for item in list_in:
    tmp = count_arr[item-1]
    result = sum - (tmp - 1)
    print(result)

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

A_keys = collections.Counter(A)
keys_list= A_keys.keys()

combi_sum = {}
for i in keys_list:
    cnt = A_keys[i]
    combi_sum[i] = cnt * (cnt-1)//2 

v_sum = sum(combi_sum.values())
for k in range(N):
    Ak = A[k]
    k_cnt = A_keys[Ak] - 1
    result = v_sum - combi_sum[Ak] + k_cnt*(k_cnt -1)//2
    print(int(result))

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
s=set(a)
d=len(s)
cc=Counter(a)
ans=0
for i in s:
    ans+=(cc[i]*(cc[i]-1))//2
for i in a:
    if cc[i]==1:
        print(ans)
    else:
        print(ans-(cc[i]-1))

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

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

cnt = 0
for i in X:
    cnt += i* (i-1) // 2

for i in A:
    ans = cnt - (X[i-1] - 1)
    print(ans)

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

import collections
c = collections.Counter(a)

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

Solution (Python):
import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
def cmb(n):
    if n == 1:
        return 0
    else:
        return n * (n-1) /2
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
s = 0
for i in mydict.values():
	s += cmb(i)
for i in range(N):
    a = A[i]
    x = mydict[a] - 1
    print(int(s-x))

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

ans_li = [0]*(n+10)

for i in li:
    ans_li[i] += 1
    
result = 0    
for i in ans_li:
    result += (i * (i-1)) // 2
    
for i in li:
    ans = result
    ans += ((ans_li[i] - 1) * (ans_li[i] - 2)) // 2- (ans_li[i] * (ans_li[i] - 1)) // 2
    print(ans)

Solution (Python):
import collections
n=int(input())
arr=list(map(int,input().split()))
cnt=collections.Counter(arr) 
total=0
for key in cnt.keys():
  total+=cnt[key]*(cnt[key]-1)//2 
for i in range(n): 
  print(total-cnt[arr[i]] + 1)

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

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

Solution (Python):
import numpy as np
import collections
n=int(input())
a=list(np.fromstring(input(),int,sep=' '))
dic=collections.Counter(a)
ans=0

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

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

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

Solution (Python):
from collections import Counter

n = int(input())
l = list(map(int, input().split()))
cl = Counter(l)


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

for i in l:
    v = cl[i]
    ans = cnt - (v * (v - 1) // 2) + (v - 1) * (v - 2) // 2
    print(ans)

Solution (Python):
from collections import Counter
N  = int(input())
A = list(map(int, input().split()))
C = Counter(A)
max_ans = sum( c * (c-1) // 2 for c in C.values() )

for i in range(N):
  print(max_ans - C[A[i]]+1)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    from collections import defaultdict
    dd = defaultdict(int)
    
    for i in range(N):
        dd[A[i]]+=1
        
    S=0
    for k,v in dd.items():
        S+=(v*(v-1))//2
        
    for i in range(N):
        v=dd[A[i]]
        ans=S-(v-1)
        print(ans)

main()

Solution (Python):
import collections

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

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

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

D={}
for i in A:
      if i not in D:
            D[i]=1
      else:
            D[i]+=1
S=0
DD=D.copy()
for i in DD:
      bu=DD[i]
      DD[i]=bu*(bu-1)//2
      S+=DD[i]

for i in range(n):
      print(S-(D[A[i]]-1))

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



count = [0] * (n + 1)


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


sum = 0
for i in a:
    count[i] += 1
for i in count:
    sum += f(i)

for i in a:
    print(sum - (count[i] - 1))

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

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

cnt=0
for i in X:
    cnt += (i * (i - 1)// 2)

for i in A:
    print(cnt - (X[i] - 1))

Solution (Python):
n  = int(input())
A = list(map(int,input().split()))
l = []
from collections import Counter
counter = Counter(A)
total = 0
def choose2(n):
    return n*(n-1)/2
for i in counter.most_common():
    c = choose2(i[1])
    total += c

for i in A:
    print(int(total-choose2(counter[i])+choose2(counter[i]-1)))

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):
N=int(input())
A=list(map(int,input().split()))
X=[0]*(N + 1)

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

cnt=0
for i in X:
    cnt += (i * (i - 1)// 2)

for i in A:
    print(cnt - (X[i] - 1))

Solution (Python):
def nPr(n, r):
  ans = 1
  for i in range(n,n-r,-1):
    ans *= i
  return ans

def nCr(n, r):
  tmp = 1
  for i in range(r,1,-1):
    tmp *= i
  return int(nPr(n, r) / tmp)

n = int(input())
a = list(map(int,input().split()))
count = len(a)
d = {}
x = 0

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

for i in d:
  x += nCr(d[i], 2)

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

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

num_list = [0]*(n+1)
for i in a:
    num_list[i] += 1

cnt = 0
for i in num_list:
    cnt += i*(i-1)/2

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

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


num_list = [0]*(N+1)
for i in A:
    num_list[i] += 1


total = 0
for j in num_list:
    total += j*(j-1)//2

for k in A:
    print(total+1-num_list[k])

Solution (Python):
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	n = int(input())
	al = list(IN())
	vv=defaultdict(lambda : 0)
	for v in al:
		vv[v]+=1
	
	dd=dict()
	total=0
	for key in vv:
		num=vv[key]
		use_all = num*(num-1)//2
		in_k = ((num-1)*(num-2))//2
		dd[key]=use_all - in_k
		total+=use_all
	
	for v in al:
		pp=total-dd[v]
		print(pp)
		
	
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
from collections import Counter

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

C = Counter(A)
a_sum = 0
for i in C.values():
    a_sum += i*(i-1)//2

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

Solution (Python):
import collections

n = int(input())
lis = list(map(int,input().split()))
 
clis = collections.Counter(lis)

count = 0
for kk in clis.values():
	count += (kk * (kk - 1)) // 2
    
for ll in lis:
	print(count - clis[ll] + 1)

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

def fac2(n):
    if n < 2:
        return 0
    ans = n * (n-1) // 2
    return ans

for key, val in c.items():
    d[key] = fac2(val)

d = {key:fac2(val) for key, val in c.items()}
sum_val = sum(d.values())
ans = [sum_val - d[a] + fac2(c[a]-1) for a in A]
print(*ans, sep="\n")

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

def fac2(n):
    if n < 2:
        return 0
    ans = n * (n-1) // 2
    return ans

d = {key:fac2(val) for key, val in c.items()}
sum_val = sum(d.values())
for a in A:
    ans = sum_val - d[a] + fac2(c[a]-1)
    print(ans)

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

freqs = {}
for ball in A:
	freqs[ball] = freqs.get(ball, 0) + 1
    
unbanned = 0
for v in freqs.values():
	unbanned += (v * (v - 1)) // 2
    
for ball in A:
	print(unbanned - freqs[ball] + 1)

Solution (Python):
import sys
myin = sys.stdin.readlines()

n = int(myin[0])
a = [int(x) for x in myin[1].split()]

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

Solution (Python):
import sys
myin = [x.rstrip() for x in sys.stdin.readlines()]

n = int(myin[0])
a = [int(x) for x in myin[1].split()]

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

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

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

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

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a_ = set(a)
x = Counter(a)
y = {i:x[i]*(x[i]-1)//2 for i in a_}

res = sum(y.values())
for i in a:
    t = x[i]
    t_ = y[i]
    print(res-t_+(t-1)*(t-2)//2)

Solution (Python):
from collections import Counter
 
N = int(input())
A = list(map(int, input().split()))
cntA = Counter(A)
 
S = 0
for c in cntA.values():
    S += c * (c - 1) // 2
 
ans = []
for a in A:
    ans.append(S - (cntA[a] - 1))
print(*ans, sep='\n')

Solution (Python):

from collections import Counter
import sys

input = sys.stdin.readline

def main():
    n = int(input().rstrip())
    l = list(input().rstrip().split())

    c = Counter(l)
    total = 0
    for key in c:
        total += c[key] * (c[key] -1) // 2
    for item in l:
        print(total - (c[item] -1))
    
if __name__ == '__main__':
    main()

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

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

from collections import defaultdict
dic=defaultdict(int)

for i in range(len(A)):
  dic[A[i]]+=1
  
all=0
for v in dic.values():
  all+=v*(v-1)//2
  
for i in range(len(A)):
  print(all-(dic[A[i]]-1))

Solution (Python):
import sys
import os
import collections

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    A = list(map(int, sys.stdin.buffer.readline().split()))

    obj = collections.Counter(A)

    p = 0
    for v in obj.values():
        if v > 1:
            p += v * (v - 1) // 2

    for a in A:
        print(p - (obj[a] - 1))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
myin = [x.rstrip() for x in sys.stdin.readlines()]

n = int(myin[0])
a = [int(x) for x in myin[1].split()]

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

Solution (Python):

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

items = {}
for a in As:
    items[a] = items[a]+1 if a in items.keys() else 1

sum_items = 0
for k in items.keys():
    if items[k] >= 2:
        sum_items += (items[k]*(items[k]-1))/2
sum_items = int(sum_items)
res = [0] * len(As)
for i,k in enumerate(As):
    res[i] = sum_items 
    if items[k] >= 2:
        res[i] -= (items[k]-1)

print(*res, sep="\n")

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

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

nums = {}
for a in A:
    nums[a] = nums[a] + 1 if a in nums else 1
res = 0
for key in nums.keys():
    res += nums[key]*(nums[key]-1)//2
for a in A:
    print( res-nums[a]+1 )

Solution (Python):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
lis = inpl()
counts = [0]*(N+10)
for i in lis:
    counts[i] += 1

S = 0
for i in lis:
    S += counts[i] - 1

S //= 2

for i in lis:
    print(S - counts[i] + 1)

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
tmp = 0
for x, y in a.items():
    if y != 0:
        tmp += y*(y-1)//2
ans = {}
for x, y in a.items():
    if y > 1:
        ans[x] = tmp-(y-1)
    else:
        ans[x] = tmp
for x in A:
    print(ans[x])

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

b = Counter(a)
sumnum=0
for j in b.keys(): 
    sumnum += (b[j] * (b[j]-1)) / 2

for i in range(N):
    print(int(sumnum - (b[a[i]]-1)))

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

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

counts = Counter(A)
total = 0
for n, count in counts.items(): 
    
    combi = choose2(count)
    total += combi 

for i in A:
    
    temp = total - choose2(counts[i])
    temp += choose2(counts[i] - 1) 
    print(temp)

Solution (Python):
import collections

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

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

counter = collections.Counter(A)

ttl = 0
for key in counter:
  ttl += choose2(counter[key])
    
for i in range(N):
  ans = ttl - choose2(counter[A[i]]) + choose2(counter[A[i]] - 1)
  print(ans)

Solution (Python):
from collections import Counter
import math

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

ctr = Counter(aa)

cmb2 = [0] * 200001
for n in range(2, 200001):
    r = 2
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

x = 0
for k, v in ctr.items():
    x += cmb2[v]

for a in aa:
    k = ctr[a] - 1
    print(x - k)

Solution (Python):
import collections

N = int(input())
A = input().split()




A_dic = collections.Counter(A)


all_count = 0

for a in A_dic.keys():
    count_a = A_dic.get(a)
    all_count += (count_a * (count_a - 1) // 2)




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

Solution (Python):
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
for i in balls:
    conbi[i-1] +=1
result = 0
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in balls:
    print(result-conbi[k-1]+1, end=" ")

Solution (Python):


from collections import Counter
N=int(input())
A=list(map(int,input().split()))
d=dict(Counter(A))
sum=0
s=[]
s.append(0)
for i in range(1,2*10**5+1):
    s.append(s[i-1]+i-1)
for value in d.values():
    sum+=s[value]
for x in A:
    print(sum-(d[x]-1))

Solution (Python):

from collections import Counter



n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
S = 0
"""
for key in C:
    S += comb(C[key], 2, exact=True)
"""
for i in C.keys():
    S += C[i]*(C[i]-1)//2

for k in range(n):
    A = a[k]
    print(S - C[A] + 1)

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

A = Counter(a)

total = sum([A[i] * (A[i] - 1) //2 for i in A.keys()])

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

Solution (Python):
import collections

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

C = collections.Counter(a)
total = 0
for i in C.keys():
    total += C[i] * (C[i] - 1) // 2
for i in range(n):
    A = a[i]
    print(total - C[A] + 1)

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

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 v in cnt.values():
    ans += v*(v-1)//2
    
for Ai in A:
    ans_i = ans
    ans_i -= cnt[Ai]*(cnt[Ai]-1)//2
    ans_i += (cnt[Ai]-1)*(cnt[Ai]-2)//2
    
    print(ans_i)

Solution (Python):
from collections import Counter

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

A_C=Counter(A)

for name,x in A_C.items():
    Com+=int(x*(x-1)/2)
    
for i in range(N):
    y=A_C[A[i]]
    print(Com-y+1)

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

import collections 
c=collections.Counter(A)
sum=0
for i in c:
  sum+=c[i]*(c[i]-1)//2  
for a in A:
  print(sum - c[a]*(c[a]-1)//2 + (c[a]-1)*(c[a]-2)//2)

Solution (Python):

from collections import Counter



n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
S = 0
"""
for key in C:
    S += comb(C[key], 2, exact=True)
"""
for i in C.keys():
    S += C[i]*(C[i]-1)//2

for k in range(n):
    A = a[k]
    print(S - C[A] + 1)

Solution (Python):

from collections import Counter
from scipy.misc import comb


n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
S = 0
for key in C:
    S += comb(C[key], 2, exact=True)

for k in range(n):
    A = a[k]
    print(S - C[A] + 1)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
import collections
C = collections.Counter(a)
S = 0
for i in C.keys():
    S += C[i]*(C[i]-1)//2

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

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

counter=defaultdict(int)

for a in a_list:
    counter[a]+=1

ans=0
prob=defaultdict(int)
for k,v in counter.items():
    p=v*(v-1)//2
    ans+=p
    if v>1:
        p2=(v-1)*(v-2)//2
        prob[k]=p2-p

for a in a_list:
    print(ans+prob[a])

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

    counter = Counter(A)
    
    res = 0
    for i in range(N+1):
        res += counter[i] * (counter[i] - 1) / 2
    
    for i in range(N):
        val = counter[A[i]]
        before = val * (val-1)/2
        after = (val - 1) * (val - 2) / 2
        print(int(res + after - before))

if __name__ == '__main__':
    solve()

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

    counter = defaultdict(int)

    for i in range(N):
        counter[A[i]] += 1
    
    res = 0
    for i in range(N+1):
        res += counter[i] * (counter[i] - 1) / 2
    
    for i in range(N):
        val = counter[A[i]]
        before = val * (val-1)/2
        after = (val - 1) * (val - 2) / 2
        print(int(res + after - before))

if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter

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

S = Counter(listA)


key = S.keys()
out = 0
for i in key:
  out = out + S[i] * (S[i]-1) /2

for i in listA:
  test = out - S[i] * (S[i]-1) /2 + (S[i] -1) * (S[i]-2) /2
  print(int(test))

Solution (Python):
import collections

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

A_counter= collections.Counter(A)

_sum = 0
for count in A_counter:
    _sum += (A_counter[count]* (A_counter[count]-1)) // 2

for k in range(N):
    l = (A_counter[A[k]]) *  (A_counter[A[k]]-1)//2
    m = (A_counter[A[k]]-1) *  (A_counter[A[k]]-2)//2
    
    
    print(_sum -l + m)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'

    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase

input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

N=2*10**5+10

n=I()
a=LI()
m=[0]*N
ans=0
for i in a:
    m[i]+=1
for i in m:
    ans+=i*(i-1)//2

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

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


d = {}
for i in range(n):
	d[a[i]] = d.get(a[i], 0) + 1



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


for i in range(n):
	print(cnt - d.get(a[i]) + 1)

Solution (Python):
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
list_M = [0 for _ in range(n+1)]

for s in list_A:
    list_M[s] += 1
total = 0

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

for s in list_A:
    ans = total - list_M[s] + 1
    print(ans)

Solution (Python):
def nc2(n):
	return (n*(n-1))//2
n=int(input())
l=list(map(int,input().split()))
cnt=[0]*(n+1)
for i in l:
	cnt[i]+=1
ans=0
for i in range(1,n+1):
	ans+=nc2(cnt[i])

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

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

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

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

def group_by_val(list_):
    res = dict()
    for v in list_:
        if v not in res:
            res[v] = [v]
            continue
        res[v].append(v)
    return res

def count_leng(dict_):
    res = dict()
    for k in dict_:
        res[k] = len(dict_[k])
    return res

def comb2(list_):
    leng = len(list_)
    if leng == 1:
        return 0
    return (leng*(leng-1)) // 2

grouped_dict = group_by_val(A)
group_leng = count_leng(grouped_dict)

sum_val = 0
for k in grouped_dict:
    sum_val += comb2(grouped_dict[k])

for a in A:
    print(sum_val-(group_leng[a]-1))

Solution (Python):
from itertools import groupby
import copy

def equalfind(A):
    A.sort()
    s=1
    count=0
    if len(A)==1:
        return count
    else:
        for i in range(0,len(A)-1):
            if A[i]==A[i+1]:
                s+=1
            else:
                count+=s*(s-1)//2
                s=1
        return count+s*(s-1)//2


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

B=copy.copy(A)
s=equalfind(B)
data=groupby(B)
ans=[0 for i in range(0,N+1)]
for key,group in data:
    g=len(list(group))
    ans[key]=g

for i in range(0,N):
    minus=ans[A[i]]-1
    print(s-minus)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
 
import collections
count_dic = collections.Counter(a_list)
 
count_dic_new = {}
for key, value in count_dic.items():
    if value == 1:
        count_dic_new[key] = 0
    elif value == 2:
        count_dic_new[key] = 1
    else: 
        count_dic_new[key] = (value * (value - 1)) // 2
fund_values = sum(list(count_dic_new.values()))
 
for a in a_list:
    if count_dic[a] == 1:
        a_value = fund_values
    elif count_dic[a] == 2:
        a_value = fund_values - 1
    else:
        n = count_dic[a]
        a_value = fund_values + (((n-1) * (n-2)) // 2) - (((n) * (n-1)) // 2) 
 
    print(a_value)

Solution (Python):
from collections import Counter
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
CA = Counter(A)
d = dict()
for k, v in CA.items():
    d[k] = v*(v-1)/2
ans = sum(d.values())
for i in range(N):
    v, a = CA[A[i]], A[i]
    print(int(ans - d[a] + (v-1)*(v-2)/2))