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()))
ct=[0]*n
cmb=[0]*n
s_cmb=0
for i in range(0,n):
  a[i]-=1
  ct[a[i]]+=1
for i in range(0,n):
  cmb[i]=ct[i]*(ct[i]-1)//2
  s_cmb+=cmb[i]
for i in range(0,n):
  print(s_cmb-cmb[a[i]]+(ct[a[i]]-1)*(ct[a[i]]-2)//2)

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

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

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

cnt = [0] * N
for i in range(N):
    cnt[A[i]] += 1
total = 0
for i in range(N):
    total += choose2(cnt[i])

for i in range(N):
    ans = total
    ans -= choose2(cnt[A[i]])
    ans += choose2(cnt[A[i]]-1)
    print(ans)

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

def comb(n,r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())
A = list(map(int,input().split()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)

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 collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
ans=0
for i in c:
    ans+=c[i]*(c[i]-1)//2
for i in range(N):
    a=A[i]
    Ans=ans-c[a]+1
    print(Ans)

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

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
  res += choose2(k)

for k in A:
  temp = res
  m = d[k]
  temp -= choose2(m)

  d[k] -= 1
  temp += choose2(d[k])
  print(temp)
  d[k] += 1

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

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):
import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp

Solution (Python):
import collections

n = int(input())
a = list(map(int, input().split()))
counter = collections.Counter(a)
diffs = {k: v - 1 for k, v in counter.items()}
s = sum(v * (v - 1) // 2 for v in counter.values())
for v in a:
    print(s - diffs[v])

Solution (Python):
n=int(input())
s=input().split()
num=[]
for i in range(n):
    num.append(0)
for i in range(n):
    num[int(s[i])-1]+=1
c=0
for i in range(n):
    c+=(num[i]*(num[i]-1))//2
for i in range(n):
    print(c-num[int(s[i])-1]+1)

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

def ncr(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

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
    if k >= 2:
      res += ncr(k, 2)

for k in A:
  temp = res
  m = d[k]
  if m >= 2:
    temp -= ncr(m, 2)

  d[k] -= 1
  if d[k] >= 2:
    temp += ncr(d[k], 2)
  print(temp)
  d[k] += 1

Solution (Python):


import collections

n = int(input())
balls = list(map(int, input().split(' ')))

dic = collections.Counter(balls)
total = 0
for v in dic.values():
    if (v < 2):
        continue
    total += int(v * (v - 1) / 2)

for i in range(n):
    num = balls[i]
    print(total - dic[num] + 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:
    print(int(counter-c[i]+1))

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

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

CONB = [CNT[j]*(CNT[j]-1)//2 for j in range(len(CNT))]

SUM = sum(CONB)
for i in A:
    ans = SUM - CNT[i] + 1
    print(ans)

Solution (Python):
from collections import Counter
n = int(input())
nums = list(map(int, input().split()))
nums_count_dict = Counter(nums)
nums_count_combi = {key: value*(value-1)/2 for key, value in nums_count_dict.items()}
total = sum(nums_count_combi.values())
for number in nums:
    print(int(total-nums_count_dict[number]+1))

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

Solution (Python):
from collections import Counter

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

a=list(set(A))
C=Counter(A)
total=0

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

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

Solution (Python):
import collections

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

count = collections.Counter(a)
sum = 0


for x in count.values():
    sum += x * (x - 1) // 2

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

Solution (Python):
from collections import Counter
n=int(input())
inp = list(map(int,input().split()))
c=Counter(inp)
ans=0
for item in c.values():
    ans+=(item*(item-1))//2
for i in range(len(inp)):
    x=c[inp[i]]
    y=(x-1)
    print (ans-(x*(x-1))//2+(y*(y-1))//2)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

T = 0
for k in a.keys():
    c = a[k]
    T += (c * (c-1)) // 2

for i in A:
    t = 0
    c = a[i]
    t = T
    t -= (c * (c-1)) // 2
    c -= 1
    t += (c * (c-1)) // 2
    print(t)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

T = 0
for k in a.keys():
    c = a[k]
    T += (c * (c-1)) // 2

for i in A:
    t = 0
    c = a[i]
    t = T
    t -= (c * (c-1)) // 2
    c -= 1
    t += (c * (c-1)) // 2
    print(t)

Solution (Python):


from sys import stdin, stdout

n = int(input())
arr = [int(x) for x in stdin.readline().split()]
store = dict()
store_grp = dict()
total = 0

for i in arr:
    try:
        if (store[i]):
            store[i] += 1
    except KeyError:
        store[i] = 1

for i,j in store.items():
    n = (j-1)
    value = int(((n)*(n+1))/2)
    store_grp[i] = value
    total += value

for i in arr:
    n = store[i]-2
    value = int(((n)*(n+1))/2)
    value = store_grp[i] - value
    print (total-value)

Solution (Python):
import sys
from collections import Counter
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

N, *A = map(int, read().split())
a = Counter(A)
s = sum(i * (i - 1) // 2 for i in a.values())
val = np.array([a[i] for i in A], np.int64)
answer = s - (val - 1)
print('\n'.join(map(str, answer.tolist())))

Solution (Python):
import sys
from collections import Counter
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

N, *A = map(int, read().split())
a = Counter(A)
s = sum(i * (i - 1) // 2 for i in a.values())
val = np.array([a[i] for i in A], np.int64)
answer = s - val * (val - 1) // 2 + (val - 1) * (val - 2) // 2
print('\n'.join(map(str, answer.tolist())))

Solution (Python):
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline

N, *A = map(int, read().split())
a = Counter(A)
s = sum(i * (i - 1) // 2 for i in a.values())

for i in A:
    v = a[i]
    answer = s - v * (v - 1) // 2 + (v - 1) * (v - 2) // 2
    print(answer)

Solution (Python):
import collections

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

counter = collections.Counter(A)

diffs = {k: v - 1 for k, v in counter.items()}
s = sum(v * (v - 1) // 2 for v in counter.values())

for v in A:
    print(s - diffs[v])

Solution (Python):
N=int(input())
A=list(input().split())
check=[0]*N
for i in range(N):
	check[int(A[i])-1]+=1
num=0
for i in range(N):
	num+=check[i]*(check[i]-1)//2
for i in range(N):
	if check[int(A[i])-1]!=2:
		print(num-(check[int(A[i])-1]-1))
	else:
		print(num-1)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
dic = {}
for i in arr:
    if i not in dic:
        dic[i]=1
    else:
        dic[i]+=1
ans=0
for j in dic.keys():
    t=dic[j]
    ans+=(t*(t-1))//2
for i in arr:
    sm = ans-(dic[i]-1)
    print(sm)

Solution (Python):
"""
"""
from math import factorial
from collections import defaultdict


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


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


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


cache = {}


def fac(x):
    return factorial(x)


def choose_combination(n, r):
    if r > n:
        return 0
    
    
    
    return (n * (n-1)) // 2


def solve(n, array):
    counts = defaultdict(int)
    for x in array:
        counts[x] += 1
    total_ways = 0
    for x, count in counts.items():
        total_ways += choose_combination(counts[x], 2)
    for k in array:
        ways = choose_combination(counts[k] - 1, 2)
        print(total_ways + ways - choose_combination(counts[k], 2))


N = read_int()
array = read_array()
solve(N, array)

Solution (Python):
N = int(input())
A = [int(a)-1 for a in input().split()]
X = [0] * N
for a in A:
    X[a] += 1
s = 0
for x in X:
    s += x * (x-1) // 2

for a in A:
    print(s - (X[a] - 1))

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

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

D = {}
for number in A:
  if not number in D:
    D[number] = 0
  D[number] += 1

sum = 0
for key in D:
  sum += hoge(D[key])

for number in A:
  print(sum - hoge(D[number]) + hoge(D[number]-1))

Solution (Python):
from math import factorial
N = int(input())
line = input()
l = []
counts = {}
for n in line.split(' '):
  n = int(n)
  if n not in counts:
    counts[n] = 0
  counts[n] += 1
  l.append(n)

comb = {}

for n in counts:
  comb[n] = 0
  count = counts[n]
  if count > 1:
    comb[n] += int(factorial(count)) // 2 // int(factorial(count - 2))

total = sum([comb[n] for n in comb])

for n in l:
  count = counts[n]
  result = total - comb[n]
  if count - 1 > 1:
    result += comb[n] * (count - 2) // count
  print(result)

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

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


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



CONB = [CNT[x]*(CNT[x]-1)//2 for x in range(len(CNT))]

SUM = sum(CONB)
for i in A:
    ans = SUM - CNT[i] + 1
    print(ans)

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

dic={}
for i in A:
    if i in dic.keys():
        dic[i]+=1
    else:
        dic.setdefault(i,1)

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

for k in A:
    print(hoge-(dic[k]-1))

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

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

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

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
S = set(A)
D = {}
for i in S:
    D[str(i)]=0
for i in range(n):
    D[str(A[i])]=D[str(A[i])]+1

ans = 0
for key in D:
    value = D[key]
    ans += value*(value-1)//2
for i in range(n):
    print(ans-   (D[str(A[i])]-1)  )

Solution (Python):
from collections import Counter





















































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

def nC2(n):
    return n * (n - 1) // 2
counter = Counter(A)

mapping = {}
for k, v in counter.items():
    mapping[k] = nC2(v)

all_sum = 0
for v in mapping.values():
    all_sum += v

memo = {}
for i in range(n):
    num = A[i]
    if num in memo:
        print(memo[num])
    else:
        t = counter[num]
        ans = all_sum - nC2(t) + nC2(t - 1)
        print(ans)
        memo[num] = ans

Solution (Python):
from collections import Counter

mod = (10 ** 9 + 7) ** 5
MAX = 2 * 10 ** 5 + 1 

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n, r):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

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

counter = Counter(A)

mapping = {}
for k, v in counter.items():
    mapping[k] = nCr(v, 2)

all_sum = 0
for v in mapping.values():
    all_sum += v

memo = {}
for i in range(n):
    num = A[i]
    if num in memo:
        print(memo[num])
    else:
        t = counter[num]
        ans = all_sum - nCr(t, 2) + nCr(t - 1, 2)
        print(ans)
        memo[num] = ans

Solution (Python):
from collections import Counter

mod = (10 ** 9 + 7) ** 5
MAX = 2 * 10 ** 5 + 1 

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n, r):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

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

counter = Counter(A)

mapping = {}
for k, v in counter.items():
    mapping[k] = nCr(v, 2)

all_sum = 0
for v in mapping.values():
    all_sum += v

memo = {}
for i in range(n):
    num = A[i]
    if num in memo:
        print(memo[num])
    else:
        t = counter[num]
        ans = all_sum - nCr(t, 2) + nCr(t - 1, 2)
        print(ans)
        memo[num] = ans

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

num_list = [0 for i in range(N)]


for n in A :
  num_list[n-1] += 1
  
calc_list = list(map(lambda x : max(0, int(x*(x-1)/2)), num_list))
s = sum(calc_list)

for k in range(N) :
  print(s - num_list[A[k]-1] + 1)

Solution (Python):
from collections import Counter


def choose(n, r):
    x, y = 1, 1
    for i in range(r):
        x *= n - i
        y *= i + 1
    return x // y


N = int(input())
*a, = map(int, input().split())

ctr = Counter(a)

b = 0
for cnt in ctr.values():
    b += choose(cnt, 2)

ret = []
for x in a:
    cnt = ctr[x]
    res = b - choose(cnt, 2) + choose(cnt - 1, 2)
    ret.append(res)

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

Solution (Python):
N = int(input())
ball_array = list(map(int, input().split()))
count_array = [0] * (N+1)
for i in ball_array:
    count_array[i] += 1
ans_max = 0

for i in count_array:
    ans_max += (i * (i-1) // 2)

for i in ball_array:
    count = count_array[i]
    print(ans_max - (count-1))

Solution (Python):
import collections 

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

num_count = collections.Counter()
for a in a_list:
    num_count[a] += 1
    
total_count = 0
for n in num_count:
    total_count += num_count[n] * (num_count[n]-1) / 2

def count(a):
    return int(total_count - (num_count[a]-1))

for n in range(N):
    print(count(a_list[n]))

Solution (Python):
from collections import Counter

N = int(input())
numbers = list(map(int, input().split()))
counter = Counter(numbers)

num_pairs = sum(
  (v * (v - 1)) // 2
  for v in counter.values()
)

for k in numbers:
  v = counter[k]
  print(num_pairs - (v * (v - 1)) // 2 + ((v - 1) * (v - 2)) // 2)

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

Solution (Python):
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    c = Counter(A)

    data = [0] * (N+1)
    sum_count = 0
    for i, v in c.items():
        if v < 2:
            continue
        value = v * (v - 1) // 2
        data[i] = value - value * (v - 2) // v
        sum_count += value

    print('\n'.join([str(sum_count - data[a]) for a in A]))

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
values, counts = zip(*c.most_common())
values, counts = list(values), list(counts)
k = 0
for i in range(len(counts)):
  k += counts[i]*(counts[i]-1)//2
output = [0]*len(a)
for i in range(len(a)):
  temp = c[a[i]]
  if temp == 1:
    output[i] = k
  else:
    output[i] = k-temp*(temp-1)//2+(temp-1)*(temp-2)//2
  print(output[i])

Solution (Python):
import glob
import bisect




REL_PATH = 'ABC\\159\\D'


TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def calc(self, num):
        if num < 2:
            return 0
        return num * (num-1) / 2

    def resolve(self):

        N = int(self.input_data())
        balls = [int(i)-1 for i in self.input_data().split()]
        balls_org = balls.copy()
        ball_count = [0 for i in range(N)]

        balls.sort()
        ptn_all = 0
        count = 0
        now = -1
        for b in balls:
            if b != now:
                if now != -1:
                    ball_count[now] = count
                ptn_all += self.calc(count)
                now = b
                count = 1
            else:
                count += 1

        if count > 1:
            ball_count[now] = count
            ptn_all += self.calc(count)

        for i in balls_org:
            print(str(int(ptn_all - self.calc(ball_count[i]) + self.calc(ball_count[i]-1))))



solver = Solver(REL_PATH)
solver.exec_resolve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A_dic = { x: 0 for x in set(A)}
for a in A:
    A_dic[a] += 1
res_norm = sum([x*(x-1)//2 for x in A_dic.values()])
for a in A:
    print(res_norm - A_dic[a] + 1)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A_dic = { x: 0 for x in set(A)}
for a in A:
    A_dic[a] += 1
res_norm = 0
for a in set(A):
    x = A_dic[a]
    res_norm += x*(x-1)//2
for a in A:
    x = A_dic[a]
    print(res_norm - x*(x-1)//2 + (x-1)*(x-2)//2)

Solution (Python):
import collections

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

T=sum(A[i]*~-A[i] for i in A)//2
for i in a:
  print(T-~-A[i])

Solution (Python):

from collections import Counter

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

c = Counter(A)



L = len(c)


def nCm(x):
    return x * (x - 1) / 2

c_list = list(c.keys())

All = 0
for i in range(L):
    All += nCm(c[c_list[i]])

for i in range(N):
    Ans = All - (c[A[i]]) + 1
    print(int(Ans))

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

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

Solution (Python):
import collections

n = int(input())
k = [int(a) for a in input().split()]
k_set = set(k)
all = 0
count_dic = collections.Counter(k)

for b in k_set:
    tmp = count_dic[b]
    all += tmp * (tmp - 1) // 2

for c in k:
    tmp = count_dic[c]
    print(all - (tmp - 1))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
import collections
import math
def c_c(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

B= collections.Counter(A)
l=0
for b in B.values(): 
  if b>=2:
    l+=c_c(b,2) 

for k in range(N):
  if B[A[k]]==0 or B[A[k]]==1:
    print(l)
  else:
    print(l-B[A[k]]+1)

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

cnt = [0 for i in range(n+1)]
for val in a:
    cnt[val] += 1
    
total = 0
for l in cnt:
    total += (l*(l-1))//2

for val in a:
    print(total - cnt[val] + 1)

Solution (Python):
import collections

n = int(input())
li = list(map(int, input().split()))
counter = collections.Counter(li)

sum_count = sum([n*(n-1)//2 for n in counter.values()])

for k in range(n):
    print(sum_count - counter[li[k]] + 1)

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

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

ans = sum(a*(a-1)//2 for a in Li)

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

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

val = {}
for a in A:
    if a not in val:
        val[a] = 0
    val[a] += 1

norm = sum(v * (v-1) // 2 for v in val.values())

for a in A:
    v = val[a]
    print(norm - v * (v-1) // 2 + (v-1) * (v-2) // 2)

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

def nc2(x): return x*(x-1)//2
dic = {i+1:0 for i in range(N)}
for a in A: dic[a] += 1

tmp = 0
for i in range(N):
    tmp += nc2(dic[i+1])

for i in range(1,N+1):
    print(tmp-dic[A[i-1]]+1)

Solution (Python):
N = int(input())
s = list(map(int,input().split()))
M = max(s)
count = [0] * (M+1)
for i in range(1,N):
    count[s[i]] += 1
ans = 0

for j in count:
    if j == 0:
        continue
    ans += int(j*(j-1)/2)
print(ans)
for i in range(1,N):
    ans += count[s[i-1]]
    count[s[i-1]] += 1
    count[s[i]] -= 1
    ans -= count[s[i]]
    print(ans)

Solution (Python):
from fractions import gcd
import sys

sys.setrecursionlimit(4100000)

def ols(): return input()
def oli(): return map(int, input().split())
def olai(): return list(map(int, input().split()))
def olas(): return list(input().split())
def mlai(L): return [int(input()) for _ in range(L)]
def mlas(L): return [input() for _ in range(L)]

def palindrome(S):
    return S == S[::-1]

n = oli()
a = olai()
num = [0] * 200001
for i in a:
    num[i]+=1
ans = 0
for i in num:
    ans += i*(i-1)//2

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

Solution (Python):
from fractions import gcd
import sys

sys.setrecursionlimit(4100000)

def ols(): return input()
def oli(): return map(int, input().split())
def olai(): return list(map(int, input().split()))
def olas(): return list(input().split())
def mlai(L): return [int(input()) for _ in range(L)]
def mlas(L): return [input() for _ in range(L)]

def palindrome(S):
    return S == S[::-1]

n = oli()
a = olai()
num = [0] * 200001
for i in a:
    num[i]+=1
ans = 0
for i in num:
    ans += i*(i-1)//2

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

Solution (Python):
from fractions import gcd
import sys

sys.setrecursionlimit(4100000)

def ols(): return input()
def oli(): return map(int, input().split())
def olai(): return list(map(int, input().split()))
def olas(): return list(input().split())
def mlai(L): return [int(input()) for _ in range(L)]
def mlas(L): return [input() for _ in range(L)]

def palindrome(S):
    return S == S[::-1]

n = oli()
a = olai()
num = [0] * 200001
for i in a:
    num[i]+=1
ans = 0
for i in num:
    ans += i*(i-1)//2

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

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):
    if cnt[A[i]-1] == 1:
        print(int(S))
    else:
        print(int(S+(3-2*cnt[A[i]-1])/2))

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

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

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):
    if cnt[A[i]-1] == 1:
        print(int(S))
    else:
        print(int(S+(3-2*cnt[A[i]-1])/2))

Solution (Python):
import math
import sys
from collections import Counter
N=int(input())
a=sys.stdin.readline().split()
A=[int(b) for b in a]
numbers=[0]*N
count=Counter(A)
kotae=0
for a in range(N+1):
    b=count[a]
    kotae+=b*(b-1)//2
for a in A:
    print(kotae+1-count[a])

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

tem = 0
ans = [0]*(n+1)

for i in x:
    tem += x[i] * (x[i] - 1) // 2
    ans[i] = x[i] - 1

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

Solution (Python):
from collections import Counter

n = int(input())
aaa = list(map(int, input().split()))
cnt = Counter(aaa)

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

buf = []
cache = {}
for a in aaa:
    if a in cache:
        buf.append(cache[a])
        continue
    c = cnt[a]
    ans = base - c * (c - 1) // 2 + (c - 1) * (c - 2) // 2
    buf.append(ans)
    cache[a] = ans
print('\n'.join(map(str, buf)))

Solution (Python):


import collections

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

if __name__ == "__main__":
    N, A = parse_input()
    counts = collections.defaultdict(int)
    for i in range(N):
        counts[A[i]] += 1

    total = 0
    subtracts = collections.defaultdict(int)
    for a, c in counts.items():
        num_patterns = max((c * (c - 1)) // 2, 0)
        subtracts[a] = num_patterns - max(((c - 1) * (c - 2)) // 2, 0)
        total += num_patterns

    for i in range(N):
        print(total - subtracts[A[i]])

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

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0

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

for j in A:
	cnt = counter[j]
	if cnt <= 1:
		print(ans)
	else:
		print(ans - cnt + 1)

Solution (Python):
from scipy.misc import comb
import collections
n = int(input())
c = list(map(int, input().split()))
collections.Counter(c)
cou = collections.Counter(c)
d = dict()
d2 = dict()
for i in cou:
    d[i] = comb(cou[i], 2, exact=True)
    d2[i] = comb(cou[i] - 1, 2, exact=True)

s = sum(d.values())
ans = [s - d[k] + d2[k] for k in c]
print(*ans, sep='\n')

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

for i in range(n):
    a_kosu[a_sort[i] - 1] = a_kosu[a_sort[i] - 1] + 1

sum = 0

for i in range(n):
    if a_kosu[i] != 0:
        sum = sum + int(a_kosu[i] * (a_kosu[i] - 1) / 2)
        
for i in range(n):
    ans[i] = sum - (a_kosu[a[i] -1] - 1)
    print(ans[i])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
c = [0 for i in range(N)]

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

ans = [c[i] * (c[i] - 1) // 2 for i in range(N)]
s = sum(ans)

for val in A:
  m = c[val - 1] - 1
  print(s - m)

Solution (Python):
from collections import Counter

n = int(input())
nums = [int(s) for s in input().split()]
counter = Counter(nums)
res = 0

for cnt in counter.values():
    res += (cnt - 1)*cnt // 2

for outlier in nums:
    cnt = counter[outlier]
    if cnt <= 1:
        print(res)
    else:
        print(res - cnt + 1)

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

list2 = [0]*(n+1)
list3 =[0]*(n+1)
list4 = []
for x in list:
  list2[x]+=1
 
for i in range(1,n+1):
    list3[i] = list2[i]*(list2[i]-1)/2

SUM=sum(list3)
for k in range(n):
    print(int(SUM-list2[list[k]]+1))

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

A_dict = dict()
for i in range(N):
    if A[i] in A_dict:
        A_dict[A[i]] += 1
    else:
        A_dict[A[i]] = 1
        
sum_all = 0
for k, v in A_dict.items():
    sum_all += v*(v-1)//2
    
for i in range(N):
    num = A_dict[A[i]]
    ans = sum_all - (num*(num-1)//2) + ((num-1)*(num-2)//2)
    print(ans)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    l = [0 for i in range(n)]
    for a_i in a:
        l[a_i - 1] += 1
    all = 0
    for x in l:
        all +=  x * (x - 1) // 2
    for y in a:
        print(all - l[y - 1] + 1)


if __name__ == "__main__":
    main()