Problem p02881 (python)

Fixed submission:
import math

def main():
    N = int(input())
    rt_N = math.ceil(math.sqrt(N))

    mn_ij = 10**12
    for i in range(1, rt_N+1):
        if N % i == 0:
            j = N // i

            mn_ij = min(mn_ij, i+j)
        
        mn_ij = min(mn_ij, i+j)

    # print(list(map(len,[ st, facs]) ))
    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):

    gaps = [1,2,2,4,2,4,2,4,6,2,6]
    length, cycle = 11, 3
    f, fs, nxt = 2, [], 0
    while f * f <= n:
        while n % f == 0:
            fs.append(f)
            n /= f
        f += gaps[nxt]
        nxt += 1
        if nxt == length:
            nxt = cycle
    if n > 1: fs.append(n)
    return fs

import itertools
from itertools import combinations, chain
import copy 

# def powerset(L):
#   pset = set()
#   for n in range(len(L) + 1):
#     for sset in itertools.combinations(L, n):
#       pset.add(sset)
#   return pset
def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
    
def list_diff(first, second):
        first = copy.copy(first)
        for s in second:
            first.remove(s)
        return first

def prod(lst):
    ret = 1
    for a in lst:
        ret *= a
    return ret

def sup(x):
    return [sorted(x[:i]+x[i+s:]) for i in range(len(x)) for s in range(len(x))]

def main():
    N = int(input())
    facs = factors(N)
    # st = powerset(facs)
    st=sup(facs)

    mn_ij = 10**12
    for i in st:
        i = list(i)
        j = list_diff(facs, i)
        i, j = prod(i), prod(j)

        mn_ij = min(mn_ij, i+j)

    # print(list(map(len,[ st, facs]) ))
    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import itertools
from itertools import combinations, chain
import copy 

# def powerset(L):
#   pset = set()
#   for n in range(len(L) + 1):
#     for sset in itertools.combinations(L, n):
#       pset.add(sset)
#   return pset
def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
    
def list_diff(first, second):
        first = copy.copy(first)
        for s in second:
            first.remove(s)
        return first

def prod(lst):
    ret = 1
    for a in lst:
        ret *= a
    return ret

def sup(x):
    return [sorted(x[:i]+x[i+s:]) for i in range(len(x)) for s in range(len(x))]

def main():
    N = int(input())
    facs = factors(N)
    # st = powerset(facs)
    st=sup(facs)

    mn_ij = 10**12
    for i in st:
        i = list(i)
        j = list_diff(facs, i)
        i, j = prod(i), prod(j)

        mn_ij = min(mn_ij, i+j)

    # print(list(map(len,[ st, facs]) ))
    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import itertools
from itertools import combinations, chain
import copy 

# def powerset(L):
#   pset = set()
#   for n in range(len(L) + 1):
#     for sset in itertools.combinations(L, n):
#       pset.add(sset)
#   return pset
def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
    
def list_diff(first, second):
        first = copy.copy(first)
        for s in second:
            first.remove(s)
        return first

def prod(lst):
    ret = 1
    for a in lst:
        ret *= a
    return ret

def sup(x):
    return [sorted(x[:i]+x[i+s:]) for i in range(len(x)) for s in range(len(x))]

def main():
    N = int(input())
    facs = factors(N)
    # st = powerset(facs)
    st=sup(facs)

    mn_ij = 10**12
    for i in st:
        i = list(i)
        j = list_diff(facs, i)
        i, j = prod(i), prod(j)

        mn_ij = min(mn_ij, i+j)

    # print(list(map(len,[ st, facs]) ))
    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import itertools
import numpy as np

def powerset(L):
  pset = set()
  for n in range(len(L) + 1):
    for sset in itertools.combinations(L, n):
      pset.add(sset)
  return pset
    
def list_diff(first, second):
        first = first.copy()
        for s in second:
            first.remove(s)
        return first

def main():
    N = int(input())
    facs = factors(N)
    st = powerset(facs)

    mn_ij = 10**12
    for i in st:
        i = list(i)
        j = list_diff(facs, i)
        i, j = np.prod(i), np.prod(j)

        mn_ij = min(mn_ij, i+j)

    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import itertools
import numpy as np

def powerset(L):
  pset = set()
  for n in range(len(L) + 1):
    for sset in itertools.combinations(L, n):
      pset.add(sset)
  return pset
    
def list_diff(first, second):
        first = first.copy()
        for s in second:
            first.remove(s)
        return first

def main():
    N = int(input())
    facs = factors(N)
    st = powerset(facs)

    mn_ij = 10**12
    for i in st:
        i = list(i)
        j = list_diff(facs, i)
        i, j = np.prod(i), np.prod(j)

        assert i * j == N, f'{i} {j} {N}'
        mn_ij = min(mn_ij, i+j)

    print(int(mn_ij-2))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
for line in sys.stdin:
    A, B = list(map(int, line.split(' ')))