Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math
def comb(n, r):
    # print(n, r)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

# All combination
total = 0
for (key, val) in c.items():
    # print('\n', key, val)
    if val > 1:
        total += comb(val, 2)

# print('all:', total)

for i in range(n):
    num = a[i]
    org = c[num]
    # print(org)
    # total - orgC2 + (org-1)C2
    if org > 2:
        ans = total - comb(org, 2) + comb(org-1, 2)
    elif org == 1 or org == 0:
        ans = total
    else:
        ans = total - comb(org, 2)
    print(ans)


'''
5
1 1 2 1 2
'''

Fixed submission:
from collections import Counter
import math
def comb(n, r):
    # print(n, r)
    return (n * (n-1))//2
    # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

# All combination
total = 0
for (key, val) in c.items():
    # print('\n', key, val)
    if val > 1:
        total += comb(val, 2)

# print('all:', total)

for i in range(n):
    num = a[i]
    org = c[num]
    # print(org)
    # total - orgC2 + (org-1)C2
    if org > 2:
        ans = total - comb(org, 2) + comb(org-1, 2)
    elif org == 1 or org == 0:
        ans = total
    else:
        ans = total - comb(org, 2)
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
import math
def comb(n, r):
    # print(n, r)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
combination = Combination(n-1)

# All combination
total = 0
for (key, val) in c.items():
    # print('\n', key, val)
    total += comb(val, 2)

# print('all:', total)

for i in range(n):
    num = a[i]
    org = c[num]

    # total - orgC2 + (org-1)C2
    if org > 2:
        ans = total - comb(org, 2) + comb(org-1, 2)
    else:
        ans = total - comb(org, 2)
    print(ans)


'''
5
1 1 2 1 2
'''

Fixed submission:
from collections import Counter
import math
def comb(n, r):
    # print(n, r)
    return (n * (n-1))//2
    # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

# All combination
total = 0
for (key, val) in c.items():
    # print('\n', key, val)
    if val > 1:
        total += comb(val, 2)

# print('all:', total)

for i in range(n):
    num = a[i]
    org = c[num]
    # print(org)
    # total - orgC2 + (org-1)C2
    if org > 2:
        ans = total - comb(org, 2) + comb(org-1, 2)
    elif org == 1 or org == 0:
        ans = total
    else:
        ans = total - comb(org, 2)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math
def comb(n, r):
    # print(n, r)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int, input().split()))

# comb = Combination(n-1)
c = Counter(a)

for i in range(n):
    num = a[i]
    # c[num] - 1
    temp = 0
    for (key, val) in c.items():
        # print('\n', key, val)
        if val < 2:
            continue
        if key == num:
            if val > 2:
                temp += comb(val - 1, 2)
        else:
            temp += comb(val, 2)
    print(temp)

'''
5
1 1 2 1 2
'''

Fixed submission:
from collections import Counter
import math
def comb(n, r):
    # print(n, r)
    return (n * (n-1))//2
    # return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

# All combination
total = 0
for (key, val) in c.items():
    # print('\n', key, val)
    if val > 1:
        total += comb(val, 2)

# print('all:', total)

for i in range(n):
    num = a[i]
    org = c[num]
    # print(org)
    # total - orgC2 + (org-1)C2
    if org > 2:
        ans = total - comb(org, 2) + comb(org-1, 2)
    elif org == 1 or org == 0:
        ans = total
    else:
        ans = total - comb(org, 2)
    print(ans)