Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
an = 0
for i in range(len(list_B)):
    c = list_A.count(list_B[i])
    an += (c*(c-1))//2


for i in range(n):
    c = list_A.count(list_A[i])
    if c != 2:
        ans = an - c + 1
    else:
        ans = an - 1
    print(ans)

Fixed submission:
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
list_M = [0 for _ in range(n+1)]

for s in list_A:
    list_M[s] += 1
total = 0

for i in range(n+1):
    total += list_M[i]*(list_M[i]-1)//2

for s in list_A:
    ans = total - list_M[s] + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
an = 0
for i in range(len(list_B)):
    c = list_A.count(list_B[i])
    an += (c*(c-1))//2


for i in range(n):
    c = list_A.count(list_A[i])
    if c != 2:
        ans = an - (c*(c-1))//2 + ((c-1)*(c-2))//2
    else:
        ans = an - 1
    print(ans)

Fixed submission:
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
list_M = [0 for _ in range(n+1)]

for s in list_A:
    list_M[s] += 1
total = 0

for i in range(n+1):
    total += list_M[i]*(list_M[i]-1)//2

for s in list_A:
    ans = total - list_M[s] + 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
list_A = list(map(int, input().split()))

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

list_B = list(set(list_A))
an = 0
for i in range(len(list_B)):
    c = list_A.count(list_B[i])
    an += cmb(c, 2)


for i in range(n):
    c = list_A.count(list_A[i])
    if c != 2:
        ans = an - cmb(c, 2) + cmb(c-1, 2)
    else:
        ans = an - 1
    print(ans)

Fixed submission:
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
list_M = [0 for _ in range(n+1)]

for s in list_A:
    list_M[s] += 1
total = 0

for i in range(n+1):
    total += list_M[i]*(list_M[i]-1)//2

for s in list_A:
    ans = total - list_M[s] + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
n = int(input())
list_A = list(map(int, input().split()))

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(n):
    a = list_A.pop(i)
    b = list(set(list_A))
    ans = 0
    for j in range(len(b)):
        c = list_A.count(b[j])
        if c != 1:
            ans += cmb(c,2)
    print(ans)
    list_A.insert(i,a)

Fixed submission:
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(set(list_A))
list_M = [0 for _ in range(n+1)]

for s in list_A:
    list_M[s] += 1
total = 0

for i in range(n+1):
    total += list_M[i]*(list_M[i]-1)//2

for s in list_A:
    ans = total - list_M[s] + 1
    print(ans)