Buggy python submission (verdict: Time Limit Exceeded):
def q4():
    import collections
    N = int(input())
    A = [int(i) for i in input().split()]

    def combinations_count(n, r):
        """ 組み合わせ総数を計算 """
        import math
        ret = 0 if n < r else math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        return ret

    all_sum = 0  # 総数
    counter = collections.Counter(A)
    # all_sumを作成
    for v in counter.values():
        all_sum += combinations_count(v, 2)

    for i in range(N):
        cnt = counter[A[i]]  # i番目の値の出現回数を取得
        ans = all_sum - combinations_count(cnt, 2) + combinations_count(cnt - 1, 2)
        print(ans)

        
if __name__ == '__main__':
    q4()


Fixed submission:
def q4():
    import collections
    N = int(input())
    A = [int(i) for i in input().split()]

    def n_C_2(n):
        """ n個から2個選ぶ組み合わせ総数を計算 """
        ret = 0 if n < 2 else n * (n - 1) / 2
        return ret

    all_sum = 0  # 総数
    counter = collections.Counter(A)
    # all_sumを作成
    for v in counter.values():
        all_sum += n_C_2(v)

    for i in range(N):
        cnt = counter[A[i]]  # i番目の値の出現回数を取得
        ans = all_sum - n_C_2(cnt) + n_C_2(cnt - 1)
        print(int(ans))


if __name__ == '__main__':
    q4()

Buggy python submission (verdict: Time Limit Exceeded):
def q4():
    N = int(input())
    A = [int(i) for i in input().split()]

    def combinations_count(n, r):
        """ 組み合わせ総数を計算 """
        import math
        ret = 0 if n < r else math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        return ret

    unique_values = set(A)

    all_sum = 0  # 総数
    # all_sumを作成
    for u in unique_values:
        cnt = A.count(u)
        all_sum += combinations_count(cnt, 2)

    for i in range(N):
        cnt = A.count(A[i])
        ans = all_sum - combinations_count(cnt, 2) + combinations_count(cnt - 1, 2)
        print(ans)


if __name__ == '__main__':
    q4()


Fixed submission:
def q4():
    import collections
    N = int(input())
    A = [int(i) for i in input().split()]

    def n_C_2(n):
        """ n個から2個選ぶ組み合わせ総数を計算 """
        ret = 0 if n < 2 else n * (n - 1) / 2
        return ret

    all_sum = 0  # 総数
    counter = collections.Counter(A)
    # all_sumを作成
    for v in counter.values():
        all_sum += n_C_2(v)

    for i in range(N):
        cnt = counter[A[i]]  # i番目の値の出現回数を取得
        ans = all_sum - n_C_2(cnt) + n_C_2(cnt - 1)
        print(int(ans))


if __name__ == '__main__':
    q4()

Buggy python submission (verdict: Time Limit Exceeded):
def q4():
    N = int(input())
    A = [int(i) for i in input().split()]

    def combinations_count(n, r):
        """ 組み合わせ総数を計算 """
        import math
        ret = 0 if n < r else math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        return ret

    unique_values = set(A)

    all_sum = 0  # 総数
    # all_sumを作成
    for u in unique_values:
        cnt = A.count(u)
        all_sum += combinations_count(cnt, 2)

    for i in range(N):
        cnt = A.count(A[i])
        ans = all_sum - combinations_count(cnt, 2) + combinations_count(cnt - 1, 2)
        print(ans)


if __name__ == '__main__':
    q4()


Fixed submission:
def q4():
    import collections
    N = int(input())
    A = [int(i) for i in input().split()]

    def n_C_2(n):
        """ n個から2個選ぶ組み合わせ総数を計算 """
        ret = 0 if n < 2 else n * (n - 1) / 2
        return ret

    all_sum = 0  # 総数
    counter = collections.Counter(A)
    # all_sumを作成
    for v in counter.values():
        all_sum += n_C_2(v)

    for i in range(N):
        cnt = counter[A[i]]  # i番目の値の出現回数を取得
        ans = all_sum - n_C_2(cnt) + n_C_2(cnt - 1)
        print(int(ans))


if __name__ == '__main__':
    q4()