Buggy python submission (verdict: Time Limit Exceeded):
import collections
import copy
n = int(input())
aa = list(map(int, input().split()))

def comb(n, k):
    return (n * (n - 1)) // 2
    

memo = {}
for i in range(len(aa)):
    if not aa[i] in memo:
        hu = copy.deepcopy(aa)
        del hu[i]
        a = collections.Counter(hu)
        summ = 0
        for j in a:
            summ += comb(a[j], 2)
        memo[aa[i]] = summ
    print(memo[aa[i]])


Fixed submission:
import collections
n = int(input())
a = list(map(int,input().split()))

sub = collections.Counter(a)
ans = 0
for i in sub:
    ans += sub[i] * (sub[i] - 1) // 2
for i in range(n):
    ad = sub[a[i]] * (sub[a[i]] - 1) // 2 - ((sub[a[i]] - 1) * (sub[a[i]] - 2) // 2)
    print(ans - ad)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import copy
n = int(input())
aa = list(map(int, input().split()))

def comb(n, k):
    p = (10 ** 9) + 7
    """power_funcを用いて(nCk) mod p を求める"""
    from math import factorial
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    a=factorial(n) %p
    b=factorial(k) %p
    c=factorial(n-k) %p
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
    """a^b mod p を求める"""
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a * power_func(a, b - 1, p)) % p   

memo = {}
for i in range(len(aa)):
    if not aa[i] in memo:
        hu = copy.deepcopy(aa)
        del hu[i]
        a = collections.Counter(hu)
        summ = 0
        for j in a:
            summ += comb(a[j], 2)
        memo[aa[i]] = summ
    print(memo[aa[i]])


Fixed submission:
import collections
n = int(input())
a = list(map(int,input().split()))

sub = collections.Counter(a)
ans = 0
for i in sub:
    ans += sub[i] * (sub[i] - 1) // 2
for i in range(n):
    ad = sub[a[i]] * (sub[a[i]] - 1) // 2 - ((sub[a[i]] - 1) * (sub[a[i]] - 2) // 2)
    print(ans - ad)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import copy
n = int(input())
aa = list(map(int, input().split()))

def comb(n, k):
    p = (10 ** 9) + 7
    """power_funcを用いて(nCk) mod p を求める"""
    from math import factorial
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    a=factorial(n) %p
    b=factorial(k) %p
    c=factorial(n-k) %p
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
    """a^b mod p を求める"""
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a * power_func(a, b - 1, p)) % p
    
memo = {}
a = collections.Counter(aa)
ans = 0
for i in range(len(aa)):
    if not aa[i] in memo:
        aaa = a[aa[i]]
        if aaa - 2 >= 0:
            sub = comb(aaa, 2)
            memo[aa[i]] = sub
        else:
            memo[aa[i]] = 0

memo2 = {}
for i in range(len(aa)):
    if not aa[i] in memo2:
        aaa = a[aa[i]] - 1
        if aaa - 2 >= 0:
            sub = comb(aaa, 2)
            memo2[aa[i]] = sub
        else:
            memo2[aa[i]] = 0

for i in range(len(aa)):
    ans = 0
    ans += memo2[aa[i]]
    for key in memo:
        if aa[i] != key:
            ans += memo[key]
    print(ans)


Fixed submission:
import collections
n = int(input())
a = list(map(int,input().split()))

sub = collections.Counter(a)
ans = 0
for i in sub:
    ans += sub[i] * (sub[i] - 1) // 2
for i in range(n):
    ad = sub[a[i]] * (sub[a[i]] - 1) // 2 - ((sub[a[i]] - 1) * (sub[a[i]] - 2) // 2)
    print(ans - ad)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math
n = int(input())
aa = list(map(int, input().split()))

def factor(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
memo = {}
a = collections.Counter(aa)
ans = 0
for i in range(len(aa)):
    if not aa[i] in memo:
        aaa = a[aa[i]]
        if aaa - 2 >= 0:
            sub = factor(aaa, 2)
            memo[aa[i]] = sub
        else:
            memo[aa[i]] = 0

memo2 = {}
for i in range(len(aa)):
    if not aa[i] in memo2:
        aaa = a[aa[i]] - 1
        if aaa - 2 >= 0:
            sub = factor(aaa, 2)
            memo2[aa[i]] = sub
        else:
            memo2[aa[i]] = 0

for i in range(len(aa)):
    ans = 0
    ans += memo2[aa[i]]
    for key in memo:
        if aa[i] != key:
            ans += memo[key]
    print(ans)

Fixed submission:
import collections
n = int(input())
a = list(map(int,input().split()))

sub = collections.Counter(a)
ans = 0
for i in sub:
    ans += sub[i] * (sub[i] - 1) // 2
for i in range(n):
    ad = sub[a[i]] * (sub[a[i]] - 1) // 2 - ((sub[a[i]] - 1) * (sub[a[i]] - 2) // 2)
    print(ans - ad)