qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import numpy as np
n, m, x = map(int, input().split())
Book = [list(map(int, input().split())) for _ in range(n)]
select = [np.array([])]*(2**n)
cost = [0]*(2**n)
skill = [np.array([0]*m)]*(2**n)
cost2 = []
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1:
            cost[i] += Book[j][0]
            skill[i] += np.array(Book[j])[1:m+1]
    if np.min(skill[i]) >= x:
        cost2.append(cost[i])
if len(cost2) > 0:
    print(min(cost2))
else:
    print(-1)

Fixed code:
import numpy as np
n, m, x = map(int, input().split())
Book = [list(map(int, input().split())) for _ in range(n)]
cost = [0 for _ in range(2**n)]
skill = [np.zeros(m) for _ in range(2**n)]
cost2 = []
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1:
            cost[i] += Book[j][0]
            skill[i] += np.array(Book[j])[1:m+1]
    if np.min(skill[i]) >= x:
        cost2.append(cost[i])
if len(cost2) > 0:
    print(min(cost2))
else:
    print(-1)
Buggy code:
import numpy as np
from itertools import product

if __name__ == '__main__':
    T = input().split()
    N = int(T[0])
    M = int(T[1])
    X = int(T[2])
    price = np.zeros(N)
    qual = np.zeros((N, M))
    for n in range(N):
        t = input().split()
        price[n] = int(t[0])
        qual[n, :] = np.array([int(m) for m in t[1:]])

    cost_min = 1e18
    for idx in product([0, 1], repeat=N):
        cost = 0
        t = X * np.ones(M)
        for j in range(N):
            if idx[j] == 1:
                t -= qual[j, :]
                cost += price[j]
        if max(t) <= 0:
            if cost < cost_min:
                cost_min = cost
    if cost_min == 1e09:
        print(-1)
    else:
        print(int(cost_min))

Fixed code:
import numpy as np
from itertools import product

if __name__ == '__main__':
    T = input().split()
    N = int(T[0])
    M = int(T[1])
    X = int(T[2])
    price = np.zeros(N)
    qual = np.zeros((N, M))
    for n in range(N):
        t = input().split()
        price[n] = int(t[0])
        qual[n, :] = np.array([int(m) for m in t[1:]])

    cost_min = 1e18
    for idx in product([0, 1], repeat=N):
        cost = 0
        t = X * np.ones(M)
        for j in range(N):
            if idx[j] == 1:
                t -= qual[j, :]
                cost += price[j]
        if max(t) <= 0:
            if cost < cost_min:
                cost_min = cost
    if cost_min == 1e18:
        print(-1)
    else:
        print(int(cost_min))
Buggy code:
N, M, X = map(int,input().split())
A=[]
for i in range(N):
    A.append(list(map(int, input().split())))
    
pr=10**9
for s in range(2**N):
    x_m = [0]*13
    for i in range(N):
        b = (s >> i) & 1
        if b == 1:
            pr_s += A[i][0]
            for j in range(M+1):
                x_m[j] += A[i][j]

    xOk = True
    for j in range(1,M+1):
        if x_m[j] < X:
            xOk = False
    
    if xOk == True:
        pr = min(pr, x_m[0])

if pr<10**9:
    print(pr)
else:
    print(-1)

Fixed code:
N, M, X = map(int,input().split())
A=[]
for i in range(N):
    A.append(list(map(int, input().split())))
    
pr=10**9
for s in range(2**N):
    x_m = [0]*13
    for i in range(N):
        b = (s >> i) & 1
        if b == 1:
            for j in range(M+1):
                x_m[j] += A[i][j]
 
    xOk = True
    for j in range(1,M+1):
        if x_m[j] < X:
            xOk = False
    
    if xOk == True:
        pr = min(pr, x_m[0])
 
if pr<10**9:
    print(pr)
else:
    print(-1)
Buggy code:
import itertools
import numpy as np
N,M,X=map(int,input().split())
lista=[]
for i in range(N):
    lista.append(list(map(int,input().split())))
