qyliang/CodeNanoFix huggingface dataset:
# Buggy code:

KN = input("").split()
A = input("").split()

K = int(KN[0])
N = int(KN[1])
A_0 = int(A[0])
A_N = int(A[N-1])
L = A_0

for j in range(N-1):
    A_i = int(A[j+1])
    A_m = int(A[j])
    if A_i - A_m > L:
        L == A_i - A_m

if L > K - A_N + A_0:
    print(K-L)
else:
    print(K - A_N + A_0)



# Fixed code:
KN = input("").split()
A = input("").split()

K = int(KN[0])
N = int(KN[1])
A_0 = int(A[0])
A_N = int(A[N-1])
L = A_0

for j in range(N-1):
    A_i = int(A[j+1])
    A_m = int(A[j])
    if A_i - A_m > L:
        L = A_i - A_m

if L > K - A_N + A_0:
    print(K-L)
else:
    print(A_N - A_0)
# Buggy code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
result = 0
mx = -float("inf")
for i in range(N-1):
    mx = max(mx, A[i+1] - A[i])
mx = max(mx, K - A[-1])

result = K - mx
print(result)

# Fixed code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
result = 0
mx = -float("inf")
for i in range(N-1):
    mx = max(mx, A[i+1] - A[i])
mx = max(mx, K - A[-1] + A[0])

result = K - mx
print(result)
# Buggy code:

K, N = map(int, input().split())
A = list(map(int, input().split()))
lst = []
for i in range(1, N-1):
    diff_1 = abs(A[i + 1] - A[i])
    lst.append(diff_1)
    diff_2 = abs(A[i] - A[i - 1])
    lst.append(diff_2)

lst.append(K + A[0] - A[N-1])
print(lst)
print(K - max(lst))

# Fixed code:

K, N = map(int, input().split())
A = list(map(int, input().split()))
lst = []
for i in range(1, N-1):
    diff_1 = abs(A[i + 1] - A[i])
    lst.append(diff_1)
    diff_2 = abs(A[i] - A[i - 1])
    lst.append(diff_2)

lst.append
lst.append(K + A[0] - A[N-1])
print(K - max(lst))
# Buggy code:
KN = list(map(int, input().split()))
dis = list(map(int, input().split()))
lists = []
for i in range(KN[1]-1):
    lists.append(dis[i+1]-dis[i])

lists.append(KN[0]+dis[0]-dis[KN[1]-1])
print(lists)
print(KN[0]-max(lists))

# Fixed code:
KN = list(map(int, input().split()))
dis = list(map(int, input().split()))
lists = []
for i in range(KN[1]-1):
    lists.append(dis[i+1]-dis[i])

lists.append(KN[0]+dis[0]-dis[KN[1]-1])
print(KN[0]-max(lists))
# Buggy code:
k, n = map(int, input().split())
A = list(map(int, input().split()))
A[-1] -= k
maximum = 0
for i in range(n):
    x = A[i] - A[i-1]
    if x > maximum:
        maximum = x
print(k - maximum)


# Fixed code:
k, n = map(int, input().split())
A = list(map(int, input().split()))
maximum = 0
for i in range(n):
    x = A[i] - A[i-1]
    if i == 0:
        x += k
    if x > maximum:
        maximum = x
print(k - maximum)
# Buggy code:
k,n=map(int,input().split())
a=list(map(int,input().split()))
t=0
for i in range(1,n):
  t=max(t,a[i]-a[0])
print(k-t)

# Fixed code:
k,n=map(int,input().split())
a=list(map(int,input().split()))
t=0
for i in range(1,n):
  t=max(t,a[i]-a[i-1])
s=max(t,k-a[n-1]+a[0])
print(k-s)
# Buggy code:
def check(a):
  if a < 0:
    return a * -1
  else:
    return a

def main():
  K, N = map(int, input().split())
  As = list(map(int, input().split()))
  r = []
  for x in range(N-1, -1, -1):
    if As[x] == 0:
      r.append(check(K - As[x-1]))
      continue
    elif As[x-1] == 0:
      r.append(check(As[x]))
      continue
    solve = As[x] - As[x-1]
    r.append(check(solve))
  ans = sorted(r)
  print(K-ans)

if __name__ == "__main__":
  main()

# Fixed code:
def check(a):
  if a < 0:
    return a * -1
  else:
    return a

def main():
  K, N = map(int, input().split())
  As = list(map(int, input().split()))
  r = []
  r.append(K-As[-1]+As[0])
  for x in range(N-1, -1, -1):
    solve = As[x] - As[x-1]
    r.append(check(solve))
  ans = sorted(r)
  ans.remove(ans[-1])
  print(K-ans[-1])

