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


nc2_memo = {}
def nc2(n):
    if n <= 1:
        return 0
    if n in nc2_memo:
        return nc2_memo[n]
    r = math.factorial(n)//(2*math.factorial(n-2))
    nc2_memo[n] = r
    return r



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

cnt = collections.Counter(a)
each_ans = {}
for key, value in cnt.items():
    each_ans[key] = (nc2(value), nc2(value-1))
all_sum = sum(value[0] for _, value in each_ans.items())
ans = {}
for key in cnt.keys():
    ans[key] = all_sum - each_ans[key][0] + each_ans[key][1]
for i in a:
    print(ans[i])


Fixed submission:
import math
import collections


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))


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

cnt = collections.Counter(a)
each_ans = {}
for key, value in cnt.items():
    t = nc2(value)
    each_ans[key] = (t, t-value+1)
all_sum = sum(value[0] for _, value in each_ans.items())
ans = {}
for key in cnt.keys():
    ans[key] = all_sum - each_ans[key][0] + each_ans[key][1]
for i in a:
    print(ans[i])

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


nc2_memo = {}
def nc2(n):
    if n <= 1:
        return 0
    if n in nc2_memo:
        return nc2_memo[n]
    r = math.factorial(n)//(2*math.factorial(n-2))
    nc2_memo[n] = r
    return r


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

cnt = collections.Counter(a)
ans = {}
for key1 in cnt.keys():
    ans[key1] = sum(nc2(value) if key1 != key2 else nc2(value-1) for key2, value in cnt.items())
for v in a:
    print(ans[v])


Fixed submission:
import math
import collections


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))


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

cnt = collections.Counter(a)
each_ans = {}
for key, value in cnt.items():
    t = nc2(value)
    each_ans[key] = (t, t-value+1)
all_sum = sum(value[0] for _, value in each_ans.items())
ans = {}
for key in cnt.keys():
    ans[key] = all_sum - each_ans[key][0] + each_ans[key][1]
for i in a:
    print(ans[i])

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


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))

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

cnt = collections.Counter(a)
ans = {}
for key1 in cnt.keys():
    ans[key1] = sum(nc2(value) if key1 != key2 else nc2(value-1) for key2, value in cnt.items())
for v in a:
    print(ans[v])


Fixed submission:
import math
import collections


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))


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

cnt = collections.Counter(a)
each_ans = {}
for key, value in cnt.items():
    t = nc2(value)
    each_ans[key] = (t, t-value+1)
all_sum = sum(value[0] for _, value in each_ans.items())
ans = {}
for key in cnt.keys():
    ans[key] = all_sum - each_ans[key][0] + each_ans[key][1]
for i in a:
    print(ans[i])

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


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))

n = int(input())
a = list(map(int, input().split()))
cnt = {}
for v in a:
    if v not in cnt:
        cnt[v] = 0
    cnt[v] += 1
ans = {}
for key1 in cnt.keys():
    ans[key1] = sum(nc2(value) if key1 != key2 else nc2(value-1) for key2, value in cnt.items())
for v in a:
    print(ans[v])


Fixed submission:
import math
import collections


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))


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

cnt = collections.Counter(a)
each_ans = {}
for key, value in cnt.items():
    t = nc2(value)
    each_ans[key] = (t, t-value+1)
all_sum = sum(value[0] for _, value in each_ans.items())
ans = {}
for key in cnt.keys():
    ans[key] = all_sum - each_ans[key][0] + each_ans[key][1]
for i in a:
    print(ans[i])

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


n = int(input())
a = list(map(int, input().split()))
cnt = {}
for v in a:
    if v not in cnt:
        cnt[v] = 0
    cnt[v] += 1
ans = {}
for key1 in cnt.keys():
    s = 0
    for key2, value in cnt.items():
        if key1 == key2:
            value -= 1
        if value <= 1:
            continue
        s += math.factorial(value)//(2*math.factorial(value-2))
    ans[key1] = s
for v in a:
    print(ans[v])

Fixed submission:
import math
import collections


def nc2(n):
    if n <= 1:
        return 0
    return math.factorial(n)//(2*math.factorial(n-2))


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

cnt = collections.Counter(a)
each_ans = {}
for key, value in cnt.items():
    t = nc2(value)
    each_ans[key] = (t, t-value+1)
all_sum = sum(value[0] for _, value in each_ans.items())
ans = {}
for key in cnt.keys():
    ans[key] = all_sum - each_ans[key][0] + each_ans[key][1]
for i in a:
    print(ans[i])