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(' ')))
B=[]
i = 0
while i < n:
    B.append((A[i],i))
    i += 1
B.sort()
klist = [0]*n
total = 0;count = 1;value = B[0][0];k_temp = [B[0][1]]
i = 1
while i < n:
    if value == B[i][0]:
        count += 1
        k_temp.append(B[i][1])
    else:
        t = count*(count-1)//2
        if t != 0:
            total += t
            diff = t - (count-1)*(count-2)//2
            for p in k_temp:
                klist[p] = -1*diff
        count = 1
        k_temp = [B[i][1]]
        value = B[i][0]
    i += 1
if count != 1:
    t = count*(count-1)//2
    total += t
    diff = t - (count-1)*(count-2)//2
    for p in k_temp:
        klist[p] = -1*diff
for k in klist:
    print(k+total)

Solution (Python):
import numpy as np

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

counter = np.bincount(A)

total = (counter * (counter - 1)).sum() // 2
diff = counter -1
ans = total - diff[A]

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

Solution (Python):
import numpy as np

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

counter = np.bincount(A)

total = (counter * (counter - 1)).sum() // 2
diff = (counter * (counter-1)//2 - (counter-1) * (counter-2)//2)
ans = total - diff[A]

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

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

Solution (Python):
from itertools import combinations
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
ans=0
for i in range(N):
    B[A[i]]+=1
for i in range(1,N+1):
    ans+=B[i]*(B[i]-1)//2
for k in range(0,N):
    print(ans-B[A[k]]+1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
import numpy as np
num_list = np.zeros(N+1)
for A_ in A:
    num_list[A_] += 1

all_pattern = 0
for number_ in num_list:
    all_pattern += number_ * (number_ - 1) / 2

for A_ in A:
    print(int(all_pattern - (num_list[A_] - 1)))

Solution (Python):
import numpy as np

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

counter = np.bincount(A)
 
total = (counter * (counter - 1)).sum() // 2
answer = (total - (counter - 1))[A]
 
print('\n'.join(answer.astype(str)))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N = int(readline())
A = np.array(read().split(), np.int64)
counter = np.bincount(A)
 
total = (counter * (counter - 1)).sum() // 2
answer = (total - (counter - 1))[A]
 
print('\n'.join(answer.astype(str)))

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

A_e = list(set(A))

x = Counter(A)

for i in A_e:
    if x[i] >= 2:
        xc2 = x[i]*(x[i]-1)/2
        X = X + xc2

for k in A:
    print(int(X-x[k]+1))

Solution (Python):
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)


args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])



def main():
    N = input(int)
    A = input([int, N])

    count = dd(int)
    for a in A:
        count[a] += 1
    sum_ = 0
    for k, v in count.items():
        sum_ += (v * (v - 1)) // 2
    for a in A:
        print(sum_ - count[a] + 1)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Solution (Python):
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)


args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])



def main():
    N = input(int)
    A = input([int, N])

    count = dd(int)
    for a in A:
        count[a] += 1
    sum_ = 0
    for k, v in count.items():
        sum_ += (v * (v - 1)) // 2
    for a in A:
        print(sum_ - count[a] + 1)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

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

Solution (Python):
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


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


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        if col[key] < 2:
            com[key] = 0
        else:
            com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = com[v] - c
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict

def r(i) :
  if i < 2:
    return 1
  else :
    return i*(i-1)/2

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

total = 0
c = defaultdict(int)
for j in range(a):
  c[b[j]] += 1
for key in c.keys():
  if c[key] > 1:
    total += r(c[key])

for j in range(a):
  print(int(total - c[b[j]]+1))

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

c = collections.Counter(a)

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

for i in a:
    print(s-(c[i]-1))

Solution (Python):
from collections import Counter
def main():
    n = int(input())
    a = list(map(int,input().split()))
    full = [0 for i in range(n+1)]
    one = [0 for i in range(n+1)]


    c = Counter(a)
    for i in range(1,n+1):
        if 1 <= c[i]:
            full[i] = c[i]*(c[i]-1)//2
        if 2 <= c[i]:
            one[i] = (c[i]-1)*(c[i]-2)//2
    sum_full = sum(full)

    for i in range(len(a)):
        print(sum_full - full[a[i]]+one[a[i]])

    return

