Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def combinations_count(n, r):
    #r = min(r, n - r)
    if r > n:
        return 0
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

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

d = dict()
for a in A:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1

if len(d) == n:
    for i in range(n):
        print(0)
    exit()

d1 = dict()
for a in d.keys():
    d1[a] = combinations_count(d[a], 2)

ans = []
d3 = dict()
for a in A:
    if a not in d3.keys():
        ans.append(sum(d1.values()) - (d[a] - 1))
    else:
        ans.append(d3[a])

for a in ans:
    print(a)

Fixed submission:
from operator import mul
from functools import reduce

def combinations_count(n, r):
    #r = min(r, n - r)
    if r > n:
        return 0
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

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

d = dict()
for a in A:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1

if len(d) == n:
    for i in range(n):
        print(0)
    exit()

d1 = dict()
for a in d.keys():
    d1[a] = combinations_count(d[a], 2)

d2 = dict()
for a in d.keys():
    d2[a] = combinations_count(d[a] - 1, 2)

ans = []
d3 = dict()
s = sum(d1.values())
for a in A:
    if a not in d3.keys():
        ans.append(s - d1[a] + d2[a])
    else:
        ans.append(d3[a])

for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def combinations_count(n, r):
    #r = min(r, n - r)
    if r > n:
        return 0
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

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

d = dict()
for a in A:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1

if len(d) == n:
    for i in range(n):
        print(0)
    exit()

d1 = dict()
for a in d.keys():
    d1[a] = combinations_count(d[a], 2)

d2 = dict()
for a in d.keys():
    d2[a] = combinations_count(d[a] - 1, 2)

ans = []
d3 = dict()
for a in A:
    if a not in d3.keys():
        ans.append(sum(d1.values()) - d1[a] + d2[a])
    else:
        ans.append(d3[a])

for a in ans:
    print(a)

Fixed submission:
from operator import mul
from functools import reduce

def combinations_count(n, r):
    #r = min(r, n - r)
    if r > n:
        return 0
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

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

d = dict()
for a in A:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1

if len(d) == n:
    for i in range(n):
        print(0)
    exit()

d1 = dict()
for a in d.keys():
    d1[a] = combinations_count(d[a], 2)

d2 = dict()
for a in d.keys():
    d2[a] = combinations_count(d[a] - 1, 2)

ans = []
d3 = dict()
s = sum(d1.values())
for a in A:
    if a not in d3.keys():
        ans.append(s - d1[a] + d2[a])
    else:
        ans.append(d3[a])

for a in ans:
    print(a)