Buggy python submission (verdict: Time Limit Exceeded):
def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
E = []

for i in range(n):
    if E.count(a[i]) == 0:
        E.append(a[i])

m = len(E)
count = 0

for i in range(m):
    num = a.count(E[i])
    count += C(num)

for i in range(n):
    l = a.count(a[i])
    print(count - C(l) + C(l-1))

Fixed submission:

from collections import Counter

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

count = 0

for i, j in c.items():
    count += C(j)

for i in a:
    m = c[i]
    print(count - m + 1)

Buggy python submission (verdict: Time Limit Exceeded):
def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    


n = int(input())
a = list(map(int, input().split()))
E = []

for i in range(n):
    if E.count(a[i]) == 0:
        E.append(a[i])

m = len(E)

num = [0] * m
comb = [0] * m
count = 0

for i in range(m):
    num[i] = a.count(E[i])
    comb[i] = C(num[i])
    count += comb[i]

for i in range(n):
    l = E.index(a[i])
    print(count - comb[l] + C(num[l]-1))

Fixed submission:

from collections import Counter

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

count = 0

for i, j in c.items():
    count += C(j)

for i in a:
    m = c[i]
    print(count - m + 1)

Buggy python submission (verdict: Time Limit Exceeded):
def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    


n = int(input())
a = list(map(int, input().split()))
E = []

for i in range(n):
    if E.count(a[i]) == 0:
        E.append(a[i])

m = len(E)

num = [0] * m
comb = [0] * m

for i in range(m):
    num[i] = a.count(E[i])
    comb[i] = C(num[i])

count = sum(comb)

for i in range(n):
    l = E.index(a[i])
    print(count - comb[l] + C(num[l]-1))

Fixed submission:

from collections import Counter

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

count = 0

for i, j in c.items():
    count += C(j)

for i in a:
    m = c[i]
    print(count - m + 1)

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

def C(n,r):
    if n < r: return 0    
    r = min(n-r,r)
    if r == 0: return 1
    nume = reduce(mul, range(n, n - r, -1))
    deno = reduce(mul, range(1,r + 1))
    return nume // deno


n = int(input())
a = list(map(int, input().split()))
E = []

for i in range(n):
    if E.count(a[i]) == 0:
        E.append(a[i])

m = len(E)

num = [0] * m
comb = [0] * m

for i in range(m):
    num[i] = a.count(E[i])
    comb[i] = C(num[i], 2)

count = sum(comb)

for i in range(n):
    l = E.index(a[i])
    print(count - comb[l] + C(num[l]-1, 2))
    

Fixed submission:

from collections import Counter

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

count = 0

for i, j in c.items():
    count += C(j)

for i in a:
    m = c[i]
    print(count - m + 1)

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

def P(n, r):
    if n < r:
        return 0
    return math.factorial(n)//math.factorial(n-r)
 
 
def C(n, r):
    return P(n, r)//math.factorial(r)


n = int(input())
a = list(map(int, input().split()))
E = []

for i in range(n):
    if E.count(a[i]) == 0:
        E.append(a[i])

num = [0] * len(E)
comb = [0] * len(E)

for i in range(len(E)):
    num[i] = a.count(E[i])
    comb[i] = C(num[i], 2)

count = sum(comb)

for i in range(n):
    l = E.index(a[i])
    print(count - comb[l] + C(num[l]-1, 2))

Fixed submission:

from collections import Counter

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

count = 0

for i, j in c.items():
    count += C(j)

for i in a:
    m = c[i]
    print(count - m + 1)