peterverebics/CodeNet_Python_118 huggingface dataset:
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):
    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]])
import collections
n=int(input())
a=list(map(int,input().split()))
c = collections.Counter(a)

a1=len(list(set(a)))

total=0
for j in range(a1):
    x=c.most_common()[j][1]
    total+=x*(x-1)/2
    print('total',total)

for i in range(n):
    ans=total-a.count(a[i])+1
    print(int(ans))
def combination(n,r,mod=10**9+7):
  n1,r = n+1, min(r,n-r)
  numer = denom = 1
  for i in range(1, r+1):
    numer = (numer*(n1-i)) % mod
    denom = (denom*i) % mod
  return numer * pow(denom, mod-2, mod) % mod

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

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

total = 0
for i in d:
  if d[i] > 1:
    total += combination(d[i],2)

for i in a:
  ans = total - (d[i]-1)
  print(ans)
n = int(input())
an = list(map(int, input().split()))
n_list = [0]*n

for i in range(n):
  n_list[an[i]-1] += 1

for j in range(n):
  n_list1 = n_list[:]
  n_list1[an[j]-1] -= 1
  answer = 0
  for k in n_list1:
    answer += k*(k-1)/2
  print(answer)
import itertools as iter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [A.count(i) for i in range(N+1)]
    comb = sum((int(i*(i-1)/2) for i in nums))
    for k in range(1, N+1):
        print(comb-A[k-1])

if __name__ == '__main__':
    main()
