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

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

n = int(input())
lis = list(map(int, input().split()))

c = collections.Counter(lis)
dic = {}

for key, value in c.items():
    dic[key] = cmb(value)

for i in range(n):
    ans = sum(list(dic.values()))
    ans -= dic[lis[i]]
    
    ans += cmb(c[lis[i]] -1)
    
    print(ans)

Fixed submission:

n = int(input())
lis = list(map(int, input().split()))

ban = [0] * n

tmp = 0
for i in lis:
    ban[i-1] += 1

for i in ban:
    tmp += i*(i-1)//2
    
for i in lis:
    print(tmp+(1-ban[i-1]))

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

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
lis = list(map(int, input().split()))

c = collections.Counter(lis)
dic = {}

for i in range(n):
    if lis[i] in dic.keys():
        continue
    else:
        if c[lis[i]] < 2:
            dic[lis[i]] = 0
        else:
            dic[lis[i]] = cmb(c[lis[i]], 2)


for i in range(n):
    ans = sum(list(dic.values()))
    ans -= dic[lis[i]]
    if c[lis[i]] <= 2:
        ans += 0
    else:
        ans += cmb(c[lis[i]]-1, 2)
    
    print(ans)

Fixed submission:

n = int(input())
lis = list(map(int, input().split()))

ban = [0] * n

tmp = 0
for i in lis:
    ban[i-1] += 1

for i in ban:
    tmp += i*(i-1)//2
    
for i in lis:
    print(tmp+(1-ban[i-1]))

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

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
lis = list(map(int, input().split()))

c = collections.Counter(lis)


for i in range(n):
    ans = 0
    a = lis[i]
    for key, value in c.items():
        if key == a:
            if value-1 < 2:
                ans += 0
            else:
                ans += cmb(value-1, 2)
        else:
            if value == 1:
                ans += 0
            else:
                ans += cmb(value, 2)
    
    print(ans)

Fixed submission:

n = int(input())
lis = list(map(int, input().split()))

ban = [0] * n

tmp = 0
for i in lis:
    ban[i-1] += 1

for i in ban:
    tmp += i*(i-1)//2
    
for i in lis:
    print(tmp+(1-ban[i-1]))

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

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
lis = list(map(int, input().split()))

c = collections.Counter(lis)


for i in range(n):
    ans = 0
    a = lis[i]
    for key, value in c.items():
        if key == a:
            if value-1 < 2:
                ans += 0
            else:
                ans += cmb(value-1, 2)
        else:
            if value == 1:
                ans += 0
            else:
                ans += cmb(value, 2)
    
    print(ans)

Fixed submission:

n = int(input())
lis = list(map(int, input().split()))

ban = [0] * n

tmp = 0
for i in lis:
    ban[i-1] += 1

for i in ban:
    tmp += i*(i-1)//2
    
for i in lis:
    print(tmp+(1-ban[i-1]))