peterverebics/CodeNet_Python_118 huggingface dataset:
def main():
    N = int(input())
    *a, = map(int, input().split())

    d = [0] * (N + 1)
    for x in a:
        d[x] += 1

    b = 0
    for x in d:
        b += x * (x - 1) // 2

    for x in a:
        t = b - (d[x] - 1)

        print(t)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
import collections
N = int(input())
A = list(map(int,input().split()))
dic = collections.Counter(A)
def helper(n):
    return n*(n-1)//2
ans = 0
for i in dic.keys():
    ans += helper(dic[i])
for i in A:
    print(ans-dic[i]+1)
from collections import defaultdict, Counter

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

#要素数の確認
C = Counter(A)

# 総パターンは普遍
k = 0
for i,j in C.items():
  if j == 1:
    k += 0
  else:
    k += j*(j-1)//2
# 自分の数字のパターンがへる
# delta = j(j-1)/2 - (j-1)(j-2)/2 = j - 1
d = defaultdict(int)
for i,j in C.items():
  if j == 1:
    d[i] = 0
  else:
    d[i] = j-1
    
for i in A:
  print(k-d[i])
import copy
N = int(input())
A = list(map(int, input().split()))

a_types = set(A)

count_dict = [0] * N
for each in A:
    count_dict[each - 1] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a - 1] + 1)
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
for i in balls:
    conbi[i-1] +=1
result = 0
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in balls:
    print(result-conbi[k-1]+1, end=" ")
import sys
#input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    l=[0]*(n+1)
    s=0
    for i in range(n):
        l[a[i]]+=1
    for i in range(n+1):
        if l[i]==0:
            continue
        else:
            s+=l[i]*(l[i]-1)//2
    for i in range(n):
        print(s-(l[a[i]]-1))

if __name__ == '__main__':
    main()
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
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c= Counter(A)
sum = 0
for i in c.values():
    sum += i * (i - 1) // 2
for i in A:
    print(sum - c[i] + 1)
n=int(input())
a=[int(i) for i in input().split()]
nC2=[0 for i in range(n+1)]
for i in range(2,n+1):
    nC2[i]=i*(i-1)//2
cnt=[0 for i in range(n)]
for i in a:
    cnt[i-1]+=1
res=0
for i in cnt:
    res+=nC2[i]
for i in a:
    print(res-nC2[cnt[i-1]]+nC2[cnt[i-1]-1])
N=int(input())
A=list(map(int,input().split()))

from collections import Counter

Num=Counter(A)

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

for k in range(N):
    n=Num[A[k]]
    ans=S-n*(n-1)//2+(n-1)*(n-2)//2
    print(ans)
n = int(input())
a = [int(i) for i in input().split()]

ball_count = [0] * (n + 1)

for i in a:
    ball_count[i] += 1
def nCr(i):
    if i<=1:
        return 0
    else:
        return i*(i-1)//2

def get_total(ball_count):
    ans = 0
    for i in ball_count:
        ans += nCr(i)
    return ans


total = get_total(ball_count)
for i in range(1, n + 1):
    num = ball_count[a[i - 1]]
    ans = total - nCr(num) + nCr(num-1)
    print(ans)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0
for k, v in counter.items():
    if 2 <= v:
        ans += v * (v - 1) // 2
for a in A:
    if a in counter and 2 <= counter[a]:
        v = counter[a]
        diff = v * (v - 1) // 2 - ((v- 1) * (v - 2) // 2)
        print(ans - diff)
    else:
        print(ans)
import collections
n=int(input())
a=list(map(int,input().split()))
b = collections.Counter(a)
total = 0

for i in b.values():
  total += i*(i-1)//2
  
