Buggy python submission (verdict: Time Limit Exceeded):
import copy
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
total = 0
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 v in c.values():
    if v >= 2:
        total += cmb(v, 2)
# print(total)

for ai in a:
    if c[ai] >= 2:
        # print('Y')
        ans = total - cmb(c[ai], 2)
        if c[ai] - 1 >= 2:
            ans += cmb(c[ai] - 1, 2)
    else:
        ans = total
    print(ans)
    # ans = 0
    # temp = copy.copy(c)
    # temp[ai] = temp[ai] - 1

    # for v in temp.values():
    #     # print(v)
    #     if v >= 2:
    #         ans += cmb(v, 2)
    # print(ans)
# temp = copy.copy(c)
# temp[1] = temp[1] - 1
# print(c)
# print(temp)

Fixed submission:
import copy
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
total = 0
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
    
for v in c.values():
    if v >= 2:
        total += cmb(v, 2)
# print(total)

for ai in a:
    if c[ai] >= 2:
        # print('Y')
        ans = total - cmb(c[ai], 2)
        if c[ai] - 1 >= 2:
            ans += cmb(c[ai] - 1, 2)
    else:
        ans = total
    print(ans)
    # ans = 0
    # temp = copy.copy(c)
    # temp[ai] = temp[ai] - 1

    # for v in temp.values():
    #     # print(v)
    #     if v >= 2:
    #         ans += cmb(v, 2)
    # print(ans)
# temp = copy.copy(c)
# temp[1] = temp[1] - 1
# print(c)
# print(temp)

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

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 ai in a:
    ans = 0
    temp = copy.copy(c)
    temp[ai] = temp[ai] - 1
    for v in temp.values():
        # print(v)
        if v >= 2:
            ans += cmb(v, 2)
    print(ans)
temp = copy.copy(c)
temp[1] = temp[1] - 1
# print(c)
# print(temp)

Fixed submission:
import copy
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
total = 0
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
    
for v in c.values():
    if v >= 2:
        total += cmb(v, 2)
# print(total)

for ai in a:
    if c[ai] >= 2:
        # print('Y')
        ans = total - cmb(c[ai], 2)
        if c[ai] - 1 >= 2:
            ans += cmb(c[ai] - 1, 2)
    else:
        ans = total
    print(ans)
    # ans = 0
    # temp = copy.copy(c)
    # temp[ai] = temp[ai] - 1

    # for v in temp.values():
    #     # print(v)
    #     if v >= 2:
    #         ans += cmb(v, 2)
    # print(ans)
# temp = copy.copy(c)
# temp[1] = temp[1] - 1
# print(c)
# print(temp)