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

N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = collections.Counter(listA)
countA_calc = {}
countA_calc2 = {}
for i in listA:
    count = 0
    for x, y in countA.most_common():
        if x == i:
            if x not in countA_calc2:
                countA_calc2[x] = (y -1) * (y - 2) // 2
            count += countA_calc2[x]
        else:
            if x not in countA_calc:
                countA_calc[x] = y * (y -1) // 2 
            count += countA_calc[x]
    print(count)

Fixed submission:
import collections
import math
def combination(a, b):
    tmp = 1
    for i in range(a - b + 1, a + 1):
        tmp *= i
    return tmp // math.factorial(b)
 
N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = dict(collections.Counter(listA).most_common())
countA_calc = {k: v * (v -1) // 2 for (k, v) in countA.items()}
countA_calc2 = {k: (v - 1) * (v -2) // 2 for (k, v) in countA.items()}
summery = sum(countA_calc.values())
for i in listA:
    print(summery - countA_calc[i] + countA_calc2[i])

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

N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = dict(collections.Counter(listA).most_common())
countA_calc = {}
countA_calc2 = {}
for i in listA:
    count = 0
    for x, y in countA.items():
        if x == i:
            if x not in countA_calc2:
                countA_calc2[x] = (y -1) * (y - 2) // 2
            count += countA_calc2[x]
        else:
            if x not in countA_calc:
                countA_calc[x] = y * (y -1) // 2 
            count += countA_calc[x]
    print(count)

Fixed submission:
import collections
import math
def combination(a, b):
    tmp = 1
    for i in range(a - b + 1, a + 1):
        tmp *= i
    return tmp // math.factorial(b)
 
N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = dict(collections.Counter(listA).most_common())
countA_calc = {k: v * (v -1) // 2 for (k, v) in countA.items()}
countA_calc2 = {k: (v - 1) * (v -2) // 2 for (k, v) in countA.items()}
summery = sum(countA_calc.values())
for i in listA:
    print(summery - countA_calc[i] + countA_calc2[i])

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math
def combination(a, b):
    tmp = 1
    for i in range(a - b + 1, a + 1):
        tmp *= i
    return tmp // math.factorial(b)

N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = dict(collections.Counter(listA).most_common())
countA_calc = {k: v * (v -1) // 2 for (k, v) in countA.items()}
countA_calc2 = {k: (v - 1) * (v -2) // 2 for (k, v) in countA.items()}
for i in listA:
    count = 0
    for x, y in countA.items():
        if x == i:
            count += countA_calc2[x]
        else:
            count += countA_calc[x]
    print(count)

Fixed submission:
import collections
import math
def combination(a, b):
    tmp = 1
    for i in range(a - b + 1, a + 1):
        tmp *= i
    return tmp // math.factorial(b)
 
N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = dict(collections.Counter(listA).most_common())
countA_calc = {k: v * (v -1) // 2 for (k, v) in countA.items()}
countA_calc2 = {k: (v - 1) * (v -2) // 2 for (k, v) in countA.items()}
summery = sum(countA_calc.values())
for i in listA:
    print(summery - countA_calc[i] + countA_calc2[i])

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math
def combination(a, b):
    tmp = 1
    for i in range(a - b + 1, a + 1):
        tmp *= i
    return tmp // math.factorial(b)

N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = collections.Counter(listA)

for i in listA:
    count = 0
    for x, y in countA.most_common():
        if x == i:
            y -= 1
        count += combination(y, 2)
    print(count)

Fixed submission:
import collections
import math
def combination(a, b):
    tmp = 1
    for i in range(a - b + 1, a + 1):
        tmp *= i
    return tmp // math.factorial(b)
 
N = int(input())
listA = list(map(int, input().split()))
# 各数字の出現回数をカウント
countA = dict(collections.Counter(listA).most_common())
countA_calc = {k: v * (v -1) // 2 for (k, v) in countA.items()}
countA_calc2 = {k: (v - 1) * (v -2) // 2 for (k, v) in countA.items()}
summery = sum(countA_calc.values())
for i in listA:
    print(summery - countA_calc[i] + countA_calc2[i])