for i in a:
  c = b[i]
  print(total-(c*(c-1)//2)+((c-1)*(c-2)//2))
import collections
n = int(input())
a = list(map(int,input().split()))
x = collections.Counter(a)
keys = []
values = []
b = list(set(a))
for i in b:
    z = x[i]
    keys.append(i)
    values.append(z*(z-1)//2)
s = sum(values)
d = dict(zip(keys,values))
for i in a:
    ans = s
    ans -= d[i]
    ans += (x[i]-1)*(x[i]-2)//2
    print(ans)
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (n+1)
for x in a: cnt[x] += 1
s = 0
for x in cnt: s += x * (x-1) // 2

for x in a:
    ans = s
    if cnt[x] >= 2: ans -= cnt[x]-1
    print(ans)
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)
from collections import Counter
def comb(x):
    return x*(x-1)//2
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
b = 0
for i in c.values():
    b+=comb(i)
for k in range(n):
    print(b-c[a[k]]+1)
from collections import defaultdict

n = int(input())
alst = list(map(int, input().split()))
ans = 0
dd = defaultdict(int)
for a in alst:
    dd[a] += 1
for _, num in dd.items():
    ans += num * (num - 1) // 2
for a in alst:
    num = dd[a]
    ret = ans - num * (num - 1) // 2 + (num - 1) * (num - 2) // 2
    print(ret)
from collections import defaultdict

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

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

S = sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2])

for i in range(N):
  print(S - A_dic[A[i]] + 1)
N = int(input())
A = list(map(int, input().split()))

a = list(set(A))
a_c = {}
for v in A:
  if v in a_c:
    a_c[v] += 1
  else:
    a_c[v] = 1

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

S = 0
for k in a_c:
  S += cmb(a_c[k])

for i in range(N):
  print(S - cmb(a_c[A[i]]) + cmb(a_c[A[i]]-1))
n=int(input())
a=list(map(int, input().split()))
a_list=[0]*(n+1)
for i in a:
  a_list[i]+=1
ans1=[0]*(n+1)
ans2=[0]*(n+1)
for i,m in enumerate(a_list):
  if m>=2:
    ans1[i]=m*(m-1)//2
    ans2[i]=(m-2)*(m-1)//2
all=sum(ans1)
for i in a:
  print(all-ans1[i]+ans2[i])
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

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

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

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

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

S //= 2

for i in lis:
    print(S - counts[i] + 1)
from collections import Counter

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

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

c = Counter(a)
s = 0

for i in c.values():
    s += combination2(i)

for i in a:
    n = c[i]
    ans = s - combination2(n) + combination2(n-1)
    print(ans)
import collections
N = int(input())
A = list(map(int,input().split()))

c = collections.Counter(A)
cc = c.items()

f_ans = 0
for m,n in cc:
  f_ans += n*(n-1)/2

for i in range(N):
  a = A[i]
  b = c[a]
  sa = b*(b-1)/2 - (b-1)*(b-2)/2

  print(int(f_ans - sa))
N=int(input())
A=list(map(int,input().split()))
num_A = [0]*(N+1)
for a in A:
  num_A[a]+=1

s=0
for n in num_A:
  s+=n*(n-1)//2
#print(s)
for a in A:
  ans = s - (num_A[a]*(num_A[a]-1)//2) + ((num_A[a]-1)*(num_A[a]-2)//2)
  print(ans)
import sys
myin = [x.rstrip() for x in sys.stdin.readlines()]

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

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

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)
N=int(input())
m=list(map(int,input().split()))
t=[]
for i in range(N):
  t.append(0)
for i in range(N):
  t[m[i]-1]+=1
total=0
for i in range(N):
  total+=(t[i]*(t[i]-1))//2
for i in range(N):
  if t[m[i]-1]<2:
    print(total)
  else:
    print(total-(t[m[i]-1]-1))
def conbination_2(n):
  if n <= 1:
    return 0
  else:
    return int(n * (n - 1) / 2)


N = int(input())
A = list(map(int,input().split()))
S = 0
Count = [0] * N

for i in range(N):
  Count[A[i] - 1] += 1
  
for i in range(N):
  S += conbination_2(Count[i])
  
for i in range(N):
  Ans = S - (Count[A[i] - 1] - 1)
  print(Ans)
import copy
from collections import Counter

l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
c = Counter

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

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

count = 0
C = Counter(A)
for num in C.values():
    count += num*(num-1)//2
#print(count)

for a in A:
    print(count - (C[a] - 1))
import collections

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

