Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A_num = [0] * N
    for a in A:
        A_num[a-1] += 1
        
    A_product = [0] * N
    A_product_1 = [0] * N
    for i in range(N):
        a = A_num[i]
        A_product[i] = int(a * (a-1) / 2)
        if a == 0:
            A_product_1[i] = 0
        else:
            A_product_1[i] = int((a-1) * (a-2) / 2)

    for k in A:
        s = sum(A_product) - A_product[k-1] + A_product_1[k-1]
        print(s)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A_num = [0] * N
    for a in A:
        A_num[a-1] += 1

    A_product = [0] * N
    A_product_1 = [0] * N
    for i in range(N):
        a = A_num[i]
        A_product[i] = int(a * (a-1) / 2)
        if a == 0:
            A_product_1[i] = 0
        else:
            A_product_1[i] = int((a-1) * (a-2) / 2)


    su = sum(A_product)
    for k in A:
        print(su - A_product[k-1] + A_product_1[k-1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A_num = [0] * N
    for i in range(N):
        A_num[A[i]-1] += 1
        
    A_product = [0] * N
    A_product_1 = [0] * N
    for i in range(N):
        a = A_num[i]
        A_product[i] = int(a * (a-1) / 2)
        if a == 0:
            A_product_1[i] = 0
        else:
            A_product_1[i] = int((a-1) * (a-2) / 2)

    for i in range(N):
        k = A[i]
        s = sum(A_product) - A_product[k-1] + A_product_1[k-1]
        print(s)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A_num = [0] * N
    for a in A:
        A_num[a-1] += 1

    A_product = [0] * N
    A_product_1 = [0] * N
    for i in range(N):
        a = A_num[i]
        A_product[i] = int(a * (a-1) / 2)
        if a == 0:
            A_product_1[i] = 0
        else:
            A_product_1[i] = int((a-1) * (a-2) / 2)


    su = sum(A_product)
    for k in A:
        print(su - A_product[k-1] + A_product_1[k-1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A_num = [0] * N
    for i in range(N):
        A_num[A[i]-1] += 1
    #print(A_num)
    A_product = [0] * N
    A_product_1 = [0] * N
    for i in range(N):
        A_product[i] = int(A_num[i] * (A_num[i]-1) / 2)
        if A_num[i] == 0:
            A_product_1[i] = 0
        else:
            A_product_1[i] = int((A_num[i]-1) * (A_num[i]-2) / 2)
    #print(A_product)
    #print(A_product_1)
    for i in range(N):
        k = A[i]
        s = sum(A_product) - A_product[k-1] + A_product_1[k-1]
        print(s)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A_num = [0] * N
    for a in A:
        A_num[a-1] += 1

    A_product = [0] * N
    A_product_1 = [0] * N
    for i in range(N):
        a = A_num[i]
        A_product[i] = int(a * (a-1) / 2)
        if a == 0:
            A_product_1[i] = 0
        else:
            A_product_1[i] = int((a-1) * (a-2) / 2)


    su = sum(A_product)
    for k in A:
        print(su - A_product[k-1] + A_product_1[k-1])


if __name__ == "__main__":
    main()