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,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    c = collections.Counter(a)
    s = 0
    for v in c.values():
        s += v * (v-1) // 2
    r = []
    for i in range(n):
        v = c[a[i]]
        r.append(s - v*(v-1)//2 + (v-1)*(v-2)//2)

    return JA(r, "\n")


print(main())

Solution (Python):
from collections import Counter
def cmb(n):
    if n < 2:
        return 0
    else:
        return (n * (n-1)) // 2

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

cs = Counter(ls)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(cs[a]) + cmb(cs[a] - 1))

Solution (Python):

"""
Created on Sat Apr  4 19:37:51 2020

@author: Kanaru Sato
"""

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

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

for i in range(n):
    print(count-(dic[a[i]]-1))

Solution (Python):
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

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

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Solution (Python):
n = int(input())
data = list(map(int, input().split(" ")))
count = [0]*(n+1)
for i in range(n):
    count[data[i]] = count[data[i]]+1

val = [0]*(n+1)
sumval = 0
for i in range(n+1):
    if(count[i] >= 2):
        val[i] = count[i]-1
        sumval = sumval + int(count[i]*(count[i]-1)/2)

for i in range(n):
    print(sumval - val[data[i]])

Solution (Python):
from collections import Counter


def comb_2(x):
    if x < 2:
        return 0
    return x * (x - 1) // 2


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

c = Counter(arr)
s = 0
for item, cnt in c.items():
    s += comb_2(cnt)

for a in arr:
    print(s - comb_2(c[a]) + comb_2(c[a] - 1))

Solution (Python):
def main():
    dates = int(input())
    numbers = list(map(int, input().split()))
    count = {i: 0 for i in range(1, dates + 1)}
    for n in numbers:
        count[n] += 1
    answer = 0
    for c in count.values():
        answer += c * (c - 1) // 2
    for n in numbers:
        print(answer - count[n] + 1)


if __name__ == '__main__':
    main()

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

from collections import Counter

N = int(input())

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

c = Counter(A)

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

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

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


L = [0]*N
for i in A:
    L[i-1] += 1



SumAll = 0
for i in range(N):
    x = L[i]
    if x >= 2:
        SumAll += int((x * (x-1))/2)



for k in range(N):
    i = A[k] - 1
    Sub = 0
    x = L[i]
    if x >= 2:
        Sub += int((x * (x-1)/2))
    if x >= 3:
        Sub -= int((x-1)*(x-2)/2)
    print(SumAll - Sub)

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

Anum = [0] * N
for i in A:
    Anum[i-1] += 1

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

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

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

Anum = [0] * N
for i in A:
    Anum[i - 1] += 1

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

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

Solution (Python):
from collections import Counter

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

c=Counter(a)
ans=0
for i in c.keys():
  ans+=(c[i]*(c[i]-1))//2

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

Solution (Python):
from collections import Counter

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

c=Counter(a)
ans=0
for i in c.keys():
  ans+=(c[i]*(c[i]-1))//2

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

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

count = [0] * (N+1)
for aa in a:
    count[aa] += 1

su = 0
for ct in count:
    su += ct*(ct-1)/2
    
for aa in a:
    print(int(su-count[aa]+1))

Solution (Python):
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
di = defaultdict(int)
for a in A:
    di[a] += 1
