Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    for a in A:
        cal_A = deepcopy(count_A)
        cal_A[a] -= 1
        print(count(cal_A))

Fixed submission:
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    combi_A = 0

    for c in count_A:
        combi_A += (c*(c-1))//2
    for a in A:
        print(combi_A-(count_A[a]*(count_A[a]-1)-(count_A[a]-1)*(count_A[a]-2))//2)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    for a in A:
        cal_A = deepcopy(count_A)
        cal_A[a] -= 1
        print(count(cal_A))

Fixed submission:
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    combi_A = 0

    for c in count_A:
        combi_A += (c*(c-1))//2
    for a in A:
        print(combi_A-(count_A[a]*(count_A[a]-1)-(count_A[a]-1)*(count_A[a]-2))//2)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb


N = int(input())
A = list(map(int, input().split()))
sorted_A = sorted(A)
countNums = [0]*(N+1)

target = sorted_A[0]
for i in range(N):
    if target==sorted_A[i]:
        countNums[target] += 1
    else:
        target = sorted_A[i]
        countNums[target] += 1;


for i in range(N):
    a = A[i]
    countNums[a] -= 1
    ans = 0
    for c in countNums:
        ans += int(comb(c, 2))
    print(ans)
    countNums[a] += 1





Fixed submission:
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    combi_A = 0

    for c in count_A:
        combi_A += (c*(c-1))//2
    for a in A:
        print(combi_A-(count_A[a]*(count_A[a]-1)-(count_A[a]-1)*(count_A[a]-2))//2)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.special import comb

INF = 100100100

N = int(input())
A = list(map(int, input().split()))
sorted_A = sorted(A)
countNums = [0]*(N+1)

target = sorted_A[0]
for i in range(N):
    if target==sorted_A[i]:
        countNums[target] += 1
    else:
        target = sorted_A[i]
        countNums[target] += 1;


for i in range(N):
    a = A[i]
    countNums[a] -= 1
    ans = 0
    for c in countNums:
        ans += int(comb(c, 2))
    print(ans)
    countNums[a] += 1




Fixed submission:
from copy import deepcopy

def count(A):
    cnt = 0
    for a in A:
        cnt += (a*(a-1))//2
    return cnt


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    max_A = max(A)

    count_A = [0]*(max_A+1)

    for a in A:
        count_A[a]+= 1

    combi_A = 0

    for c in count_A:
        combi_A += (c*(c-1))//2
    for a in A:
        print(combi_A-(count_A[a]*(count_A[a]-1)-(count_A[a]-1)*(count_A[a]-2))//2)