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()))

a_dict = {}
for i in a:
    if a_dict.get(i, False):
        a_dict[i] += 1
    else:
        a_dict[i] = 1

def mC2(m):
    return m * (m - 1) // 2

sum = 0
for v in a_dict.values():
    sum += mC2(v)

for i, k in enumerate(a):
    ans = sum - (a_dict[k] - 1)
    print(ans)

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
s=0
def f(n):
    return n*(n-1)//2
for i in c:
    c[i]=(f(c[i]),(f(c[i]-1)))
    s+=c[i][0]
for j in A:
    print(s-c[j][0]+c[j][1])

Solution (Python):
from collections import Counter

n= int(input())
a=list(map(int,input().split()))
ca = Counter(a)
sa = set(a)
sum_ans=0
for i in sa:
  sum_ans+=(ca[i]*(ca[i]-1))//2

for i in a:
  print(sum_ans-(ca[i]*(ca[i]-1))//2+((ca[i]-1)*(ca[i]-2))//2)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d={}
for b in a:
  if b not in d:
    d[b]=0
  d[b]+=1

ans=0
for c in d:
  ans+=(d[c]*(d[c]-1))//2
  
for k in range(n):
  e=a[k]
  print(ans-(d[e]*(d[e]-1))//2+(d[e]-1)*(d[e]-2)//2)

Solution (Python):
from collections import Counter
def comb(a, b):
    if b > a:
        return 0
    tmp1 = 1
    tmp2 = 1
    for i in range(b):
        tmp1 *= (a-i)
        tmp2 *= (b-i)
    return tmp1//tmp2

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

comp_sum = 0
for key in count_dict.keys():
    comp_sum += comb(count_dict[key], 2)


for i in range(N):
    print(comp_sum + comb(count_dict[A[i]]-1, 2) -  comb(count_dict[A[i]], 2))

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

import collections
C = collections.Counter(a)



sum=0
for v in list(C.values()):
	sum+=v*(v-1)//2
 
for k in range(n):
	x = C[a[k]]
	print(sum-(x*(x-1)//2)+((x-1)*(x-2)//2))

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
c={}
for i in set(L):
  c[i]=0
for i in L:
  c[i]+=1
s=sum([(i*(i-1))//2 for i in c.values()])
for i in L:
  print(s-c[i]+1)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
D = {a:0 for a in set(A)}
for a in A:
  D[a] += 1
S = 0
for v in D.values():
  if v>=2:
    S += v*(v-1)//2
for a in A:
  d = D[a]
  if d==1:
    print(S)
  else:
    print(S-d*(d-1)//2+(d-1)*(d-2)//2)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))        
C = lambda x: x*(x-1)//2
s = 0
D = Counter(A)
for i,j in D.items():
  s += C(j)
for i in A:
  print(s-D[i]+1)

Solution (Python):
import collections

N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
C=sum([x*(x-1)//2 for x in B.values()])

for i in A:
  temp=B[i]
  print(C-(temp*(temp-1)//2-(temp-1)*(temp-2)//2))

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


def combinations_count(n, r):
    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0

c = Counter()
n = int(input())
A = list(map(int, input().split()))
for i in A:
    c[i] += 1
ans = 0
for k, v in c.items():
    ans += combinations_count(v, 2)

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

Solution (Python):
from collections import defaultdict

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

cnt = defaultdict(int)
for v in a:
  cnt[v] += 1

ans = 0
for v in cnt:
  ans += cnt[v]*(cnt[v]-1)//2

for v in a:
  print(ans + (cnt[v]-1)*(cnt[v]-2)//2 - cnt[v]*(cnt[v]-1)//2)

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

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

cnt = sum([value*(value-1)//2 for value in d.values()])

for i in range(n):
    val = d[a[i]]
    res = cnt - val*(val-1)//2

    if val >= 3:
        res += (val-1)*(val-2)//2

    print(res)

Solution (Python):
import math

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

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

ne = [0]*(nn+1)
cn = [0]*(nn+1)
cnminus1 = [0]*(nn+1)


for i in range(nn):
    ne[aa[i]] += 1

for i in range(nn+1):
 
    if ne[i] == 0:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 1:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 2:
        cn[i] = 1
        cnminus1[i] = 0
    else:
        cn[i] = combinations_count(ne[i],2)
        cnminus1[i] = combinations_count(ne[i]-1,2)

sum_cn = sum(cn)

for i in range(nn):
    print(sum_cn - cn[aa[i]] + cnminus1[aa[i]])

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

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

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

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

c = 0
cnt = [0]*n

for i in range(n):
    A[i] -= 1

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

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

for i in range(n):
    c += combinations(cnt[i])

for i in range(n):
    ans = c
    ans -= combinations(cnt[A[i]])
    ans += combinations(cnt[A[i]]-1)
    print(ans)

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

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

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i])

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])
    tmp = S + S_dif
    print(int(tmp))

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

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

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i])

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])
    tmp = S + S_dif
    print(int(tmp))

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

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

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

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i],2)

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1,2) - cmb(num_dict[A[i]],2)
    tmp = S + S_dif
    print(tmp)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



N = INT()
A = LIST()
C = Counter(A)

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

for x in A:
	print(tmp - (C[x]-1))

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

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

Solution (Python):
import sys
from collections import Counter

c = None

def resolve(in_, out):
    n = int(in_.readline())
    a = tuple(map(int, in_.readline().split()))

    c = dict(Counter(a))

    total = sum(v * (v - 1) // 2 for v in c.values())

    for ai in a:
        ans = total - (c[ai] - 1)
        print(ans, file=out)


def main():
    resolve(sys.stdin.buffer, sys.stdout)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import Counter
from functools import lru_cache

c = None

@lru_cache(maxsize=200000)
def _num_of_ways_to_choose(x):
    v = c[x]
    return (v * (v - 1)) // 2


def resolve(in_, out):
    n = int(in_.readline())
    a = tuple(map(int, in_.readline().split()))
    global c
    c = dict(Counter(a))

    _num_of_ways_to_choose.cache_clear()
    total = sum(map(_num_of_ways_to_choose, c.keys()))

    for ai in a:
        ans = total - _num_of_ways_to_choose(ai) + ((c[ai] - 1) * (c[ai] - 2)) // 2
        print(ans, file=out)


def main():
    resolve(sys.stdin.buffer, sys.stdout)


if __name__ == '__main__':
    main()

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

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

for i in range(1, N+1):
    S += B[i]*(B[i]-1)//2

for k in range(N):
    print(S-B[A[k]]+1)

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

d = [0]*n
for i in a:
    d[i-1] += 1

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

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

Solution (Python):
from scipy.special import comb
from collections import Counter

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

count = Counter(A)
combs = {k:comb(count[k], 2) for k in count.keys()}
combs_minas_one = {k:comb(count[k]-1, 2) for k in count.keys()}
all = sum(combs.values())

for a in A:
    ans = all - combs[a] + combs_minas_one[a]
    print(int(ans))

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

Solution (Python):
import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
answer = 0
for num in c:
  answer += c[num]*(c[num]-1)//2

for k in range(N):
  print(answer - c[A[k]] + 1)

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

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

Solution (Python):
import collections
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
num = 0
for i in set(A):
    if B[i] > 1:
        num += combinations_count(B[i], 2)
for i in A:
    print(num-B[i]+1)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
kosuu = [0]*(200000+1)
cnt = [0]*(200000+1)
ans = [0]*(200000+1)

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

s = 0
for i in kosuu:
  s += i * (i - 1) // 2

for i in range(n):
  tmp = kosuu[a[i]]
  
  print(s - max(0,tmp-1))

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

Solution (Python):
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
ca = Counter(A)
ts = 0
for k in ca:
    ts += (ca[k] * (ca[k] - 1)) // 2
ans = [0]*N
for i,a in enumerate(A):
    ans[i] = ts - (ca[a] - 1)
print("\n".join(map(str, ans)))

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

lis = [0]*(N+1)
for a in A[1:]:
    lis[a] += 1

sum_combinations = 0
for x in lis[1:]:
    if x >= 2:
        sum_combinations += x*(x-1)//2

for i in range(1,N+1):
    ans = sum_combinations
    num = lis[A[i]]
    if num >= 2:
        ans += (num-1)*(num-2)//2 - num*(num-1)//2
    
    print(ans)

Solution (Python):
from collections import Counter

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

C=Counter(A)

C_={}
sum_ = 0
for k in C.keys():
    c=C[k]
    if c == 1:
        C_[k]=0
    else:
        C_[k]=(c*(c-1))//2
        
    sum_ += C_[k]

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

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

    c = defaultdict(int)
    for a in A:
        c[a] += 1

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

    for k in range(N):
        tmp = ans
        tmp -= c[A[k]] * (c[A[k]] - 1) // 2
        tmp += max(0, (c[A[k]] - 1) * (c[A[k]] - 2) // 2)
        print(tmp)


def main():
    solve()


if __name__ == '__main__':
    main()

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

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

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

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

total = 0
for i in range(n+1):
  total += choose2(inp[i])

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

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

nums = [0] * (max(a) + 1)
for i in range(len(a)):
    nums[a[i]] += 1

from scipy.special import comb

all = 0
for i in range(len(nums)):
    all += comb(nums[i], 2, exact=True)

for k in range(n):
    print(all - (nums[a[k]] - 1))

Solution (Python):
import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
answer = 0
for num in c:
    answer += c[num] * (c[num] - 1) // 2

for k in range(N):
    print(answer - c[A[k]] + 1)

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

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in a_count.items():
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n = int(stdin.readline().rstrip())
a = [x for x in stdin.readline().rstrip().split()]

d = {}
for i in range(n):
    if a[i] not in d:
        d[a[i]] = 1
    else:
        d[a[i]] += 1

m = sum([v*(v-1) // 2 for v in list(d.values())])

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

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

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

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

Solution (Python):
from collections import Counter

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

ac = Counter(a)
sm = 0
for v in ac.values():
    if v > 1:
        sm += v * (v - 1) // 2
for v in a:
    print(sm - ac[v] * (ac[v] - 1) // 2 + (ac[v] - 1) * (ac[v] - 2) // 2)

Solution (Python):
from collections import Counter

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

ac = Counter(a)
sm = 0
for v in ac.values():
    if v > 1:
        sm += v * (v - 1) // 2
for v in a:
    print(
        sm
        if ac[v] <= 1
        else sm - ac[v] * (ac[v] - 1) // 2 + (ac[v] - 1) * (ac[v] - 2) // 2
    )

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


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

  dic = defaultdict(int)
  for a in A:
    dic[a] += 1

  C2 = lambda N: int(N * (N-1) / 2)

  sum_ = 0
  for key in dic.keys():
    sum_ += C2(dic[key])

  for i in range(N):
    print( sum_ - (C2(dic[A[i]]) - C2(dic[A[i]]-1)) )


if(__name__ == '__main__'):
  main()

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(1,n+1):
    Ans += cnt[i] * (cnt[i]-1) // 2

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

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

ind_A = {}

for i in range(N):
  if A[i] in ind_A:
    ind_A[A[i]] += 1
  else:
    ind_A[A[i]] = 1

ans = 0

for (i, v) in ind_A.items():
  ans += (v * v - v) // 2


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

Solution (Python):

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

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

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

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

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    A = list(map(int, input().split()))
    a_c = Counter(A)
    a_s = list(set(A))
    tot = 0
    for a in a_s:
        tot += a_c[a] * (a_c[a] - 1) // 2
    ans = list(map(lambda x: tot - (a_c[x] - 1), a_s))
    ans_dic = dict(zip(a_s, ans))
    for a in A:
        print(ans_dic[a])


if __name__ == "__main__":
    main()

Solution (Python):

import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
cnt = Counter(A)
sum = 0
for n in cnt.values():
    sum += n*(n-1)//2
for a in A:
    print(sum-cnt[a]+1)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
dict_A = Counter(A)
sum_comb = 0
for v in dict_A.values():
    sum_comb += int((v * (v - 1)) / 2)

for a in A:
    print(sum_comb - dict_A[a] + 1)

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

c = Counter(a)


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

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

Solution (Python):
from math import factorial
n=int(input())
cnt=[0]*(n+1)
lst=list(map(int,input().split()))
for i in lst:
    cnt[i]+=1
ans=0
for i in range(n+1):
    p=cnt[i]
    if p>=2:
        ans+=factorial(p)//factorial(p-2)//2
for i in range(n):
    print(ans-cnt[lst[i]]+1)

Solution (Python):
from math import factorial
n=int(input())
cnt=[0]*(n+1)
lst=list(map(int,input().split()))
tmp=[0]*(n+1)
change=[0]*(n+1)
for i in lst:
    cnt[i]+=1
ans=0
for i in range(n+1):
    p=cnt[i]
    if p>=2:
        q=factorial(p)//factorial(p-2)//2
        ans+=q
        tmp[i]=q
    if p>=3:
        change[i]=factorial(p-1)//factorial(p-3)//2
for i in range(n):
    print(ans-tmp[lst[i]]+change[lst[i]])

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):
  tmp = total
  tmp -= cnt[arr[i]]*(cnt[arr[i]] - 1)//2
  tmp += (cnt[arr[i]] - 1)*(cnt[arr[i]] - 2)//2
  print(tmp)

Solution (Python):

from collections import Counter


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

def solve(n,a):
  d = Counter(a)
  patterns = dict((k,combi(v)) for k,v in d.items())
  patterns_sum = sum(patterns.values())
  ans = [0]*n
  for i in range(n):
    ans[i] = patterns_sum - patterns[a[i]] + combi(d[a[i]]-1)
  return ans



def main():
  N = int(input())
  a = list(map(int,input().split()))
  ans = solve(N,a)
  for i in range(len(ans)):
    print(ans[i])
  return

if __name__ == '__main__':
  main()

Solution (Python):
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    combi_A = 0

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
l = (2 * 10 ** 5) + 1
b = [0] * l


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


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

ttl = 0
for j in range(l):
    ttl += b[j] * (b[j] - 1) // 2

for k in range(n):
    print(ttl - nC2(b[a[k]]) + nC2(b[a[k]] - 1))

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

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

Solution (Python):
n=int(input(""))
lista=input("").split(" ")
lisa=[]
listn=[]
for i in range(n+1):
    listn+=[0]
for i in lista:
    lisa+=[int(i)]
    listn[int(i)]+=1
s=0
for i in listn:
    if(i<2):
        continue
    else:
        s+=i*(i-1)/2
for i in lisa:
    print(int(s-listn[i]+1))

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
from collections import Counter
cnt = Counter(A)
ans = 0
for key,val in cnt.items():
    if val>=2:
        ans += val*(val-1)//2
for a in A:
    cur = ans
    if cnt[a]>=2:
        cur -= cnt[a]-1
    print(cur)

Solution (Python):
import collections
import itertools

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

ac = collections.Counter(A)

dp = [0] * (N+1)
dp2 = [0] * (N+1)
total = 0
for no, num in ac.items():
    dp[no] = int(num*(num-1)/2)
    dp2[no] = dp[no] - (num-1)
    total += dp[no]

for k in range(1,N+1):
    no = A[k-1]
    print(int(total - dp[no] + dp2[no]))

Solution (Python):
from collections import Counter
N = int(input())
T = tuple(map(int, input().split()))
C = Counter(T)
d = dict()
sum = 0
for c in C.most_common():
  if c[1] == 0:
    break
  if d.get(c[1]):
    sum += d[c[1]]
  else:
    x = (c[1] * (c[1] - 1)) // 2
    d[c[1]] = x
    sum += x
for t in T:
  x = C[t]
  if x >= 2:
    if d.get(x):
      minus = d[x]
    else:
      minus = (x * (x - 1)) // 2
      d[x] = minus
    if d.get(x-1):
      plus = d[x - 1]
    else:
      plus = ((x - 1) * (x - 2)) // 2
      d[x - 1] = plus
    print(sum - minus + plus)
  else:
    print(sum)

Solution (Python):
import math
N = int(input())
K = list(map(int,input().split()))
hashmap = {}
for k in K:
  if k not in hashmap:
    hashmap[k] = 0
  hashmap[k]+=1
total = 0
for v in hashmap.values():
  if v>=2:
  	total+=math.factorial(v) // (math.factorial(v - 2) * 2)

for k in K:
  print(total-(hashmap[k]-1))

Solution (Python):
from collections import Counter
N, = list(map(int,input().split()))
A  = list(map(int,input().split()))
c = Counter(A)
p = sum([(c[k]*(c[k]-1)//2) for k in c.keys()])
for ai in A:
    print(p - c[ai] + 1)

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


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


t = sum(list(map(comb, C)))
for a in A:
    print(t - comb(C[a]) + comb(C[a] - 1))

Solution (Python):

from collections import Counter

N = int(input())
X = list(map(int, input().split()))
ctr = Counter(X)

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

for i in range(N):
    val = ctr[X[i]]
    print(ans - val * (val - 1) // 2 + (val - 1) * (val - 2) // 2)

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = collections.Counter(a)
    all_comb = 0
    for i in cnt.keys():
        all_comb += cnt[i] * (cnt[i]-1) // 2
    for i in range(n):
        comb = all_comb
        comb -= cnt[a[i]] * (cnt[a[i]]-1) // 2
        comb += (cnt[a[i]]-1) * (cnt[a[i]]-2) // 2
        print(comb)
        
if __name__ == '__main__':
    main()

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

from collections import Counter
c = Counter(l)

num = [[] for _ in range(n+1)]

tot = 0
for i,j in c.items():
    if j >= 2:
        tmp1 = j*(j-1)//2
        tot += tmp1
    else:
        tmp1 = 0
    if j >= 3:
        tmp2 = (j-1)*(j-2)//2
    else:
        tmp2 = 0
    num[i] = [tmp1, tmp2]

for k in l:
    print(tot - num[k][0] + num[k][1])

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

import collections
B = collections.Counter(A)
count = 0
for a in B.values():
    count += (a*(a-1))//2

for a in range(N):
    D = A[a]
    print(count-B[D]+1)

Solution (Python):

import sys
import collections as cl


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 main():
    N = II()
    A = LI()
    count = [0] * (N + 1)

    for a in A:
        count[a] += 1

    total = 0

    for idx in range(N+1):
        total += count[idx] * (count[idx] - 1) / 2
    for a in A:
        a_count = count[a]
        print(int(total - (a_count * (a_count - 1) /
                           2) + ((a_count - 1)*(a_count - 2)/2)))


main()

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

from collections import Counter
c = Counter(l)

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

for j in range(n): 
    tmp = c[l[j]]
    before = tmp*(tmp-1)//2 
    after = (tmp-1)*(tmp-2)//2
    print(total - before + after)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2

    for k in range(N):
        v = c[A[k]]
        diff = -v*(v-1)//2 + (v-1)*(v-2)//2
        print(ans + diff)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2

    for k in range(N):
        v = c[A[k]]
        diff = -v*(v-1)//2 + (v-1)*(v-2)//2
        print(ans + (diff if v != 1 else 0))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = {}
ANS = 0
for x,y in Counter(A).items():
    if y >= 2: 
        a[x] = [y, (y*(y-1))//2]
        ANS += (y*(y-1))//2
for i in range(n):
    ans = ANS
    if A[i] in a:
        x = a[A[i]][0]-1
        ans -= a[A[i]][1]
        ans += (x*(x-1))//2
    print(ans)

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

total = 0
for key in Acount.keys():
    total += Acount[key] * (Acount[key] - 1) // 2

for i in range(n):
    tmp = total
    tmp -= Acount[A[i]]*(Acount[A[i]]-1) // 2
    tmp += (Acount[A[i]]-1)*(Acount[A[i]]-2) // 2
    print(tmp)