import collections
N = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
L = {key:(B[key] * (B[key] - 1) // 2) for key in B}
total = sum(L.values())
#print(f"A = {A}\nB = {B}\nL = {L}\ntotal = {total}")
[print(0 if L[i] == 0 else total - L[i] + ((B[i] - 1) * (B[i] - 2)) // 2) for i in A]
from math import factorial

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

def combination(n,r):
  if n < 2:
    return 0
  else:
    print(factorial(n) / factorial(r) / factorial(n-r) )
    return factorial(n) / factorial(r) / factorial(n-r)

lens = []
ans = 0
for p in range(N):
  lens.append(An.count(p))
for p in range(N):
  lend = lens.copy()
  if lend[p] == 0:
    continue
  else:
    lend[p] -= 1
  for k in range(N):
    ans += combination(lend[k], 2)

print(int(ans))
n=int(input())

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

X=[0]*(n+1)

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

ans=0

for i in range(n):
    if X[i]>1:
        ans+=X[i]*(X[i]-1)//2      
for i in range(n):
    if X[A[i]]==1:
        print(ans)
    elif X[A[i]]>1:
        print(ans-(X[A[i]]-1))
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5)+10)
for i in range(N):
    li[A[i]]+=1
for j in range(N):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-(li[A[k]]*(li[A[k]]-1))//2+((li[A[k]]-1)*(li[A[k]]-2))//2)
n = int(input())
a = list(map(int, input().split()))
for i in range(0, n):
    ai = list(a)
    del ai[i]
    count = -1
    for x in range(len(a)):
        for y in range(x, len(a)):
            if x == y:
                count += 2
    print(count)
n = int(input())
a = [int(i) for i in input().split()]

ball = [0]*(n+1)

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

zenbu = 0
    
for i in range(n):
    tmp = ball[i]
    if tmp > 1:
        zenbu += (tmp*(tmp-1))//2
        
for i in range(n):
    tmp = ball[a[i]]
    if tmp > 1:
        #sabun = (tmp*(tmp-1))//2 - ((tmp-1)*(tmp-2))//2
        print(zenbu-(tmp-1))
    else:
        print(zenbu)
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
  n = int(input())
  a = list(map(int, input().split()))
  c = collections.Counter(a)
  s = 0
  for i in list(c.values()):
    s += i*(i-1)//2
  print(c)
  for i in a:
    print(c[i])
    print(s-(c[i]-1))
  return 0
 
if __name__ == "__main__":
  solve()
def comb2(a):
  if a < 2: return 0
  return a * (a - 1) / 2
N = int(input())
A = list(map(int, input().split()))
dp = [[0, 0] for i in range(N+1)]
for i in range(N):
  dp[A[i]][0] += 1
x = 0
for i in range(N):
  dp[i][1] = comb2(dp[i][0])
  x += dp[i][1]
for i in range(N):
  print(int(x - (dp[A[i]][0]-1)))
from collections import Counter
n = int(input())
a = map(int, input().split())
counter = Counter(a)

ans = 0
for i in counter.values():
    ans += i * (i - 1) // 2
for ai in a:
    print(ans - (counter[ai] - 1))
from collections import Counter

n = int(input())
a = input().split()
freq = Counter(a)
print(freq)
total=0
    
for key,val in freq.items():
    total+=(val*(val-1))//2

for k in range(n): 

    kth = (freq[a[k]]*(freq[a[k]]-1))//2
    newkth = ((freq[a[k]]-2)*(freq[a[k]]-1))//2  

    total -= kth
    total += newkth
    
    print(total)
    
    total -=newkth
    total +=kth
import sys
N=int(sys.stdin.readline())
L=list(map(int,sys.stdin.readline().split()))
count=[0]*N
C=list(set(L))
x=0
for i in range(len(C)):
  x += int((L.count(C[i]))*(L.count(C[i])-1)/2)  
for K in range(N):
  print(x-L.count(L[K])-1)
from collections import Counter

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

for i in range(k):
    b = 0
    x = a.pop(a[i])
    count = Counter(a)
    a.insert(i, x)
    x = ""
    for k,v in count.items():
        if v == 1:
            b += 0
        else:
            b += v * (v-1) / 2
    print(int(b))
N = int(input())
A = list(map(int, input().split()))
count = [0] * (N + 1)

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

total = 0

for i in range(N):
    if count[i] > 1:
        total += count[i] * (count[i] - 1) / 2

for i in range(N):
    num = A[i]
    if count[num] > 2:
        result = total - (count[num] * (count[num] - 1) / 2) + ((count[num] - 1) * (count[num] - 2) / 2)
    elif count[num] == 2:
        result = total - 1
    else:
        result = total
    print(int(result))
import math
import numpy as np

N = int(input())
arr = np.array(list(map(int, input().split(" "))))
#val, count = np.unique(arr, return_counts=True)
count = np.bincount(arr)

for i in range(len(arr)):
    k_val = arr[i]
    count[k_val] -= 1
    conv = (count * (count - 1) / 2).astype(int)
    print(np.sum(conv))
import itertools

# 入力
N = int(input())
An = [int(x) for x in input().split()]

# 組み合わせ
L = []
for i in range(0,N+1):
    l = [0] * i
    L.append(len(list(itertools.combinations(l,2))))
    
# 各数字の個数を求める
Cn = [An.count(i) for i in range(1,N+1)]

# 全部の組み合わせ
Dn = [L[Cn[i-1]] for i in range(1,N+1)]
s = sum(Dn)
import collections


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

    counter = collections.Counter(A)
    ans = 0

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

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


resolve()
#!/usr/bin/python3


def nC2(x):
    if x == 1 or x == 0:
        return 0
    else:
        return x * (x - 1) // 2


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

C = [0] * (N + 1)
C2 = [0] * (N + 1)
for i in A:
    C[i] += 1
for i in range(N):
    C2[i] = nC2(C[i])
sumup = sum(C2)

for k in A:
    print(sumup - C2[k] + nC2(C[k] - 1))
import math
N = (int(input()))
items = list(map(int,input().split()))
for i in range(len(items)):    
    rest = items[:i] + items[i+1:]
    rest_unique = list(set(rest))
    out = 0
    for j in rest_unique:
        cnt = sum([1 for x in rest if x == j])
        if cnt < 2:
            out = out
        else:
            out = out + math.factorial(cnt)/math.factorial(cnt-2)/2
    print(out)
import copy
import math
import collections
def comb(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
#A
N = int(input())
A = list(map(int, input().split()))
count = collections.Counter(A)
ans = [0]*N
for i in range(2,N):
    ans[i] = comb(i, 2)
#print(ans)
for i in range(N):
    arr = copy.copy(count)
    arr[A[i]] -= 1
    cnt = 0
    #print(count)
    for num in count:
        cnt += ans[arr[num]]
    #print(cnt)
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    comb = 0
    for i in c.values():
        if i >= 2:
            comb += i*(i-1)/2
    for i in range(N):
        print(comb - (c[A[i]] - 1))

if __name__ == '__main__':
    main()
n = int(input())
ball = list(map(int,input().split()))

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

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

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

for i in range(n):
    print(x - data[ball[i]] + sentaku[ball[i]])
# coding: utf-8

import collections
import copy

# 標準入力 <int>
N = int(input())

# 標準入力 <str> list[]
A = list(map(str, input().split()))

print(A)
for _N in range(N):
  A2 = copy.copy(A)
  del A2[_N]
  c = collections.Counter(A2)
  ans = 0
  for v in c.values():
    if v >= 2:
      ans += int(((v * (v - 1)) / 2))
  print(ans)
import sys
input=sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
nCr = {}
def cmb(n):
    if n == 1:
        return 0
    else:
        return n * n-1 /2
mydict = {}
for i in range(N):
    a = A[i]
    if a in mydict.keys():
        mydict[a] += 1
    else:
        mydict[a] = 1
s = 0
for i in range(N):
    a = A[i]
    s += cmb(a)
for i in range(N):
    a = A[i]
    x = mydict[a] - 1
    print(s-x)
from collections import Counter
from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
all_comb = 0
for v in c.values():
    all_comb += v*(v-1)/2

for i in range(n):
    tmp = c[a[i]]
    print(all_comb-tmp+1)
#input
N = int(input())
A = list(map(int, input().split()))

#output
from collections import  Counter
L = Counter(A)

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

for i in range(N):
    if L[A[i]] == 1:
        print(original_answer)
    elif L[A[i]] == 2:
        print(original_answer -1)
    elif L[A[i]] > 2:
        print(original_answer - L[A[i]]*(L[A[i]]-1)//2 + (L[A[i]]-1)*(L[A[i]]-2)//2)
import collections
n=int(input())
a=list(map(int,input().split()))
ct=[0 for i in range(n+1)]
for i in range(n):
  ct[a[i]]+=1
ans=0
for i in range(n):
  ans+=ct[i]*(ct[i]-1)//2
for i in range(n):
  print(ans-ct[a[i]]+1)
import collections

N = int(input())
A = list(map(int,input().split()))
AS = set(A)
print(AS)
def comb(n):
    return n*(n-1)//2

L = collections.Counter(A)

for i in range(N):
    ans = 0
    for a in AS:
        if A[i] == a:
            ans += comb(L[a]-1)
        else:
            ans += comb(L[a])
    print(ans)
from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

if all_count == 0:
    all_count = 1

for i in a_list:
    print(all_count - c[i])
import collections 
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
c=defaultdict(int)
for s in a:
    c[s]+=1

a1=list(set(a))

total=0
for j in range(len(a1)):
    x=c[a[j]]
    total+=x*(x-1)/2


for i in range(n):
    ans=total-c[a[i]]+1
    print(int(ans))
import sys
input = sys.stdin.readline
import math
import collections

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

_ = int(input())
ns = input().split(" ")
cs = collections.Counter(ns)

c = 0
for n in ns:
	for k, v in cs.items():
		if v==1:
			c += 0
		elif n==k:
#			c += math.factorial(v-2)
			c += combinations_count(v-1, 2)
		else:
#			c += math.factorial(v-1)
			c += combinations_count(v, 2)
	print(c)
	c = 0
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):
    b=count[a]
    kotae+=b*(b-1)//2
for a in A:
    print(kotae+1-count[a])
N = int(input())
A = list(map(int, input().split()))

ANSWER = []
for i in range(N):
    A_ = A.copy()
    del A_[i]
    unique_i = list(set(A_))

    answer_i = 0
    for j in unique_i:
        answer_i += (A_.count(j) * (A_.count(j)-1)/2)
    
    ANSWER.append(int(answer_i))
import math
import collections
def calc_combi2(n):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))
n=int(input())
data=list(map(int,input().split()))
data_cnt=collections.Counter(data)
count=0
for i in data_cnt.values():
    if 2<=i:
        count+=calc_combi2(i)
for i in data:
    if i<=1:
        print(count)
    else:
        ans=count+(calc_combi2(data_cnt[i]-1)-calc_combi2(data_cnt[i]))
        print(int(ans))
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(N)]
ans = []
for i in A:
    num[i-1]+=1