lista=np.array(lista)
cost=1000000000000000
judge=[X]*M
data=[k for k in range(1,N+1)]
for i in range(1,N+1):
    a=list(itertools.combinations(data,i))
    for j in a:
        clist=np.array([0]*(M+1))
        for k in j:
            clist=clist+lista[k-1]
        if all(clist[1:]>=judge):
            if clist[0]<cost:
                cost=clist[0]
                m=j
c=0
for i in m:
    c+=lista[i][0]

print(c)    

Fixed code:
import itertools
import numpy as np
N,M,X=map(int,input().split())
lista=[]
for i in range(N):
    lista.append(list(map(int,input().split())))
lista=np.array(lista)
cost=1000000000000000
judge=[X]*M
data=[k for k in range(1,N+1)]
for i in range(1,N+1):
    a=list(itertools.combinations(data,i))
    for j in a:
        clist=np.array([0]*(M+1))
        for k in j:
            clist=clist+lista[k-1]
        if all(clist[1:]>=judge):
            if clist[0]<cost:
                cost=clist[0]
                m=j
c=0
try:
    for i in m:
        c+=lista[i-1][0]

    print(c)
except:
    print(-1)
Buggy code:
import itertools

def list_add(in1, in2):
   return list(map(sum, zip(in1, in2)))

N, M ,X = map(int, input().split())
C = [0] * N
A = [[] * M] * N
for i in range(N):
    T = list(map(int, input().split()))
    C[i] = T[0]
    A[i] = T[1:]

n = [i for i in range(N)]
c_sum = 0

for i in range(N):
    min_sum = 10e5
    flag = 0
    for v in itertools.combinations(n,i+1):
        c_sum = 0
        At = [0] * M
        for j in range(len(v)):
            At = list_add(At, A[v[j]])
            c_sum += C[v[j]]
        overX = [k for k in At if k >= X]
        if len(overX) == M:
            print(v)
            min_sum = min([min_sum, c_sum])
            flag = 1
    if flag == 1:
        print(min_sum)
        exit()
print(-1)

Fixed code:
import itertools

def list_add(in1, in2):
   return list(map(sum, zip(in1, in2)))

N, M ,X = map(int, input().split())
C = [0] * N
A = [[] * M] * N
for i in range(N):
    T = list(map(int, input().split()))
    C[i] = T[0]
    A[i] = T[1:]

n = [i for i in range(N)]
c_sum = 0
min_sum = 12 * 10e5
for i in range(N):
    flag = 0
    for v in itertools.combinations(n,i+1):
        c_sum = 0
        At = [0] * M
        for j in range(len(v)):
            At = list_add(At, A[v[j]])
            c_sum += C[v[j]]
        overX = [k for k in At if k >= X]
        if len(overX) == M:
            flag = 1
            min_sum = min([min_sum, c_sum])
if flag == 1:
    print(min_sum)
else:
    print(-1)
Buggy code:
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((M, N))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]

a = a.reshape(M, N)

answer_price = 2**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1
    if all(tmp >= X) and cost < answer_price:
        answer_price = cost
        
if answer_price == 2**10:
    print("-1")
else:
    print(int(answer_price))

Fixed code:
import numpy as np

N, M, X = list(map(int, input().split()))
a = np.zeros((N, M))
C = np.zeros(N)
for i in range(N):
    tmp = list(map(int, input().split()))
    C[i] += tmp[0]
    a[i] += tmp[1:]
    
answer_price = 10**10

for i in range(1 << N):
    tmp = np.zeros(M)
    cost = 0
    for j in range(N):
        if i % 2 == 1:
            tmp += a[j]
            cost += C[j]
        i = i >> 1

    if all(tmp >= X) and (cost < answer_price):
        answer_price = cost
        
if answer_price == 10**10:
    print("-1")
else:
    print(int(answer_price))
Buggy code:
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]

min_money = 10 ** 5 * 12 + 1

for bits in range(1 << N):
    money = 0
    algo = [0] * M
    for i in range(N):
        if bits >> i & 1 == 1:
            money += books[i][0]
            for j in range(M):
                algo[j] += books[i][j + 1]

    if min(algo) >= X:
        min_money = min(min_money, money)

