peterverebics/CodeNet_Python_118 huggingface dataset:
import bisect
import copy
N = int(input())
a = list(map(int, input().split()))
b = sorted(a)
c = list(set(b))
length = 0
l = []
num = []
sumlen = 0
for i in c:
    bs = bisect.bisect_right(b, i)
    length = bs - sumlen
    sumlen += length
    l.append(length)
    num.append(int((length * (length - 1)) / 2))
for k in a:
    idx = c.index(k)
    n = l[idx]
    number = copy.copy(num)
    number[idx] = number[idx] * (n-2) / n
    print(int(sum(number)))
n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(len(l)):
        print(n+1)
else:
    for k in range(len(l)):
        tp = l.pop(k)
        print(sum(set([l.count(i) for i in l])))
        l.insert(k,tp)
n = int(input())
a_list = [int(x) for x in input().split()]
a_dict = {}

for a in a_list:
  if a in a_dict.keys():
    a_dict[a] += 1
  else:
    a_dict[a] = 0

for a in a_list:
  print(a_dict[a])
import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n=ii()
    a=lmis()
    nlis=[0]*(n+1)
    cnt=0
    for i in range(n): nlis[a[i]]+=1
    for i in range(n): cnt+=nlis[i]*(nlis[i]-1)//2
    for i in range(n): print(cnt+1-nlis[a[i]])

if __name__ == "__main__":
    main()
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-1))
        else:
            print(0)
import math
import collections

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

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

for i in range(N):
    result = 0
    pop = A.pop(i)
    c = collections.Counter(A)
    v = c.values()
    for i in v:
        if i > 1:
            result = result + combinations_count(i, 2)
    A.insert(i, pop)
    print(result)
def main():
    N = int(input())
    A = list(map(int, input().split()))

    print(N)
    print(A)

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




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

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

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

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

ansdic = {}

for a in dic:
    ansdic[a] = 0
    if dic[a] > 1:
        ansdic[a] = ans - (dic[a] - 1)

for a in A:
    print(ansdic[a])
import collections

num = int(input())
a_i = list(map(int, input().split()))
anslist = collections.Counter(a_i)
ans = sum(anslist.values())
for x in range(num):
    val = a_i[x]
    cnt = a_i.count(val)
    sa = (cnt - 1)
    print(ans - sa)
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
print(c.items())
all=0
for i,j in c.items():
    all += j*(j-1)//2
for i in range(N):
    print(all-(a.count(a[i])-1))
N = int(input())
values = list(map(int, input().split(' ')))



count = {}
for i in range(N):
    if values[i] not in count:
        count[values[i]] = 1
    else:
        count[values[i]] = count[values[i]] + 1

for i in range(N):
    temp = count
    temp[values[i]] = temp[values[i]] - 1
    num = 0
    for j in temp:
        num = num + int(temp[j]*(temp[j]-1)/2)
    print(num)
n = int(input())
a =list(map(int,input().split()))
d = [0]*(n+1)
answer = 0
for i in range(n):
  d[a[i]]+=1
for j in range(n):
  answer+= (d[j]*(d[j]-1))//2
for k in range(n):
  print(answer+1-(d[a[k]]))
N = int(input())
a = (input().split())
a_str = ''.join(a)
a_str2 = a_str
sum = 0
l_dict = {}
while len(a_str)>0:
    n = a.count(a_str[0])
    sum += int(n*(n-1)/2)
    l_dict[a_str[0]] = n
    a_str = a_str.replace(a_str[0],'')
for k in range(N):
    print(int(sum-l_dict[a_str2[k]]+1))
n = int(input())
A = []
A = [int(i) for i in input().split()]

number_set = list(set(A))
#print("number set is :", number_set)    
    
for k in range(n):
    out = 0
    ans = []
    ans += A[0:k]
    ans += A[k+1:n]
    #print(ans)
    for i in range(len(number_set)):
        #print(ans.count(number_set[i]))
        out += ans.count(number_set[i]) * (ans.count(number_set[i]-1)) //2
        
    print(out)
