Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from scipy.misc import comb
from collections import defaultdict
d = defaultdict(lambda: -1)
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(len(a)):
  a_ = a.copy()
  b = a_.pop(i)
  if d[str(b)] != -1:
    print(d[str(b)])
    continue
  A = list(set(a_))
  ans = 0
  for j in A:
    ans += comb(a_.count(j), 2, exact=True)

  d[str(b)] = ans
  print(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)))

from scipy.misc import comb
from collections import defaultdict
d = defaultdict(lambda: -1)
d_ = defaultdict(lambda: -1)
n = int(input())
a = [int(x) for x in input().split()]

for i in range(len(a)):
  a_ = a.copy()
  b = a_.pop(i)
  if d[str(b)] != -1:
    print(d[str(b)])
    continue
  A = list(set(a_))
  ans = 0
  for j in A:
    c = a_.count(j)
    if d_[str(c)] != -1:
      ans += d_[str(c)]
    else:
      e = comb(c, 2, exact=True)
      ans += e
      d_[str(c)] = e

  d[str(b)] = ans
  print(ans)




from scipy.misc import comb
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(len(a)):
  a_ = a.copy()
  a_.pop(i)
  A = list(set(a_))
  ans = 0
  for j in A:
    ans += comb(a_.count(j), 2, exact=True)

  print(ans)




from scipy.misc import comb
from collections import defaultdict
from collections import deque
d = defaultdict(lambda: -1)
d_ = defaultdict(lambda: -1)
n = int(input())
a = deque([int(x) for x in input().split()])

for i in a:
  a_ = a.copy()
  b = a_.remove(i)
  if d[str(b)] != -1:
    print(d[str(b)])
    continue
  A = list(set(a_))
  ans = 0
  for j in A:
    c = a_.count(j)
    if d_[str(c)] != -1:
      ans += d_[str(c)]
    else:
      e = comb(c, 2, exact=True)
      ans += e
      d_[str(c)] = e

  d[str(b)] = ans
  print(ans)




from scipy.misc import comb
from collections import defaultdict
from collections import deque
d = defaultdict(lambda: -1)
d_ = defaultdict(lambda: -1)
n = int(input())
a = deque([int(x) for x in input().split()])

for i in a:
  a_ = a.copy()
  b = a_.remove(i)
  if d[str(b)] != -1:
    print(d[str(b)])
    continue
  A = list(set(a_))
  ans = 0
  for j in A:
    c = a_.count(j)
    if d_[str(c)] != -1:
      ans += d_[str(c)]
    else:
      e = comb(c, 2, exact=True)
      ans += e
      d_[str(c)] = e

  d[str(b)] = ans
  print(ans)




from scipy.misc import comb
from collections import defaultdict, deque
d = defaultdict(lambda: -1)
d_ = defaultdict(lambda: -1)
n = int(input())
a = deque([int(x) for x in input().split()])
for i in a:
  a_ = a.copy()
  a_.remove(i)
  b = i
  if d[str(b)] != -1:
    print(d[str(b)])
    continue
  A = list(set(a_))
  ans = 0
  for j in A:
    c = a_.count(j)
    if d_[str(c)] != -1:
      ans += d_[str(c)]
    else:
      e = comb(c, 2, exact=True)
      ans += e
      d_[str(c)] = e

  d[str(b)] = ans
  print(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))+((x-1)*(x-2)/2)))

Verdicts: Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Runtime Error

Runtime Error

Accepted