Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif r < 0:
        return 0
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    n = int(input())
    As = list(map(int, input().split()))

    a_set = set(As)
    a_dict = {}
    for a in a_set:
        Bs = deepcopy(As)
        Bs.remove(a)
        b_set = set(Bs)
        a_dict[a] = 0
        for b in b_set:
            a_dict[a] += cmb(Bs.count(b), 2)

    for a in As:
        ans = a_dict[a]
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    arr = list(map(int, input().split()))

    cnt = Counter(arr)
    total = 0
    for key in cnt.keys():
        total += cnt[key]*(cnt[key]-1)//2

    for i in range(n):
        tmp = total
        tmp -= cnt[arr[i]]*(cnt[arr[i]]-1)//2
        tmp += (cnt[arr[i]]-1)*(cnt[arr[i]]-2)//2
        print(tmp)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif r < 0:
        return 0
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    n = int(input())
    As = list(map(int, input().split()))

    for a in As:
        Bs = deepcopy(As)
        Bs.remove(a)
        b_set = set(Bs)
        ans = 0
        for b in b_set:
            a = cmb(Bs.count(b), 2)
            ans += a
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    arr = list(map(int, input().split()))

    cnt = Counter(arr)
    total = 0
    for key in cnt.keys():
        total += cnt[key]*(cnt[key]-1)//2

    for i in range(n):
        tmp = total
        tmp -= cnt[arr[i]]*(cnt[arr[i]]-1)//2
        tmp += (cnt[arr[i]]-1)*(cnt[arr[i]]-2)//2
        print(tmp)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as comb
from copy import deepcopy
import sys


def main():
    input = sys.stdin.readline
    n = int(input())
    As = list(map(int, input().split()))

    for a in As:
        Bs = deepcopy(As)
        Bs.remove(a)
        b_set = set(Bs)
        ans = 0
        for b in b_set:
            ans += len(list(comb(range(Bs.count(b)), 2)))
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    arr = list(map(int, input().split()))

    cnt = Counter(arr)
    total = 0
    for key in cnt.keys():
        total += cnt[key]*(cnt[key]-1)//2

    for i in range(n):
        tmp = total
        tmp -= cnt[arr[i]]*(cnt[arr[i]]-1)//2
        tmp += (cnt[arr[i]]-1)*(cnt[arr[i]]-2)//2
        print(tmp)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as comb
from copy import deepcopy


def main():
    n = int(input())
    As = list(map(int, input().split()))

    for a in As:
        Bs = deepcopy(As)
        Bs.remove(a)
        b_set = set(Bs)
        ans = 0
        for b in b_set:
            ans += len(list(comb(range(Bs.count(b)), 2)))
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    arr = list(map(int, input().split()))

    cnt = Counter(arr)
    total = 0
    for key in cnt.keys():
        total += cnt[key]*(cnt[key]-1)//2

    for i in range(n):
        tmp = total
        tmp -= cnt[arr[i]]*(cnt[arr[i]]-1)//2
        tmp += (cnt[arr[i]]-1)*(cnt[arr[i]]-2)//2
        print(tmp)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as comb
from copy import deepcopy


def main():
    n = int(input())
    As = list(map(int, input().split()))

    for a in As:
        Bs = deepcopy(As)
        Bs.remove(a)
        b_set = set(Bs)
        ans = 0
        for b in b_set:
            ans += len(list(comb(range(Bs.count(b)), 2)))
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    arr = list(map(int, input().split()))

    cnt = Counter(arr)
    total = 0
    for key in cnt.keys():
        total += cnt[key]*(cnt[key]-1)//2

    for i in range(n):
        tmp = total
        tmp -= cnt[arr[i]]*(cnt[arr[i]]-1)//2
        tmp += (cnt[arr[i]]-1)*(cnt[arr[i]]-2)//2
        print(tmp)


if __name__ == "__main__":
    main()