print(min_money)


Fixed code:
N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(N)]

default = 10 ** 5 * 12 + 1
min_money = default

for bits in range(1 << N):
    money = 0
    algo = [0] * M
    for i in range(N):
        if bits >> i & 1 == 1:
            money += books[i][0]
            for j in range(M):
                algo[j] += books[i][j + 1]

    if min(algo) >= X:
        min_money = min(min_money, money)

print('-1' if min_money == default else min_money)
Buggy code:
INF=100100100

n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    t=list(map(int,input().split()))
    c.append(t[0])
    a.append(t[1:])
print(a)
cost=INF
for i in range(n**2-1):
    ab=[0]*m
    tmp=0
    for j in range(n):
        idx=i>>j & 1
        if(idx):
            tmp+=c[j]
            for k in range(m):
                ab[k]+=a[j][k]
    for k in range(m):
        if(ab[k]<x):break
    else:cost=min(cost,tmp)
if(INF==cost):print(-1)
else:print(cost)

Fixed code:
INF=100100100

n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    t=list(map(int,input().split()))
    c.append(t[0])
    a.append(t[1:])
cost=INF
for i in range(2**n):
    ab=[0]*m
    tmp=0
    for j in range(n):
        idx=i>>j & 1
        if(idx):
            tmp+=c[j]
            for k in range(m):
                ab[k]+=a[j][k]
    for k in range(m):
        if(ab[k]<x):break
    else:cost=min(cost,tmp)
if(INF==cost):print(-1)
else:print(cost)
Buggy code:
N,M,X = map(int, input().split())
A = []
C = []
for i in range(N) :
    I = list(map(int,input().split()))
    C.append(I[0])
    A.append(I[1:])

ans = 10**12
for iv in range(1 << N) :
    r = [0] * M
    c = 0
    isOk = True
    for i in range(N) :
        if(not iv >> i & 1) :
            continue
        c += C[i]
        for j in range(M) :
            r[j] += A[i][j]
    for i in range(M) :
        if(r[i] < X) :
            isOk = False
    if(isOk) :
        ans = min(ans,c)
if(ans == 10**6) :
    ans = -1
print(ans)

Fixed code:
N,M,X = map(int, input().split())
A = []
C = []
for i in range(N) :
    I = list(map(int,input().split()))
    C.append(I[0])
    A.append(I[1:])

ans = 10**12
for iv in range(1 << N) :
    r = [0] * M
    c = 0
    isOk = True
    for i in range(N) :
        if(not iv >> i & 1) :
            continue
        c += C[i]
        for j in range(M) :
            r[j] += A[i][j]
    for i in range(M) :
        if(r[i] < X) :
            isOk = False
    if(isOk) :
        ans = min(ans,c)
if(ans == 10**12) :
    ans = -1
print(ans)
Buggy code:
import itertools


def m():
    N, M, X = map(int, input().split())
    CA = [list(map(int, input().split())) for _ in range(N)]
    ans = float('inf')
    for i in itertools.product([True, False], repeat=N):
        tmp = [0] * (M + 1)
        for j, v in enumerate(i):
            if j:
                for k in range(M + 1):
                    tmp[k] += CA[j][k]
        f = 1
        for p in range(1, M + 1):
            if tmp[p] < X: f = 0
        if f: ans = min(ans, tmp[0])
    return ans if ans != float('inf') else "-1"


print(m())


Fixed code:
import itertools


def m():
    N, M, X = map(int, input().split())
    CA = [list(map(int, input().split())) for _ in range(N)]
    ans = float('inf')
    for i in itertools.product([True, False], repeat=N):
        tmp = [0] * (M + 1)
        for j, v in enumerate(i):
            if v:
                for k in range(M + 1):
                    tmp[k] += CA[j][k]
        f = 1
        for p in range(1, M + 1):
            if tmp[p] < X: f = 0
        if f: ans = min(ans, tmp[0])
    return ans if ans != float('inf') else "-1"