N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = list(c.values())
d2 = sum([c2c(i) for i in c_l])
#print(d2)

for i in range(len(A)):
    print(d2-(c[A[i]]-1))
def resolve():
    import collections

    N = int(input())
    A_list = [int(item) for item in input().split()]
    origin_dict = collections.Counter(A_list)

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

    for j in range(N):
        deff = origin_dict[A_list[j]] -1

        print(twopair_in_N - deff)
    

if __name__ == "__main__":
    resolve()
import collections
N=int(input())
A=list(map(int,input().split()))
S=collections.Counter(A)
s=list(S.values())
num=0
for i in s:
  num+=i*(i-1)/2
for i in A:
  tmp=S[i]-1
  ans=int(num-tmp)
  print(ans)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
total = 0
for k, v in c.items():
  total += v* (v-1)/2
for a in A:
  print(int(total - c[a]+1))
from collections import Counter
from sys import stdin

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

cnt = Counter(A)


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


sumall = 0

for i in cnt.values():
    sumall += comb(i)

for a in A:
    ans = sumall - (cnt[a] - 1)
    print(ans)
from sys import stdin,setrecursionlimit
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = [0]*(n+1)
for i in li:
    lin[i] += 1
liv = [0]*(n+1)
point = 0
for j,k in enumerate(lin):
    point += k*(k-1)//2
    liv[j] += k*(k-1)//2
