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

def comb(n):
    if dp[n]!=-1:
        return dp[n]
    if n-2<0:
        dp[n]=0
        return dp[n]
    dp[n]=math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    return dp[n]

N=int(input())
A=list(map(int,input().split()))

dp=[-1 for i in range(N+1)]
nums={}

for i in range(N):
    if not A[i] in nums:
        nums[A[i]]=1
    else:
        nums[A[i]]+=1

ans=[]
for i in range(N):
    number=0
    nums[A[i]]-=1
    for j in nums.keys():
        number+=comb(nums[j])
    ans.append(number)
    nums[A[i]]+=1

for i in range(N):
    print(ans[i])

Fixed submission:
import math

def comb(n):
    if n-2<0:
        return 0
    return math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    
N=int(input())
A=list(map(int,input().split()))

nums=[0 for i in range(N+1)]
for i in range(N):
    nums[A[i]]+=1

num=0
for i in range(len(nums)):
    num+=comb(nums[i])

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

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

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

N=int(input())
A=list(map(int,input().split()))

nums=[0 for i in range(N+1)]

for i in range(N):
    nums[A[i]]+=1

ans=[]
for i in range(N):
    number=0
    nums[A[i]]-=1
    for j in range(1,N+1):
        number+=comb(nums[j],2)
    ans.append(number)
    nums[A[i]]+=1

for i in range(N):
    print(ans[i])

Fixed submission:
import math

def comb(n):
    if n-2<0:
        return 0
    return math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    
N=int(input())
A=list(map(int,input().split()))

nums=[0 for i in range(N+1)]
for i in range(N):
    nums[A[i]]+=1

num=0
for i in range(len(nums)):
    num+=comb(nums[i])

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

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

dp=[-1 for i in range(N)]

def comb(num):
    if dp[num]!=-1:
        return dp[num]
    dp[num]=(num*(num-1))//2
    return dp[num]

A=list(map(int,input().split()))

dict={i:0 for i in A}

for i in A:
    dict[i]+=1

for i in A:
    num=0
    for j in dict.keys():
        if j==i:
            num+=comb(dict[j]-1)
            continue
        num+=comb(dict[j])
    print(num)

Fixed submission:
import math

def comb(n):
    if n-2<0:
        return 0
    return math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    
N=int(input())
A=list(map(int,input().split()))

nums=[0 for i in range(N+1)]
for i in range(N):
    nums[A[i]]+=1

num=0
for i in range(len(nums)):
    num+=comb(nums[i])

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

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

A=list(map(int,input().split()))

dict={i:0 for i in A}

for i in A:
    dict[i]+=1

for i in A:
    num=0
    for j in dict.keys():
        if j==i:
            num+=((dict[i]-1)*(dict[i]-2)//2)
            continue
        num+=((dict[j]*(dict[j]-1))//2)
    print(num)

Fixed submission:
import math

def comb(n):
    if n-2<0:
        return 0
    return math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    
N=int(input())
A=list(map(int,input().split()))

nums=[0 for i in range(N+1)]
for i in range(N):
    nums[A[i]]+=1

num=0
for i in range(len(nums)):
    num+=comb(nums[i])

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