Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
 
n = int(input())
A = np.array(list(map(int, input().split(' '))))
 
A_unique = np.unique(A)
num_dict = {}
total = 0
for a in A_unique:
  tmp = np.count_nonzero(A==a)
  num_dict[a] = (tmp*(tmp-1)/2, (tmp-1)*(tmp-2)/2)
  total += tmp*(tmp-1)/2

ans_dict = {}
for a in A_unique:
  ans_dict[a] = int(total - num_dict[a][0] + num_dict[a][1])

for a in A:
  print(ans_dict[a])

Fixed submission:
import collections

n = int(input())
A = list(map(int, input().split(' ')))
 
c = dict(collections.Counter(A))
num_dict = {}
total = 0
for a, count in c.items():
  num_dict[a] = (count*(count-1)/2, (count-1)*(count-2)/2)
  total += count*(count-1)/2

ans_dict = {}
for a in c.keys():
  ans_dict[a] = total - num_dict[a][0] + num_dict[a][1]

for k in range(n):
  print(int(ans_dict[A[k]]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
 
n = int(input())
A = np.array(list(map(int, input().split(' '))))
 
A_unique = np.unique(A)
num_dict = {}
total = 0
for a in A_unique:
  tmp = np.count_nonzero(A==a)
  num_dict[a] = (tmp*(tmp-1)/2, (tmp-1)*(tmp-2)/2)
  total += tmp*(tmp-1)/2

for k in range(n):
  print(int(total - num_dict[A[k]][0] + num_dict[A[k]][1]))

Fixed submission:
import collections

n = int(input())
A = list(map(int, input().split(' ')))
 
c = dict(collections.Counter(A))
num_dict = {}
total = 0
for a, count in c.items():
  num_dict[a] = (count*(count-1)/2, (count-1)*(count-2)/2)
  total += count*(count-1)/2

ans_dict = {}
for a in c.keys():
  ans_dict[a] = total - num_dict[a][0] + num_dict[a][1]

for k in range(n):
  print(int(ans_dict[A[k]]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
A = np.array(list(map(int, input().split(' '))))

A_unique = np.unique(A)
num_dict = {}
total = 0
for a in A_unique:
  tmp = np.sum(A==a)
  num_dict[a] = (tmp*(tmp-1)/2, (tmp-1)*(tmp-2)/2)
  total += tmp*(tmp-1)/2

for k in range(n):
  print(int(total - num_dict[A[k]][0] + num_dict[A[k]][1]))
  

Fixed submission:
import collections

n = int(input())
A = list(map(int, input().split(' ')))
 
c = dict(collections.Counter(A))
num_dict = {}
total = 0
for a, count in c.items():
  num_dict[a] = (count*(count-1)/2, (count-1)*(count-2)/2)
  total += count*(count-1)/2

ans_dict = {}
for a in c.keys():
  ans_dict[a] = total - num_dict[a][0] + num_dict[a][1]

for k in range(n):
  print(int(ans_dict[A[k]]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
A = np.array(list(map(int, input().split(' '))))

A_unique = np.unique(A)
num_dict = {}
for a in A_unique:
  tmp = np.sum(A==a)
  num_dict[a] = (tmp*(tmp-1)/2, (tmp-1)*(tmp-2)/2)
total = sum([x[0] for x in num_dict.values()])

for k in range(n):
  print(int(total - num_dict[A[k]][0] + num_dict[A[k]][1]))

Fixed submission:
import collections

n = int(input())
A = list(map(int, input().split(' ')))
 
c = dict(collections.Counter(A))
num_dict = {}
total = 0
for a, count in c.items():
  num_dict[a] = (count*(count-1)/2, (count-1)*(count-2)/2)
  total += count*(count-1)/2

ans_dict = {}
for a in c.keys():
  ans_dict[a] = total - num_dict[a][0] + num_dict[a][1]

for k in range(n):
  print(int(ans_dict[A[k]]))