for i in li:
    print(point-liv[i]+(lin[i]-1)*(lin[i]-2)//2)
n = int(input())
a = [int(_) for _ in input().split()]

num_cnt = [0] * 200001
for i in a:
    num_cnt[i] += 1

pat_cnt = [0] * 200001
for i in range(200001):
    b = num_cnt[i]
    pat_cnt[i] = (b*(b-1))//2

ans = sum(pat_cnt)

for i in range(n):
    #print(ans, pat_cnt[a[i]], num_cnt[a[i]])
    print(ans - pat_cnt[a[i]] + ((num_cnt[a[i]]-1) * (num_cnt[a[i]]-2))//2)
n = int(input())
data = [int(x) for x in input().split()]
cnt = [0]*(n+1)

# ボールに書かれた整数を集計する
for x in data:
    cnt[x] += 1

total = int(sum([x*(x-1)/2 for x in cnt]))

for k in range(n):
    answer = total - cnt[data[k]] + 1
    print(answer)
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[0]*(n+1)
for i in range(n):
    b[a[i]]+=1
for k in b:
    ans+=k*(k-1)//2
for i in range(n):
    print(ans-b[a[i]]+1)
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
st = 0
for i in dic.values():
    st += i*(i-1)//2
for i in range(n):
    j = a[i]
    if dic[j] == 1:
        print(st)
    else:
        d = dic[j]
        print(st-d*(d-1)//2 + (d-1)*(d-2)//2)
n = int(input())
A = list(map(int, input().split()))
num = [0]*n
for i in A:
  num[i-1] += 1
def comb(n):
    if n < 2:
      return 0
    else:
      return n * (n-1) // 2
ans_sub = 0
for i in num:
  ans_sub += comb(i)
for i in A:
  if num[i-1] < 2:
    a = 0
  else:
    a = num[i-1]-1
  print(ans_sub-a)
import bisect

n = int(input())
a = list(map(int, input().split()))
A = sorted(a)
s = [0]*(n+1)
b = [0]*(n+1)
c = []
for i in range(1, n+1):
    x = a[i-1]
    s[i] = bisect.bisect_right(A, x) - bisect.bisect_left(A, x)
    if b[a[i-1]] == 0:
        c.append(s[i]*(s[i]-1)//2)
        b[a[i-1]] = 1
S = sum(c)
# print(c)
for i in range(1, n+1):
    print(S - s[i] + 1)
from collections import Counter

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

Count = Counter(A)
s = sum(x * (x-1) // 2 for x in Count.values())

for a in A:
  print(s - Count[a] + 1)
N  = int(input())
A = list(map(int, input().split()))
count = [0]*(N)
for i in range(N):
  count[A[i]-1] += 1
total = 0
for i in range(N):
  s = count[i]
  total += s*(s-1)/2
for i in range(N):
  j = count[A[i]-1]
  ans = total-j*(j-1)/2+(j-1)*(j-2)/2
  print(int(ans))
import math

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
for i in a:
    d=mycounter(d,i)
p=sum([ABC159D(i) for i in d.values()])
for i in a:
    print(p-d[i]+1)
n = int(input())
l = [int(x) for x in input().split()]
k = [0]*n
for i in range(n):
  k[l[i] - 1] = k[l[i] - 1] + 1
def motomeru(i):
  return int((k[i-1])*(k[i-1]-1)/2)
def herasu(i):
  if k[i-1] == 0 or k[i-1] == 1:
    return 0
  else:
    return int((k[i-1]-1)*(k[i-1]-2)/2)
zenbu = 0
for i in range(n):
  zenbu = zenbu + motomeru(i+1)
for i in range(n):
  a = zenbu - motomeru(l[i]) + herasu(l[i])
  print(a)
import collections

def combinations_count(n, r):
    return n * (n-1) // r


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

l1 = []
l2 = []
c = collections.Counter(l)

total = sum([combinations_count(i, 2) for i in c.values()])

for a in l:
    l1.append(combinations_count(c[a], 2))
    l2.append(combinations_count(c[a]-1, 2))
# print(l1, l2)
for i in range(len(l)):
    print(total-l1[i]+l2[i])
import collections
N = int(input())
A = list(map(int, input().split()))

A_num = collections.Counter(A)
values, counts = zip(*A_num.most_common())

ans = 0

for i in values :
  num = int(A_num[i])
  ans += num * (num - 1 ) // 2

for j in A :
  print(ans - int(A_num[j]) + 1 )
import collections
import math
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
zenbu = 0
for i in c.values():
    zenbu += i*(i-1)//2

for i in range(N):
    part = c[A[i]]-1
    print(zenbu-part)
from collections import Counter

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

cA = Counter(A)

binomials = [0, 0, 1]
for i in range(3, max(cA.values()) + 1):
    binomials.append(binomials[-1] * i // (i - 2))

ans0 = sum(binomials[v] for v in cA.values())

for a in A:
    print(ans0 - binomials[cA[a]] + binomials[cA[a] - 1])
n = int(input())
a = list(map(int, input().split()))

# a_set = sorted(set(a))

count = [0] * (n + 1)


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


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

for i in a:
    print(sum - (count[i] - 1))
from collections import Counter
N, li = int(input()), list(map(int, input().split()))
cnt_dict, cnt_total = Counter(li), 0
cnt_total =sum([i[1] * (i[1]-1) // 2 for i in cnt_dict.items()])
for k in range(N):
    print(cnt_total - cnt_dict[li[k]]*(cnt_dict[li[k]]-1)//2 + (cnt_dict[li[k]]-1)*(cnt_dict[li[k]]-2)//2)
def nC2(n):
    return n*(n-1)//2

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

cnt = [0]*(n+1)
total = 0
ans = 0

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

for i in range(1, n+1):
    total += nC2(cnt[i])

for i in range(n):
    print(total - nC2(cnt[a[i]]) + nC2(cnt[a[i]] - 1))
n = int(input())
a = list(map(int, input().split()))
l = [0]*10**6
ans1 = 0
for i in a:
    l[i] += 1
for i in l:
    ans1 += i*(i-1)/2
for i in a:
    print(int(ans1-(l[i]-1)))
import sys
def input():
    return sys.stdin.readline()[:-1]


import collections
def main():
    N = int(input())
    A = list(map(int,input().split()))
    c = collections.Counter(A)
    total = 0
    for j in c.values():
        total += j * (j - 1) / 2
    for i in range(N):
        k = c[A[i]]
        before = k * (k - 1) / 2
        after = (k -1) * (k - 2) / 2
        ans = total - before  + after
        print(int(ans))

if __name__ == "__main__":
    main()
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)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

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

for i in A:
    ans = comb - (c[i]-1)
    print(ans)
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)

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

for a in A:
    k = B[a]
    print(ans - (k*(k-1)//2)+((k-1)*(k-2)//2))
n = int(input())
num_list =  list(map(int,input().split()))
num_list2 = [0]*n
num_list3 = [0]*n
for i in num_list:
    num_list2[i-1] += 1
for i in range(n):
    ans = num_list2[i]*(num_list2[i]-1)//2
    num_list3[i] = ans
sum_V = sum(num_list3)
for i in num_list:
    ans = (num_list2[i-1]-1)*(num_list2[i-1]-2)//2
    print(ans-num_list3[i-1]+sum_V)
from collections import Counter
from math import factorial
N=int(input())
A=list(map(int,input().split()))
B=Counter(A)
count=0
def combination(x,y):
    return factorial(x) // (factorial(x - y) * factorial(y))
for key,b in B.items():
    if b>=2:
        count+=combination(b,2)
for a in A:
    ans=count
    ans-=B[a]-1
    print(ans)
N = int(input())
lis = input().split()

count_list = [0] * (N + 1)

for k in lis:
  count_list[int(k)] += 1

Sum = 0
for k in count_list:
  Sum += ( k * (k-1)) // 2



for i in lis:
  count = count_list[int(i)]
  s = int(count) - 1
  ans = Sum - s
  print(ans)
N = int(input())
K = list(map(int,input().rstrip().split()))
CK = [0 for i in range(N + 1)]
ans = 0
for i in K:
  CK[i] += 1
for i in range(N + 1):
  ans += CK[i] * (CK[i] - 1) /2
for i in range(N):
  bans = ans - CK[K[i]] * (CK[K[i]] -1 ) / 2 + (CK[K[i]] -1) * (CK[K[i]] -2) / 2
  print(int(bans))
n = int(input())
l = list(map(int,input().split()))
from collections import Counter
c = Counter(l)
v = list(c.values())
s = 0
for i in v:
  s += i*(i-1)//2
for i in l:
  print(s-(c[i]-1))
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = {}
sum = 0
for i in c:
    k = c[i]
    sum += k * (k - 1) / 2
for i in range(n):
    print(int(sum - c[a[i]] + 1))
from collections import defaultdict

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

yag = defaultdict(int)

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

result = 0
for i in yag.keys():
    t = yag[i]
    result += (t*(t-1))//2

for i in a:
    t = yag[i]
    print(result - (t*(t-1))//2 + ((t-1)*(t-2))//2)
from collections import Counter


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


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


def solve():
    N = read_int()
    A = read_ints()
    counter = Counter(A)
    total = 0
    for count in counter.values():
        total += count*(count-1)//2
    for a in A:
        if counter[a] > 1:
            print(total-(counter[a]-1))
        else:
            print(total)


if __name__ == '__main__':
    solve()
N = int(input())
A = list(map(int, input().split()))
B = [-1 for i in range(2*100000)]

ans = 0
for a in A:
    B[a-1] += 1

    if B[a-1] != 0:
        ans += B[a-1]


A.append(0)
ans -= B[A[0] - 1]
for k in range(N):
    print(ans)
    ans += B[A[k] - 1] - B[A[k+1] - 1]
import sys
import math
from collections import Counter

n = int(sys.stdin.readline().strip())
a = [int(s) for s in sys.stdin.readline().strip().split()]
c = Counter(a)

total = 0
for key, val in c.items():
    total += val * (val-1) // 2

for i in range(n):
    ai = a[i]
    ai_count = c[ai]

    original = ai_count * (ai_count-1) // 2
    updated = (ai_count-1) * (ai_count-2) // 2
    print(total - original + updated)
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(A)
C = {key:(B[key]*(B[key]-1)//2) for key in B}
ans = sum(C.values())
#print(C,ans)
#print(C[3])
for i in A:
    if C[i] < 1:
        print(ans)
    else:
        print(ans - C[i] + (B[i]-1)*(B[i]-2)//2)
from collections import Counter
import time

N = int(input())
line = list(map(int, input().split()))
dic = Counter(line)
nums = 0
for num, cnt in dic.items():
    if cnt > 1:
        nums += (cnt * (cnt - 1)) // 2
for i in line:
    print(nums - (dic[i] - 1))
from scipy.misc import comb
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)

#print(C)
ans = 0
for k,v in C.items():
  ans += v * (v-1) // 2
  
for a in A:
  cnt = C[a]
  if cnt > 0:
    print(ans - cnt*(cnt-1)//2 + (cnt-1)*(cnt-2)//2)
  else:
    print(ans)
n = int(input())
an= list(map(int, input().split()))
 
datas = [0] * (n+1)
for a in an:
    datas[a] += 1
 
ans = 0
for i in range(1,n+1):
    if datas[i] > 1:
        ans += datas[i] * (datas[i]-1)/2
ans = int(ans)
 
for k in range(0,n):
    if datas[an[k]] > 1:
        print(int(ans - datas[an[k]] * (datas[an[k]]-1)/2 + (datas[an[k]]-1) * (datas[an[k]]-2)/2))
    else:
        print(ans)
n = int(input())
a = list(map(int,input().split()))
c = [0 for _ in range(n+1)]
r = []
for i in range(n):
    c[a[i-1]-1] += 1
for i in range(n):
    r.append(c[i])
kai = []
v = []
for i in range(len(r)):
    kai.append((r[i]*(r[i]-1)//2))
    v.append(kai[i] - max(((r[i]-1)*(r[i]-2)//2),0))
#print(v,kai)
ans = sum(kai)
for i in range(len(a)):
    print(ans - v[a[i]-1])
l = int(input())
a = list(map(int, input().split()))

from collections import Counter

count_dic = Counter(a)


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

for k in a:
    print(int(all_count - (count_dic[k] - 1)))
#!/usr/bin/env python3

import collections

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

c = collections.Counter(A)
values = c.keys()
counts = c.values()

subs = {}
a_sum = 0
for v, c in zip(values, counts):
    subs[v] = c
    a_sum += (c * (c-1)) // 2

for i in range(N):
    print(a_sum - subs[A[i]] + 1)
import sys
import collections

ni = lambda: int(sys.stdin.readline())
nl = lambda: list(map(int, sys.stdin.readline().split()))

N = ni()
A = nl()
counter = collections.Counter(A)
total = 0
for n in counter.values():
    total += n * (n - 1) // 2
for i in range(N):
    n = counter[A[i]]
    k = total - (n * (n - 1) // 2) + (n - 1) * (n - 2) // 2
    print(k)
n=int(input())

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

memo = [0]*(2*10**5+1)

for i in t:
    memo[i] += 1

ans = 0

for i in memo:
    ans += i*(i-1)//2

for i in t:
    print(ans-(memo[i]*(memo[i]-1)//2)+((memo[i]-1)*(memo[i]-2)//2))
n = int(input())
a = list(map(int,input().split()))

import collections
count = collections.Counter(a)

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

# print(count)
s = 0
cmb = {}
for i in count.keys():
    cmb[i] = (c(count[i], 2),c(count[i] - 1, 2))
    s += cmb[i][0]
# print(s)
# print(cmb)

for i in range(n):
    ans = s - cmb[a[i]][0] + cmb[a[i]][1]
    print(ans)
import copy
N = int(input())
A = list(map(int, input().split()))
A_sum = 0
A2 = []
idx = dict()

for i in A:
  if i in idx:
    idx[i] += 1
  else:
    idx[i] = 1
    
for key in idx:
  if idx[key] == 1:
    idx[key] = [idx[key], 0]
  else:
    temp = int(idx[key] * (idx[key] - 1)/2)
    A_sum += temp
    temp = temp - int(temp * (idx[key] - 2) / idx[key])
    idx[key] = [idx[key], temp]
  
for i in range(N):
  key = A[i]
  print(A_sum - idx[key][1])
import copy

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

c=0

a_uniq=[0]*(n+1)

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

for i in a_uniq:
  c+=sum(range(1,i))
#a_uniq=list(set(a))
#for i in a_uniq:
#  c+=sum(range(1, a.count(i)))

for i in a:
  print('{:.0f}'.format(c-a_uniq[i]+1))