print(m())
Buggy code:
n,m,x=map(int,input().split())
arr=[[0 for i in range(m+1)] for j in range(n)]
b=[0]*18

flag=1
for i in range(n):
    arr[i]=list(map(int,input().split()))
for i in range(2**n):
    b=[0]*18
    for j in range(n):
        flag=1
        if (1& i>>j):
            for s in range(m+1):
                b[s]= b[s]+arr[j][s]
        for y in range(1,m+1):
            if(b[y]<x):
                flag=0
                
        if flag :
            if ans==-1 or ans>b[0]:
                ans=b[0]
print(ans)


Fixed code:
n,m,x=map(int,input().split())
arr=[[0 for i in range(m+1)] for j in range(n)]
b=[0]*18
ans=-1
flag=1
for i in range(n):
    arr[i]=list(map(int,input().split()))
for i in range(2**n):
    b=[0]*18
    for j in range(n):
        flag=1
        if (1& i>>j):
            for s in range(m+1):
                b[s]= b[s]+arr[j][s]
        for y in range(1,m+1):
            if(b[y]<x):
                flag=0
                
        if flag :
            if ans==-1 or ans>b[0]:
                ans=b[0]
print(ans)
Buggy code:
def main():
    import numpy as np
    from itertools import combinations
    n, m, x = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(n)]

    ans = 10 ** 20
    for i in range(1,m+1):
        for comb in combinations(l,i):
            y = np.array([x for _ in range(m)])
            tmp = 0
            for p in comb:
                tmp += p[0]
                y -= np.array(p[1:])
            s = sum([j <= 0 for j in y])
            if s == m:
                ans = min(ans,tmp)

    if ans == 10**9:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()


Fixed code:
def main():
    import numpy as np
    from itertools import combinations
    n, m, x = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(n)]

    ans = 10 ** 15
    for i in range(1, n + 1):
        for comb in combinations(l, i):
            y = np.array([x for _ in range(m)])
            tmp = 0
            for p in comb:
                tmp += p[0]
                y -= np.array(p[1:])
            s = sum([j <= 0 for j in y])
            if s == m:
                ans = min(ans, tmp)

    if ans == 10 ** 15:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
Buggy code:
n,m,x = map(int,input().split())
books = []

for i in range(n):
    arr = list(map(int,input().split()))
    books.append(arr)

def tobin(x,n):
    return format(x,'b').zfill(n)

ans = 1e10
for i in range(2**n):
    b = format(i,'b').zfill(n)
    # print(b)
    buf = [0 for i in range(m)]
    temp = 0
    for j in range(n):
        if b[j]=="1":
            temp += books[j][0]
            for k in range(1,m+1):
                buf[k-1] += books[j][k]
        else:
            continue
    # print(buf)
    flag = True
    for val in buf:
        if val < x:
            flag = False

    if flag and ans > temp:
        ans = temp
    else:
        continue

print(ans)




Fixed code:
n,m,x = map(int,input().split())
books = []

for i in range(n):
    arr = list(map(int,input().split()))
    books.append(arr)

def tobin(x,n):
    return format(x,'b').zfill(n)

ans = 1e10
for i in range(2**n):
    b = format(i,'b').zfill(n)
    # print(b)
    buf = [0 for i in range(m)]
    temp = 0
    for j in range(n):
        if b[j]=="1":
            temp += books[j][0]
            for k in range(1,m+1):
                buf[k-1] += books[j][k]
        else:
            continue
    # print(buf)
    flag = True
    for val in buf:
        if val < x:
            flag = False

    if flag and ans > temp:
        ans = temp
    else:
        continue

if ans > 1e9:
    print(-1)
else:
    print(ans)
Buggy code:
import itertools as it

n,m,x=map(int, input().split())
l=[]
check=[0]*(m)
ans=0
for i in range(n):
    a=list(map(int, input().split()))
    ans+=a[0]
    for j in range(m):
        check[j]+=a[j+1]
    l.append(a)

