Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

af=collections.Counter(A)
res2=list(af.items())
res3=[0]*n
s=0
for i in range(0,len(res2)):
    s=s+com(res2[i][1],2)
for j in range(0,len(res2)):
    res3[res2[j][0]-1]=s-com(res2[j][1],2)+com(res2[j][1]-1,2)
for i in range(n):
    res[i]=res3[A[i]-1]

for j in range(n):
    print(res[j])

Fixed submission:
import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

af=collections.Counter(A)
res2=list(af.items())
res3=[0]*n
s=0
for i in range(0,len(res2)):
    s=s+com(res2[i][1],2)
for j in range(0,len(res2)):
    res3[res2[j][0]-1]=s-res2[j][1]+1
for i in range(n):
    res[i]=res3[A[i]-1]

for j in range(n):
    print(res[j])

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
res1=[-1]*n
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
    if res1[A[i]-1]==-1:
        ac=copy.deepcopy(A)
        del ac[i]
        ak=collections.Counter(ac)
        aj=list( ak.values() )
        s=0
        for j in range(len(aj)):
            s=s+com(aj[j],2)
        res[i]=s
        res1[A[i]-1]=s
    else:
        res[i]=res1[A[i]-1]
for j in range(n):
    print(res[j])

Fixed submission:
import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

af=collections.Counter(A)
res2=list(af.items())
res3=[0]*n
s=0
for i in range(0,len(res2)):
    s=s+com(res2[i][1],2)
for j in range(0,len(res2)):
    res3[res2[j][0]-1]=s-res2[j][1]+1
for i in range(n):
    res[i]=res3[A[i]-1]

for j in range(n):
    print(res[j])

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(n):
    ac=copy.deepcopy(A)
    del ac[i]
    ak=collections.Counter(ac)
    aj=list( ak.values() )
    s=0
    for j in range(len(aj)):
        s=s+com(aj[j],2)
    res[i]=s
print(' '.join(map(str,res)))
    

Fixed submission:
import math
n=int(input())
A = list(map(int, input().split()))
res=[0]*n
import collections
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

af=collections.Counter(A)
res2=list(af.items())
res3=[0]*n
s=0
for i in range(0,len(res2)):
    s=s+com(res2[i][1],2)
for j in range(0,len(res2)):
    res3[res2[j][0]-1]=s-res2[j][1]+1
for i in range(n):
    res[i]=res3[A[i]-1]

for j in range(n):
    print(res[j])