Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    X = []
    Y = []
    for _ in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y)
    
    ans = float('inf')
    for P in itertools.combinations(range(N), K):
        X_k = [X[p] for p in P]
        Y_k = [Y[p] for p in P]
        s = (max(X_k) - min(X_k)) * (max(Y_k) - min(Y_k))
        ans = min(ans, s)
    
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import itertools
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    X = []
    Y = []
    for _ in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y)
    
    ans = float('inf')
    for i in range(N-1):
        for j in range(i+1, N):
            for k in range(N-1):
                for l in range(k+1, N):
                    cnt = 0
                    for p in range(N):
                        if min(X[i], X[j])<=X[p] and X[p]<=max(X[i], X[j]):
                            if min(Y[k], Y[l])<=Y[p] and Y[p]<=max(Y[k], Y[l]):
                                cnt += 1
                    if cnt>=K:
                        s = abs(X[i]-X[j]) * abs(Y[k]-Y[l])
                        if s!=0:
                            ans = min(ans, s)
    
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(K):
	m = max(l)
	ans += m
	l[l.find(str(m))] = 0
print(ans)

Fixed submission:
N, K = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(K):
	m = max(l)
	ans += m
	l[l.index(m)] = 0
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(K):
	m = max(l)
	ans += m
	l[l.find(m)] = 0
print(ans)

Fixed submission:
N, K = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(K):
	m = max(l)
	ans += m
	l[l.index(m)] = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
X, A, B = input().split()

if A-B>=0:
	print('delicious')
elif X+A-B>=0:
	print('safe')
else:
	print('dangerous')

Fixed submission:
X, A, B = list(map(int, input().split()))
if A-B>=0:
	print('delicious')
elif X+A-B>=0:
	print('safe')
else:
	print('dangerous')
Buggy python submission (verdict: Runtime Error):
a, b = list(input())

if a=='H':
	if b=='H':
		print('H')
	else:
		print('D')
else:
	if b=='H':
		print('D')
	else:
		print('H')

Fixed submission:
a, b = input().split()

if a=='H':
	if b=='H':
		print('H')
	else:
		print('D')
else:
	if b=='H':
		print('D')
	else:
		print('H')
Buggy python submission (verdict: Runtime Error):
A, B = int(input())

if A==B:
	print('Draw')
elif A>B or A==1:
	print('Alice')
else:
	print('Bob')

Fixed submission:
A, B = list(map(int, input().split()))

if A==1:
	if A==B:
		print('Draw')
	else:
		print('Alice')
elif B==1:
	print('Bob')
else:
	if A==B:
		print('Draw')
	elif A>B:
		print('Alice')
	else:
		print('Bob')
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(list(int, input().split()))

if A*B >= C*D:
	print(A*B)
else:
	print(C*D)

Fixed submission:
A, B, C, D = list(map(int, input().split()))

if A*B >= C*D:
	print(A*B)
else:
	print(C*D)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if a==b and b==c:
	print(1)
elif a!=b and b!=c and c!=a:
	print(3)
else:
	print(2)

Fixed submission:
a, b, c = list(map(int, input().split()))

if a==b and b==c:
	print(1)
elif a!=b and b!=c and c!=a:
	print(3)
else:
	print(2)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import Counter
import bisect
from collections import defaultdict
import itertools

def main():
    N, Q = MI()
    #i行の一番右をline_right[i],　j列目の一番下をcolumn_under[j]とする。
    line_right = [N] * N
    column_under = [N] * N
    bla = pow(N - 2, 2)
    x_min = N
    y_min = N
    for i in range(Q):
        query = LI()
        if query[0] == 1:
            w = query[1]
            x = column_under[w]
            bla -= x - 2
            if w < x_min:
                for j in range(x):
                    line_right[j] = w
                x_min = w
        else:
            y = query[1]
            z = line_right[y]
            bla -= z - 2
            if y < y_min:
                for j in range(z):
                    column_under[j] = y
                y_min = y
    print(bla)
if __name__ == "__main__":
    main()



Fixed submission:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import Counter
import bisect
from collections import defaultdict
import itertools