if __name__ == "__main__":
  main()
# Buggy code:
"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append(2*np.pi*(K-A[i]+A[0])/K)
    else:
        theta.append(2*np.pi*(A[i+1]-A[i])/K)

theta.remove(max(theta))
#print(theta)
s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=(s*K)/(2*np.pi)
print(l_min)


# Fixed code:
"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append((K-A[i]+A[0]))
    else:
        theta.append((A[i+1]-A[i]))

#print("sum",sum(theta))

theta.remove(max(theta))
#print(theta)
s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=s
print(l_min)
# Buggy code:
k,n = map(int,input().split())
n_inf = list(map(int,input().split()))
n_inf.append(k)
n_inf.insert(0,0)
#print(n_inf)
kyori_list = [j for j in range(n+1)]
for i in range(n+1):
  kyori_list[i] = n_inf[i+1]-n_inf[i]
#print(kyori_list)
kyori_list.sort(reverse=1)
#print(kyori_list)
print(sum(kyori_list[1:n+1]))

# Fixed code:
k,n = map(int,input().split())
n_inf = list(map(int,input().split()))
#n_inf.append(k)
#n_inf.insert(0,0)
kyori_list = [j for j in range(n-1)]
for i in range(n-1):
  kyori_list[i] = n_inf[i+1]-n_inf[i]
#print(kyori_list)
kyori_list.append((n_inf[0])+(k-n_inf[n-1]))
#print(kyori_list)
kyori_list.sort(reverse=1)
print(sum(kyori_list[1:n+1]))
# Buggy code:
import math
N = int(input())
K = list(map(int,input().split()))
hashmap = {}
for k in K:
  if k not in hashmap:
    hashmap[k] = 0
  hashmap[k]+=1
total = 0
for v in hashmap.values():
  total+=math.factorial(v) // (math.factorial(v - 2) * 2)

for k in K:
  print(total-(hashmap[k]-1))

# Fixed code:
import math
N = int(input())
K = list(map(int,input().split()))
hashmap = {}
for k in K:
  if k not in hashmap:
    hashmap[k] = 0
  hashmap[k]+=1
total = 0
for v in hashmap.values():
  if v>=2:
  	total+=math.factorial(v) // (math.factorial(v - 2) * 2)

for k in K:
  print(total-(hashmap[k]-1))
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * (N+1)

for i in A:
    B[i] += 1