from itertools import combinations
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    cnt = [0] * (2 * 10 ** 5 + 1)
    for i in range(N):
        cnt[A[i]] += 1

    cnt_comb = 0
    for i in range(N):
        cnt_comb += len(list(combinations(range(cnt[i]), 2)))
    
    for i in range(N):
        print(max(0,cnt_comb - (cnt[A[i]]-1)))

if __name__ == '__main__':
    solve()
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:
    if lin[i] < 2:
        print(0)
        continue
    print(point-liv[i]+(lin[i]-1)*(lin[i]-2)//2)
N = int(input())
A = list(map(int,input().split()))

count = [0]*(N+1)

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

total= 0
for j in range(N):
  cj = count[j]*(count[j]-1)//2
  total = total + cj

ans = total
for k in range(N):
  ans = total - (count[A[k]] - 1)
  print(ans)
N = int(input())
A = list(map(int, input().split()))

a = list(set(A))
a_n = []
c = []
if len(a) != N:
  for i in range(len(a)):
    x = A.count(a[i])
    a_n.append(x)
    c.append(x*(x-1)//2)

  ans = sum(c)
  print(c)
  for i in range(N):
    n = a.index(A[i])
    new = (a_n[n]-1)*(a_n[n]-2)//2
    print(ans-c[n]+new)
else:
  for _ in range(N):
    print(0)
from scipy.misc import comb
N=int(input())
A=list(map(int,input().split()))
for j in range(1,N+1):
    print(int(sum([comb((A[:j-1]+A[j:]).count(i),2) for i in range(1,N+1)])))
import collections
n = int(input())
num_list = list(map(int, input().split()))
all = 0

c = collections.Counter(num_list)
value_list = list(c.values())

for i in range(len(value_list)):
    if not value_list[i] == 1:
        all += value_list[i]*value_list[i-1]//2

for k in range(n):
    print(all - num_list.count(num_list[k])-1)
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(n+1)]

for i in a:
  l[i]+=1
cmb1=[0 for i in range(n+1)]
cmb2=[0 for i in range(n+1)]

for i in range(n):
  cmb1[i]=(l[i]*(l[i]-1))//2
  cmb2[i]=((l[i]-1)*(l[i]-2))//2

kei1=0
for i in range(n):
  kei1+=cmb1[i]

for i in range(n):
  print(kei1-cmb1[a[i]]+cmb2[a[i]])
from collections import Counter
from math import factorial


def choose(n: int) -> int:
    if n < 2:
        return 0
    else:
        return factorial(n) // (2 * factorial(n - 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)
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)
ans = 0
for i in range(N):
    ans += d[A[i]]*(d[A[i]]-1)/2

for i in range(N):
    print(ans - (d[A[i]]- 1))
N = int(input())
A = list(map(int,input().split()))
import copy


s = [0 for i in range(N)]
for i in range(N):
    s[A[i]-1] += 1
    
s1 = copy.copy(s)
for i in range(N):
    if s[i] == 0:
        s1[i] = 0
    else:
        s1[i] -= 1

amount = sum(s)

for i in range(N):
    print(amount-s1[A[i]-1])
def comb(n, r):
    upper = 1
    for i in range(r):
        upper *= (n-i)
    lower = r*(r-1)*2
    # print(n, r, upper, lower, int(upper/lower))
    return int(upper/lower)

n = int(input())
a = list(map(int, input().split()))
for k in range(n):
    temp = a[:]
    temp[k:k+1] = []
    ms = set(temp)
    total = 0
    for m in ms:
        times = temp.count(m)
        if times < 2:
            continue
        total += comb(times, 2)
    print(int(total))
import collections
from collections import defaultdict

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

dict = defaultdict(int)
for i in l:
    dict[i]+=1
print(dict)

