Problem p02683 (python)

Fixed submission:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    arr = []
    for _ in range(n):
        temp = nl()
        arr.append(temp)

    costs = []
    for i in range(2**n):
        binary = bin(i)[2:]
        binary = '0'*(n-len(binary)) + binary
        count = [0]*m
        cost = 0
        for i, num in enumerate(binary):
            if num == '1':
                for j in range(m):
                    count[j] += arr[i][j+1]
                cost += arr[i][0]
        #print(binary, cost)
        flag = True
        for value in count:
            if value < x:
                flag = False
        if flag:
            costs.append(cost)
    if costs == []:
        print(-1)
    else:
        print(min(costs))
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    arr = []
    for _ in range(n):
        temp = nl()
        arr.append(temp)

    costs = []
    for i in range(2**n):
        binary = bin(i)[2:]
        binary = '0'*(m-len(binary)) + binary
        count = [0]*m
        cost = 0
        for i, num in enumerate(binary):
            if num == '1':
                for j in range(m):
                    count[j] += arr[i][j+1]
                cost += arr[i][0]
        #print(binary, cost)
        flag = True
        for value in count:
            if value < x:
                flag = False
        if flag:
            costs.append(cost)
    if costs == []:
        print(-1)
    else:
        print(min(costs))
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    arr = []
    for _ in range(n):
        temp = nl()
        arr.append(temp)

    costs = []
    for i in range(2**n):
        binary = bin(i)[2:]
        binary = '0'*(m-len(binary)) + binary
        count = [0]*m
        cost = 0
        for i, num in enumerate(binary):
            if num == '1':
                for j in range(m):
                    count[j] += arr[i][j+1]
                cost += arr[i][0]
        #print(binary, cost)
        flag = True
        for value in count:
            if value < x:
                flag = False
        if flag:
            costs.append(cost)
    try:
        print(min(costs))
    except ValueError:
        print(-1)
    

if __name__ == '__main__':
    main()