Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    
    N = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    
    set_a = set(A)
    
    d = {}
    comb_sum = 0
    
    for i in set_a:
        n = A.count(i)
        if n == 1:
            comb = 0
            comb_ex = 0
        else:
            comb = n * (n - 1) / 2
            comb_ex = (n - 1) * (n - 2) / 2
        comb_sum += comb
        d[i] = comb_ex - comb
     
    for n in A:
        ans = int(d[n] + comb_sum)
        print(ans)
      
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    
    N = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    
    count = Counter(A)
    
    d = {}
    comb_sum = 0
    
    for i, n in count.items():
        if n == 1:
            comb = 0
            comb_ex = 0
        else:
            comb = n * (n - 1) / 2
            comb_ex = (n - 1) * (n - 2) / 2
        comb_sum += comb
        d[i] = comb_ex - comb
     
    for n in A:
        ans = int(d[n] + comb_sum)
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    import sys
    
    N = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    
    set_a = set(A)
    
    num_dic = {}
    comb_dic = {}
    comb_dic_ex = {}
    comb_sum = 0
    
    for i in set_a:
        num_dic[i] = A.count(i)
        n = num_dic[i]
        if num_dic[i] == 1:
            comb_dic[i] = 0
            comb_dic_ex[i] = 0
        else:
            comb_dic[i] = n * (n - 1) / 2
            comb_dic_ex[i] = (n - 1) * (n - 2) / 2
        comb_sum += comb_dic[i]
     
    for j in range(N):
        n = A[j]
        ans = int(comb_dic_ex[n] + comb_sum - comb_dic[n])
        print(ans)

Fixed submission:
def main():
    import sys
    from collections import Counter
    
    N = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    
    count = Counter(A)
    
    d = {}
    comb_sum = 0
    
    for i, n in count.items():
        if n == 1:
            comb = 0
            comb_ex = 0
        else:
            comb = n * (n - 1) / 2
            comb_ex = (n - 1) * (n - 2) / 2
        comb_sum += comb
        d[i] = comb_ex - comb
     
    for n in A:
        ans = int(d[n] + comb_sum)
        print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

N = int(input())
A = list(map(int, sys.stdin.readline().split()))

set_a = set(A)

num_dic = {}
comb_dic = {}
comb_dic_ex = {}

for i in set_a:
    num_dic[i] = A.count(i)
    if num_dic[i] == 1:
        comb_dic[i] = 0
        comb_dic_ex[i] = 0
    else:
        comb_dic[i] = cmb(num_dic[i])
        comb_dic_ex[i] = cmb(num_dic[i] - 1)
    
comb_sum = sum(comb_dic.values())
 
for j in range(N):
    n = A[j]
    ans = int(comb_dic_ex[n] + comb_sum - comb_dic[n])
    print(ans)

Fixed submission:
def main():
    import sys
    from collections import Counter
    
    N = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    
    count = Counter(A)
    
    d = {}
    comb_sum = 0
    
    for i, n in count.items():
        if n == 1:
            comb = 0
            comb_ex = 0
        else:
            comb = n * (n - 1) / 2
            comb_ex = (n - 1) * (n - 2) / 2
        comb_sum += comb
        d[i] = comb_ex - comb
     
    for n in A:
        ans = int(d[n] + comb_sum)
        print(ans)

if __name__ == '__main__':
    main()