sum_original = sum(j*(j-1)//2 for j in B)
for k in range(N):
    print(sum_original - (B[A[k]]+1)


# Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * (N+1)

for i in A:
    B[i] += 1
sum_original = sum([j*(j-1)//2 for j in B])
for k in range(N):
    print(sum_original - B[A[k]] + 1)
# Buggy code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a_ = set(a)
x = Counter(a)
y = []
for i in a_:
    t = x[i]
    y.append(t*(t-1)//2)
res = sum(y)
for i in a:
    t = x[i]
    t_ = y[i-1]
    print(res-t_+(t-1)*(t-2)//2)

# Fixed code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a_ = set(a)
x = Counter(a)
y = {i:x[i]*(x[i]-1)//2 for i in a_}

res = sum(y.values())
for i in a:
    t = x[i]
    t_ = y[i]
    print(res-t_+(t-1)*(t-2)//2)
# Buggy code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

c = 0
cnt = [0]*n

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

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

for i in range(n):
    c += combinations(cnt[i])

for i in range(n):
    ans = c
    ans -= combinations(cnt[A[i]])
    ans += combinations(cnt[A[i]]-1)
    print(ans)



# Fixed code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

c = 0
cnt = [0]*n

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

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

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

for i in range(n):
    c += combinations(cnt[i])

for i in range(n):
    ans = c
    ans -= combinations(cnt[A[i]])
    ans += combinations(cnt[A[i]]-1)
    print(ans)
# Buggy code:
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))


# Fixed code:
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 key in d:
    ans += d[key]*(d[key]-1)//2

for i in range(N):
    print(ans - (d[A[i]] - 1))
# Buggy code:
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))


# Fixed code:
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

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

for k in l:
    print(ans - (dict[k] - 1))
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
nsum=0
for i in range(n):
    b[a[i]]+=1
for k in range(n):
    nsum+=max(b[k]*(b[k]-1)//2,0)


for j in range(n):
    print((nsum+1-b[a[j]]))


# Fixed code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
nsum=0
for i in range(n):
    b[a[i]]+=1
for k in range(n+1):
    nsum+=max(b[k]*(b[k]-1)//2,0)

for j in range(n):
    print((nsum+1-b[a[j]]))
# Buggy code:
import math
import collections

n = int(input())
a = list(map(int, input().split()))
num_list = []
ans_total = 0

c = collections.Counter(a)

for d in c:
    ans_total += int(math.factorial(c[d])/(2*math.factorial(c[d]-2)))

for i in range(n):
    print(ans_total-c[a[i]]+1)

# Fixed code:
import math
import collections

n = int(input())
a = list(map(int, input().split()))
num_list = []
ans_total = 0

c = collections.Counter(a)

for d in c:
    if not c[d] == 1:
        ans_total += int(math.factorial(c[d])/(2*math.factorial(c[d]-2)))

for i in range(n):
    print(ans_total-c[a[i]]+1)
# Buggy code:
import math
 
def permutations_count(n, r):
    if r == 2:
        return int( (n*(n-1) ) / r )
    if r == 1:
        return n
 
 
N = int(input())
A = list(map(int,input().split()))
 
data = [0] * (N+1)
 
for i in range(N):
    data[A[i]] += 1
 
total = 0
 
for i in range(N+1):
    if data[i] >= 2:
        total += permutations_count(data[i],2)
 
 
 
for i in range(N):
    if data[A[i]] - 1 > 0 :
        print( total - permutations_count(data[A[i]]-1,1) )
    else:
        print(total)

print(permutations_count(3,1))

# Fixed code:
import math
 
def permutations_count(n, r):
    if r == 2:
        return int( (n*(n-1) ) / r )
    if r == 1:
        return n
 
 
N = int(input())
A = list(map(int,input().split()))
 
data = [0] * (N+1)
 
for i in range(N):
    data[A[i]] += 1
 
total = 0
 
for i in range(N+1):
    if data[i] >= 2:
        total += permutations_count(data[i],2)
 
 
 
for i in range(N):
    if data[A[i]] - 1 > 0 :
        print( total - permutations_count(data[A[i]]-1,1) )
    else:
        print(total)
# Buggy code:
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]))


# Fixed code:
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():
    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]))
# Buggy code:
n = int(input())
a = list(map(int,input().split()))

a_2 = [0 for i in range(n)]
for i in range(n):
    a_2[a[i]-1] += 1

al = [0 for i in range(n)]
c = 0
for i in a_2:
    if i > 1:
        al[c] += i * (i-1) / 2
    c += 1

for i in range(n):
    f = a[i]
    t = a_2[f-1] - 1
    #print(int(sum(al)-(al[f-1]-t*(t-1)/2)))
    


# Fixed code:
n = int(input())
a = list(map(int,input().split()))

a_2 = [0 for i in range(n)]
for i in range(n):
    a_2[a[i]-1] += 1

al = [0 for i in range(n)]
c = 0
for i in a_2:
    if i > 1:
        al[c] += i * (i-1) / 2
    c += 1