ans = 0
for v in dict.values():
    ans += int((v*(v-1)) // 2)

for k in l:
    print(ans - (dict[k] - 1))
from collections import Counter

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

cA = Counter(A)

allS = 0
for key in cA:
    allS += cA[key] * (cA[key] - 1) / 2

for i in range(N):
    if i in cA.keys():
        print(int(allS - (cA[i] - 1)))
    else:
        print(int(allS))
N=int(input())
A=list(map(int,input().split()))

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

S=0
for i in range(N):
    if B[i]!=0:
        S += int(B[i]*(B[i]-1)/2)

for i in range(N):
    print(S - (B[A[i]] -1))
N = int(input())
AList = [int(i) for i in input().split()]

sum =0

for i in range(N):
  for j in range(N):
    if AList[i] == AList[j]:
      sum += 1
  print(sum-1)
  sum = 0
n=int(input())
a=list(map(int,input().split()))

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

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

for i in range(n):
  count = total - inp[a[i]]*(inp[a[i]]-1) // 2 + (inp[a[i]]-1)*(inp[a[i]]-2) // 2
  print(count)
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5)+1)
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]]+1)
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    c = Counter(a)
    b = sum(v * (v - 1) // 2 for v in c.values())
    print(c, b)
    return "\n".join(str(b - c[_a] + 1) for _a in a)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    cnt = [0] * (2 * 10 ** 5 + 1)
    for i in range(N):
        cnt[A[i]] += 1

    cnt_comb = 0
    for i in range(N):
        cnt_comb += calcComb(cnt[i])
    
    for i in range(N):
        print(max(0,cnt_comb - (calcComb(cnt[A[i]]) - calcComb(cnt[A[i]]-1))))

def calcComb(n):
    if n == 0:
        return 0
    return (n*(n-1)) // (2*1)
if __name__ == '__main__':
    solve()
n = int(input())
k = list(input().split())
dic = {}
c = 0

for i in range(len(k)):
    if k[i] not in dic:
        freq = k.count(k[i])
        dic[int(k[i])] = k.count(k[i])

for m in dic.values():
    c += (m*(m-1))/2


for n in range(len(k)):
    c - (dic[int(k[n])]*(dic[int(k[n])]-1)/2)
    c + ((dic[int(k[n])]-1)*((dic[int(k[n])]-2))/2)
    print(int(c))
N=int(input())
A=list(map(int,input().split()))
count=[0]*(N+1)
for a in A:
    count[a]+=1
combination=0
for i in range(N):
    if count[i]!=0:
        combination+=count[i]*(count[i]-1)//2
for a in A:
    print(combination-(count[a]-1))
from collections import Counter

n = int(input())
a = input().split()
freq = Counter(a)
print(freq)
total = []



for k in range(n): 
    freq[a[k]]-=1
    total=0
    
    for key,val in freq.items():
        total+=(val*(val-1))//2
        
    freq[a[k]]+=1
    
    print(total)
n=int(input())
a=[int(s) for s in input().split()]
d={}
for i in range(0,n):
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1 
for i in range(0,n):
    print(d[a[i]]-1)
N = int(input())
a = (input().split())
a_str = ''.join(a)
a_str2 = a_str
sum = 0
l_dict = {}
while len(a_str)>0:
    n = a.count(a_str[0])
    sum += int(n*(n-1)/2)
    l_dict[a_str[0]] = n
    a_str = a_str.replace(a_str[0],'')
print(l_dict,sum)
for k in range(N):
    print(sum-l_dict[a_str2[k]]+1)
N = int(input())
A = list(map(int,input().split()))
S = 0
for i in range(N):
    S += int(A[i]*(A[i]-1)/2)
for k in range(N):
    print(S - A.count(A[k]) + 1)
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
print(c.items())
all=0
for i,j in c.items():
    all += j*(j-1)//2
for i in range(N):
    print(all-(c[a[i]]-1))
import collections as cl
n = int(input())
A = list(map(int,input().split()))
cn = cl.Counter(A)
sumC = sum([(n-2)*(n-1)/2 for n in cn.values()])
for k in range(n):
  print(sumC - cn[k] +1)
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):
    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]])
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(n):
    total += int(count[i] * (count[i] - 1) / 2)

