Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict.values():
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans_dict = {}
    for k in ball_dict:
        ans = 0
        for l in ball_dict:
            if k == l:
                ans += (ball_dict[l] - 1) * (ball_dict[l] - 2) // 2
            else:
                ans += ball_dict[l] * (ball_dict[l] - 1) // 2
        ans_dict.setdefault(k, ans)

    for i in range(n):
        print(ans_dict[a[i]])

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    for i in range(n):
        new_dict = ball_dict.copy()
        new_dict[a[i]] -= 1
        ans = 0
        for v in new_dict.values():
            ans += v * (v - 1) // 2
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {a[0]:1}
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            ball_dict[a_sort[i]] += 1
        else:
            ball_dict.setdefault(a_sort[i], 1)

    for i in range(n):
        new_dict = ball_dict.copy()
        new_dict[a[i]] -= 1
        ans = 0
        for v in new_dict.values():
            ans += v * (v - 1) // 2
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python

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

    ball_dict = {}
    for i in range(n):
        if a[i] in ball_dict.keys():
            ball_dict[a[i]] += 1
        else:
            ball_dict.setdefault(a[i], 1)

    for i in range(n):
        new_dict = ball_dict.copy()
        new_dict[a[i]] -= 1
        ans = 0
        for v in new_dict.values():
            ans += v * (v - 1) // 2
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()