Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = B[0]
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)			# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)		# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)
idx_sum_set = []
all_c = 0
for i in range(len(idx_set)):
  all_c += idx_set[i][1]
for i in range(len(idx_set)):
  tmp = all_c-idx_set[i][1]+idx_set[i][2]
  idx_sum_set.append([idx_set[i][0], tmp])    

if len(idx_sum_set) == 1:
  for i in range(N):
    print(idx_sum_set[0][1])
elif all_c == 0:
  for i in range(N):
    print(0)
else:
  for i in range(N):
    j = int(len(idx_sum_set)/2)
    while 1:
      if A[i] == idx_sum_set[j][0]:
        print(idx_sum_set[j][1])
        break
      elif A[i] > idx_sum_set[j][0]:
        j = j + int((len(idx_sum_set)-j)/2)
      elif A[i] < idx_sum_set[j][0]:
        j = int(j/2)



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = B[0]
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)			# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)		# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)
idx_sum_set = []
all_c = 0
for i in range(len(idx_set)):
  all_c += idx_set[i][1]
for i in range(len(idx_set)):
  tmp = all_c-idx_set[i][1]+idx_set[i][2]
  idx_sum_set.append([idx_set[i][0], tmp])    

if len(idx_sum_set) == 1:
  for i in range(N):
    print(idx_sum_set[0][1])
else:
  for i in range(N):
    j = int(len(idx_sum_set)/2)
    while 1:
      if A[i] == idx_sum_set[j][0]:
        print(idx_sum_set[j][1])
        break
      elif A[i] > idx_sum_set[j][0]:
        j = j + int((len(idx_sum_set)-j)/2)
      elif A[i] < idx_sum_set[j][0]:
        j = int(j/2)



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = B[0]
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)			# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)		# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)
idx_sum_set = []
all_c = 0
for i in range(len(idx_set)):
  all_c += idx_set[i][1]
for i in range(len(idx_set)):
  tmp = all_c-idx_set[i][1]+idx_set[i][2]
  idx_sum_set.append([idx_set[i][0], tmp])    

if len(idx_sum_set) == 1:
  for i in range(N):
    print(idx_sum_set[0][1])
else:
  for i in range(N):
    j = int(len(idx_sum_set)/2)
    while 1:
      if A[i] == idx_sum_set[j][0]:
        print(idx_sum_set[j][1])
        break
      elif A[i] > idx_sum_set[j][0]:
        j = j + int((len(idx_sum_set)-j)/2)
      elif A[i] < idx_sum_set[j][0]:
        j = int(j/2)



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = B[0]
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)			# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)		# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)
idx_sum_set = []
all_c = 0
for i in range(len(idx_set)):
  all_c += idx_set[i][1]
for i in range(len(idx_set)):
  tmp = all_c-idx_set[i][1]+idx_set[i][2]
  idx_sum_set.append([idx_set[i][0], tmp])    

for i in range(N):
  j = int(len(idx_sum_set)/2)
  while 1:
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
      break
    elif A[i] > idx_sum_set[j][0]:
      j = j + int((len(idx_sum_set)-j)/2)
    elif A[i] < idx_sum_set[j][0]:
      j = int(j/2)



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = 1
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)			# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)		# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])

idx_sum_set = []
all_c = 0
for i in range(len(idx_set)):
  all_c += idx_set[i][1]
for i in range(len(idx_set)):
  for j in range(len(idx_set)):
    if i == j:
      tmp = all_c-idx_set[j][1]+idx_set[j][2]
      idx_sum_set.append([idx_set[i][0], tmp])
"""
for i in range(len(idx_set)):
  tmp = 0
  for j in range(len(idx_set)):
    if i == j:	tmp += idx_set[j][2]
    else:		tmp += idx_set[j][1]
  idx_sum_set.append([idx_set[i][0],tmp])
"""

for i in range(N):
  j = int(len(idx_sum_set)/2)
  while 1:
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
      break
    elif A[i] > idx_sum_set[j][0]:
      j = j + int((len(idx_sum_set)-j)/2)
    elif A[i] < idx_sum_set[j][0]:
      j = int(j/2)
"""
for i in range(N):
  for j in range(len(idx_sum_set)):
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
"""



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = 1
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])

idx_sum_set = []
for i in range(len(idx_set)):
  tmp = 0
  for j in range(len(idx_set)):
    if i == j:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  idx_sum_set.append([idx_set[i][0],tmp])

for i in range(N):
  j = int(len(idx_sum_set)/2)
  while 1:
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
      break
    elif A[i] > idx_sum_set[j][0]:
      j = j + int((len(idx_sum_set)-j)/2)
    elif A[i] < idx_sum_set[j][0]:
      j = int(j/2)
"""
for i in range(N):
  for j in range(len(idx_sum_set)):
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
"""



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = 1
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])

idx_sum_set = []
for i in range(len(idx_set)):
  tmp = 0
  for j in range(len(idx_set)):
    if i == j:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  idx_sum_set.append([idx_set[i][0],tmp])
  
for i in range(N):
  for j in range(len(idx_sum_set)):
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
"""
for i in range(N):
  tmp = 0
  for j in range(len(idx_set)):
    if A[i] == idx_set[j][0]:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  print(tmp)
"""



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

idx = 1
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# あるボールの等価な組み合わせ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# あるボールを1つ除いたときの等価な組み合わせ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)		# あるボールの等価な組み合わせ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)	# あるボールを1つ除いたときの等価な組み合わせ数
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)

for i in range(N):
  tmp = 0
  for j in range(len(idx_set)):
    if A[i] == idx_set[j][0]:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  print(tmp)



Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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

all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			# 同一の整数を持つボールの組合せ数
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))