sine = sum(al)
for i in range(n):
    f = a[i]
    t = a_2[f-1] - 1
    print(int(sine-(al[f-1]-t*(t-1)/2)))
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
IND = list(set(A))
CNT = [A.count(x) for x in IND]
# print(IND)
# print(CNT)
# CONB = [A.count(x)*(A.count(x)-1)//2 for x in IND]
CONB = [CNT[x]*(CNT[x]-1)//2 for x in range(len(CNT))]
# print(CONB)
SUM = sum(CONB)
for i in A:
    ans = SUM - CNT[i-1] + 1
    print(ans)

# Fixed code:
N = int(input())
A = list(map(int, input().split()))
CNT = [0]*(N+1)
# IND = list(set(A))
# CNT = [A.count(x) for x in IND]
for i in A:
    CNT[i] += 1
# print(IND)
# print(CNT)
# CONB = [A.count(x)*(A.count(x)-1)//2 for x in IND]
CONB = [CNT[x]*(CNT[x]-1)//2 for x in range(len(CNT))]
# print(CONB)
SUM = sum(CONB)
for i in A:
    ans = SUM - CNT[i] + 1
    print(ans)
# Buggy code:
from collections import Counter

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

ans_sum = 0

counter = Counter(a_li)
print(counter)

for i in counter:
    ans_sum += i*(i - 1)//2

for a in a_li:
    count = counter[a]
    if count == 1:
        print(ans_sum)
    else:
        print(ans_sum - count*(count - 1) // 2 + (count - 1)*(count - 2) // 2)

# Fixed code:
from collections import Counter

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

ans_sum = 0

counter = Counter(a_li)

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

for a in a_li:
    count = counter[a]
    if count == 1:
        print(ans_sum)
    else:
        print(ans_sum - count*(count - 1) // 2 + (count - 1)*(count - 2) // 2)
# Buggy code:
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)


# Fixed code:
n = int(input())
A = list(map(int,input().split()))
from collections import Counter

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



for i in A:
    X = c[i]
    ans = cou - X*(X-1)//2 + (X-1)*(X-2)//2
    print(ans)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
cnt = [0 for _ in range(N)]
for i in range(N):
    cnt[A[i]-1] += 1
S = 0
for i in range(N):
    S += cnt[i]*(cnt[i]-1)/2
for i in range(N):
    if cnt[A[i]] == 1:
        print(S)
    else:
        print(int(S+(3-2*cnt[A[i]-1])/2))


# Fixed code:
N = int(input())
A = list(map(int, input().split()))
cnt = [0 for _ in range(N)]
for i in range(N):
    cnt[A[i]-1] += 1
S = 0
for i in range(N):
    S += cnt[i]*(cnt[i]-1)/2
for i in range(N):
    if cnt[A[i]-1] == 1:
        print(int(S))
    else:
        print(int(S+(3-2*cnt[A[i]-1])/2))
# Buggy code:
n = int(input())
a_list = list(map(int, input().split()))

import collections
count_dic = collections.Counter(a_list)

count_dic_new = {}
for key, value in count_dic.items():
    if value == 1:
        count_dic_new[key] = 0
    elif value == 2:
        count_dic_new[key] = 1
    else: 
        count_dic_new[key] = (value * (value - 1)) // 2

fund_values = sum(list(count_dic_new.values()))

for a in a_list:
    if count_dic[a] == 1:
        a_value = fund_values
    elif count_dic[a] == 2:
        a_value = fund_values - 1
    else:
        n = count_dic[a]
        a_value = fund_values + (n-1)

    print(a_value)


# Fixed code:
n = int(input())
a_list = list(map(int, input().split()))

import collections
count_dic = collections.Counter(a_list)

count_dic_new = {}
for key, value in count_dic.items():
    if value == 1:
        count_dic_new[key] = 0
    elif value == 2:
        count_dic_new[key] = 1
    else: 
        count_dic_new[key] = (value * (value - 1)) // 2

fund_values = sum(list(count_dic_new.values()))

for a in a_list:
    if count_dic[a] == 1:
        a_value = fund_values
    elif count_dic[a] == 2:
        a_value = fund_values - 1
    else:
        n = count_dic[a]
        a_value = fund_values + (((n-1) * (n-2)) // 2) - (((n) * (n-1)) // 2) 

    print(a_value)
# Buggy code:
from collections import Counter

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

table = set(a)

con = {}
dic = {}
ans = []

con = Counter(a)
dic = {}
#for i in table:
#    con[i] = a.count(i)
#    dic[i] = -1

for x in a:
    if dic[x] == None:
        ex = (con[x] - 1) * (con[x] - 2) / 2
        no = (con[x]) * (con[x] - 1) / 2
        dic[x] = (int(no), int(ex))

su = sum([int(x[0]) for x in dic.values()])

for i,x in enumerate(a):
    print(su - (dic[x][0] - dic[x][1]))


# Fixed code:
from collections import Counter

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

#table = set(a)
con = Counter(a)
dic = {}
#for i in table:
#    con[i] = a.count(i)
#    dic[i] = -1

for x in a:
    if x not in dic:
        ex = (con[x] - 1) * (con[x] - 2) / 2
        no = (con[x]) * (con[x] - 1) / 2
        dic[x] = (int(no), int(ex))

su = sum([int(x[0]) for x in dic.values()])

for i,x in enumerate(a):
    print(su - (dic[x][0] - dic[x][1]))
# Buggy code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=[0]*n
    for i in range(n):
        cnt[a[i]-1]+=1
    res=0
    for i in range(n):
        if cnt[i]>1:
            res+=cnt[i]*(cnt[i]-1)//2
    ans=[0]*n
    for i in range(n):
        if cnt[i]>=1:
            ans[i]=res-(cnt[i]-1)
    print(cnt)
    print(ans)
    for i in range(n):
        print(ans[a[i]-1])
        
if __name__=="__main__":
    main()

# Fixed code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=[0]*n
    for i in range(n):
        cnt[a[i]-1]+=1
    res=0
    for i in range(n):
        if cnt[i]>1:
            res+=cnt[i]*(cnt[i]-1)//2
    ans=[0]*n
    for i in range(n):
        if cnt[i]>=1:
            ans[i]=res-(cnt[i]-1)
    for i in range(n):
        print(ans[a[i]-1])
        
if __name__=="__main__":
    main()
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
 
D = defaultdict(int)
for a in A:
    D[a] += 1
 
ans_base = 0
for v in D.values():
    ans_base += v * (v - 1) // 2
 
for a in A:
    print(ans_base - (D[a] * (D[a] - 1) // 2) + ((D[a] - 1) * (D[a] - 2) // 2))

# Fixed code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

D = defaultdict(int)
for a in A:
    D[a] += 1

ans_base = 0
for v in D.values():
    ans_base += v * (v - 1) // 2

for a in A:
    print(ans_base - (D[a] * (D[a] - 1) // 2) + ((D[a] - 1) * (D[a] - 2) // 2))
# Buggy code:
N = int(input())
nums = list(map(int, input().split()))
counts = [0 for _ in range(N+1)]
for num in nums:
  counts[num] += 1
combination = 0
for count in counts:
  if count >= 2
    combination += (count*(count-1))//2
for i in range(1, N+1):
  print(combination-counts[i]+1)


# Fixed code:
N = int(input())
nums = list(map(int, input().split()))
counts = [0 for _ in range(N+1)]
for num in nums:
  counts[num] += 1
combination = 0
for count in counts:
  if count >= 2:
    combination += (count*(count-1))//2
for num in nums:
  print(combination-counts[num]+1)
# Buggy code:
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))

# Fixed code:
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():
    count+=calc_combi2(i)
for i in data:
    ans=count-data_cnt[i]+1
    print(int(ans))
# Buggy code:
import sys
input = sys.stdin.readline

from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_c = Counter(a)
    a_c_sum = 0
    for c in a_c:
        a_c_sum += cmb(a_c[c], 2)

    for ea in a:
        if a_c[ea] <= 1:
            sa = 0
        elif a_c[ea] == 2:
            sa = 1
        else:
            sa = cmb(a_c[ea], 2) - cmb(a_c[ea] - 1, 2)
        print(a_c_sum - sa)


if __name__ == '__main__':
    main()


# Fixed code:
import sys
input = sys.stdin.readline

from math import factorial
from itertools import combinations
from collections import Counter
from copy import deepcopy
from operator import mul
from functools import reduce

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_c = Counter(a)
    a_c_sum = 0
    for c in a_c:
        if a_c[c] >= 2:
            a_c_sum += cmb(a_c[c], 2)

    for ea in a:
        if a_c[ea] <= 1:
            sa = 0
        elif a_c[ea] == 2:
            sa = 1
        else:
            sa = cmb(a_c[ea], 2) - cmb(a_c[ea] - 1, 2)
        print(a_c_sum - sa)


if __name__ == '__main__':
    main()
# Buggy code:
import collections
n = int(input())
*a, = map(int, input().split())
counter = collections.Counter(a)
d = {}
for key, value in counter.items():
    d[key] = (value * (value - 1)) // 2

sum_d = {}
for k in range(n):
    if a[k] not in sum_d:
        if d[a[k]] > 0: tmp = ((counter[a[k]] - 1) * (counter[a[k]] - 2)) // 2
        sum_d[a[k]] = sum(d.values())  - d[a[k]] + tmp
        print(sum_d[a[k]])
    else:
        print(sum_d[a[k]])

# Fixed code:
import collections
n = int(input())
*a, = map(int, input().split())
counter = collections.Counter(a)
d = {key: (value * (value - 1)) // 2 for key, value in counter.items()}
#print(d)
all_sum = sum(d.values())
#print(all_sum)

sum_d = {}
for k in range(n):
    if a[k] not in sum_d:
        if d[a[k]] > 0:
            tmp = ((counter[a[k]] - 1) * (counter[a[k]] - 2)) // 2
            sum_d[a[k]] = all_sum  - d[a[k]] + tmp
            print(sum_d[a[k]])
        else:
            print(all_sum)
    else:
        print(sum_d[a[k]])
# Buggy code:
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*n
for i in range(n):
    coun[a[i]]+=1
foi i in range(n):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)
 

# Fixed code:
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*(n+1)
for i in range(n):
    coun[a[i]]+=1
for i in range(n+1):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)
# Buggy code:
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)

# Fixed code:
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

for a in A:
    n = d[a]
    if n >= 2:
        print(ans - n + 1)
    else:
        print(ans)