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

balls = {}

for a in A:
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

for a in A:
  balls[a] -= 1
  res = 0
  for b in balls:
    count = balls[b]
    res += count * (count-1) // 2
  balls[a] += 1
  print(res)

Fixed submission:
from copy import deepcopy
dp = {0: 0}

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

balls = {}
fact = 1
for (i, a) in enumerate(A):
  count = i+1
  dp[count] = count * (count-1) // 2
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

res = 0
for count in balls.values():
  res += dp[count]

for a in A:
  print(res - dp[balls[a]] + dp[balls[a]-1])

Buggy python submission (verdict: Runtime Error):
from copy import deepcopy
dp = {}

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

balls = {}
fact = 1
for (i, a) in enumerate(A):
  count = i+1
  dp[count] = count * (count-1) // 2
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

res = 0
for count in balls.values():
  res += dp[count]

for a in A:
  print(res - dp[balls[a]] + dp[balls[a]-1])

Fixed submission:
from copy import deepcopy
dp = {0: 0}

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

balls = {}
fact = 1
for (i, a) in enumerate(A):
  count = i+1
  dp[count] = count * (count-1) // 2
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

res = 0
for count in balls.values():
  res += dp[count]

for a in A:
  print(res - dp[balls[a]] + dp[balls[a]-1])

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
dp = {}
dpa = {}

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

balls = {}
fact = 1
for (i, a) in enumerate(A):
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

for a in A:
  if not a in dpa:
    check_balls = deepcopy(balls)
    check_balls[a] -= 1
    res = 0
    for count in check_balls.values():
      if not count in dp:
        dp[count] = count * (count-1) // 2
      res += dp[count]
    dpa[a] = res
  print(dpa[a])

Fixed submission:
from copy import deepcopy
dp = {0: 0}

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

balls = {}
fact = 1
for (i, a) in enumerate(A):
  count = i+1
  dp[count] = count * (count-1) // 2
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

res = 0
for count in balls.values():
  res += dp[count]

for a in A:
  print(res - dp[balls[a]] + dp[balls[a]-1])

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
dp = {}

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

balls = {}
fact = 1
for (i, a) in enumerate(A):
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

for a in A:
  check_balls = deepcopy(balls)
  check_balls[a] -= 1
  res = 0
  for count in check_balls.values():
    if not count in dp:
      dp[count] = count * (count-1) // 2
    res += dp[count]
  print(res)

Fixed submission:
from copy import deepcopy
dp = {0: 0}

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

balls = {}
fact = 1
for (i, a) in enumerate(A):
  count = i+1
  dp[count] = count * (count-1) // 2
  if a in balls:
    balls[a] += 1
  else:
    balls[a] = 1

res = 0
for count in balls.values():
  res += dp[count]

for a in A:
  print(res - dp[balls[a]] + dp[balls[a]-1])