if __name__ == "__main__":
    main()

Solution (Python):

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

S = [0] * (N+1)

for i in range(N):
    S[A[i]] += 1
    ans_ = 0
for i in range(1,N+1):
    s = S[i]
    ans_ += s*(s-1)//2
for i in range(N):
    ans = copy.copy(ans_)
    a = S[A[i]]
    if a > 1:
        ans -= a*(a-1)//2
        ans += (a-1)*(a-2)//2
    print(ans)

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

d={}
sum=0
for i in range(n):
  if l[i] not in d:
    d[l[i]]=1
  else:
    d[l[i]]+=1
   
l1=[]
for i in d:
  if d[i]>1:
    l.append((d[i]*(d[i]-1))//2)
    sum+=((d[i]*(d[i]-1))//2)


for i in range(n):
  if d[l[i]]==2:
    print(sum-1)
  elif d[l[i]]>2:
    we=((d[l[i]]*(d[l[i]]-1))//2-((d[l[i]]-1)*(d[l[i]]-2))//2)
    print(sum-we)
  else:
    print(sum)

Solution (Python):


import sys



from collections import defaultdict          















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    d = defaultdict(int)
    for num in a:
        d[num] += 1
    total = 0
    for _, v in d.items():
        total += v * (v-1) // 2
    for num in a:
        print(total - (d[num] - 1))

if __name__ == "__main__":
    main()

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

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


dic={}
for a in al:
    dic[a]=dic.get(a,0)+1
total=0
for v in dic.values():
    total+=v*(v-1)//2

for k in range(n):
    res=total-(dic[al[k]]-1)
    print(res)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

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


def main():
	N = int(input())
	A = getlist()
	D = defaultdict(int)
	for i in range(N):
		D[A[i]] += 1

	ans_pre = 0
	for i in D:
		var = D[i]
		ans_pre += int(var * (var - 1) // 2)

	for i in range(N):
		ans = ans_pre - D[A[i]] + 1
		print(ans)


if __name__ == '__main__':
	main()

Solution (Python):
from collections import Counter
n=int(input())
ar=list(map(int,input().split()))
x=Counter(ar)
dct={}
y=list(set(ar))
pair=0

for i in y:
    ct=x[i]-1
    pair+=(ct*(ct+1))//2

for i in range(n):
    el=ar[i]
    ct=x[el]-1
    add=((ct*(ct+1))//2)-(((ct-1)*((ct-1)+1))//2)
    
    print(pair-add)

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

Solution (Python):
import collections

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


C = collections.Counter(A)

s_all = 0
for c in C:
    s_all += C[c] * (C[c] - 1) // 2

for a in A:
    s = 0
    s += s_all - (C[a] - 1)
    print(s)

Solution (Python):
N = int(input())
K = list(map(int, input().split()))
C = [0]*(N+1)
for k in K:
    C[k] += 1
Sc = 0
for c in C:
    Sc += c*(c-1)//2
for k in K:
    print(Sc-(C[k]-1))

Solution (Python):
from collections import Counter

N = int(input())
*A, = map(int, input().split())
C = Counter(A)
S = 0
for v in C.values():
    S += v*(v-1)//2

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

Solution (Python):
from sys import stdin
import numpy as np
N = list(map(int, (stdin.readline().strip().split())))[0]
M = list(map(int, (stdin.readline().strip().split())))
num_list=np.array([0]*(2*10**5+1))
ans=0
for i in M:
    num_list[i-1]+=1
ans=sum(num_list*(num_list-1))//2
for k in range(N):
    num=num_list[M[k]-1]-1
    print(ans-num)

Solution (Python):
N = int(input())
K = list(map(int, input().split()))
C = [0]*(N+1)
for k in K:
    C[k] += 1
Sc = 0
for c in C:
    Sc += c*(c-1)//2
for k in K:
    print(Sc-(C[k]-1))

Solution (Python):
from collections import Counter

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

sum = 0
c = Counter(A)
for i in c.values():
    sum += i * (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)
D=dict()
sum_D =0
for key,val in C.items():
    r = val*(val-1)//2
    D[key] =r
    sum_D+=r

for a in A:
    cnt = C[a]
    gain= (cnt-1)*(cnt-2)//2
    less = D[a]
    print(sum_D - less + gain)

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

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

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():
    num = [0]*(((10**5) * 2) + 1)
    c_num = [0]*(((10**5) * 2) + 1)

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

    for i in range(0,len(num)):
        if num[i] >= 2:
            c_num[i] = cmb(num[i],2)

    c_sum = sum(c_num)
    

    for i in range(N):

        if num[A[i]] >= 2:
            
            Def = cmb(num[A[i]],2)
            tmp = 0

            if num[A[i]]-1 >= 2:
                tmp = cmb(num[A[i]]-1,2)

            
            print(c_sum-(Def-tmp))

        else:
            print(c_sum)
            


    

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
ans = 0

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

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

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

Solution (Python):
N = int(input())
A = []
counter = {}
for ele in input().split():
    ele = int(ele)
    if not ele in counter:
        counter[ele] = 1
    else:
        counter[ele] += 1
    A.append(ele)

variation_count = {}
base_sum = 0
for key in counter.keys():
    count = counter[key]
    variation_count[key] = count*(count-1)//2
    base_sum += count*(count-1)//2

for k in range(N):
    tmp = base_sum
    count = counter[A[k]] - 1
    tmp = tmp - variation_count[A[k]] + count*(count-1)//2
    print(tmp)

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

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

B_sum = 0
for i in B:
    B_sum += i * (i-1) //2

for i in range(N):
    print(B_sum-B[A[i]-1]+1)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num = [0] * n
cnt = 0

for i in a:
    num[i - 1] += 1

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num = [0] * n
cnt = 0

for i in a:
    num[i - 1] += 1

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num = [0] * n
cnt = 0

for i in a:
    num[i - 1] += 1

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

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

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

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

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

ans = 0
for i in num_A:
    ans += 0.5 * (i - 1) * i
        
for i in range(N):
    print(int(ans - (num_A[A[i]-1] - 1)))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
ans = 0

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

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

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

Solution (Python):
from collections import Counter

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


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

c = Counter(A_i)


total = sum(list(map(Get_nC2, c.values())))

for a_i in A_i:
    result =  total - Get_nC2(c[a_i]) + Get_nC2(c[a_i]-1)
    print(result)

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

count =[0 for i in range(N)]
for i in range(N):
    count[A_n[i]-1] +=1
ans =[count[i]*(count[i]-1)//2 for i in range(N)]
a1=sum(ans)
for i in range(N):
    print(a1-count[A_n[i]-1]+1)

Solution (Python):
n = int(input())
a = list(map(int, input().split(' ')))
dic = {}
com = {}
ans = 0
for v in a:
    try:
        t = dic[v]
        ans += t
        com[v] += t
        dic[v] += 1
    except:
        dic[v] = 1
        com[v] = 0

for k in range(n):
    print(ans - (dic[a[k]]-1))

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

for k, v in count_number.items():
    all_selection += (v)*(v-1)//2

for i in range(N):
    
    print(all_selection-(count_number[A[i]]-1))

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
b=[0]*n
ans=0

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

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
b=[0]*n
ans=0

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

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


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

for a in A:
    cnt[a] = cnt.get(a, 0) + 1

base = sum(map(lambda x: nC2(x), cnt.values()))

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a0=[ai for ai in a]
a0.sort()
b=[-1]*(n+1)
base=0
i=0
while i < n:
    t=a0[i]
    c=1
    while i < n-1 and a0[i]==a0[i+1]:
        c+=1
        i+=1
    b[t]=c
    base+=c*(c-1)//2
    i+=1
for i in range(n):
    d=b[a[i]]
    print(base-d+1)

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

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

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

for i in a:
  counts[i-1] +=1

total=0
for i in counts:
  if i>=2:
    total += i*(i-1)//2

for i in a:
  c=counts[i-1]
  if c>=2:
  	minus=c*(c-1)//2 - (c-1)*(c-2)//2
  else:
    minus=0
  print(total-minus)

Solution (Python):
import collections
N = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
L = {key:(B[key] * (B[key] - 1) // 2) for key in B}
total = sum(L.values())

[print(total if L[i] == 0 else total - L[i] + ((B[i] - 1) * (B[i] - 2) // 2)) for i in A]

Solution (Python):
import collections

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

s = 0
for k, i in B.items():
    s += i*(i-1) // 2
for a in A:
    print(s-(B[a]-1))

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

from collections import Counter

Num=Counter(A)

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

for k in range(N):
    n=Num[A[k]]
    ans=S-n*(n-1)//2+(n-1)*(n-2)//2
    print(ans)

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

all=0
for i in range(n):
  c[a[i]-1]+=1
for i in range(n):
  if c[i]>=2:
    d=c[i]*(c[i]-1)/2
    all+=d
for i in range(n):
  print(int(all-(c[a[i]-1]-1)))

Solution (Python):
import numpy as np


def solve(a):
    b = np.bincount(a)
    be = b*(b-1)//2
    ans = np.sum(be)
    for i in range(n):
        print(ans-max((b[a[i]]-1),0))
    return





n = int(input())
a = [int(s) for s in input().split(" ")]
solve(a)

Solution (Python):
def Main(N, A):
    ans = [0]*N
    hist = [0]*N
    for i in range(N):
        hist[A[i]-1] += 1
    whole = 0
    for i in range(N):
        whole += hist[i]*(hist[i]-1)//2
    for i in range(N):
        ans[i] = whole - hist[A[i]-1] + 1
    return ans

def main():
    N = int(input())
    A = list(map(int, input().split()))
    out = Main(N, A)
    for e in out:
        print(e)

if __name__ == '__main__':
    main()

Solution (Python):
import math
import collections

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

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

counter = collections.Counter(A)
dic = {c: comb(counter[c], 2) for c in counter.keys()}
sum_dic = sum(dic.values())

for i in A:
    print(sum_dic - (counter[i] - 1))

Solution (Python):



import sys
input = sys.stdin.readline

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


if __name__ == '__main__':
    main()

Solution (Python):



def nC2(n):
    return n * (n-1) // 2
  
def main():
    n = int(input())
    li = list(map(int, input().split()))
    nums = [0] * n
    for num in li:
        nums[num - 1] += 1
        
    sumv = 0
    for num in nums:
        if num == 0:
            continue
        sumv += nC2(num)
    
    for num in li:
        cnt = nums[num - 1]
        v = sumv + nC2(cnt-1) - nC2(cnt)
        print(v)
        
  
if __name__ == '__main__':
    main()

Solution (Python):
import collections


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


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

count = collections.Counter(A)

total = 0
for cnt in count.values():
    total += choose2(cnt)

for a in A:
    ans = total
    c = count[a]
    ans -= choose2(c)
    ans += choose2(c-1)
    print(ans)

Solution (Python):
from collections import Counter

N = int(input())
*l, = map(int, input().split())
c = Counter(l)

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

for i in l:
    print(v-(c[i]*(c[i]-1)//2)+((c[i]-1)*(c[i]-2)//2))

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

num = [0] * (n + 1)
for i in ball:
    num[i] += 1

data = [0] * (n + 1)
sentaku = [0] * (n + 1)

for i in range(n+1):
        data[i] = num[i] * (num[i] - 1) // 2
        sentaku[i] = (num[i] - 1) * (num[i] - 2) // 2
x = sum(data)

for i in ball:
    print(x - data[i] + sentaku[i])

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

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

num = [0] * (n + 1)
data = [0] * (n + 1)

for i in ball:
    num[i] += 1

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

x = sum(data)

for i in ball:
    print(x - num[i] + 1)

Solution (Python):
n = int(input())
an = list(map(int, input().split()))
n_list = [0]*n

for i in range(n):
  n_list[an[i]-1] += 1
n_sum = int(sum([x*(x-1)/2 for x in n_list]))

for j in range(n):
  n_remove = n_list[an[j]-1] - 1
  print(n_sum - n_remove)

Solution (Python):
import collections

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

c = collections.Counter(a)

ans = 0

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

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

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

count = []
ans = 0
pt = [0 for i in range(n)]
for k, v in c.items():
  count.append([k,v])
  if v > 1:
    ans += v*(v-1)//2
    pt[k-1] = v-1
    
for i in a:
  print(ans - pt[i-1])

Solution (Python):
n = input()
n = int(n)
lin = input().split()

dic_s = {}
for c in lin:
  dic_s.setdefault(c, 0)
  dic_s[c] += 1

tot = 0
for key,value in dic_s.items():
  v = value
  tot += v * (v - 1) / 2


for c in lin:
  if tot > 0:
    v = dic_s[c]
    print(int(tot-(v-1)))
  else:
    print(0)

Solution (Python):
import numpy as np

N = int(input())

A_l = np.array(list(map(int, input().split())))

num_dict = {}

for num in A_l:
    if num not in num_dict:
        num_dict[num] = 1
    else:
        num_dict[num] += 1

sum_all = 0

for num in num_dict.values():
    sum_all += num*(num-1)/2


for i in range(N):
    ans = sum_all - (num_dict[A_l[i]] - 1)
    print(int(ans))

Solution (Python):
from collections import Counter


N = int(input())
A = list(map(int, input().split()))
count_A = Counter(A)
sum_A = sum([i*(i-1)//2 for i in count_A.values()])

for k in range(N):
    n = count_A[A[k]]
    ans = sum_A - n + 1
    print(ans)

Solution (Python):
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1

    ans = 0
    for i, j in d.items():
        ans += j * (j - 1) // 2

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



if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)

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

from collections import Counter

c = Counter(L)
d = {}
sum = 0

for i in c:
    k = c[i]
    sum += k * (k-1) //2
for i in range(N):
    print(int(sum - c[L[i]] + 1))

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

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


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

    D = [0]*(N+1)
    for i in range(N):
        D[A[i]] += 1
    
    tmp = 0
    for n in range(1, N+1):
        tmp += cmb(D[n])
    for k in range(N):
        res = tmp - cmb(D[A[k]]) + cmb(D[A[k]]-1)
        print(res)


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
ans = 0
c = Counter(a)  



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


for k in range(n):
    
    print(ans - (c[a[k]] - 1))
    """
    c[a[k]]-1というのはｋ番目のボールを隠す前と隠した後についての差。
    隠す前、aのリストにA_kがｍ個あったとする。隠した後、aのリストにA_kはｍ－１個
    なので、mC2 - (m-1)C2 = m-1 である。ここでｍとはc[a[k]]なので、上が成り立つ。
    """

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
lst1=[0]*(n+1)
lst2=[0]*(n+1)
for i in a:
  lst1[i]+=1
for i in range(n+1):
  if lst1[i]>0:
    lst2[i]=lst1[i]-1
lst3=list(map(lambda x:x*(x-1)//2,lst1))
lst4=list(map(lambda x:x*(x-1)//2,lst2))
ans=sum(lst3)
for i in a:
  print(ans-(lst3[i]-lst4[i]))

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
count = []
ans = 0
pt = [0 for i in range(N)]
for k,v in C.items():
    count.append([k,v])
    if v > 1:
        ans += v*(v-1)//2
        pt[k-1] = v-1
for i in A:
    print(ans - pt[i-1])

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

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

Solution (Python):
N = int(input())
As = [int(n) for n in input().split()]

vals = {}
for A in As:
    if A in vals:
        vals[A] += 1
    else:
        vals[A] = 1



choose2 = {}
for val in vals:
    num = vals[val]
    choose2[val] = num*(num - 1) // 2



total = 0
for k in choose2:
    total += choose2[k]


for Ak in As:
    print(total - (vals[Ak] - 1))

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

c = collections.Counter(l)
ans=0
for v in c.values():
  ans+=v*(v-1)//2

for x in l:
  print(ans-c[x]+1)

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

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



def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))



def main():
	n=II()
	A=LI()
	B=[0]*(n+1)
	for i in A:
		B[i]+=1

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









if __name__ == "__main__":
	main()

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




def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))



from collections import deque

def main():
	n=II()
	A=LI()
	B=[0]*(n+1)
	for i in A:
		B[i]+=1

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









if __name__ == "__main__":
	main()

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

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

Solution (Python):
from collections import Counter
from scipy.misc import comb
N = int(input())
A = input().split()
C = Counter(A)
s = sum([comb(j, 2, exact=True) for j in C.values()])
for i in range(N):
    print(s-C[A[i]]+1)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
total = 0
def cmb(n):
  return n*(n-1)//2

X = [0]*(max(A)+1)
for a in A:
  X[a] += 1


for x in X:
  total += cmb(x)


for a in A:
  ans = total
  ans -= cmb(X[a])
  ans += cmb(X[a]-1)
  print(ans)