def main():
    N, Q = MI()
    #i行の一番右をline_right[i],　j列目の一番下をcolumn_under[j]とする。
    line_right = deque([(N, N)])
    line_right_keys = deque([N])
    column_under = deque([(N, N)])
    column_under_keys = deque([N])
    bla = pow(N - 2, 2)
    x_min = N
    y_min = N
    for i in range(Q):
        query = LI()
        if query[0] == 1:
            w = query[1]
            x = bisect.bisect_left(column_under_keys, w)
            bla -= column_under[x][1] - 2
            if w < x_min:
                line_right.appendleft((column_under[x][1], w))
                line_right_keys.appendleft(column_under[x][1])
                x_min = w
        else:
            y = query[1]
            z = bisect.bisect_left(line_right_keys, y)
            bla -= line_right[z][1] - 2
            if y < y_min:
                column_under.appendleft((line_right[z][1], y))
                column_under_keys.appendleft(line_right[z][1])
                y_min = y
    print(bla)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import deque
import bisect
from decimal import *
from functools import reduce
def main():
    def comb(n, r):
        numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
        denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
        return numerator * pow(denominator, mod - 2, mod) % mod
    S = I()
    mod = 10 ** 9 + 7
    N = S // 3
    ans = 0
    for i in range(1, N + 1):
        x = S - 3 * i
        ans += comb(x + i - 1, x)
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()



Fixed submission:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import deque
import bisect
from decimal import *
from functools import reduce
def main():
    def comb(n, r):
        if r == 0:
            return 1
        else:
            numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
            denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
            return numerator * pow(denominator, mod - 2, mod) % mod
    S = I()
    mod = 10 ** 9 + 7
    N = S // 3
    ans = 0
    for i in range(1, N + 1):
        x = S - 3 * i
        ans += comb(x + i - 1, i - 1)
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import bisect
def main():
    N, Q = map(int, input().split())
    C = list(map(int, input().split()))
    E = []

    D = {C[i]: -1 for i in range(N)}
    for i in range(N):
        if D[C[i]] == -1:
            D[C[i]] = i
        else:
            E.append((D[C[i]], i, -1))
            D[C[i]] = i

    for i in range(Q):
        l, r = map(int, input().split())
        E.append((l - 1, r - 1, i))

    def f(tup):
        return tup[0]
    E.sort(key=f, reverse=True)

    ANS = [0] * Q
    y_list = []
    for e in E:
        if e[2] == -1:
            y_list.append(e[1])
            y_list.sort()
        else:
            ans = bisect.bisect_right(y_list, e[1])
            ANS[e[2]] = e[1] - e[0] + 1 - ans

    for i in range(Q):
        print(ANS[i])

if __name__ == '__main__':
    main()

Fixed submission:
X = int(input())
if X >= 30:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
K = int(input())
mod = K
if K % 2 == 0 or K % 5 ==0:
    print(-1)
elif K % 7 != 0:
    x = 10 % mod
    y = 1 % mod
    X = [y] * K
    S = [y] * K
    for i in range(1, K + 1):
        X[i] = (X[i - 1] * x) % mod
        S[i] = S[i - 1] + X[i]
        if S[i] % mod == 0:
            print(i + 1)
            exit()
        elif X[i] == 1 % mod:
            loop = i
            print(loop * K)
            exit()
else:
    mod = K // 7
    x = 10 % mod
    y = 1 % mod
    X = [y] * K
    S = [y] * K
    for i in range(1, K + 1):
        X[i] = (X[i - 1] * x) % mod
        S[i] = S[i - 1] + X[i]
        if S[i] % mod == 0:
            print(i + 1)
            exit()
        elif X[i] == 1 % mod:
            loop = i
            print(loop * K)
            exit()

Fixed submission:
K = int(input())
mod = K
if K == 1:
    print(1)
elif K % 2 == 0 or K % 5 == 0:
    print(-1)
elif K % 7 != 0:
    x = 10 % mod
    X = [1] * K
    S = [1] * K
    for i in range(1, K + 1):
        X[i] = (X[i - 1] * x) % mod
        S[i] = S[i - 1] + X[i]
        if S[i] % mod == 0:
            print(i + 1)
            exit()
    print(-1)
else:
    mod = K // 7
    if mod == 1:
        print(1)
    else:
        x = 10 % mod
        y = 1 % mod
        X = [y] * K
        S = [y] * K
        for i in range(1, K + 1):
            X[i] = (X[i - 1] * x) % mod
            S[i] = S[i - 1] + X[i]
            if S[i] % mod == 0:
                print(i + 1)
                exit()
        print(-1)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