if min(check)<x:
    print('-1')
    exit()


for i in range(1,n+1):
    for p in it.combinations(range(n), i):
        print(p)
        mon=0
        che=[0]*m
        for j in range(len(p)):
            mon+=l[p[j]][0]
            for k in range(m):
                che[k]+=l[p[j]][k+1]
        #print(che)
        if min(che)>=x:
            ans=min(ans,mon)

print(ans)

Fixed code:
import itertools as it

n,m,x=map(int, input().split())
l=[]
check=[0]*(m)
ans=0
for i in range(n):
    a=list(map(int, input().split()))
    ans+=a[0]
    for j in range(m):
        check[j]+=a[j+1]
    l.append(a)

if min(check)<x:
    print('-1')
    exit()


for i in range(1,n+1):
    for p in it.combinations(range(n), i):
        #print(p)
        mon=0
        che=[0]*m
        for j in range(len(p)):
            mon+=l[p[j]][0]
            for k in range(m):
                che[k]+=l[p[j]][k+1]
        #print(che)
        if min(che)>=x:
            ans=min(ans,mon)

print(ans)
Buggy code:
import itertools 
def solve():
    n, m, x = map(int, input().split())
    c = []
    a = []
    for _ in range(n):
        C, *A = map(int, input().split())
        c.append(C)
        a.append(A)

    ans = n*1e5
    for i in range(n):
        for j in itertools.combinations(range(n), i+1):
            cnt = [0]*m
            for k in j:
                for l in range(m):
                    cnt[l] += a[k][l]
            for s in range(m):
                if cnt[s] < x:
                    break
                if s == m-1:
                    num = 0
                    for q in j:
                        num += c[q]
                    ans = min(ans, num)

            
    return ans
    

print(solve())


Fixed code:
import itertools 
def solve():
    n, m, x = map(int, input().split())
    c = []
    a = []
    for _ in range(n):
        C, *A = map(int, input().split())
        c.append(C)
        a.append(A)

    ans = n*1e8
    for i in range(n):
        for j in itertools.combinations(range(n), i+1):
            cnt = [0]*m
            for k in j:
                for l in range(m):
                    cnt[l] += a[k][l]
            for s in range(m):
                if cnt[s] < x:
                    break
                if s == m-1:
                    num = 0
                    for q in j:
                        num += c[q]
                    ans = min(ans, num)
    if ans == n*1e8:
        ans = -1
            
    return ans
    

print(solve())
Buggy code:
N, M, X = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
ans = 10**20

for mask in range(2**N):
    C = [0]*M
    cst = 0
    for i in range(N):
        if (mask>>i)&1:
            cst += x[i][0]
            for j in range(1, M+1):
                C[j-1] += x[i][j]
    if min(C) >= X:
        ans = min(ans, cst)

if ans < 10**20:
    print(ans)

Fixed code:
N, M, X = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
ans = 10**20

for mask in range(2**N):
    C = [0]*M
    cst = 0
    for i in range(N):
        if (mask>>i)&1:
            cst += x[i][0]
            for j in range(1, M+1):
                C[j-1] += x[i][j]
    if min(C) >= X:
        ans = min(ans, cst)

if ans < 10**20:
    print(ans)
else:
    print(-1)
Buggy code:
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for i in range(N)]
min_can = set()


def cal_score(bought_books):
    global CA
    global M
    global N
    global X
    algo_Q = [0]*M
    cost = 0
    for i in range(N):
        if bought_books[i] == 1:
            for j in range(1, M+1):
                algo_Q[j-1] += CA[i][j]
            cost += CA[i][0]
    flag = True
    for i in range(M):
        if algo_Q[i] < X:
            flag = False
            break
    if flag:
        global min_can
        min_can.add(cost)
    return 0


def next_book(book_list):
    global N
    global M

    if len(book_list) == N:
       return cal_score(book_list)
    book_list.append(0)
    next_book(book_list)
    book_list.pop(-1)

    book_list.append(1)
    next_book(book_list)
    book_list.pop(-1)
    return 0


