Buggy python submission (verdict: Time Limit Exceeded):
#%%
import copy, math, collections

n = int(input())
a = input().split()

result = []

num_dict = dict(collections.Counter(a))

def calc(x):
    if x >= 2:
        return math.factorial(x) / (math.factorial(x - 2) * 2)
    else:
        return 0

result_dict = {}
result_minus1_dict = {}

for key in num_dict.keys():
    result_dict[key] = calc(num_dict[key])
    result_minus1_dict[key] = calc(num_dict[key] - 1)

for i in range(len(a)):
    result = 0

    for key, value in result_dict.items():
        if key == a[i]:
            result += result_minus1_dict[a[i]]
        else:
            result += value

    print(int(result))


# %%


Fixed submission:
#%%
import copy, math, collections

n = int(input())
a = input().split()

result = []

num_dict = dict(collections.Counter(a))

def calc(x):
    if x >= 2:
        return math.factorial(x) / (math.factorial(x - 2) * 2)
    else:
        return 0

result_dict = {}
result_minus1_dict = {}

for key, value in num_dict.items():
    result_dict[key] = calc(num_dict[key])
    result_minus1_dict[key] = calc(num_dict[key] - 1)

result_all = sum(result_dict.values())

for i in range(len(a)):
    print(int(result_all - result_dict[a[i]] + result_minus1_dict[a[i]]))

# %%

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

n = int(input())
a = input().split()

result = []

num_dict = {}

for x in set(a):
    num_dict[x] = a.count(x)

def calc(x):
    if x >= 2:
        return math.factorial(x) / (math.factorial(x - 2) * 2)
    else:
        return 0

result_dict = {}
result_minus1_dict = {}

for x in set(a):
    result_dict[x] = calc(num_dict[x])
    result_minus1_dict[x] = calc(num_dict[x] - 1)

for i in range(len(a)):
    result = 0

    for key, value in result_dict.items():
        if key == a[i]:
            result += result_minus1_dict[a[i]]
        else:
            result += value

    print(int(result))


Fixed submission:
#%%
import copy, math, collections

n = int(input())
a = input().split()

result = []

num_dict = dict(collections.Counter(a))

def calc(x):
    if x >= 2:
        return math.factorial(x) / (math.factorial(x - 2) * 2)
    else:
        return 0

result_dict = {}
result_minus1_dict = {}

for key, value in num_dict.items():
    result_dict[key] = calc(num_dict[key])
    result_minus1_dict[key] = calc(num_dict[key] - 1)

result_all = sum(result_dict.values())

for i in range(len(a)):
    print(int(result_all - result_dict[a[i]] + result_minus1_dict[a[i]]))

# %%

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

n = int(input())
a = input().split()

result = []

num_dict = {}

for x in set(a):
    num_dict[x] = a.count(x)

def calc(x):
    if x >= 2:
        return math.factorial(x) / (math.factorial(x - 2) * 2)
    else:
        return 0

for i in range(len(a)):
    result = 0

    temp_num_dict = copy.copy(num_dict)

    temp_num_dict[a[i]] -= 1

    for x in num_dict.keys():
        result += calc(temp_num_dict[x])

    print(int(result))

Fixed submission:
#%%
import copy, math, collections

n = int(input())
a = input().split()

result = []

num_dict = dict(collections.Counter(a))

def calc(x):
    if x >= 2:
        return math.factorial(x) / (math.factorial(x - 2) * 2)
    else:
        return 0

result_dict = {}
result_minus1_dict = {}

for key, value in num_dict.items():
    result_dict[key] = calc(num_dict[key])
    result_minus1_dict[key] = calc(num_dict[key] - 1)

result_all = sum(result_dict.values())

for i in range(len(a)):
    print(int(result_all - result_dict[a[i]] + result_minus1_dict[a[i]]))

# %%