K = int(input())
i_ans = 0
j_ans = 0
for i in range(0,8):
    B_after = B * (2 ** i)
    if B_after > A:
        i_ans = i
        break
B_after = B * (2 ** i_ans)
for j in range(0,8):
    C_after = C * (2 ** j)
    if C_after > B_after:
        j_ans = j
        break
if i_ans + j_ans <=K:
    print('Yes')
else:
    pri

Fixed submission:
A, B, C = map(int, input().split())
K = int(input())
i_ans = 0
j_ans = 0
for i in range(0,8):
    B_after = B * (2 ** i)
    if B_after > A:
        i_ans = i
        break
B_after = B * (2 ** i_ans)
for j in range(0,8):
    C_after = C * (2 ** j)
    if C_after > B_after:
        j_ans = j
        break
if i_ans + j_ans <=K:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1, N + 1):
    a = i * (N // i) * (N // i + 1) / 2
    ans += round(a)
print(ans)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N + 1):
    b = N // i
    ans += i * b * (b + 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(1, N + 1):
    a = i * (N // i) * (N // i + 1) / 2
    A.append(round(a))
print(sum(A))

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N + 1):
    b = N // i
    ans += i * b * (b + 1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and A.count(a) == 1 for a in A))


Fixed submission:
x = list(map(int,input().split()))
ans = x.index(0) + 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and A.count(a) == 1 for a in A))


Fixed submission:
x = list(map(int,input().split()))
ans = x.index(0) + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and A.count(a) == 1 for a in A))


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and counter[a] == 1 for a in A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = []
cnt = 0
for i in range(N):
    if A[i] in B == True:
        cnt += 1
    else:
        for j in range(i):
            if A[i] % A[j] == 0:
                cnt += 1
                if A[i] == A[j] and i == j+1:
                    cnt += 1
                for k in range(10 ** 5):
                    B.append(A[i] * k)
                break
print(N - cnt)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and counter[a] == 1 for a in A))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
cnt = 0
for i in range(N):
    for j in range(i):
        if A[i] % A[j] == 0:
            cnt += 1
            if A[i] == A[j] and i == j+1:
                cnt += 1
            break
print(N - cnt)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and counter[a] == 1 for a in A))
Buggy python submission (verdict: Runtime Error):
from sympy import prime
import numpy as np

N = int(input())
A = list(map(int, input().split()))
ans = np.prod(A)
if ans <= 10 ** 18:
    print(ans)
else:
    print(-1)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
for i in range(len(A)):
    ans *= A[i]
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table
#引数nが素数かどうかを判定
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

N = int(input())
p_list = sieve(10000000)
cnt = 0
for i in range(100000):
    for j in range(1,100):
        q, mod = divmod(N, (p_list[i] ** j))
        if mod == 0:
            cnt += 1
            N = q
        else:
            break
    if N > 104743:
        a = is_prime(N)
        if a == True:
            cnt += 1
            break
print(cnt)


Fixed submission:
import collections
#nを素因数分解したリストを返す
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

N = int(input())
if N == 1:
    print(0)
else:
    A = prime_decomposition(N)

    c = collections.Counter(A)
    values, counts = zip(*c.most_common())


    cnt = 0
    for i in range(len(counts)):
        for j in range(10,0,-1):
            if counts[i] >= j * (j + 1)//2:
                cnt += j
                break
    print(cnt)

Buggy python submission (verdict: Runtime Error):
import sympy
N = int(input())
p_list = list(sympy.primerange(2,1000000))
print(p_list)
cnt = 0
for i in range(10000):
    j = 1
    while N % (p_list[i] ** j) == 0:
        cnt += 1
        N = N / (p_list[i] ** j)
        j += 1
    a = sympy.isprime(N)
    if a == True:
        cnt += 1
        break
print(cnt)

Fixed submission:
import collections
#nを素因数分解したリストを返す
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

N = int(input())
if N == 1:
    print(0)
else:
    A = prime_decomposition(N)

    c = collections.Counter(A)
    values, counts = zip(*c.most_common())


    cnt = 0
    for i in range(len(counts)):
        for j in range(10,0,-1):
            if counts[i] >= j * (j + 1)//2:
                cnt += j
                break
    print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