sums = 0
for i in A:
    num[i-1]-=1
    for j in range(N):
        if num[j] > 1:
            sums += 1/2*num[j]*(num[j]-1)
    ans.append(int(sums))
    sums = 0
    num[i-1]+=1

print(ans)
n = int(input())
A = list(map(int, input().split()))
num = [0]*n
import numpy as np
for i in A:
  num[i-1] += 1
num = np.array(num)
def comb(n):
    if n < 2:
      return 0
    else:
      return n * (n-1) // 2
ans_sub = np.sum(np.array(num))
for i in A:
  if num[i-1] < 2:
    a = 0
  else:
    a = num[i-1]-1
  print(ans_sub-a)
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

for i in A:
    t = 0
    for k in a.keys():
        c = a[k]
        if k == i:
            c -= 1
        t += (c * (c-1)) // 2
    print(t)
from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

print(all_count)

for i in range(n):
    print(all_count - c[i])
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N+1)

ans1=0
s=0

for A_i in A:
    C[A_i]+=1

for j in range(N):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
        
for A_k in A:
    d=C[A_k]
    if d<2:
        ans=ans1
    else:
        ans=ans1-(d-1)
    print(int(ans))
n = int(input())
l = list(map(int, input().split()))

import collections
 
c = collections.Counter(l)
ans = 0