ans = sum([i*(i-1)//2 for i in di.values()])

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

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

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

def choose2(n):
    if n >= 2:
        return (n * (n - 1)) // 2
    else:
        return 0

count = [0] * (n + 1)
for i in range(n):
    count[a[i]] += 1
total = 0
for i in range(n + 1):
    total += choose2(count[i])
for k in range(n):
    print(total - (choose2(count[a[k]]) - choose2(count[a[k]] - 1)))

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

Solution (Python):
from collections import Counter


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

c = Counter(arr)
c_ = {k: v*(v-1)//2 for k, v in c.items()}
s = sum(c_.values())

for a in arr:
    tmp = c[a] - 1
    ans = s - c_[a] + tmp*(tmp-1)//2
    print(ans)

Solution (Python):
import collections 
from collections import Counter

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

A = [int(i*(i-1)/2) for i in c.values()]
A_sum = sum(A)

for j in l:
	print(A_sum - c[j] + 1)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
d = {}
s = set()
for i in l:
    s.add(i)
    if i in d:
        d[i] = d[i]+1

    else:
        d[i] = 1

som = 0
for i in s:
    x = d[i]
    if x >= 2:
        w = x*(x-1)
        w = w//2
        som = som + w

for i in l:
    x = d[i]
    if x > 2:
        f = x*(x-1)
        f = f//2
        x = x-1
        w = x*(x-1)
        w = w//2
        re = som - f + w
        print(re)
        continue

    if x == 2:
        re = som - 1
        print(re)
        continue

    print(som)

Solution (Python):
from collections import Counter as f
n=input()
*l,=map(int,input().split())
A=f(l)
c=sum([i*(i-1)//2 for i in A.values()])
for j in l:
  print(c-A[j]+1)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
cnt = 0
cnt += sum([i*(i-1)//2 for i in a])
for i in A:
    print(cnt - (a[i-1]-1))

Solution (Python):
from collections import Counter
N = int(input())
B = [int(x) for x in input().split()]
A=Counter(B)
V, C = zip(*A.most_common())
count=0
i=0
dict={}
for x in C:
  count+=x*(x-1)/2
  dict[V[i]]=x
  i+=1
for x in B:
  ans=count-dict[x]+1
  print(int(ans))

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

Solution (Python):
from collections import Counter
N = int(input())
B = [int(x) for x in input().split()]
A=Counter(B)
V, C = zip(*A.most_common())
count=0
for x in C:
  if x==0:
    break
  count+=x*(x-1)/2
for x in B:
  ans=count-A[x]+1
  print(int(ans))

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

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

ans = 0

dic = dict()
for i in A:
    if i not in dic.keys():
        dic[i] = 1
    else:
        dic[i] += 1


for j in dic.values():
    if j >= 2:
        ans += (j*(j-1))//2

    

for k in A:
    yo = dic[k]
    if yo >= 3:
        ans_k = ans - (yo*(yo-1))//2 + ((yo-1)*(yo-2))//2
    elif yo == 2:
        ans_k = ans -(yo*(yo-1))//2
    else:
        ans_k = ans
        pass
    print(ans_k)

Solution (Python):
import math


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


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

b = 0
for n in d.values():
    b += comb(n, 2)

for k in range(N):
    a = A[k]
    print(b - d[a] + 1)

Solution (Python):
mod = 10**9 + 7

def main():
    N = iip(listed=False)
    A = iip(True)
    

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

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

    result = []
    for k in A:
        nk = num[k]
        if nk <= 1:
            result.append(defres)
            continue
        diff = nk*(nk-1)//2 - (nk-1)*(nk-2)//2
        result.append(defres - diff)

    print("\n".join([str(i) for i in result]))




def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a_s = list(map(int, input().split()))
count_a = [0] * (n+1)

for a in a_s:
  count_a[a] += 1

choices = sum(map(lambda x: x*(x-1)//2, count_a))

for a in a_s:
  print(choices - (count_a[a]-1))

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

Solution (Python):
import collections

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

num_count = collections.Counter(a)
total = sum([num*(num-1)//2 for num in num_count.values()])

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

Solution (Python):
import collections

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

Solution (Python):
import collections


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

    A_count = collections.Counter(A)
    conv_all = sum([(A_c_i * (A_c_i-1))//2 for A_c_i in A_count.values()])

    for i in range(n):
        print(conv_all - A_count[A[i]] + 1)


if __name__ == "__main__":
    main()

Solution (Python):
def f(n):
  return (n*(n-1))//2
N=int(input())
A=list(map(int,input().split()))
d=dict()
ans=0

for i in range(len(A)):
  if A[i] not in d:
    d[A[i]]=0
  d[A[i]]+=1
for i in d:
  ans+=f(d[i])
for i in range(len(A)):
  print(ans-d[A[i]]+1)

Solution (Python):

n = int(input())
a = input().split()
ans = 0
import collections
dic = collections.Counter(a)
for i in dic.values():
    ans += i * (i-1)
ans /= 2
for i in range(n):
    print(int(ans - dic[a[i]] + 1))

Solution (Python):
n = int(input())
a_s = list(map(int, input().split()))
count_a = [0] * (n+1)

for a in a_s:
  count_a[a] += 1

choices = sum(map(lambda x: x*(x-1)//2, count_a))

for a in a_s:
  print(choices - (count_a[a]-1))

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


d={}
for i in l:
  if i in d:
    d[i]+=1
  else:
    d[i]=1


all = 0
decrease = {}
for k, v in d.items():
  all+=v*(v-1)//2
  decrease[k] = v-1


for i in l:
  print(all-decrease[i])

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

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

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

d = {}
for i in a:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
    
s = sum([nC2(i) for i in d.values()])

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

Solution (Python):
from collections import Counter

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


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


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

Solution (Python):
import collections
N=int(input())
lst=input().split()
s=0
dic=collections.Counter(lst)
for i in dic.values():
    s+=(i*i-i)//2
for i in lst:
    print(s+1-dic[i])

Solution (Python):

import sys, math
from collections import Counter

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

def comb(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))

total = 0
L = Counter(A)
for v in L.values():
    if v>=2:
        total += comb(v)

for k in range(N):
    print(total - (L[A[k]]-1))

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

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

a = [int(i) for i in input().split()];
b = [int(0) for i in range(n)];

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




sum = 0;
for i in b:
  sum += i * (i - 1) // 2;

for i in a:
  print(sum - b[i - 1] + 1);

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

dic = dict()
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

base = 0

for v in dic.values():
    base += v * (v - 1) // 2

for i in range(N):
    ord = dic[A[i]]
    print(base - (ord * (ord - 1) // 2) + ((ord - 1) * (ord - 2) // 2))

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

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

for i in range(n):
    print(s-(d[a[i]]*(d[a[i]]-1))//2+(max(d[a[i]]-1,0))*(max(d[a[i]]-2,0))//2)

Solution (Python):
n=int(input())
l=[int(x) for x in input().split()]
m=[0]*(200007)
for x in l:
    m[x]=m[x]+1

total=0
for x in m:
    total+=(x*(x-1))//2

for x in l:
    print(total-m[x]+1)

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

Solution (Python):

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

dict = {}
for i in range(N):
  if A[i] in dict.keys():
    dict[A[i]] += 1
  else:
    dict[A[i]] = 1

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


ret = 0
for key in dict.keys():
  val = dict[key]
  ret += comb(val)


for i in range(N):
  val_n = dict[A[i]]
  next_ret = ret - comb(val_n) + comb(val_n - 1)
  print(next_ret)

Solution (Python):

import collections



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

C = collections.Counter(A)

Total = sum([i*(i-1)/2 for i in C.values()])

for Ak in A:
    print(int(Total - C[Ak]+1))

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

Solution (Python):
import collections

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

L=len(b)

total=0
for i in range(L):
    total += c[i][1]*(c[i][1]-1)//2

for i in a:
    ans = total - (b[i]-1)
    print(ans)

Solution (Python):

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

d = collections.Counter(A)
total = 0
for i in d.values():
    n = i*(i-1)//2
    total+=n

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

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

Solution (Python):
import collections

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

a=collections.Counter(A)

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

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

Solution (Python):
import collections

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

cnt = collections.Counter(num_list)
ttl = 0
for v in cnt.values():
    ttl += v*(v-1)//2
for a in num_list:
    print(ttl - (cnt[a] - 1))

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
A = iln()
cnt = collections.Counter(A)

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

total = 0
for value in cnt.values():
    if value >= 2:
        total += c2(value)

for i in range(N):
    if A[i] in cnt.keys() and cnt[A[i]] >= 2:
        print(total-c2(cnt[A[i]])+c2(cnt[A[i]]-1))
    else:
        print(total)

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

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

cnt = [0 for _ in range(n)]
for i in range(n):
  cnt[a[i]-1] += 1

s = 0
for i in range(n):
  s += cnt[i] * (cnt[i] - 1) // 2

for i in range(n):
  print(s-cnt[a[i]-1]+1, end="")
  if i != n-1:
    print(" ")
  else:
    print("\n")

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

from collections import Counter

ac = Counter(a)
acm = ac.most_common()

ans = 0

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

for ai in a:
    print(ans - ac[ai] + 1)

Solution (Python):
n=int(input())
arr=list(map(int,input().strip().split()))[:n]
dict1={}
for i in arr:
	if i in dict1:
		dict1[i]+=1
	else:
		dict1[i]=1
sum1=0
for i in dict1:
	sum1+=((dict1[i]*(dict1[i]-1))//2)
for i in arr:
	k=sum1
	n1=dict1[i]
	k-=((n1*(n1-1))//2)
	k+=((n1-1)*(n1-1-1)//2)
	print(k)

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

Solution (Python):


from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

N = int(input())

s = input().split()
p = [int(w) for w in s]


number_list = [0 for i in range(N)]
'''
for i in range(N):
    counter = 0
    for j in range(N):
        if(p[j] == i+1):
            counter +=1
    number_list.append(counter)
'''


for i in range(N):
    number_list[p[i] - 1] += 1




def n_C_2(n):
    if(n == -1):
        return 0
    else:
        return int(n * (n-1) / 2)


full_combi = []
pickup_combi = []
print_combi = []

for i in range(N):
    full_combi.append(n_C_2(number_list[i]))
    pickup_combi.append(n_C_2(number_list[i] - 1))



all_full = sum(full_combi)
for i in range(N):
    print_combi.append(all_full - full_combi[i] + pickup_combi[i])


for i in range(N):
    index = p[i] - 1
    print(print_combi[index])

Solution (Python):
def main():
    import math
    import collections
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    
    ann = 0

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

    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''

    C = collections.Counter(A)
    for i in C.values():
        if i>=2:
            tt = tt + comb(i, 2)

    for i in A:
        f = C[i] 
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(int(ann))

    
    


if __name__ == '__main__':
    main()

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())

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

def LLI(rows_number): return [LI() for _ in range(rows_number)]

n = II()
a = LI()

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

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

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

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

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

Solution (Python):
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    c = Counter(a)
    b = sum(v * (v - 1) // 2 for v in c.values())
    return "\n".join(str(b - c[_a] + 1) for _a in a)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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


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


ans = 0
for d in dict.values():
    if d > 1:
        ans += (d * (d - 1)) // 2


for k in range(N):
    w = dict[A[k]]
    
    decrease = 0
    if w == 1:
        pass
    elif w == 2:
        decrease = -1
    elif w > 2:
        decrease = ((w - 1) * (w - 2) // 2) - (w * (w - 1) // 2 )
    print(ans + decrease)

Solution (Python):
import collections as cl
N = int(input())
A = list(map(int,input().split()))
cn = cl.Counter(A)
sumC = sum([N*(N-1)//2 for N in cn.values()])
for k in range(N):
  sum = sumC - cn[A[k]] +1
  print(sum)

Solution (Python):
import collections as cl
N = int(input())
A = list(map(int,input().split()))
cn = cl.Counter(A)
sumC = sum([n*(n-1)//2 for n in cn.values()])
for k in range(N):
  print(sumC - cn[A[k]] +1)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
kosuu = [0]*(N+1)
for i in range(N):
    kosuu[A[i]] += 1

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

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

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

normal = 0
for i in ball:
    normal += i*(i-1)//2

for i in range(N):
    m = ball[A[i]]
    print(normal-m*(m-1)//2+(m-1)*(m-2)//2)

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

from collections import Counter

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

c = Counter(A)

sum_comb = 0

for key in c:
    sum_comb += c[key] * (c[key] - 1) // 2

for num in A:
    tmp = c[num] * (c[num] - 1) // 2
    tmp2 = (c[num]-1) * (c[num] - 2) // 2
    print(sum_comb - tmp + tmp2)

Solution (Python):
import collections

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

count = collections.Counter(a)
total = 0

for i in count.keys():
    total += int(count[i] * (count[i] - 1) / 2)

for v in a:
    print(total - count[v] + 1)

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

import collections
c= collections.Counter(A)

counter = 0
for j in c.keys():
    if c[j]>=2:
        counter += c[j]*(c[j]-1)/2


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

Solution (Python):
import math

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

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

sum = 0
for i in range(N):
    t = count[i]
    if t >= 2:
        sum += math.factorial(t) // (math.factorial(t - 2) * 2)

for i in range(N):
    t = count[A[i] - 1]
    if t > 1:
        print(sum - t + 1)
    else:
        print(sum)

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

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

    
ans1=dict()
ans2=dict()

for i in d.keys():
  ans1[i]=d[i]*(d[i]-1)//2
  ans2[i]=(d[i]-1)*(d[i]-2)//2
  


  
s=0
for i in d.values():
  s+=i*(i-1)//2
  
ans=[0 for i in range(n)]
for i in range(n):
  ans[i]=s-ans1[a[i]]+ans2[a[i]]
  
for i in ans:
  print(i)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
counter = Counter(a)
d = [0]*(n+1)
count = 0
for el, cnt in counter.most_common():
    d[el] = cnt
    count += cnt*(cnt-1)
count //= 2
for el in a:
    print(count - d[el] + 1)

Solution (Python):
from math import factorial
from collections import Counter

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

N = int(input())
A = list(input().split())
sum = 0
counter = Counter(A)
for key,value in counter.items():
    sum = sum + combinations_count(value,2)

for k in range(N):
    add = 0
    add = sum - combinations_count(counter[A[k]],2) + combinations_count(counter[A[k]]-1,2) 
    print(add)

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

for i in range(N):
    sameNum[array[i]-1] += 1
for i in range(N):
    sum += sameNum[i]*(sameNum[i]-1)//2

for k in range(1, N+1):
    sumT = sum
    print(sumT - sameNum[array[k-1]-1] + 1)

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


counter = [0 for i in range(N+1)]
for i in range(N):
    counter[As[i]] += 1


k_C_2 = [0 for i in range(N+1)]
k_C_2[2] = 1
for i in range(3, N+1):
    k_C_2[i] = k_C_2[i-1] * i / (i-2)



all_case = 0
for i in range(N+1):
    if counter[i] >= 2:
        all_case += k_C_2[counter[i]]


for i in range(N):
    if counter[As[i]] == 2:
        print(int(all_case - 1))
    elif counter[As[i]] >= 3:
        print(int(all_case - k_C_2[counter[As[i]]] + k_C_2[counter[As[i]]-1]))
    else:
        print(int(all_case))

Solution (Python):
from collections import Counter

n = int(input())
integer = list(map(int, input().split()))
length = len(integer)
counter = Counter(integer)
keys = counter.keys()
total = 0
for key in keys:
  total += counter[key] * ( counter[key] -1 ) / 2
total = int(total)

for i in integer:
  tmp = total
  tmp -= counter[i] - 1
  print(tmp)

Solution (Python):
import collections

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

count = collections.Counter(a)

tmp = [0 for _ in range(n)]
tmp2 = [0 for _ in range(n)]

for key,value in count.items():
	if value == 1:
		continue
	tmp[key-1] = value*(value-1) // 2
	tmp2[key-1] = (value-1)*(value-2) // 2
tmp3 = sum(tmp)

for i in range(n):
	print(tmp3 - tmp[a[i]-1] + tmp2[a[i]-1])

Solution (Python):
import collections
N = int(input())
li = list(map(int, input().split()))
cn = collections.Counter(li)
sumC = sum([n*(n-1)//2 for n in cn.values()])
for k in range(N):
    print(sumC-cn[li[k]] + 1)

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

for i in A:
    D[i] += 1
S = 0
for i in range(1,N+1):
    tmp = D[i]
    S += tmp*(tmp-1)//2

for i in A:
    tmp = D[i]
    print(S-tmp*(tmp-1)//2+(tmp-1)*(tmp-2)//2)