A.sort()
B.sort()
N_q, N_mod = divmod(N, 2)
if N_mod == 1:
    ans = B[N_q] - A[N_q] + 1
else:
    ans_list = []
    for x in range(A[N_q - 1], B[N_q - 1] + 1, 1):
        for y in range(A[N_q], B[N_q] + 1, 1):
            ans_list.append((x + y) / 2)
    c = collections.Counter(ans_list)
    values, counts = zip(*c.most_common())
    ans = len(values)
print(ans)

Fixed submission:
import collections
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
A.sort()
B.sort()
N_q, N_mod = divmod(N, 2)
if N_mod == 1:
    ans = B[N_q] - A[N_q] + 1
else:
    ans = B[N_q - 1] - A[N_q - 1] + B[N_q] - A[N_q] + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())
Graph = [[]for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    Graph[a].append(b)
    Graph[b].append(a)

dist = [-1] * (N + 1)
dist[0] = 0
dist[1] = 0

d = deque()
d.append(1)
while d:
    v = d.popleft()
    for i in Graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        d.append(i)

ans = dist[0:]
C = [0] * (N + 1)
for j in range(2, len(ans)):
    if ans[j] == 1:
        C[j] = 1
    for k in range(2, max(ans) +1):
        if ans[j] == k:
            index_num = [n for n, v in enumerate(ans) if v == k - 1]
            for l in index_num:
                if l in Graph[j]:
                    C[j] = l
                    break
print('Yes')
for m in range(2,N + 1):
    print(C[m])

Fixed submission:
from collections import deque
N, M = map(int, input().split())
Graph = [[]for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, input().split())
    Graph[a].append(b)
    Graph[b].append(a)

dist = [-1] * (N + 1)
dist[0] = 0
dist[1] = 0

pre = [-1] * (N + 1)
pre[0] = 0
pre[1] = 1

d = deque()
d.append(1)
while d:
    v = d.popleft()
    for i in Graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        pre[i] = v
        d.append(i)
ans = dist[0:]
print('Yes')
for j in range(2, len(pre)):
    print(pre[j])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = [1]
    a = 1
    check = [0] * len(A)
    while True:
        a = A[a - 1]
        if check[a - 1] == 1:
            x = B.index(a)
            roop = B[x:]
            print(roop[(K - x) % len(roop)])
            exit()
        B.append(a)
        check[a - 1] += 1
    if len(B) >= K + 1:
        print(B[K])
if __name__ == '__main__':
    main()

Fixed submission:
S = input()
T = input()
U = T[0:len(S)]
if U == S:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [1]
for i in range(1,K + 1):
    a = A[B[i - 1] - 1]
    if a in B:
        x = B.index(a)
        y = i - x
        z = (K - x) % y
        print(B[x + z])
        exit()
    B.append(a)
if len(B) == K + 1:
    print(B[K])

Fixed submission:
S = input()
T = input()
U = T[0:len(S)]
if U == S:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
    x = list(map(int, input().split()))
    C[i] = x[0]
    A[i] = [0] * M
    for j in range(M):
        A[i][j] = x[j + 1]
cnt = [0] * (2 **N)
ans_list = []
for i in range(2 ** N):
    bag = []
    cnt[i] = [0] * M
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(C[j])  # フラグが立っていたら bag に果物を詰める
            for k in range(M):
                cnt[i][k] += A[j][k]
    if bisect.bisect_left(cnt[i], X) == 0:
        ans_list.append(sum(bag))
if ans_list == []:
    print(-1)
else:
    print(min(ans_list)

Fixed submission:
import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
    x = list(map(int, input().split()))
    C[i] = x[0]
    A[i] = [0] * M
    for j in range(M):
        A[i][j] = x[j + 1]
cnt = [0] * (2 ** N)
ans_list = []
for i in range(2 ** N):
    bag = []
    cnt[i] = [0] * M
    for j in range(N):
        if ((i >> j) & 1):
            bag.append(C[j])
            for k in range(M):
                cnt[i][k] += A[j][k]
    cnt[i].sort()
    if bisect.bisect_left(cnt[i], X) == 0:
        ans_list.append(sum(bag))
if ans_list == []:
    print(-1)
else:
    print(min(ans_list))