for i in c.values():
    ans += i * (i - 1) // 2
    
for i in l:
    print(ans - c[i] - 1)
N=int(input())
A=list(map(int,input().split()))
B=A
S=list(set(B))
m=[]
for i in range(len(S)):
  B.remove(S[i])
  sum=0
  for j in range(len(S)):
    a=B.count(S[j])
    if a!=1:
      sum+=a*(a-1)//2
  m.append(sum)
  B.append(S[i])
for i in range(N):
  for j in range(len(S)):
    if A[i]==S[j]:
      print(m[j])
import collections
N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
ans = 0
for i in range(N):
  ans+=c[i]*(c[i]-1)//2

for i in range(N):
  print(ans-(c[A[i]]-1)) if c[A[i]]>1 else print(ans)
N = int(raw_input())
A = map(int, raw_input().split())


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

sumN = 0
for i in range(N):
    sumN = sumN + int(count[i]*(count[i]-1)/2)

#print answer
for i in range(N):
    id = A[i]
    sumz = sumN - int(count[id]*(count[id]-1)/2)
    sumz = sumz + int((count[id] - 1)*(count[id] - 2)/2)
    print(sumz)
from collections import Counter

N = int(input())
A_array = map(int, input().split())
Ai_dict = Counter(A_array)


def calc_comb(Ai, dictionary):
    num = 0
    for k,v in dictionary.items():
        if k == Ai:
            N_Ai = v -1 #1こ抜いた数. 
        else:
            N_Ai = v
        num += N_Ai*(N_Ai-1)/2
    return int(num)

