Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
N = int(input())
k = list(map(int, input().split()))

# 書かれている数字のぼーるがいくつあるか、辞書
from collections import Counter
A =Counter(k)

from math import factorial
def nC2(n): # 組み合わせ n「C」r
    if  n<2:
        return 0
    return n*(n-1)//2

# 順番付きの辞書
from collections import OrderedDict
D = OrderedDict()
D2 = OrderedDict()

# 各数字を連続でとる場合の数
futatu_onaji =0

x =[ nC2(v) for i,v in A.items() ]    # n個の中から2つをとる組み合わせ
futatu_onaji = sum(x)

#D =[0]*N
D =[]

D = [ futatu_onaji - (vj -1) for i,v in enumerate(k) for ij,vj in A.items() if v == ij] #vj-1 = 最初のボールと同じ番号を次に取る場合の数
print(*D,sep="\n")

Fixed submission:
from collections import Counter 
N = int(input())
A = list(map(int, input().split()))
c_A = Counter(A)
all =sum( [i*(i-1)//2 for i in c_A.values()] )

for i in range(N):
    ans =all -( c_A[A[i]] -1)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
N = int(input())
k = list(map(int, input().split()))

# 書かれている数字のぼーるがいくつあるか、辞書
from collections import Counter
A =Counter(k)

from math import factorial
def nC2(n): # 組み合わせ n「C」r
    if  n<2:
        return 0
    return n*(n-1)//2

# 順番付きの辞書
from collections import OrderedDict
D = OrderedDict()
D2 = OrderedDict()

# 各数字を連続でとる場合の数
futatu_onaji =0
for i,v in A.items():
    futatu_onaji += nC2(v)


#D =[0]*N
D =[]
for i,v in enumerate(k):
    for ij,vj in A.items():
        if v == ij :
            x = vj-1 #最初のボールと同じ番号を次に取る
            D.append(futatu_onaji - x ) #全体から引いたものをリストに追加
print(*D,sep="\n")


Fixed submission:
from collections import Counter 
N = int(input())
A = list(map(int, input().split()))
c_A = Counter(A)
all =sum( [i*(i-1)//2 for i in c_A.values()] )

for i in range(N):
    ans =all -( c_A[A[i]] -1)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
N = int(input())
k = list(map(int, input().split()))

# 書かれている数字のぼーるがいくつあるか、辞書
from collections import Counter
A =Counter(k)

from math import factorial
def kumiawase_num(n, r): # 組み合わせ n「C」r
    if  n<r:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))

# 順番付きの辞書
from collections import OrderedDict
D = OrderedDict()
D2 = OrderedDict()

# 各数字を連続でとる場合の数
futatu_onaji =0
for i,v in A.items():
    futatu_onaji += kumiawase_num(v,2)


#D =[0]*N
D =[]
for i,v in enumerate(k):
    for ij,vj in A.items():
        if v == ij :
            x = kumiawase_num(vj-1,1) #最初のボールと同じ番号を次に取る
            D.append(futatu_onaji - x ) #全体から引いたものをリストに追加
print(*D,sep="\n")

Fixed submission:
from collections import Counter 
N = int(input())
A = list(map(int, input().split()))
c_A = Counter(A)
all =sum( [i*(i-1)//2 for i in c_A.values()] )

for i in range(N):
    ans =all -( c_A[A[i]] -1)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 初期入力
N = int(input())
k = list(map(int, input().split()))

# 書かれている数字のぼーるがいくつあるか、辞書
from collections import Counter
A =Counter(k)

# 各数字を連続でとる場合の数
from math import factorial
def kumiawase_num(n, r): # 組み合わせ n「C」r
    if  n<r:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))

# 順番付きの辞書
from collections import OrderedDict
D = OrderedDict()
D2 = OrderedDict()

for i,v in enumerate(k):
    D[i] =[ kumiawase_num(A[ij]-1,2) for ij,vj in A.items() if v == ij ]
    D2[i] = [ kumiawase_num(A[ij] ,2) for ij,vj in A.items() if v != ij ] 

D3 = [ sum(i) + sum(v) for i,v in zip(D.values(),D2.values()) ]      
print(*D3,sep="\n")

Fixed submission:
from collections import Counter 
N = int(input())
A = list(map(int, input().split()))
c_A = Counter(A)
all =sum( [i*(i-1)//2 for i in c_A.values()] )

for i in range(N):
    ans =all -( c_A[A[i]] -1)
    print(ans)