peterverebics/CodeNet_Python_118 huggingface dataset:
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))
n=int(input())
l=list(map(int,input().split()))

d = [0]*n
ans=0
 
for a in l:
    d[a-1] += 1
  
for a in d:
  ans+=a*(a-1)//2
  
print(ans)
#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):
    original_answer += ( L[i] * (L[i]-1) )// 2

for i in range(N):
    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()))

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

V=list(S.values())
c = sum([v*(v-1)//2 for v in V])

cdiff=0
K=[]
for i in range(n):
    a = A[i]
    s=S[a]
    if s>=2 :
        cdiff=(s*(s-1)-(s-1)*(s-2))//2
    print(c-cdiff)
import copy
n=int(input())
a=list(map(int,input().split()))
aset=list(set(a))
ans=0
alist=[ 0 for i in range(n)]
for _ in a:
    alist[_ - 1] += 1
for j in aset:
    ans += (a.count(j)*a.count(j)-1) // 2
for u in a:
    print(ans - alist[u - 1])
import collections

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

ctr_A = collections.Counter(A).most_common()
less_A = collections.Counter(A)

total = 0

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

for i in range(N):
    summ = total
    num = A[i]
    n = less_A[num]

    if (n <= 2):
        summ -= 1
    else:
        new = (n - 1) * (n - 2) // 2
        old = n * (n - 1) // 2
        summ += new - old
    
    ans = max(0, summ)

    print(ans)
n = int(input())
balls = list(map(int, input().split()))
conbi = [0]*n
result = 0
for i in balls:
    conbi[i-1] +=1
print(conbi)
for j in range(n):
    result += (conbi[j]*(conbi[j]-1))//2
for k in balls:
    print(result-conbi[k-1]+1)
import sys
def II(): return int(sys.stdin.readline())

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

N = II()
A = LI()

def comb(k):
	if k == 1:
		return 1
	else:
		return int(k*(k-1)/2)

result = 0
kind = list(set(A))
for k in kind:
	result += comb(A.count(k))

for a in A:
	n = A.count(a)
	print(result-n+1)
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

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

count=Counter(A)
ans=0
for i in range(len(count)):
	ans+=ch_2(count[A[i]])
print(ans)
for j in range(N):
	ttl=ans
	ttl-=ch_2(count[A[j]])
	ttl+=ch_2(count[A[j]]-1)
	print(int(ttl))
n = int(input())
a = list(map(int, input().split()))
count = 0

while count < n:
  p = a.pop(0)
  ans = len(a) - a.count(p)
  print(ans)
  a.append(p)
  count += 1
def nc2(n):
    if n==0:
        return 0
    return n*(n-1)/2


n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
ans=0
dic={}
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]==1 :
        continue
    ans+=nc2(dic[i])
    
print(dic)

for i in range(n):
    curr_nc2=nc2(dic[arr[i]])
    # print(curr_nc2)
    print(int(ans-curr_nc2+nc2(dic[arr[i]]-1)))
import collections as cl
N = int(input())
A = list(map(int,input().split()))
cn = cl.Counter(A)
sumC = sum([N*(N-1)//2 for N in cn.values()])
for k in range(N):
  sum = sumC - cn[A[k]] +1
print(sum)
import copy
n = int(input())
a = list(map(int,input().split()))

a_2 = set(a)
ans = 0
for i in a_2:
    p = a.count(i)
    ans += int((p * (p-1)) / (2 * 1))
#print(ans)
final = [ans for i in range(n)]
for i in range(n):
    a_2 = copy.copy(a)
    del a_2[i]
    h = a_2.count(a[i])
    final[i] -= int((h-1))
for i in final:
    print(i)
from collections import Counter
n = int(input())
a = map(int, input().split())
counter = Counter()

for ai in a:
    counter[ai] += 1

for ai in a:
    print(max(0, counter[ai]))
from collections import defaultdict
n, *D  = [list(map(int, s.split())) for s in open(0)]
D = D[0]
dic = defaultdict(int)
for d1 in D:
    dic[d1] += 1

total_comb = 0
for k in dic:
    if dic[k] >= 2:
        total_comb += dic[k] * (dic[k] - 1) / 2

for d2 in D:
    comb = 0
    if dic[d2] >= 2:
        print(int(total_comb - dic[d2] + 1))
    else:
        print(total_comb)
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
C=Counter(a)
#print(C)
total=0
for k,v in C.items():
    if v>=2:
        total+=v*(v-1)//2
print(total)
for i in range(n):
    V=C[a[i]]
    ans=total-(V*(V-1))//2+((V-1)*(V-2))//2
    print(ans)
def aC(a):
  if a == 0:
    return 0
  return a*(a-1)/2

N = input()
N = int(N)
B = input().split(" ")
A = []
for a in B:
  A.append(int(a))
  
for i in range(0,N):
  pre_A = A[:]
  pre_A.pop(i)
  count_list = []
  for i in range(1,N+1):
    count_list.append(pre_A.count(i))

  ans = 0
  for i in count_list:
    ans = ans + aC(i)

  print(ans)
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1


for i in range(1,n+1):
    x[a[i-1]-1]-=1
    count = 0
    x_ = [(k*(k-1))/2 for k in x if k>=2]
    count = sum(x_)
    # for j in x:
    #     if j>=2:
    #         count += int((j*(j-1)/2))
    x[a[i-1]-1]+=1
    print(count)
import collections

N=int(input())
A=list(map(int, input().split()))
c = collections.Counter(A)
sum=0
for i, j in c.items():
    sum+=j*(j-1)//2

for i in A:
        b = c[i]
        if b >= 2:
            print(sum-b*(b-1)//2+(b-1)*(b-2)//2)
        else:
            print(0)
#TLE
n = int(input())
a = input().split()
dic = {}
ans = 0
for i in range(n):
    if a[i] in dic:
        ans += dic[a[i]]
    else:
        num = a.count(a[i]) - 1
        ans += num
        dic[a[i]] = num
ans /= 2
for i in range(n):
    print(int(ans - dic[a[i]]))
print(dic)
N = int(input())
A = [int(i) for i in input().split()]
a = 0
b = []

for i in range(N):
    c=0
    for j in range(N):
        if A[i] == A[j]:
            c+=1
    c-=1
    b.append(c)
    a+=c
a/2
for i in range(N):
    print(a-b[i])
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
  for j in range(N):
    if A[i] == A[j]:
      count += 1
    else:
      count += 0
  print(count-i-1)
N = int(input())
A_list = list(map(int,input().split()))

count=-1

for k in range(len(A_list)):
    for l in range(len(A_list)):
        if A_list[k] == A_list[l]:
            count+=1
    print(count)
    count=-1
import sys
sys.setrecursionlimit(2147483647)

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

for k in range(n):
    c = a[k]
    del a[k]
    for v in range(1,n+1):
        co = a.count(v)
        co2 = co - 1
        if co >= 2:
            ans += co*co2/2
    ans = 0
    print(int(ans))
    a.append(c)
N = int(input())
A = [int(i) for i in input().split()]

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

print(cnt_list)

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

res = int(result)
for i in range(0,N):
  print(res-cnt_list[A[i]]+1)
from scipy.misc import comb

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

dic = dict()

for a in A:
    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1

tmp = 0
for d in dic.values():
	tmp += comb(d,2,exact=True) 

for a in A:
    ans = 0
    t = dic[a]
    ans = tmp - comb(t,2,exact=True) + comb(t,2,exact=True)
    print(ans)
N = int(input())
l = list(map(int, input().split()))
set_l = set(l)

dictionary = {ll: l.count(ll) for ll in set_l}
ll_dict = {}
ll2_dict = {} # 1つ抜け版 

for k, v in dictionary.items():
  ll_dict[k] = v*(v-1)//2
for k, v in dictionary.items():
  ll2_dict[k] = (v-1)*(v-2)//2 if v!=2 else 1
sum_num = sum([v for v in ll_dict.values()])

for n in range(N):
  print(sum_num-ll2_dict[l[n]])
import collections
import math
N = int(input())
A = list(map(int, input().split(' ')))
c = collections.Counter(A)
d1 = {}
d2 = {}
for i in c:
    d1[str(i)] = (c[i]*(c[i]-1))/2
    d2[str(i)] = ((c[i]-1)*(c[i]-2))/2

s = sum(d1.values())

print(c)
for i in range(N):
    ans = s - d1[str(A[i])]+d2[str(A[i])]
    print(int(ans))
import collections

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


c = collections.Counter(A)

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

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

for aa in A:
    count = 0
    for ab in A:
        if(aa == ab):
            count += 1
    print(count - 1)
import math

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

n = (int)(input())
a = list(map(int, input().split(" ")))
temp = [0 for i in range(n + 1)]
aaa = sorted(a)
count = 0
for i in range(n - 1):
  if aaa[i] == aaa[i + 1]:
    count+= 1
  else:
    temp[aaa[i]] = count + 1
    count = 0
else:
  if len(a) == 1:
    temp[aaa[0]] = 1
  else:
    temp[aaa[-1]] = count + 1
ans = 0
#print(temp)#各数字の出現回数
for i in range(n + 1):
  if temp[i] >= 2:
    ans += comb(temp[i], 2)
n=int(input())
k=list(map(int,input().split()))
print(k)
for i in range(n):
    x=k.pop(i)
    ans=0
    for j in range(n):
        c=k.count(j)
        ans=ans+c*(c-1)//2
    print(ans)
    if i!=n-1:
        k.insert(i,x)
    else:
        k.append(x)
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 range(n):
    print(all_count - c[i])
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):
  print(N - cnt[A[i]])
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = dict(Counter(a))
ans = 0
for v in c.values():
    ans += v*(v-1)//2
for i in range(n):
    print(ans-a[i]-1)
N = int(input())
A = list(int(x) for x in input().split())
import math
n=int(input())
a=list(map(int,input().split()))
t=0
u=0
for i in range(n):
  if u!=n-1:
    m=a[i]
    del a[i]
    s=sorted(a)
    x=s.count(s[u])
    t+=math.factorial(x)//2
    u+=x
    a.insert(i,m)
  print(t)
import collections

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

C = collections.Counter(A).most_common()
w1 = C[0][0]
w2 = C[-1][0]
n1 = C[0][1]
n2 = C[-1][1]

if n1 == n2 and w1 != w2:
    for _ in range(N):
        print(n1*(n1-1)//2)
else:
    for a in A:
        if a != w1:
            print(n1*(n1-1)//2)
        else:
            print((n1-1)*(n1-2)//2)
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
for i in range(N):
    s = 0
    a = A[i]
    mydict[a] -= 1
    for j in mydict.values():
        s += cmb(j)
    print(s)
    mydict[a] += 1
N = int(input())
A = list(map(int,input().split()))
D = {}
for i in A:
    if not i in D.keys():
        D[i] = 1
    else:
        D[i] += 1
for i in A:
    n = 0
    for j,k in D.items():
        if j != i:
            n += int(((D[i]-1)*k)/2)
        elif j == i:
            n += int(((D[i]-1)*(D[i]-2)/2))
    print(n)
import math
num=int(input())
target=list(map(int, input().split()))

def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))

for i in range(num):
    A=target.copy()
    A.pop(i)
    B=[x for x in set(A) if A.count(x) > 1]
    out=0
    if len(B)>1:
        for j in B:
            base = comb(A.count(j),2)
            out=out+base
    print(out)
n=int(input())
a=list(map(int,input().split()))

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

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

for i in a:
    print(ans-l[i]*(l[i]-1)//2+(l[i]-1)*(l[i]-2)//2)
import collections
N = int(input())
A = list(map(int, input().split()))
wlists = collections.Counter(A)
print(wlists)
print(wlists[1])
print(wlists[2])
sum_num = 0
for i in wlists:
  sum_num += wlists[i] * (wlists[i] - 1) // 2
print("num_sum:{}".format(sum_num))
for i in range(N):
  num = sum_num - wlists[A[i]] * (wlists[A[i]] - 1) // 2
  if wlists[A[i]] > 1:
    num += (wlists[A[i]] - 1) * (wlists[A[i]] - 2) // 2
  print(num)
n=int(input())
L=list(map(int,input().split()))
NW=[]
for i in range(n+1):
    NW.append(L.count(i))
print(NW)
for i in L:
    NW[i]=NW[i]-1
    num=0
    for j in range(n):
        if NW[j]>=2:
            num+=1
    print(num)
    NW[i]=NW[i]+1
n = int(input())
a = list(map(int, input().split()))
for i in a:
    a_ = a[:i]+a[i+1:]
    s = set(a_)
    l = []
    for s_ in s:
        n = a_.count(s_)
        l.append(int(n*(n-1)/2))
    print(sum(l))
n = int(input())
a = list(map(int, input().split()))
c = [0 for _ in range(n + 10)]

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


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

for i in range(n):
    r = a[i]
    tmp = ans - c[r] * (c[r] - 1) / 2 + (c[r] - 1) * (c[r] - 2) / 2
    print(tmp)
def com(n,k):
  x,y=1,1
  for i in range(k):
    x*=n-i
    y*=k-i
  return x//y

n=int(input())
a=list(map(int,input().split()))
comb=[0]*n

for i in range(n):
  num = a.count(a[i])
  comb[i] = com(num,2)-num+1 if num >= 2 else 0

print(*comb,sep='\n')
import collections
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n+1)
ans=0
for i in range(n):
    l[a[i]]+=1
for j in range(n):
    if l[j]>1:
        ans+=(l[j])*(l[j]-1)//2
for k in range(n):
    s=l[a[k]]
    if s<2:
        print(ans)
    else:
        print(ans-s+1)
n=int(input())
a=list(map(int,input().split()))
sum=0
m=len(a)
c=list(set(a))
sum1=0

for i in range(len(c)):
    k=c.count(c[i])
    sum1+=k*(k-1)//2
    
for j in range(m):
    g=a.count(a[i])
    t=sum1-(g*(g-1))//2+((g-1)*(g-2))//2
    print(t)
import collections
import math


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


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

pre = 0
for i in range(n):
    if i == 0:
        c[a[i]] -= 1
    else:
        c[pre] += 1
        c[a[i]] -= 1
        print(sum(comb(v, 2) for v in c.values()))
    pre = a[i]
import collections
n=int(input())
a = list(map(int,input().split()))
b = collections.Counter(a)
c = list()
for i in range(1,n+1):
    c.append(int((b[i]*(b[i]-1))/2))
print(c)
for i in range(n):
    d = int(a[i]-1)
    if c[d]>2:
        e = sum(c) - c[d] + int( (c[d])*(b[d+1]-2) /(b[d+1]) )
    else:
        e = sum(c) - c[d]
    print(e)
import itertools

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

A.sort()
for k in range(N):
  a=A[:k]+A[k+1:]
  gr=itertools.groupby(a)
  s=0
  for _,group in gr:
    l=len(list(group))
    if l>=2:
      s+=int(l*(l-1)/2)
  print(s)
import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict

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

d = defaultdict(int)

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

print(d)
a = defaultdict(int)
b = defaultdict(int)
for key, value in d.items():
    a[key] = value * (value - 1) //2
    b[key] = value * (value - 1) //2 - (value - 1) * (value - 2) // 2
#print(a)
#print(b)
total = 0
for key, value in a.items():
    total += value
#print(total)
for i in range(N):
    ans = total - b[A[i]]
    print(ans)
info = input("").split(" ")
N = int(info[0])
A = list(map(lambda x : int(x),info[1:]))
for i in range(N):
    count = 0
    n_list = []
    B = A[0:i] + A[i + 1:]
    for j in B :
        c = B.count(j)
        if c != 1 and not j in n_list:
            n_list.append(j)
            count += c*(c-1)/2
    print(int(count))
n=int(input())
a=list(map(int,input().split()))
c=[0]*200001##個数
s=0
t=0
nsum=0
for i in range(n):
    c[a[i]]+=1
for j in range(n):
    nsum+=max(c[j]*(c[j]-1)//2,0)
for k in range(n):
    t=(nsum+1-c[a[k]])
    print(int(t))
N = int(input())
a = list(map(int,input().split()))
b = list(set(a))
ans = 0
for i in range(len(b)):
  k = a.count(b[i])
  ans += k*(k-1)/2
print(ans)
#!/usr/bin/env python3
import collections
import copy
import itertools as it
import math
import numpy as np

# A = input()
N = int(input())
# A = map(int, input().split())
A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
c = collections.Counter(A)

cache = {}

A_ = copy.deepcopy(A)

count = len(A)
for (k, v) in c.most_common():
    if v == 1:
        count -= 1

for a in A:
    if c[a] == 2:
        print(count - 2)
    if c[a] == 1:
        print(count)
    else:
        print(count)

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

from collections import Counter
counter=Counter(a)

# すべての組み合わせを事前に計算しておく
combi_sum=0
for num,cnt in counter.items():
    n_cnt=cnt
    if num==n:
        n_cnt-=1
    combi_sum+=n_cnt*(n_cnt-1)//2

for i in range(n):
    print(combi_sum - counter[a[i]] + 1)
from scipy.misc import comb
N=int(input())
A=list(map(int,input().split()))
for j in range(1,N+1):
    B=A[:j-1]+A[j:]
    print(int(sum([comb(B.count(i),2) for i in range(1,N+1)])))
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
d = {}
for k, v in list(c.items()):
    if v < 2:
        del c[k]
if len(c) == 1:
    b = list(c)[0]
    for i in range(n):
        print(b * 2)
else:
    for i in range(n):
        b = {k: count for k, count in c.items() if k != a[i]}
        print(sum(b.values()))
def aC(a):
  if a == 0:
    return 0
  return a*(a-1)/2

N = input()
N = int(N)
B = input().split(" ")
A = []
for a in B:
  A.append(int(a))
  
for i in range(0,N):
  pre_A = A[:]
  pre_A.pop(i)
  count_list = []
  for i in range(1,N+1):
    count_list.append(pre_A.count(i))

  print(sum(map(aC,count_list)))
def comb(n):
    if n < 2:
        return 0
    else:
        return int(n*(n-1)/2)
        
def sabun(n):
    if n < 2:
        return 0
    else:
        return n-1

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

origin = list(set(AS))
num = []
for i in origin:
    num.append(AS.count(i))

all_num = 0
for i in num:
    all_num += comb(i)
    
for i in range(n):
    j = num[origin.index(AS[i])]
    ans = all_num - sabun(n)
    print(ans)
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):
  total += choose2(inp[i])

for i in range(n):
  count = total - choose2(inp[a[i]]) + choose2(inp[a[i]]-1)
  print(count)
N = int(input())
A = list(map(int, input().split()))
#L = [0 for i in range(N)]
dict = {}

for i in A:
  if i in dict:
    dict[i] = dict[i] + 1
  else:
    dict[i] = 1

print(dict)
total = 0;
for i in dict:
#  print("i:" + str(i) + " " + str(dict[i]))
  total += dict[i]*(dict[i]-1) // 2

#print("T:" + str(total))

for i in A:
  print(total - dict[i] + 1)
n = int(input())
a = list(map(int, input().split()))

from collections import Counter
c = Counter(a)

print(c)
for i in range(n):
   c[a[i]] -= 1
   tmp = [x*(x-1)//2 for x in c.values()]
   print(sum(tmp))
   c[a[i]] += 1
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
for i in range(N):
	for j in range(i+1,N):
		if a[i]==a[j]:
			b[i]+=1
for i in range(N):
	ans=0
	for j in range(N):
		if i==j:
			pass
		else:
			ans+=b[j]
	print(ans)
#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)
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 入力はstringで入る．
# intにしたければ int(input())
# floatで受け取ると 1.0 になる．

# 入力 : N
# 入力 : A1 A2 ... AN
N = int(input())
A = list(map(int, input().split()))

Number = []
Total = 0

Number = [A.count(i+1) for i in range(N)]
Total = sum([Number[i]*(Number[i]-1)/2 for i in range(N)])

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

print('\n'.join([str(Total-Number[Ak-1]+1) for Ak in A]))
n = int(input())
a = list(map(int,input().split()))
a3 = list(set(a))

z = []
for i in range(len(a3)):
     z.append(a.count(a3[i]))

suma = sum([i*(i-1)/2 for i in z])

for j in range(n):
    print(int(suma - z[a3.index(a[j])]))
N = int(input())
A = list(map(int, input().split()))

# 要素を計算
A_unique = set(A)
cnt = dict()

total = 0

# 組み合わせ数
for a in A_unique :
  total += int(A.count(a) * (A.count(a) -1) / 2)
  cnt[a] = A.count(a)

for a2 in A :
  print(total - cnt[a2])
# -*- coding: utf-8 -*-
import collections

n = int(input())
num = list(map(int, input().split()))
list_num = list(num)
print(list_num)
cntAll = 0

for i in list_num:
    iter_list_num = list_num
    del iter_list_num[0]
    # すうじごとに確認
    for j in iter_list_num:
        # cnt = iter_list_num.count(iter_list_num[j])
        cnt = collections.Counter()
    print(cnt)
from collections import Counter
N=int(input())
A = list(map(int,input().split()))
ans = [0] * N
B = Counter(A)
for i in range(N):
    ans[i] = B[A[i]]-1
total=sum(A)
C=[]
for i in range(N):
    c = (total-ans[i])//2
    C.append(c)

for num in C:
    print(num)
import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)/2
for k in range(N):
    print(S - A.count(A[k]) + 1)
N = int(input())
K = list(map(int, input().split()))
counter = dict()
for i in range(N):
  if K[i] not in counter:
  	counter[K[i]] = 1
  else:
   	counter[K[i]] += 1

results = 0
remove_counter = dict()
for key, value in counter.items():
  remove_counter[key] = (value * (value - 1) / 2) - ((value - 1) * (value - 2) / 2)
  results += value * (value - 1) / 2
for i in range(N):
  print(results - remove_counter[K[i]])
import collections
import numpy as np

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

b = collections.Counter(a)
cl = np.array([b[x] for x in sorted(list(b.keys()))])
c = {}
m = len(cl)
i = 0
for k, v in b.items():
    e = np.zeros(m)
    e[i] = 1
    c[k] = int(sum((cl - e)*(cl - e - 1))/2)
    i += 1
for i in a:
    print(c[i])
n = int(input())
kazu = list(map(int, input().split()))

kazuset=list(set(kazu))
atai=0
print(kazuset)
for i in kazuset:
    kosuu=kazu.count(i)
    atai=atai+kosuu*(kosuu-1)/2
  
for i in range(n):
    kotae=atai
    kosuu=kazu.count(kazu[i])
    if (kosuu >= 1):
        kotae=atai-kosuu*(kosuu-1)/2+(kosuu-1)*(kosuu-2)/2
    print(int(kotae))
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
print(All)
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)
n = int(input())
a = list(map(int,input().split()))
d = {}
aa = [0]
for i in range(1,n):
	aa.append(aa[-1]+i)
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i]+=1
s = 0
for i in d:
	s+=aa[d[i]-1]
dd = {}
for i in d:
	if i not in dd:
		if d[i]!=1:
			dd[i] = (s-aa[d[i]-1]+aa[d[i]-2])
		else:
			dd[i] = 0
print(dd)
for i in a:
	print(dd[i])
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(tmp)
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]<2 :
         continue
    ans+=x[i]*(x[i]-1)//2

for i in a :
    n=x[i]
    ans1=ans-(n-1)
    print(ans1)