Problem p02732 (python)

Fixed submission:
import collections

def combinations_count(n, r):
    return n * (n-1) // r


n = int(input())
l = [int(x) for x in input().split()]

l1 = []
l2 = []
c = collections.Counter(l)

total = sum([combinations_count(i, 2) for i in c.values()])

for a in l:
    print(total-combinations_count(c[a], 2)+combinations_count(c[a]-1, 2))

Buggy submission (verdict: Runtime Error):
import sys
import collections
from operator import mul
from functools import reduce
 
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
n = int(input())
l = [int(x) for x in input().split()]
c = collections.Counter(l)
 
# cl = [0 for i in range(n)]
cl = []
 
# print(ll)
 
if not ll:
    for i in range(n):
        print(0)
    sys.exit()
 
sum = 0
for a, v in c:
    nc = combinations_count(v, 2)
    sum += nc
    # print(nc)
    # cl[i-1] = nc - int(nc*(m-2)/m)
    cl.append(nc - int(nc * (v - 2) / v))
 
# print(sum)
# print(cl)
 
def my_index(l, x, default=n):
    if x in l:
        return l.index(x)
    else:
        return default
 
for i in l:
    # print(sum - cl[i-1])
    idx = my_index(ll, i)
    if idx == n:
        print(sum)
    else:
        print(sum - cl[idx])

Buggy submission (verdict: Runtime Error):
import sys
import collections
from operator import mul
from functools import reduce
 
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
n = int(input())
l = [int(x) for x in input().split()]
c = collections.Counter(l)
 
# cl = [0 for i in range(n)]
cl = []
ll = [x for x in set(l) if l.count(x) > 1]
 
# print(ll)
 
if not ll:
    for i in range(n):
        print(0)
    sys.exit()
 
sum = 0
for i in ll:
    nc = combinations_count(c[i], 2)
    sum += nc
    # print(nc)
    # cl[i-1] = nc - int(nc*(m-2)/m)
    cl.append(nc - int(nc * (m - 2) / m))
 
# print(sum)
# print(cl)
 
def my_index(l, x, default=n):
    if x in l:
        return l.index(x)
    else:
        return default
 
for i in l:
    # print(sum - cl[i-1])
    idx = my_index(ll, i)
    if idx == n:
        print(sum)
    else:
        print(sum - cl[idx])

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n = int(input())
l = [int(x) for x in input().split()]

ll = [x for x in set(l) if l.count(x) > 1]

sm = 0
m = [0 for x in range(n)]
for i in ll:
    t = l.count(i)
    sm += combinations_count(t, 2)
    m[i] = t

for i in l:
    print(sm-(m[i]-1))

Buggy submission (verdict: Runtime Error):
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

n = int(input())
l = [int(x) for x in input().split()]

# cl = [0 for i in range(n)]
cl = []
ll = [x for x in set(l) if l.count(x) > 1]

# print(ll)

if not ll:
    for i in range(n):
        print(0)
    sys.exit()

sum = 0
for i in ll:
    m = l.count(i)
    nc = combinations_count(m, 2)
    sum += nc
    # print(nc)
    # cl[i-1] = nc - int(nc*(m-2)/m)
    cl.append(nc - int(nc * (m - 2) / m))

# print(sum)
# print(cl)
for i in l:
    # print(sum - cl[i-1])
    idx = ll.index(i)
    if idx:
        print(0)
    else:
        print(sum - cl[ll.index(i)])

Buggy submission (verdict: Runtime Error):
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

n = int(input())
l = [int(x) for x in input().split()]

# cl = [0 for i in range(n)]
cl = []
ll = [x for x in set(l) if l.count(x) > 1]

# print(ll)

if not ll:
    for i in range(n):
        print(0)
    sys.exit()

sum = 0
for i in ll:
    m = l.count(i)
    nc = combinations_count(m, 2)
    sum += nc
    # print(nc)
    # cl[i-1] = nc - int(nc*(m-2)/m)
    cl.append(nc - int(nc * (m - 2) / m))

# print(sum)
# print(cl)
for i in l:
    # print(sum - cl[i-1])
    idx = ll.index(i)
    if idx:
        print(0)
    else:
        print(sum - cl[ll.index(i)])

Buggy submission (verdict: Runtime Error):
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

n = int(input())
l = [int(x) for x in input().split()]

# cl = [0 for i in range(n)]
cl = []
ll = [x for x in set(l) if l.count(x) > 1]

# print(ll)

if not ll:
    for i in range(n):
        print(0)
    sys.exit()

sum = 0
for i in ll:
    m = l.count(i)
    nc = combinations_count(m, 2)
    sum += nc
    # print(nc)
    # cl[i-1] = nc - int(nc*(m-2)/m)
    cl.append(nc - int(nc * (m - 2) / m))

# print(sum)
# print(cl)
for i in l:
    # print(sum - cl[i-1])
    print(sum - cl[ll.index(i)])