peterverebics/CodeNet_Python_118 huggingface dataset:
import sys,math,copy,queue,itertools
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
N = int(input())
A = LI()

CA = [0 for _ in range(N+1)]
for i in range(N):
    CA[A[i]] += 1

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

for i in range(N):
    ans = tc
    cnt = CA[A[i]]
    if cnt > 1:
        ans -= cnt * (cnt - 1) // 2 - (cnt - 1) * (cnt - 2) // 2
    print (ans)
from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    dd = defaultdict(int)
    ans = []
    for i in A:
        dd[i] += 1
    for i in range(n):
        ng = A[i]
        dd[ng] -= 1
        cnt = 0
        for key, val in dd.items():
            cnt += val * (val-1) // 2
        ans.append(cnt)
        dd[ng] += 1
    print(*ans, sep='\n')
n=int(input())
arr= list(map(int,input().split(' ')))

count={}
for i in range(len(arr)):
    val=arr[i]
    if val not in count.keys():
        count[val]=1
    else:
        count[val]+=1

big_sum=0
for d in count.keys():
    big_sum+= count[d]*(count[d]-1)/2

for a in arr:
    if a in count.keys():
        if count[a]==1:
            print(0)
        else:
            print(int(big_sum-(count[a]-1)))
import collections
N = int(input())

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

c = collections.Counter(a)
counter = c.most_common()
ans = 0

for j in range(len(counter)):
    ans += int(counter[j][1] * (counter[j][1] - 1) / 2)

for i in range(N):
    sliced_chr = a[i]
    a_slice = a[:i] + a[i+1:]
    
    print(ans - a_slice.count(sliced_chr)+1)
from operator import mul
from functools import reduce


def combinations_count(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())
l = [int(x) for x in input().split()]

ll = [x for x in set(l) if l.count(x) > 1]

sm = 0
m = [1 for x in range(n)]
for i in ll:
    t = l.count(i)
    sm += combinations_count(t, 2)
    m[i-1] = t

print("unchi")

for i in l:
    print(sm-(m[i-1]-1))
n = int(input())
a = list(input().split())

a_dict = dict()
for x in a:
    if x not in a_dict:
        a_dict[x] = 1
    else:
        a_dict[x] += 1

sum = 0
for k, v in a_dict.items():
    print(v)
    print((v-2)/v)
    sum += v*(v-1)//2
    a_dict[k] = (v*(v-1)//2)-((v-1)*(v-2)//2)

for i in a:
    print(int(sum-a_dict[i]))
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)
  ans = 0
  for i in range(1,N+1):
    ans = ans + aC(pre_A.count(i))
  print(ans)