for v in a:
    sub = int(count[v] * (count[v] - 1) / 2)
    add = int((count[v] - 1) * (count[v] - 2) / 2)
    print(total - sub + add)
n = int(input())
a = list(map(int, input().split()))
a_uni = list(set(a))

a_ol = {}
def_count = 0
for i in a_uni:
    a_co = a.count(i)
    a_ol[i] = a_co
    def_count += a_co * (a_co - 1)

def_count *= 0.5

for k in range(n):
    print(def_count - a_ol[a[k]] + 1)
N=int(input())
A = list(map(int, input().split()))

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

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

for k in A:
    print(hoge-(dic[k]-1))
def main():
    N = int(input())
    A = [int(v) for v in input().split()]
    C = [0] * (N + 1)

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


    b = 0
    print(C)
    for cnt in C:
        print('b', 'cnt', b, cnt)
        b += ((cnt * (cnt - 1)) // 2)

    for i in range(N):
        p = ((C[A[i]] - 1) * (C[A[i]] - 2)) >> 1
        m = (C[A[i]] * (C[A[i]] - 1)) >> 1
        print(b - m + p)


if __name__ == '__main__':
    main()
ball_value=int(input())
ball_number=list(map(int,input().split()))
i=0

for i in range(ball_value):
    counter=ball_number.count(ball_number[i])-1
    print(counter)
import math
import sys
input = sys.stdin.readline

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

N = int(input())
L = list(map(int, input().split()))
M = [0] *(N+1)

for i in L:
    M[i] += 1
ans = 0
for i in range(N):
  A = M[i]
  if A >= 2:
  	ans += combinations_count(A, 2)
for i in range(N):
  A = L[i]
  B = M[A]
  if B == 2:
  	print(ans - 1)
  elif B > 2:
    print(ans -combinations_count(B,2) +combinations_count(B-1,2))
  else:
    print(ans)
n=int(input())
As = input().split()

dic = {}
for a in As:
  if a not in dic:
    dic[a] = 0
  dic[a] += 1

tmp = 0
for k, v in dic.items():
  if v > 1:
    tmp += v * (v-1)/2

ans = []
for a in As:
  if dic[a] > 1:
    div = dic[a] * (dic[a] - 1) / 2
    kakeru = (dic[a]-1) * (dic[a]-2)/2
    ans.append(int(tmp - div + kakeru))
  else:
    ans.append(tmp)
for a in ans:
  print(a)
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
  tmp = a[i]
  num = a.count(tmp) - 1
  print(num*(num-1)//2)
n = int(input())
a = list(map(int,input().split()))
c = [0 for _ in range(n)]
r = []
for i in range(n):
    c[a[i-1]-1] += 1
for i in range(n):
    r.append(c[i-1])
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(v)):
    for j in range(v[i]+1):
        print(ans - v[i])
from scipy.misc import comb

def banned(al):
    d = {}
    for a in al:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    # print(d)
    for a in al:
        d[a] -= 1
        ans = 0
        for v in d.values():
            if v > 1:
                ans += comb(v, 2)
        d[a] += 1
        print(int(ans))

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

banned(al)
from collections import Counter
n = int(input())
res = list(map(int,input().split()))
res2 = res.copy()
a = Counter(res)
b = set()
for i in range(len(res)):
    if res[i] not in b:
        b.add(res[i])
        a[res[i]] -= 1
        sums = 0
        for j in a.values():
            sums += j * (j - 1) // 2
        a[res[i]] += 1
        res2 = [sums if x == res[i] else x for x in res2]
for k in res2:
    print(k)
import collections
n = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = B.copy()
total = 0
for i in B.values():
    total += i*(i-1)//2
for i in A:
    print(total - i)
n=input()
arr=map(int, raw_input().split())
count=[0]*(n+1)
for i in arr:
  count[i]+=1
res=0
for i in xrange(n):
  if count[i]>1:
    res+=count[i]*(count[i]-1)/2
# print count
for i in xrange(n):
  s=count[arr[i]]
  if s>1:
    if s-1>1:
        print res-s*(s-1)/2+(s-1)*(s-2)/2
    else:
        print res-s*(s-1)/2
  else:
    print res
#TLE
n = int(input())
a = input().split()
dicti = {}
ans = 0
for i in range(n):
    if i in dicti:
        ans += dicti[i]
    else:
        num = a.count(a[i])
        ans += num
        dicti[i] = num
ans /= 2
for i in range(n):
    answer = ans - dicti[i] - 1
    print(int(answer))
from sys import stdin
input = stdin.readline

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

for i in A:
    temp = c.copy()
    temp[i] = temp[i]-1
    counter = 0
    for j in c.keys():
        n = temp[j]
        if n >= 2:
            counter += n*(n-1)/2
    print(counter)
n=input()
arr=map(int, raw_input().split())
count=[0]*(n+1)
for i in arr:
  count[i]+=1
res=0
for i in xrange(n):
  if count[i]>1:
    res+=count[i]*(count[i]-1)/2
print count
for i in xrange(n):
  s=count[arr[i]]
  if s>1:
    if s-1>1:
        print res-s*(s-1)/2+(s-1)*(s-2)/2
    else:
        print res-s*(s-1)/2
  else:
    print res
N = int(input())
array = list(map(int,input().split()))
for i in range(N):
    array1 = array.copy()
    array1.pop(i)
    SET = set(array1)
    for j in list(SET):
        if(array1.count(j) <= 1):
            print(0)
            pass
        else:
            count = array1.count(j)
            print((count*(count-1))//2)
n=int(input())
a=list(map(int,input().split()))
d={}
for x in a:
    if d.get(x):
        d[x]+=1
        continue
    d[x]=1
total=sum(d.values())
for x in a:
    print(total-d[x]+1)
n = int(input())
a = [int(x) for x in input().split()]

cnt = [0] * n
sum_count = 0
for i in range(0, n-1):
    for j in range(i+1, n):
        if a[i] == a[j]:
            cnt[i] += 1
            cnt[j] += 1
            sum_count = 1


for i in range(n):
    print(sum_count-cnt[i])
import collections

if __name__ == '__main__':

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

    c = collections.Counter(a)

    all = 0
    before = []
    after = []

    for i in range(n):
        for item in c.items():
            cnt = item[1]*(item[1]-1)//2
            all += cnt
            before.append(item[1]*(item[1]-1)//2)
            after.append((item[1]-1)*(item[1]-2)//2)

    for i in range(n):
        ans = all - before[i] + after[i]
        print(ans)
from math import factorial
N = int(input())
A = list(map(int, input().split()))

ret = [0 for k in range(N)]

for k in range(N):
    ret[A[k]-1] += 1

f2 = factorial(2)

result = [n*(n-2)/f2 if n > 1 else 0 for n in ret]

for k in range(N):
    i = A[k]
    print(int(sum([r if A[k]-1 != j else r*(ret[i-1]-2)/ret[i-1] for j, r in enumerate(result)])))
n = int(input())
a = list(map(int, input().split()))

from collections import Counter

c = Counter(a)

from scipy.misc import comb

s = set(c.values())

dic = {}
for ss in s:
    if ss not in dic.keys():
        dic[ss] = comb(ss, 2)
for ss in s:
    ss -= 1
    if ss not in dic.keys():
        dic[ss] = comb(ss, 2)

base = 0
for k in c.keys():
    base += dic[c[k]]

for k in range(len(a)):
    print(int(base - dic[c[a[k]]] + dic[c[a[k]] - 1]))
from collections import Counter
N=int(input())
A=[int(item)for item in input().split()]
c=Counter(A)
full = {i: c[i] * (c[i] - 1) / 2 for i in c.keys()}
#full = [full[item-1] for item in A]
print(full)
#ichiheri = [c[i]-1 * (c[i]-1) / 2 for i in range(1,1+len(c))]
ichiheri = {i:(c[i]-2) * (c[i]-1) / 2 for i in c.keys()}
print(ichiheri)

for a in A:
    sumA = sum(full.values())
    sumA-=full[a]
    sumA += ichiheri[a]
    print(int(sumA))
def fact(n):
    answer = 1
    for i in range(1, n+1):
        answer*=i
    return answer
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 += fact(temp.count(k))//(fact(temp.count(k)-2)*2)
    print(ans)
    ans = 0
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):
  print(p-(c[A[i]]-1))
n = int(input())
a = list(map(int,input().split()))

#aに含まれる要素とその個数を取得する
d = {}
for i in range(n):
	d[a[i]] = d.get(a[i], 0) + 1

# print(d)

for i in range(n):
	tmp = a[i]
	print(d[tmp] - 1)
import copy
n = int(input())
a = input().split()

for i in range(n):
  b = copy.copy(a)
  del b[i]
  k = 0
  c = set(b)
  for t in c:
    num = b.count(t)
    
    print('num',num)
    for i in range(num):
      k += i
  print(k)
import collections as cl
from math import factorial

def comb(n, r):
  if n >= r:
    return factorial(n) // (factorial(n - r) * factorial(r))
  elif n == 1:
      return 1
  else:
    return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
  npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
  print(npair - (clc[a_] - 1))
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = {}
for k in cnt.keys():
    ans[k] = (cnt[k] * cnt[k]-1) // 2
s = sum(list(ans.values()))
for ai in a:
    if ai == 1:
        print(s)
    else:
        print(s - ans[ai] + (ans[ai] / cnt[ai]) * (cnt[ai] - 2))
from collections import Counter
N = int(input())
B = [int(x) for x in input().split()]
A=Counter(B)
V, C = zip(*A.most_common())
count=0
for x in C:
  if x==0:
    break
  count+=x*(x-1)/2
for x in A:
  ans=count-C[V.index(x)]+1
  print(int(ans))
import collections 
from collections import Counter
*l, = map(int, input().split())
c = Counter(l)

A = [int(i*(i-1)/2) for i in c.values()]
A_sum = sum(A)

for j in l:
	print(A_sum - c[j] + 1)
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
values, counts = zip(*c.most_common())
values, counts = list(values), list(counts)
k = 0
for i in range(len(counts)):
  k += counts[i]*(counts[i]-1)//2
output = [0]*len(a)
for i in range(len(a)):
  temp = c[a[i]]
  if temp == 1:
    output[i] = k
  else:
    output[i] = k-temp*(temp-1)//2+(temp-1)*(temp-2)//2
print(output)
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])
n=int(input())

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

cnt=[0]*(n+1)
for i in range(n):
    cnt[a[i]]+=1 
aa=0
ans=[]
for i in range(n):
    aa+=(cnt[i]*(cnt[i]-1)//2)
for i in range(n):
    print(aa-(cnt[a[i]]*(cnt[a[i]]-1))//2 +((cnt[a[i]]-1)*(cnt[a[i]]-2))//2, end ="\n")
m = int(input())
q_list = list(map(int, input().strip().split()))
n = [0] * m
k = [0] * m

for i in q_list:
    n[i - 1] += 1
for j, l in zip(range(m), n):
    k[j] = int(l * (l - 1)/2)
sum_n = sum(k)

for j in q_list:
    print(sum_n - n[j - 1]-1)
import itertools
import math 
def C(n,r):
    if n-r < 0:
        return 0 
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
for i in d.values():
    c += C(i,2)
print(d)
for i in a:
    print(c - (C(d[i],2)-C(d[i]-1,2)))