Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans_hash = {}
    num_hash = {}
    for n in A:
        if n not in ans_hash:
            ans = 0
            a = A[:]
            i = a.index(n)
            del a[i]
            val = Counter(a).values()
            for num in val:
                if num in num_hash:
                    ans += num_hash[num]
                else:
                    num_hash[num] = num * (num - 1) // 2
                    ans += num_hash[num]
            ans_hash[n] = ans
        print(ans_hash[n])


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter

def choose(n):
    return n * (n - 1) // 2


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    cnt = 0
    for c in C.values():
        cnt += choose(c)

    for a in A:
        ans = cnt
        ans -= choose(C[a])
        ans += choose(C[a] - 1)
        print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans_hash = {}
    num_hash = {}
    for n in A:
        if n in ans_hash:
            print(ans_hash[n])
        else:
            ans = 0
            a = A[:]
            i = a.index(n)
            del a[i]
            val = Counter(a).values()
            for num in val:
                if num in num_hash:
                    ans += num_hash[num]
                else:
                    num_hash[num] = num * (num - 1) // 2
                    ans += num_hash[num]
            ans_hash[n] = ans
            print(ans_hash[n])


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter

def choose(n):
    return n * (n - 1) // 2


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    cnt = 0
    for c in C.values():
        cnt += choose(c)

    for a in A:
        ans = cnt
        ans -= choose(C[a])
        ans += choose(C[a] - 1)
        print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    uq = list(set(A))
    ans_hash = {}
    num_hash = {}
    for u in uq:
        ans = 0
        a = A[:]
        i = a.index(u)
        del a[i]
        val = Counter(a).values()
        for num in val:
            if num in num_hash:
                ans += num_hash[num]
            else:
                num_hash[num] = num * (num - 1) // 2
                ans += num_hash[num]
        ans_hash[u] = ans
    for n in A:
        print(ans_hash[n])


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter

def choose(n):
    return n * (n - 1) // 2


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    cnt = 0
    for c in C.values():
        cnt += choose(c)

    for a in A:
        ans = cnt
        ans -= choose(C[a])
        ans += choose(C[a] - 1)
        print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    uq = list(set(A))
    ans_hash = {}
    for u in uq:
        ans = 0
        a = A[:]
        i = a.index(u)
        del a[i]
        C = Counter(a)
        val = C.values()
        for num in val:
            ans += num * (num - 1) // 2
        ans_hash[u] = ans
    for n in A:
        print(ans_hash[n])


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter

def choose(n):
    return n * (n - 1) // 2


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    cnt = 0
    for c in C.values():
        cnt += choose(c)

    for a in A:
        ans = cnt
        ans -= choose(C[a])
        ans += choose(C[a] - 1)
        print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        ans = 0
        a = A[:]
        del a[i]
        C = Counter(a)
        val = C.values()
        for num in val:
            ans += num * (num - 1) // 2
        print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter

def choose(n):
    return n * (n - 1) // 2


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    cnt = 0
    for c in C.values():
        cnt += choose(c)

    for a in A:
        ans = cnt
        ans -= choose(C[a])
        ans += choose(C[a] - 1)
        print(ans)


if __name__ == '__main__':
    main()