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

K = {}
for row in A:
    if row in K:
        K[row] += 1
    else:
        K[row] = 1

# 辞書Kに関して全探索
D = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            tmp = K[i]
            if i == row:
                tmp = K[i]-1
            ans += tmp * ( tmp-1 ) / 2
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])


Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

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

K = {}
for row in A:
    if row in K:
        K[row] += 1
    else:
        K[row] = 1

# 辞書Kに関して全探索
D = {}
C = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            tmp = 0
            if i == row:
                tmp = K[i]-1
            else:
                tmp = K[i]
            if tmp not in C:
                ans += tmp * ( tmp-1 ) / 2
            else:
                ans += C[tmp]
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])


Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb

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

K = {}
for row in A:
    if row in K:
        K[row] += 1
    else:
        K[row] = 1

# 辞書Kに関して全探索
D = {}
C = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            tmp = 0
            if i == row:
                tmp = K[i]-1
            else:
                tmp = K[i]
            if tmp not in C:
                ans += comb(tmp, 2, exact=True)
            else:
                ans += C[tmp]
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])


Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb

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

K = {}
for row in A:
    if row in K:
        K[row] += 1
    else:
        K[row] = 1

# 辞書Kに関して全探索
D = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            if i == row:
                ans += comb(K[i]-1, 2, exact=True)
            else:
                ans += comb(K[i], 2, exact=True)
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])

Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb

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

K = {}
for row in A:
    if row in K:
      K[row] += 1
    else:
      K[row] = 1

# 辞書Kに関して全探索
for row in A:
    ans = 0
    for i in K:
        if i == row:
            ans += comb(K[i]-1,2,exact=True)
        else:
            ans += comb(K[i],2,exact=True)
    print(int(ans))


Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb

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

K = {}
for row in A:
    if row in K:
      K[row] += 1
    else:
      K[row] = 1

# 辞書Kに関して全探索
for row in A:
    ans = 0
    for i in K:
        if i == row:
            ans += comb(K[i]-1,2)
        else:
            ans += comb(K[i],2)
    print(int(ans))

Fixed submission:
N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )