Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()
c = list(set(a))
b = [0 for _ in range(n + 1)]
for i in range(n):
    b[a[i]] += 1
for k in range(n):
    ans = 0
    for i in c:
        tmp = b[i]
        if i == a[k]:
            tmp -= 1
        if tmp >= 2:
            ans += tmp * (tmp - 1) // 2
    print(ans)


Fixed submission:
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()
c = list(set(a))
b = [0 for _ in range(n + 1)]
for i in range(n):
    b[a[i]] += 1
d = [0 for _ in range(n + 1)]
e = [0 for _ in range(n + 1)]
for i in range(n + 1):
    if b[i] >= 2:
        d[i] = b[i] * (b[i] - 1) // 2
    if b[i] >= 3:
        e[i] = (b[i] - 1) * (b[i] - 2) // 2
sd = sum(d)
se = sum(e)
for k in range(n):
    ans = sd - d[a[k]] + e[a[k]]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
for k in range(n):
    ans = 0
    for i in c:
        tmp = b[i]
        if i == a[k]:
            tmp -= 1
        if tmp >= 2:
            ans += tmp * (tmp - 1) // 2
    print(ans)


Fixed submission:
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()
c = list(set(a))
b = [0 for _ in range(n + 1)]
for i in range(n):
    b[a[i]] += 1
d = [0 for _ in range(n + 1)]
e = [0 for _ in range(n + 1)]
for i in range(n + 1):
    if b[i] >= 2:
        d[i] = b[i] * (b[i] - 1) // 2
    if b[i] >= 3:
        e[i] = (b[i] - 1) * (b[i] - 2) // 2
sd = sum(d)
se = sum(e)
for k in range(n):
    ans = sd - d[a[k]] + e[a[k]]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
for k in range(n):
    ans = 0
    for i in c:
        tmp = b[i]
        if i == a[k]:
            tmp -= 1
        if tmp >= 2:
            ans += tmp * (tmp - 1) // 2
    print(ans)


Fixed submission:
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()
c = list(set(a))
b = [0 for _ in range(n + 1)]
for i in range(n):
    b[a[i]] += 1
d = [0 for _ in range(n + 1)]
e = [0 for _ in range(n + 1)]
for i in range(n + 1):
    if b[i] >= 2:
        d[i] = b[i] * (b[i] - 1) // 2
    if b[i] >= 3:
        e[i] = (b[i] - 1) * (b[i] - 2) // 2
sd = sum(d)
se = sum(e)
for k in range(n):
    ans = sd - d[a[k]] + e[a[k]]
    print(ans)