N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}
S = {}

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for c in C.values():
    if c < 1:
        continue
    S.setdefault(c, c * (c - 1) // 2)
    if c < 2:
        continue
    S.setdefault(c - 1, c - 1 * (c - 2) // 2)

for i, a in enumerate(A):
    C[a] -= 1
    sum_ = sum([S[n] for n in C.values() if n > 1])
    C[a] += 1
    print(sum_)
from collections import Counter
from scipy.misc import comb

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

print(c)
num = 0
for v in c.values():
  if v > 1:
      num += comb(v, 2,exact=True)
print(num)
for k in range(N):
  print(int(num - (c[A[k]]-1)))
import copy
n=int(input())
a=list(map(int,input().split()))
a2=copy.copy(a)
for i in a2:
    a.append(i)
    ad=a[i+1:n+i]
    ans = 0
    adset=list(set(ad))
    for j in adset:
        k = ad.count(j)
        if(k >= 2):
           ans += (k*(k-1))//2
        else:
            continue
    print(ans)
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-sabun)
    else:
        print(zenbu)
from collections import Counter


def choose(n: int) -> int:
    if n < 2:
        return 0
    else:
        return (n * (n - 1)) // 2


N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
d = {key: choose(value) for key, value in c.items()}
if len(d) > 1:
    sum_d = sum(d.values())
    for a in A:
        print(sum_d - d[a] + (d[a] // 2))
else:
    ans = choose(N - 1)
    for _ in range(N):
        print(ans)
n,a = [input().split() for i in range(2)]

for index, item in enumerate(a):
    count = 0
    for chk_index, chk_item in enumerate(a):
        if index == chk_index:
            continue
        for cnt_index, cnt_item in enumerate(a[chk_index+1:]):
            if index == cnt_index:
                continue
            if chk_item == cnt_item:
                count += 1
    print(count)
from collections import Counter
from operator import itemgetter

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

B =[]
for i in range(N):
    B = A[0:i] + A[i+1:N]
    #print(B)
    B=Counter(B)
    C=list(B.items())
    C = sorted(C,key=itemgetter(1),reverse = True)
    #print(C)
    ans=(C[0][1])
    print(ans)
import collections
a=int(input())
b=list(map(int,input().split()))

c=collections.Counter(b)
n,m=zip(*c.most_common())
m=list(m)
n=list(n)
print(n,m)
q=0
for i in range(len(m)):
    t=(m[i]*(m[i]-1))//2
    q+=t

for i in range(a):
    w=m[n.index(b[i])]-1
    print(q-w)
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))
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
for x in a:
  c = d[x] - 1
  print(c * (c-1) // 2)
import copy
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def D159():
    N = int(input())
    A = input().split()
    #sum = 0
    for i in range(0, N):
        sum = 0
        A_ = copy.deepcopy(A)
        del A_[i]
        num = list(set(A_))
        for j in num:
            if A_.count(j) > 1:
                sum += combinations_count(A_.count(j), 2)
        print(sum)
import collections


m = int(input())
A = list(map(int,input().split()))[:m]
c = collections.Counter(A)
 
def hoge(n):
    if n <= 2:return 1 
    return n * (n - 1) // 2


full = sum([ hoge(n) for n in c.values()])

for a in A:
    print(full - (c[a]) + hoge(c[a]-1))
import collections

def check(A):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            count += n * (n - 1) / 2
            
    return int(count)


N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
print(A2)
Nsum = check(A2)
# print(Nsum)
for i in range(0,N):
    num = A[i]
    count = A2[num]
    out = Nsum - ( count - 1 )
    print(out)
N = int(input())
A = [int(i) for i in input().split()]

c = []
sum = 0

for j in A:
    _ = A.count(j)
    c.append(_)
    sum += int(_ * (_ - 1) / 2)

s = ""
for k in range(N):
    s += str(sum - c[k] + 1) + "\n"
print(s)
n = int(input())
li = list(map(int,input().split()))
lia = [0]*n
sum1 = 0
for i in range(n):
    lia[li[i]-1] += 1
for i in range(n):
    if lia[i] >= 2:
        lia[i] -= 1
        sum1 += (lia[i]*(lia[i]+1)//2)
print(lia)
for i in range(n):
    a = lia[li[i]-1]*(lia[li[i]-1]+1)//2
    b = (lia[li[i]-1]-1)*lia[li[i]-1]//2
    if sum1-a+b >= 0:
        print(sum1-a+b)
    else:
        print(0)
def main():
    from collections import Counter
    n=int(input())
    a=list(map(int,input().split()))

    q = Counter(a)
    a_cn = sum(x * (x - 1) // 2 for x in q.values())

    ans = []
    for x in a:
        ans.append(a_cn - q[x] + 1)

    print(ans, sep='\n')


if __name__ == '__main__':
    main()
n = int(input())
ao = list(map(int, input().split(' ')))
a = list(set(ao))
ac = 0
acount = {}
for i in a:
    c = ao.count(i)
    ac += c
    acount[i] = c-1
ac = int((ac**2 - ac)/2)
for i in ao:
    print(ac-acount[i])
N = int(input())
A = (input().split())
B = []
C = 0
for i in range(N + 1):
  B.append(A.count(str(i)))
  C += int(B[i] * (B[i] - 1) / 2)
print(B)
for j in range(N):
  if B[int(A[j])] > 1:
    D = C + 1 - B[int(A[j])]
    print(D)
  else:
    print(0)
def fact(n, end=1):
  if n <= end: return 1
  return n * fact(n-1, end=end)
def comb(a, b):
  if a < b:
    return 0
  return fact(a, end=a-b) / fact(b)
N = int(input())
A = list(map(int, input().split()))
an = [0 for i in range(N+1)]
av = [0 for i in range(N+1)]
for i in range(N):
  an[A[i]] += 1
for i in range(N):
  av[i] = comb(an[i], 2)
x = sum(av)
for k in range(N):
  y = comb(an[A[k]]-1, 2)
  print(int(x - av[A[k]] + y))
n = int(input())
A = list(map(int,input().split()))
from collections import Counter

c = Counter(A)
print(c)
cou = 0
for x in c:
    if c[x]>1:
        y = c[x]
        cou+=y*(y-1)//2
    else:
        break


for i in A:
    X = c[i]
    ans = cou - X*(X-1)//2 + (X-1)*(X-2)//2
    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 enumerate(list(range(n)), 1):
    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])

print(res)
n = int(input())
a = list(map(int, input().split()))
l = []
total = 0

m = max(a)

for i in range(1, m+1):
    if a.count(i):
        total += (a.count(i)*(a.count(i)-1))/2
    l.append(a.count(i))

print(l)
print(total)

for k in range(n):
    score = total
    if l[a[k]-1]:
        score -= (l[a[k]-1]-1)
    print(int(score))
import sys
input = sys.stdin.readline
from collections import defaultdict

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

d = defaultdict(int)
for i in A :
    d[i] += 1

print(d)

for i in A :
    d[i] -= 1
    ans = 0
    for a in d :
        ans += d.get(a)*(d.get(a)-1)//2
    print(ans)
    d[i] += 1
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)

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

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

N = 8#int(input())
#A = list(map(int, input().split()))
A = [1, 2, 1, 4, 2, 1, 4, 1]

c = collections.Counter(A)
#print(c)

count_dic = {}
for i in c.keys():
    count = 0
    c_copy = c.copy()
    c_copy[i] = c[i]-1
    #print(c_copy)
    for k in c.keys():
        count += int(c_copy[k]*(c_copy[k]-1)/2)
        count_dic[i] = count
        #print(count)
    #print(count_dic)

for i in range(N):
    print(count_dic[A[i]])
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
c=list(range(1,n+1))
a.insert(0,0)
num=list(map(lambda t:reduce(lambda a,b:a+1 if b==t else a,a),c))
"""
test=list(map(lambda t:map(lambda x,y:x if (y!=t or x==0) else x-1,num,c),c))
for i in range(5):
    print(list(test[i]))
"""
ans=list(map(lambda t:reduce(lambda x,y:x+y*(y-1)/2,map(lambda x,y:x if (y!=t or x==0) else x-1,num,c),0),c))

for i in range(n):
    print(int(ans[a[i]]))
# 2020/03/22
# AtCoder Beginner Contest 159 - D

# Input
n = int(input())
a = list(map(int,input().split()))
acntl = [0] * (n + 1)
anl = [0] * (n + 1)

# Count
for i in range(n):
    acntl[a[i]] = acntl[a[i]] + 1

# Calc Combination
for i in range(n):
    anl[i] = acntl[i] * (acntl[i] - 1) // 2
    anl[0] = anl[0] + anl[i]

# Output
for i in range(n):
    ans = anl[0] - anl[a[i]] + ((acntl[a[i]] - 1) * max(0, acntl[a[i]] - 2)) // 2
    print(ans)
N,A = [input() for i in range(2)]
A=A.split()
N=int(N)
A=[int(i) for i in A]

a=0
for i in range(N):
    for j in A[i+1:]:
        if A[i]==j:
            a+=1
print(a)

ans=[]
b=[]
for k in range(N):
    b_k=0
    for i in range(N-1):
        if A[k]==A[i]:
            b_k+=1
    ans.append(a-b_k)

for i in range(len(ans)):
    print(ans[i])
N = int(input())
A_list = list(map(int,input().split()))

count=-1

for k in range(len(A_list)):
    print(A_list.count(A_list[k]))
n = int(input())
ao = list(map(int, input().split(' ')))
a = list(set(ao))
ac = 0
acount = []
for i in a:
    c = ao.count(i)
    ac += sum([j for j in range(1, c)])
    acount.append(c+1)
for i in ao:
    ind = a.index(i)
    print(ac-acount[ind])
N = int(input())
A = list(map(int, input().split()))
l = [0] * 10000001
for i in A:
    l[i] += 1
s = 0
for i in range(N):
    i = l[i]
    s += i * (i - 1) // 2
for a in A:
    a = l[a]
    print(s - (a * (a - 1) // 2) + ((a - 1) * (a - 2) // 2))
N=int(input())
A=list(map(int,input().split()))
for k in range(N):
	s=0
	for i in range(N):
		for j in range(i+1,N):
			if A[i]==A[j]:
				s=s+1
	if A[i]==A[k]:
		s=s-1
	print(s)
N=int(input())
K=list(map(int, input().split()))
from collections import Counter
ans = 0
for i in range(N):
    ans += i*(i-1)//2
C = Counter(K)
for a in K:
    e = C[a]
    print(ans-a*(a-1)//2+(a-1)*(a-2)//2)
from collections import Counter

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

m = []
for i in range(N):
  b = [a for a, j in enumerate(A) if j != i]
  c = Counter(b).values()
  for j in c:
    if j != 1:
      print(int(c*(c-1)/2))
import sys
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
ans = 0
cum = {}
def couple_combination(n):
    if n >= 2:
        return int(n * (n - 1) / 2)
    else:
        return 0
for unique in list(set(A)):
    cum_count = A.count(unique)
    cum[unique] = cum_count
    ans += couple_combination(cum_count)
for i in A:
    print(ans - cum[i])
import collections

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

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

counts = [0] * (N+1)

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

sum_ = 0
for k in range(1, N+1):
    sum_ += counts[k] * (counts[k]-1) // 2

res = []
for k in range(1, N+1):
    # A[k]を抜くことで減る組み合わせを引く
    res.append(sum_ - (counts[A[k-1]] - 1))

print(res)
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)
  matches = {}
N=int(input())
A=list(map(int,input().split()))
B=list(set(A))
p=0
C=[0]*(N+1)
for k in B:
  C[k]=A.count(k)
for i in A:
  p=0
  for j in B:
    if i==j:
      p+=(C[j]-1)*(C[j]-2)//2
    else:
      p+=C[j]*(C[j]-1)//2
    print(p)
n = int(input())
a = list(map(int, input().split()))

count = [0] * (n + 1)
total = 0

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

for i in range(1, n):
    total += int(count[i] * (count[i] - 1) / 2)

for v in a:
    print(total - count[v] + 1)
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)
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(n):
    total += nC2(cnt[i])

for i in range(n):
    print(total - nC2(cnt[a[i]]) + nC2(cnt[a[i]] - 1))
N = int(raw_input())
A = map(int, raw_input().split())


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

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

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

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

N=int(input())
A=list(map(int,input().split()))
count=Counter(A)
com={}

for k,v in count.items():
  com[k]=combo(v)
  s=sum(com.values())
  for i in range(N):
    su=s-combo(count[A[i]])+combo(count[A[i]]-1)
    print(su)
import numpy as np

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

def num2len(n):
	return np.count_nonzero(ndarr == n)
  

def main():
	print(*[num2len(a) for a in A], sep="\n")
    
if __name__ == '__main__':
    main()
N=int(input())
A=list(map(int,input().split()))
C=[]

ans1=0
s=0
for i in range(1,N+1):
    a=A.count(i)
    C.append(a)
for j in range(N):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
for k in range(N):
    b=A[k]-1
    ans=ans1-(C[b]+1)
    print(ans)
n = int(input())
k = [int(i) for i in input().split()]
pair = {}

for i in range(n):
    pair.setdefault(k[i], []).append(i)

sum = 0
for value in pair.values():
    l = len(value)
    sum += l*(l-1)//2

for i in range(n):
    ans = 0
    len_pair = len(pair[k[i]])
    if len_pair != 1:
        ans = sum - ((len_pair*(len_pair-1)//2)-((len_pair-1)*(len_pair-2)//2))
        print(ans)
    else:
        print(ans)
from collections import Counter
N = int(input())
A = input().split()
c = Counter(A)
a = list(c.values())
b = len(a)
print(a,b)
AA = A
for i in range(N):
    r = 0
    x = AA.pop(i)
    c = Counter(AA)
    a = list(c.values())
    b = len(a)
    for j in range(b):
        r += (a[j]*(a[j]-1))/2
    AA.insert(i,x)
    print(int(r))
n=int(input())
k= list(map(int, input().split()))
z=[0]*n
cnt=0
for  i in range(n):
   z[k[i]-1]+=1
for m in range(n):
    cnt+=z[m]*(z[m]-1)//2
for j in range(n):
    print(cnt-z[j]+1)
n=int(input())
S=list(map(int,input().split()))
for i in S:
  print(len(S)-S.count(i)+1)
import sys
import os
import collections


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    L = int(sys.stdin.buffer.readline().decode().rstrip())
    print(L ** 3 / 27)


if __name__ == '__main__':
    main()
from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
a_s = set(a)
for i in range(n):
    l = a[i]
    a[i] = 'X'
    ans = 0
    for j in a_s:
        ans += comb(a.count(j),2)
    print(int(ans))
    a[i] = l
N=int(input())
a=list(map(int,input().split()))
import math
result=0
for i in range(N):
  b=a.copy()
  b.pop(i)
  b=sorted(b)
  res=0
  n=b[0]
  c=1
  for j in range(1,N-1):
    if n==b[j]:
      c+=1
    else:
      res+=math.factorial(c)//2
      c=1
      n=b[j]
  res+=math.factorial(c)//2
  print(res)
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
cnt=0
for i in a:
  b[i-1]+=1
cnt=sum(b)
for i in a:
  print(cnt+(1-b[i-1]))
N = int(input())
A = list(map(int, input().split()))
B = [[] for i in range(N)]
ans = [0]*N
for k, a in enumerate(A):
    a = a - 1
    B[a].append(k)


S = 0
for b in B:
    lenb = len(b)
    if lenb >= 1:
        S += lenb * (lenb-1) / 2

for i, b in enumerate(B):
    for j, k in enumerate(b):
        ans[k] = int(S - (len(b) - 1))
print(ans)
from collections import Counter
n = input()
res = list(map(int,input().split()))
a = Counter(res)
for i in a.keys():
    a[i] -= 1
    sums = 0
    for j in a.values():
        sums += j * (j - 1) // 2
    a[i] += 1
    res = [sums if x == i else x for x in res]
for k in res:
    print(k)
n = int(input())
balls = input().split()
for i in range(n):
  balls[i] = int(balls[i])
for j in range(n):
  ans = 0
  len_n = 0
  for k in range(n):
    if len_n + balls.count(k) >= n:
      break
    if balls[j] == k:
      ans += (balls.count(k) - 1) * (balls.count(k) - 2) / 2
    else:
      ans += balls.count(k) * (balls.count(k) - 1) / 2
  print(int(ans))
n = int(input())
a = [int(x) for x in input().split()]
from collections import defaultdict
d = defaultdict(int)
for i in a:
  d[i] += 1

total = 0
for i in set(a):
  x = d[i]
  total += x*(x-1)/2

for i in a:
  x = d[i]
  print(int(total-(x*(x-1)/2)))
#input
N = int(input())
A = list(map(int, input().split()))

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

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

for i in range(N):
    temp = 0
    if L[A[i]] == 2:
        temp -= 1
    elif L[A[i]] > 2:
        temp = temp - L[A[i]]*(L[A[i]]-1)//2 + (L[A[i]]-1)*(L[A[i]]-2)//2 
    print(original_answer + temp)
n = int(input())
s = input().split()
for i in range(n):
  j=0
  count=0
  text=""
  for s0 in s:
    text= s[:j] + s[j+1:]
    if i==j:
      j+=1
    else:
      j=j+1
      i0=len(text)-len("".join(text).replace(s0,""))
      if i0>1:
        count+= i0-1
        
  print(count)
n = int(input())
a = list(map(int, input().split()))
import collections
import math
def combinations_count(n):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

ans = {}
c = collections.Counter(a)
max_value = int(sum([combinations_count(i) for i in c.values() if i>1]))
for k in range(n):
    key = a[k]
    if key in ans:
        print(ans[key])
    else:
        value = 1
        if c[key]>2:
            value = combinations_count(c[key]-1)
        ans[key] = max_value - value
        print(ans[key])
n = int(input())
balls = input().split()
for j in range(n):
  ans = 0
  len_n = 0
  for k in range(n):
    cont = balls.count(str(k))
    if len_n + cont >= n:
      break
    if balls[j] == str(k):
      ans += (cont - 1) * (cont - 2) / 2
    else:
      ans += cont * (cont - 1) / 2
  print(int(ans))
l = int(input())
A = input().split(" ")

unique = set(A)

def combination(number):
  if number == 0 or number == 1:
    return 0
  else:
    return int(number * (number - 1) / 2)

def caluculate(string):
  if memo[string] == 0:
    return(0)
  if memo[string] == 1:
    return(0)
  else:
    return(memo[string] - 1) 
  
total = 0
memo = {}
for i in unique:
  times = A.count(i)
  memo[i] = times
  total += combination(times)

print(memo)
# print(memo.keys())
# print(total)

for i in A:
  #  print(caluculate(i))
  print(total - caluculate(i))
N=int(input())
A=list(map(int,input().split()))
ls=[0 for _ in range(N)]
for i in range(N):
  ls[A[i]-1]+=1
s=0
print(ls)
for i in range(len(ls)):
    m=ls[i]*(ls[i]-1)//2
    s+=m
for j in range(N):
  print(s-(ls[A[j]-1]-1))
N=int(input())
A=list(map(int,input().split()))
for k in range(N):
  ak=A[k]
  del A[k]
  AA=sorted(A)
  s=1
  ans=0
  for i in range(N-3):
    d=AA[i+1]-AA[i]
    if d == 0:
      s+=1
    else:
      ans+=int(s*(s-1)/2)
      s=1
  print(ans)
  A.insert(k,ak)
from collections import Counter
from scipy.misc import comb



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

for k in range(N):
  sum_k = 0
  temp_c = c.copy()
  temp_c[A[k]] -= 1
  for v in temp_c.values():
    if v > 1:
      sum_k += comb(v, 2)
  print(int(sum_k))
N = int(input())
a = [int(i) for i in input().split()]

d = {}
prev = 0

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

for i in range(N):
    if i != 0 and d[a[i]] <= 1:
        print(prev)
        continue

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

    d[a[i]] += 1
n=int(input())
a=list(map(int,input().split()))
ua=list(set(a))
d={}
total=0
for i in range(n):
    y=a[i]
    if y in d:
        print(d[y])
        continue
    if ua:
        for x in ua:
            c = a.count(x)
            if c==1:
                ua.remove(x)
            total+=sum(range(c - (1 if x==y else 0)))
        print(total)
        d[y]=total
        total=0
    else:
        print(0)