book_list = []
next_book(book_list)
print(min(min_can))



Fixed code:
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for i in range(N)]
min_can = set()


def cal_score(bought_books):
    global CA
    global M
    global N
    global X
    algo_Q = [0]*M
    cost = 0
    for i in range(N):
        if bought_books[i] == 1:
            for j in range(1, M+1):
                algo_Q[j-1] += CA[i][j]
            cost += CA[i][0]
    flag = True
    for i in range(M):
        if algo_Q[i] < X:
            flag = False
            break
    if flag:
        global min_can
        min_can.add(cost)
    return 0


def next_book(book_list):
    global N
    global M

    if len(book_list) == N:
       return cal_score(book_list)
    book_list.append(0)
    next_book(book_list)
    book_list.pop(-1)

    book_list.append(1)
    next_book(book_list)
    book_list.pop(-1)
    return 0


book_list = []
next_book(book_list)
if set() == min_can:
    print(-1)
else:
    print(min(min_can))
Buggy code:
from itertools import product

N, M, X = map(int, input().split())

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])

result = float('inf')
for p in product([True, False], repeat = N):
    t = [0] * M
    c = 0
    for j in range(N):
        if not p[j]:
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        result = min(result, c)
print(result)


Fixed code:
from itertools import product

N, M, X = map(int, input().split())

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])

result = -1
for p in product([True, False], repeat = N):
    t = [0] * M
    c = 0
    for j in range(N):
        if not p[j]:
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)
Buggy code:
from itertools import combinations
import numpy as np
N,M,X = map(int, input().split())
#matrix = np.array([list(map(int, input().split())) for _ in range(N)])
matrix = np.random.rand(12,13)

min_price = 1e9
for n in range(N):
  for texts in combinations(matrix, n+1):
    summation = np.sum(texts, axis=0)
    price = summation[0]
    if all(summation[1:] >= X):
      if price < min_price:
        min_price = price

print(min_price if min_price < 1e9 else -1)

Fixed code:
from itertools import combinations
import numpy as np
N,M,X = map(int, input().split())
matrix = np.array([list(map(int, input().split())) for _ in range(N)])

min_price = 1e9
for n in range(N):
  for texts in combinations(matrix, n+1):
    summation = np.sum(texts, axis=0)
    price = summation[0]
    if all(summation[1:] >= X):
      if price < min_price:
        min_price = price

print(min_price if min_price < 1e9 else -1)
Buggy code:
n, m, x = map(int, input().split())
ca = []
for _ in range(n):
    ca.append(list(map(int, input().split())))


cost_max = 12 * (10 ** 5)
book_list = []
for i in range(2**n):
    book_num = 0
    book_list = []
    if i == 0:
        continue
    for j in range(n):
        if (i >> j) & 1:
            book_list.append(ca[j])
            book_num += 1
    for j in range(m):
        skill_revel = 0
        for k in range(book_num):
            skill_revel += book_list[k][j+1]
        if skill_revel >= x:
            if j == (m-1) and k == (book_num-1):
                cost = 0
                for l in range(book_num):
                    cost += book_list[l][0]
                if cost < cost_max:
                    cost_max = cost
            continue
        else:
            break

print(cost_max)

Fixed code:
n, m, x = map(int, input().split())
ca = []
for _ in range(n):
    ca.append(list(map(int, input().split())))


cost_max = 12 * (10 ** 5)
book_list = []
flag = 0
for i in range(2**n):
    book_num = 0
    book_list = []
    if i == 0:
        continue
    for j in range(n):
        if (i >> j) & 1:
            book_list.append(ca[j])
            book_num += 1
    for j in range(m):
        skill_revel = 0
        for k in range(book_num):
            skill_revel += book_list[k][j+1]
        if skill_revel >= x:
            if j == (m-1) and k == (book_num-1):
                cost = 0
                for l in range(book_num):
                    cost += book_list[l][0]
                if cost <= cost_max:
                    flag = 1 
                    cost_max = cost
            continue
        else:
            break

if flag == 0:
    print(-1)
else:
    print(cost_max)