for n in A_array:
    print(calc_comb(n, Ai_dict))
n = int(input())
a = list(map(int, input().split()))

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

ways = 0
for i in a:
    ways += c[i]*(c[i]-1)//2

for k in a:
    ans = ways-c[k]+1
    print(ans)
def f(n):
    if n==0:
        return 0
    return n*(n-1)/2
N=int(input())
A=list(map(int,input().split()))
if len(set(A))==N:
    print(0)
    exit()
d=dict()
for i in range(N):
    if A[i] not in d:
        d[A[i]]=0
    d[A[i]]+=1
for i in range(N):
    ans=0
    for j in d:
        if j==A[i]:
            ans+=f(d[j]-1)
            continue
        ans+=f(d[j])
    print(int(ans))
from collections import Counter
from copy import copy
from math import factorial
def comb(x):
    if x<=2:
        return x-1
    else:
        return factorial(x)//(factorial(x-2)*factorial(2))
n = int(input())
a = list(map(int,input().split()))
c = dict(Counter(a))
for k in range(1,n+1):
    t = copy(c)
    t[a[k-1]]-=1
    print(sum([comb(i) for i in t.values()]))
from collections import Counter
n = int(input())
ball = list(map(int,input().split()))

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

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

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

for i in ball:
    print(x - data[i] + sentaku[i])
n=int(input())
x=[0]*n
a=list(map(int,input().split()))
for i in a:
  x[i-1]+=1
for i in a:
  x[i-1]-=1
  ans=0
  for j in x:
    cnt=1
    for k in range(1,j+1):
      cnt*=k
    ans+=cnt
  print(ans)
N = int(input())
list = list(map(int,input().split()))
list.append(-1)
kosuu = [0] * N
total = 0
listed = sorted(list)
i = 0
count = 1
while i < N:
    a = listed[i]
    if a == listed[i+1]:
        count += 1
    else:
        kosuu[a-1] = count
        total += ( count * (count-1) ) //2
        count = 1
    i += 1
for i in range(N):
    a = kosuu[list[i]-1]
    print(total-a*(a-1)//2 + (a-1)*(a-2)//2)
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
print(s)
for a in A:
	print(s - (X[a] - 1))
import copy
from scipy.misc import comb
 
n = map(int, input())
a = list(map(int, input().split()))
matches = {}
 
for i in range(len(a)):
  aa = copy.copy(a)
  del aa[i]
  for av in aa:
    if av in matches:
      matches[av] += 1
    else:
      matches[av] = 1
  combi_cnt = 0
  for v in matches:
    combi_cnt += comb(v, 2, exact=True)
  print(combi_cnt)
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):
        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())
a = list(map(int,input().split()))
tmp = {}
for i in range(n):
    if a[i] in tmp:
        print(tmp[a[i]])
    else:
        a_copy = a[:]
        a_copy.remove(a[i])
        c = collections.Counter(a_copy)
        cnt = 0
        for i in c.values():
            cnt += i * (i-1) // 2
    
        tmp[a[i]] = cnt
    
        print(cnt)
import math
n = int(input())
bs = list(map(int, input().split()))
temp = []
ans = 0
for i in bs:
    temp = list(bs)
    temp.pop(i-1)
    for k in dict.fromkeys(temp):
        if(temp.count(k) == 2):
            ans += 1
        if(temp.count(k) > 2):
            ans += math.factorial(temp.count(k))//(math.factorial(temp.count(k)-2)*2)
    print(ans)
    ans = 0
a=int(input())
b=input().split()
for i in b:
    if b.count(i)<=2:
        print(b.count(i))
    else:
        print('0')
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):
  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))
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
count=0
for i in range(1,N+1):
  a=B["i"]
  count+=(a*(a-1))/2

  
for i in range(1,N+1):
  a=B["i"]
  print(int(count-(a*(a-1))/2))
import collections

