Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
re = [0] * (n-1)

c = Counter(a)   # c: Counter({1: 3, 2: 2})など
for k, v in c.items():
    re[k] = v*(v-1) // 2

total = sum(re)
for i in a:
    print(total - re[i] + (c[i]-1)*(c[i]-2) // 2)

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
re = [0] * (n+1)

c = Counter(a)   # c: Counter({1: 3, 2: 2})など
for k, v in c.items():
    re[k] = v*(v-1) // 2

total = sum(re)
for i in a:
    print(total - re[i] + (c[i]-1)*(c[i]-2) // 2)

Buggy python submission (verdict: Runtime Error):
import math

dic = {}

def combinations_count(n, r):
    if n in dic:
        return dic[n]
    else:
        if r>n:
            re = 0
        if n==0 or n==1:
            re = 0
        if n==r:
            re = 1
        re = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        dic[n] = re
        return re


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

num_list = [0] * n
com_list1 = [0] * n
com_list2 = [0] * n

for i in range(n):
    num_list[a[i]] += 1

for i in range(n):
    num = num_list[i]
    if num>=2:
        com_list1[i] = combinations_count(num, 2)

for i in range(n):
    num = num_list[i]-1
    if num>=2:
        com_list2[i] = combinations_count(num, 2)


total = sum(com_list1)

for i in range(n):
    num = a[i]
    print(total - com_list1[num] + com_list2[num])

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
re = [0] * (n+1)

c = Counter(a)   # c: Counter({1: 3, 2: 2})など
for k, v in c.items():
    re[k] = v*(v-1) // 2

total = sum(re)
for i in a:
    print(total - re[i] + (c[i]-1)*(c[i]-2) // 2)

Buggy python submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    if r>n:
        return 0
    if n==0 or n==1:
        return 0
    if n==r:
        return 1
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

num_list = [0] * n
com_list1 = [0] * n
com_list2 = [0] * n

for i in range(n):
    num_list[a[i]] += 1

for i in range(n):
    num = num_list[i]
    if num>=2:
        com_list1[i] = combinations_count(num, 2)

for i in range(n):
    num = num_list[i]-1
    if num>=2:
        com_list2[i] = combinations_count(num, 2)


total = sum(com_list1)

for i in range(n):
    num = a[i]
    print(total - com_list1[num] + com_list2[num])

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
re = [0] * (n+1)

c = Counter(a)   # c: Counter({1: 3, 2: 2})など
for k, v in c.items():
    re[k] = v*(v-1) // 2

total = sum(re)
for i in a:
    print(total - re[i] + (c[i]-1)*(c[i]-2) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
import math

def combinations_count(n, r):
    if r>n:
        return 0
    if n==0 or n==1:
        return 0
    if n==r:
        return 1
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

memo = [0] * (2*(10**5))
num_list = [0] * (2*(10**5))

for i in range(n):
    num_list[a[i]] += 1

for i in range(n):
    num = a[i]
    if memo[num] != 0:
        print(memo[num])
    else:
        cnt = 0
        for j in range(2*(10**5)):
            if j != num:
                cnt += combinations_count(num_list[j], 2)
            else:
                cnt += combinations_count(num_list[j]-1, 2)
        print(cnt)
        memo[num] = cnt

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
re = [0] * (n+1)

c = Counter(a)   # c: Counter({1: 3, 2: 2})など
for k, v in c.items():
    re[k] = v*(v-1) // 2

total = sum(re)
for i in a:
    print(total - re[i] + (c[i]-1)*(c[i]-2) // 2)