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


combs = {}
results = {}


def get_combination(n):
    if n < 2:
        return 0
    if combs.get(n):
        return combs.get(n)
    else:
        combs[n] = factorial(n) // (factorial(n - 2) * factorial(2))
        return combs[n]


n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
S = 0
for k, v in c.items():
    S += get_combination(v)
for a in A:
    if results.get(a):
        print(results[a])
    else:
        results[a] = S - get_combination(c[a]) + get_combination(c[a] - 1)
        print(results[a])


Fixed submission:
import collections
from functools import lru_cache
from scipy.misc import comb


results = {}


@lru_cache(maxsize=None)
def get_combination(n):
    if n < 2:
        return 0
    else:
        return comb(n, 2, exact=True)


n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
S = 0
for k, v in c.items():
    S += get_combination(v)
for a in A:
    if results.get(a):
        print(results[a])
    else:
        results[a] = S - get_combination(c[a]) + get_combination(c[a] - 1)
        print(results[a])

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


combs = {}
results = {}


def get_combination(n):
    if n < 2:
        return 0
    if combs.get(n):
        return combs.get(n)
    else:
        combs[n] = factorial(n) // (factorial(n - 2) * factorial(2))
        return combs[n]


n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
for a in A:
    s = 0
    if results.get(a):
        print(results[a])
    else:
        for k, v in c.items():
            if k == a:
                v -= 1
            s += get_combination(v)
        results[a] = s
        print(s)


Fixed submission:
import collections
from functools import lru_cache
from scipy.misc import comb


results = {}


@lru_cache(maxsize=None)
def get_combination(n):
    if n < 2:
        return 0
    else:
        return comb(n, 2, exact=True)


n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
S = 0
for k, v in c.items():
    S += get_combination(v)
for a in A:
    if results.get(a):
        print(results[a])
    else:
        results[a] = S - get_combination(c[a]) + get_combination(c[a] - 1)
        print(results[a])

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


combs = {}
results = {}


def get_combination(n):
    if n < 2:
        return 0
    if combs.get(n):
        return combs.get(n)
    else:
        combs[n] = factorial(n) // (factorial(n - 2) * factorial(2))
        return combs[n]


n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
for a in A:
    s = 0
    if results.get(a):
        print(results[a])
    else:
        for k, v in c.items():
            if k == a:
                v -= 1
            s += get_combination(v)
        results[a] = s
        print(s)


Fixed submission:
import collections
from functools import lru_cache
from scipy.misc import comb


results = {}


@lru_cache(maxsize=None)
def get_combination(n):
    if n < 2:
        return 0
    else:
        return comb(n, 2, exact=True)


n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
S = 0
for k, v in c.items():
    S += get_combination(v)
for a in A:
    if results.get(a):
        print(results[a])
    else:
        results[a] = S - get_combination(c[a]) + get_combination(c[a] - 1)
        print(results[a])