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

def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = list(map(int,input().split()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)

Fixed submission:
from collections import Counter
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(r, n - r)
    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()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)

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

def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = list(map(int,input().split()))
P = list(set(A))
P.sort()
li = Counter(A).most_common()
S = sum(comb(li[i][1],2) for i in range(len(li)) if li[i][1]>=2)
for i in A:
    ans = S
    IDX = P.index(i)
    if li[IDX][1]>2:
        ans -= comb(li[IDX][1],2)-comb(li[IDX][1]-1,2)
    elif li[IDX][1]==2:
        ans -= 1
    print(ans)

Fixed submission:
from collections import Counter
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(r, n - r)
    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()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)

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

def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = list(map(int,input().split()))
P = list(set(A))
tmp = Counter(A)
tmp2 = tmp.most_common()
li = [list(tmp2[i]) for i in range(len(tmp2))]
P.sort()
li.sort()
S = sum(comb(li[i][1],2) for i in range(len(li)) if li[i][1]>=2)
for i in A:
    ans = S
    IDX = P.index(i)
    if li[IDX][1]>2:
        ans -= comb(li[IDX][1],2)-comb(li[IDX][1]-1,2)
    elif li[IDX][1]==2:
        ans -= 1
    print(ans)

Fixed submission:
from collections import Counter
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(r, n - r)
    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()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)