def cal(x):
    b=0
    for i in range(e):
        a=d.most_common()[i]
        c=a[1]
        if c==1:
            break
        if a[0]==balls[x]:
            c-=1
        b = c*(c+1)//2
    return b

N = int(input())
balls = list(map(int,input().split()))
new_balls =sorted(balls)
d = collections.Counter(new_balls)
e = len([x for x in set(balls) if balls.count(x)>1])

for j in range(N):
    print(cal(j))
#input
N = int(input())
A = list(map(int, input().split()))

#output
from collections import  Counter
L = Counter(A)

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

for i in range(N):
    if L[A[i]] == 1:
        print(original_answer)
    elif L[A[i]] == 2:
        print(original_answer -1)
    elif L[A[i]] > 2:
        print(original_answer - L[A[i]]*(L[A[i]]-1)//2 + (L[A[i]]-1)*(L[A[i]]-2)//2)
N=int(input())
A=list(map(int,input().split() ))
from collections import Counter
d=dict(Counter(A))
print(d)
cnt=0
for item in d:
    cnt += (d[item])*(d[item]-1)//2

print("cnt",cnt)
   
for num in A:
    new = max(0, (d[num]-1)*(d[num]-2)//2)
    print(cnt- d[num]*(d[num]-1)//2 + new)
n = int(input())
*li,=map(int, input().split())
from collections import Counter
c = Counter()
for i in li:
    c[i] += 1
ans=0
from math import comb
for i in c.values():
    ans += comb(i, 2)
for i in li:
    print(ans - comb(c[i], 2) + comb(c[i-1], 2))
N = int(input())
li = list(map(int, input().split()))
j1=0
#print(li)
li.sort()
#print(li)
for i in range(len(li)):
    goukei = 0
    x = li[i]
    del li[i]
    #print(li)
    for j in li:
        if j != j1:
            goukei += li.count(j) * (li.count(j)-1) / 2
        j1 = j
    li.insert(i, x)
    print(int(goukei))
# inputを高速化する。
import sys
input = sys.stdin.readline

n = int(input())

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

cnt = {}

for ball in balls:
    if ball not in cnt:
        cnt[ball] = 0
    cnt[ball] += 1

def combination(nxt, num = 0):
    return (cnt[nxt]-num) * (cnt[nxt]-1- num) // 2

total = 0
for nxt in cnt:
    total += combination(nxt)

print(total)

for ball in balls:
    ans = total -  combination(ball) + combination(ball,1)
    print(ans)
from sys import stdin
from collections import Counter

lines = stdin.readlines()

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

c = Counter(a)


res = []
for k in range(n):
    part_res = 0
    for i in c.keys():
        if i == a[k-1]:
            quant = c[i] - 1
        else:
            quant = c[i]
        if quant > 1:
            part_res += int((quant * (quant - 1)) / 2)
    res.extend([part_res])

for j in range(len(res)):
    print(res[j])
N = int(input())
a = tuple(map(int, input().split()))
for k in range(N):
  c = 0
  A = list(a)
  del A[k]
  while len(A) > 0:
    y = A.count(A[0])
    c += y*(y-1)//2
    x = A[0]
    while x in A:
        A.remove(x)
    print(A)
  print(c)
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-a.count(a[i]+1))
n = int(input())
ao = list(map(int, input().split(' ')))
aval = list(set(ao))
acount = []
for i in aval:
    acount.append(ao.count(i))

for i in ao:
    ind = aval.index(i)
    print(sum(acount)-acount[ind])
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

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

print(ans)
for a in A:
    n = d[a]
    if n >= 2:
        print(ans - n + 1)
    else:
        print(ans)
def Get_nC2(n):
    return int(n*(n-1) / 2);


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

for a_i in A_i:
    cnt = 0
    for j in range(min(A_i), max(A_i)):
        j_cnt = A_i.count(j)
        if a_i == j:
            j_cnt -= 1

        cnt += Get_nC2(j_cnt)

    print(cnt)