Harryxun/stf_run huggingface dataset:
from collections import defaultdict
from fractions import gcd

INF = 2 << 30
MAX_V = 1003
G = [[] for _ in xrange(MAX_V)]
visited = [False]*MAX_V

def add_edge(fro, to, cap):
    G[fro].append([to,cap,len(G[to])])
    G[to].append([fro,0,len(G[fro])-1])

def dfs(v,t,f):
    global visited
    if v == t:
        return f
    visited[v] = True
    for i,(to,cap,rev) in enumerate((G[v])):
        if visited[to] or cap == 0:            
            continue        
        d = dfs(to,t,min(f,cap))
        if d > 0:
            G[v][i][1] -= d
            G[to][rev][1] += d
            return d
    return 0

def max_flow(s,t):
    global visited
    flow = 0
    while True:
        visited = [False]*MAX_V
        f = dfs(s,t,INF)
        if f == 0:
            return flow
        flow += f

while True:
    m,n = map(int,raw_input().split())
    if m|n == 0:
        break
    G = [[] for _ in xrange(MAX_V)]
    data = []
    while len(data) < n+m:
        data += map(int,raw_input().split())    
    blue = data[:m]
    red = data[m:]
    for i,b in enumerate(blue):
        add_edge(MAX_V-2,i,1)
    for i,r in enumerate(red):
        add_edge(i+m,MAX_V-1,1)
    for i in xrange(m):
        for j in xrange(n):
            if gcd(blue[i],red[j]) != 1:
                add_edge(i,j+m,1)
    print max_flow(MAX_V-2,MAX_V-1)

### FIXED CODE ###

from fractions import gcd

V = 1001
G = []
visited = []
match = []

def add_edge(u,v):
    G[u].append(v)
    G[v].append(u)

def dfs(v):
    visited[v] = True
    for u in G[v]:
        w = match[u]
        if w < 0 or not visited[w] and dfs(w):
            match[v] = u
            match[u] = v
            return True

def bipartite_matching():
    global match,visited
    res = 0
    match = [-1]*V
    for v in xrange(V):
        if match[v] < 0:
            visited = [False]*V
            if dfs(v):
                res += 1
    return res

while True:
    m,n = map(int,raw_input().split())
    V = m+n
    if V == 0:
        break
    G = [[] for _ in xrange(V)]
    data = []
    while len(data) < V:
        data += map(int,raw_input().split())
    for i,b in enumerate(data[:m]):
        for j,r in enumerate(data[m:],m):
            if gcd(b,r) != 1:
                add_edge(i,j)
    print bipartite_matching()
s=input()

ans=''
for x in s:
  if ans<>'':
    if x=='B'
      ans=ans[:-1]
      continue
  if x<>'B':
    ans+=x
print(ans)

### FIXED CODE ###

s=input()
 
ans=''
for x in s:
  if x!='B':
    ans+=x
  else:
    if x!='':
      ans=ans[:-1]
print(ans)
count = 0
  n = input()

  for i in range(n):
    com,str = [str, raw_input().split()]
    if com == 'insert':
      dic[count] = str
      count += 1
    elif com == 'find':
      for j in range(count-1):
        if dic[j] == str:
          print 'yes'
        else:
          print 'no'

### FIXED CODE ###

n = input()
dic = set()
 
for i in range(n):
  com, st = map(str, raw_input().split())
  if com == 'insert':
    dic.add(st)
  elif com == 'find':
    if st in dic:
      print 'yes'
    else:
      print 'no'
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
for i in range(len(t)-k):
    if t[i] == t[i+k]:
        t[i+k] = "d"

t = "".join(t)
t = t.replace("r", "{}+".format(p)).replace("p", "{}+".format(s)).replace("s", "{}+".format(r)).replace("d", "0+") + "0"
print(eval(t))


### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
for i in range(n-k):
    if t[i] == t[i+k]:
        t[i+k] = "d"

t = "".join(t)
t = t.replace("r", "{}+".format(p)).replace("p", "{}+".format(s)).replace("s", "{}+".format(r)).replace("d", "0+") + "0"
print(eval(t))
n, m = map(int, input().split())
a = list(map(int, input().split()))

setnum = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} 
rset = {}
for i in a:
    if i in rset:
        if rset[setnum[i]] > i:
            rset[i] = setnum[i]
    else:
        rset[i] = setnum[i]

rset = sorted(rset.items(), reverse=True)
dp = [0] * (n + 1)
for i in rset:
    dp[i[1]] = i[0]
    for j in range(1, n + 1 - i[1]):
        if dp[j] != 0:
            dp[j + i[1]] = max(dp[j + i[1]], dp[j] * 10 + i[0])
print(dp[-1])


### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))

setnum = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} 
rset = {}
for i in a:
    if i in rset:
        if rset[setnum[i]] > i:
            rset[i] = setnum[i]
    else:
        rset[i] = setnum[i]

rset = sorted(rset.items(), reverse=True)
dp = [0] * (n + 1)
for i in rset:
    if n < i[1]:
        continue
    dp[i[1]] = max(dp[i[1]] , i[0])
    for j in range(i[1], n + 1 - i[1]):
        if dp[j] != 0:
            dp[j + i[1]] = max(dp[j + i[1]], dp[j] * 10 + i[0])
print(dp[-1])
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

visited = [False] * n
visited[0] = True
l = [1]
while True:
    x = A[l[-1]-1]
    if visited[x-1]:
        break
    l.append(x)
    visited[x-1] = True
# print(l[l.index(x):])
if len(l) > k-1:
    print(l[k])
else:
    print(l[l.index(x):][(k-l.index(x)) % len(l[l.index(x):])])


### FIXED CODE ###

import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

visited = [False] * n
visited[0] = True
l = [1]
while True:
    x = A[l[-1]-1]
    if visited[x-1]:
        break
    l.append(x)
    visited[x-1] = True
# print(l[l.index(x):])
if len(l) > k:
    print(l[k])
else:
    print(l[l.index(x):][(k-l.index(x)) % len(l[l.index(x):])])
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


a,b = map(int,input().split())
if a==b:
    print("H")
else:
    print("D")

### FIXED CODE ###

#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


a,b = input().split()
if a==b:
    print("H")
else:
    print("D")
import copy
def dfs(cur_node, pre_node, Node_num, map, l):
    #全てのノードを見たとき

    if Node_num == N or cur_node <= 0 or cur_node >= N-1:
        return
    elif l[pre_node][cur_node]==0: #飛んだ先が、Trueの時
        return
    elif map[cur_node]==True:
        return

    map[cur_node]=True

    for i in range(N):
        if i != cur_node:
            dfs(i, cur_node, Node_num+1, map, l)


S = input()
S = list(map(int, S.split()))

N = S[0]
M = S[1]


map = [False]*N
map[0] = True

lst = []

for i in range(N):
    lst.append([0]*N)

for i in range(N):
    S = input()
    S = list(S.split())
    idx1 = int(S[0])
    idx2 = int(S[1])
    lst[idx1-1][idx2-1] = 1

graph_count = 0
#全探索
for i in range(1, N, 1):
    map_copy = copy.copy(map)
    lst_copy = copy.copy(lst)

    dfs(i, 0, 0, map_copy, lst_copy)
    count = 0
    for i in map_copy:
        if i == True:
            count = count + 1
    if count == N-1:
        graph_count = graph_count + 1

print(graph_count)


### FIXED CODE ###

import itertools
N,M=map(int,input().split())
edges={tuple(sorted(map(int,input().split()))) for i in range(M)}
ans=0
for i in itertools.permutations(range(2,N+1),N-1):
    l=[1]+list(i)
    ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1
print(ans)
def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    # [[cx, cy, H]]
    candidates = []

    cond = conds[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(cond[0]-cx)+abs(cond[1]-cy)+cond[2]
            if 1 <= H:
                candidates.append([cx, cy, H])
    
    ans = []
    for cand in candidates:
        ansflg = True
        for n in range(1, N):
            cond = conds[n]
            if cond[2] == 0:
                ansflg = False
                break
            H = abs(cond[0]-cand[0])+abs(cond[1]-cand[1])+cond[2]
            if H != cand[2]:
                ansflg = False
                break
        if ansflg:
            ans = cand
            break
    
    print("{} {} {}".format(ans[0], ans[1], ans[2]))

    


if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    conds = [list(map(int, input().split(" "))) for i in range(N)]
    
    first = sorted(conds, reverse=True, key=lambda x:x[2])[0]
    for cx in range(101):
        for cy in range(101):
            H = abs(first[0]-cx)+abs(first[1]-cy)+first[2]
            for n in range(N):
                cond = conds[n]
                if cond[2] == 0:
                    if abs(cond[0]-cx)+abs(cond[1]-cy) < H: 
                        break
                elif abs(cond[0]-cx)+abs(cond[1]-cy)+cond[2] != H:
                    break
            else:
                print("{} {} {}".format(cx, cy, H))
                exit()


if '__main__' == __name__:
    resolve()
n, m = map(int, input().split())
l = list(map(int, input().split()))

l.sort()
distance = []
sum = 0

if m == 1:
    print("0")
    exit()

if m == 2:
    print(l[len(l)-1] - l[0])
    exit()

for i in range(len(l) - 1):
    distance.append(l[i+1] - l[i])

distance.sort(reverse=True)

for i in range(n-1):
    sum += distance[i]

print(l[len(l)-1] - l[0] - sum)


### FIXED CODE ###

n, m = map(int, input().split())
l = list(map(int, input().split()))

l.sort()
d = l[len(l)-1] - l[0]
distance = []
sum = 0

for j in range(len(l)-1):
    distance.append( l[j+1] - l[j] )

distance.sort(reverse=True)

if n >= m:
    print("0")
else:
    for i in range(n-1):
        sum += distance[i]
    print(d-sum)
import sys
sys.setrecursionlimit(3000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

x = list(map(int, input().split()))

li = [abs(i - X) for i in x]

li = [i for i in li if i]

if len(li) == 1:
	print(li[0])
else:
	print(gcd_list(li))


### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

def gcd(a, b):
	# while b:
	# 	a, b = b, a % b
	# return a

	if b:
		return gcd(b, a % b)
	else:
		return a

def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])

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

x = list(map(int, input().split()))

li = [abs(i - X) for i in x]

# li = [i for i in li if i]
# li = sorted(li)
if len(li) == 1:
	print(li[0])
else:
	ans = li[0]
	for i in range(1,N):
		ans = gcd(ans, li[i])
	print(ans)
INF = 1145141919810893
memo = [INF]*20000
def HP(K):
    if K<=0:
        return 0
    if memo[K]!=INF:
        return memo[K]
    R=INF
    for i in range(N):
        r = B[i]+HP(K-A[i])
        R=min(R,r)
    memo[K]=R
    return R

H,N = map(int,input().split())
A=[]
B=[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
print(HP(H))



### FIXED CODE ###

INF = 1145141919810893

H,N = map(int,input().split())
A=[]
B=[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

#dp[i]=体力がちょうどiのモンスターを倒すのに必要な魔力の最小値
#もしそのような魔力が存在しない場合、INF
#INFは10^9くらいあれば足りると思う(適当)
dp = [INF]*20000
dp[0]=0
#体力が0のモンスターを倒すのに必要な魔力は0
#iは小さい順に決定することができる
#なぜなら、i<jのとき決定したdp[j]の値はdp[i]に影響しないから
for i in range(H):
    #dp[H]から配る遷移は、必ずdp[H]より大きい値を配ることになるので、不要
    #よってH-1までやればOK
    #dp[i]の値はこの時点で確定する
    if dp[i]==INF:
        continue
    for j in range(N):
        #いわゆる配るDP
        dp[i+A[j]]=min(dp[i+A[j]],dp[i]+B[j])

#これで答えはdp[H]であるかというと、そうとは限らない
#なぜなら、dp[H+1]に行くコストがdp[H]に行くコストより安いかもしれないから
#今回は「与えるダメージがH以上」で条件を達成することができる
#なので、H以上のdpについて精査して、最もコストが低いものが答えである
Ans=INF
for d in dp[H:]:
    Ans=min(Ans,d)
print(Ans)
s = input()
n = len(s)
ans = ''
for i in range(n):
    if s[i] == '?':
        if i == 0:
            if s[1] == 'P':
                ans += 'D'
            else:
                ans += 'P'
        elif i == n-1:
            if ans[n-2] == 'P':
                ans += 'D'
            else:
                ans += 'P'
        else:
            if ans[i-1] == 'P' and s[i + 1] == 'P':
                ans +='D'
            else:
                ans += 'P'
    else:
        ans += s[i]

print(ans)

### FIXED CODE ###

s = input()
n = len(s)
ans = list(s)
cnt = 0
for i in range(n):
    if ans[i] == '?':
        ans[i] = 'D'
print(''.join(ans))
a=input()
#str = list(a)
print(str[0:2])

### FIXED CODE ###

a=input()
#str = list(a)
print(a[:3])
N, M = map(int, input().split())
lis = {}
if N == 1:
  s, c = map(int, input().split())
  print(c)
  exit()
for i in range(M):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    print(-1)
    exit()
  if s in lis:
    if lis[s] == c:
      continue
    else:
      print(-1)
      exit()
  else:
    lis[s] = c
if not 1 in lis:
  lis[1] = 1
for i in range(2, N+1):
  if not i in lis:
    lis[i] = 0
ans = ""
for i in range(1, N+1):
  ans += str(lis[i])
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
lis = {}
if N == 1 and M == 0:
  print(0)
  exit()
if N == 2 and M == 0:
  print(10)
  exit()
if N == 3 and M == 0:
  print(100)
  exit()
if N == 1 and M == 1:
  s, c = map(int, input().split())
  print(c)
  exit()
for i in range(M):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    print(-1)
    exit()
  if s in lis:
    if lis[s] == c:
      continue
    else:
      print(-1)
      exit()
  else:
    lis[s] = c
if not 1 in lis:
  lis[1] = 1
for i in range(2, N+1):
  if not i in lis:
    lis[i] = 0
ans = ""
for i in range(1, N+1):
  ans += str(lis[i])
print(ans)
N,K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

if all(a<0 for a in A):
    A.sort(reverse=K%2==0)
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()

arr = []
for a in A:
    if a < 0:
        arr.append((-a,1))
    else:
        arr.append((a,0))

arr.sort()
pz = []
ng = []
ans = 1
for _ in range(K):
    v,s = arr.pop()
    if s:
        ng.append(v)
    else:
        pz.append(v)

for v in ng:
    ans *= v
    ans %= MOD
for v in pz:
    ans *= v
    ans %= MOD
if len(ng)%2 == 0:
    print(ans)
    exit()

b = pz[-1] if pz else None
c = ng[-1] if ng else None
a = d = None
while arr and (a is None or d is None):
    v,s = arr.pop()
    if s:
        if a is None:
            a = v
    else:
        if d is None:
            d = v

if (a is not None and b is not None) or (c is not None and d is not None):
    print(ans)
    exit()

if a is None or b is None:
    ans *= c * pow(d,-1,MOD)
elif c is None or d is None:
    ans *= a * pow(b,-1,MOD)
else:
    if a*d > b*c:
        ans *= a * pow(b,-1,MOD)
    else:
        ans *= c * pow(d,-1,MOD)
ans %= MOD
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
MOD = 10**9+7

if all(a>=0 for a in A):
    A.sort()
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()
if all(a<0 for a in A):
    A.sort(reverse=K%2==0)
    ans = 1
    for _ in range(K):
        ans *= A.pop()
        ans %= MOD
    print(ans)
    exit()
if N==K:
    ans = 1
    for a in A:
        ans *= a
        ans %= MOD
    print(ans)
    exit()

arr = []
for a in A:
    if a < 0:
        arr.append((-a,1))
    else:
        arr.append((a,0))

arr.sort()
pz = []
ng = []
for _ in range(K):
    v,s = arr.pop()
    if s:
        ng.append(v)
    else:
        pz.append(v)

if len(ng)%2 == 0:
    ans = 1
    for v in ng:
        ans *= v
        ans %= MOD
    for v in pz:
        ans *= v
        ans %= MOD
    print(ans)
    exit()

b = pz[-1] if pz else None
c = ng[-1] if ng else None
a = d = None
while arr and (a is None or d is None):
    v,s = arr.pop()
    if s:
        if a is None:
            a = v
    else:
        if d is None:
            d = v

if (a is None or b is None) and (c is None or d is None):
    assert False

ans = 1
if a is None or b is None:
    ans = d
    for v in ng[:-1]:
        ans *= v
        ans %= MOD
    for v in pz:
        ans *= v
        ans %= MOD
elif c is None or d is None:
    ans = a
    for v in ng:
        ans *= v
        ans %= MOD
    for v in pz[:-1]:
        ans *= v
        ans %= MOD
else:
    if a*c > b*d:
        ans = a
        for v in ng:
            ans *= v
            ans %= MOD
        for v in pz[:-1]:
            ans *= v
            ans %= MOD
    else:
        ans = d
        for v in ng[:-1]:
            ans *= v
            ans %= MOD
        for v in pz:
            ans *= v
            ans %= MOD
ans %= MOD
print(ans)
cnt = 0
for moji in s:
    #print(moji)
    num = s.count(moji)
    #print(num)
    if num == 2:
        cnt+=1
    else:
        break
        
if cnt == 4:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = str(input())
cnt = 0
for moji in s:
    #print(moji)
    num = s.count(moji)
    #print(num)
    if num == 2:
        cnt+=1
    else:
        break
        
if cnt == 4:
    print("Yes")
else:
    print("No")
num = split().raw_input()

print num[1] * num[2]

### FIXED CODE ###

num = map(int, raw_input().split())

print num[0] * num[1], 2*num[0] + 2*num[1]
n=int(input().strip())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input().strip())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)  
   

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
a,b,c=map(int,input().split())
if((a*b*c)%7=0)and((a*b*c)/7=25):
	print("YES")
else:
  	print("NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
if((a*b*c)%7==0)and((a*b*c)/7==25):
	print("YES")
else:
  	print("NO")
h, w = map(int, input().split())
s = [input() for _ in range(h)]
box = [(1, 0), (0, 1), (-1, 0), (0, -1)]

black = []
white = []

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            black.append((i, j))
        else:
            white.append((i, j))

def check(u, v, p):
        for x, y in box:
            if u + x < 0 or u + x >= h or v + y < 0 or v + y >= w:
                continue
            if s[u][v] == "." and s[u+x][v+y] == "#" and p[u+x][v+y] == 0:
                p[u+x][v+y] = 1
                check(u+x, v+y, p)

            elif s[u][v] == "#" and s[u+x][v+y] == "." and p[u+x][v+y] == 0:
                p[u+x][v+y] = 1
                check(u+x, v+y, p)
        return p

ans = 0
for i, j in black:
    p = [[0]*w for _ in range(h)]
    p[i][j] = 1
    t = check(i, j, p)
    for a, b in white:
        if t[a][b] == 1:
            ans += 1

print(ans)



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

h, w = map(int, input().split())
s = [input() for _ in range(h)]
t = [[None]*w for _ in range(h)]
box = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def dfs(i, j, color):
    if not (0<=i<h and 0<=j<w): return 0, 0
    if s[i][j] == color: return 0, 0
    if t[i][j]: return 0, 0

    t[i][j] = True
    wh, bl = 0, 0
    if s[i][j] == "#":
        bl += 1
    else:
        wh += 1

    for x, y in box:
        tmp1, tmp2 = dfs(i+x, j+y, s[i][j])
        wh, bl = wh+tmp1, bl+tmp2

    return wh, bl

ans = 0
for i in range(h):
    for j in range(w):
        a, b = dfs(i, j, "!")
        ans += a*b
print(ans)
# cook your dish here
n,m = map(int,input().split())

par = [[] for i in range(n)]
op = [[]for i in range(n)]
for i in range(n+m-1):
    x,y = map(int,input().split())
    x-=1
    y-=1
    par[y].append(x)
    op[x].append(y)

res = [-1]*n
x = -1


for i in range(n):
    if len(par[i])==0:
        res[i] = 0
        x = i
        break


used = [0]*n
used[x]=1

#不使用の親がいるか
def g(y):
    for pe in par[y]:
        if used[pe]==0:
            return False
    return True
    
#xの下のusedとresを埋める
def f(z):
    for e in op[z]:
        if used[e]==0:
            if g(e):
                if e<=len(used) and e <= len(res):
                    used[e]=1
                    res[e]=z+1
                    f(e)

f(x)

for i in range(n):
    print(res[i])


### FIXED CODE ###

from collections import deque

n,m = map(int,input().split())

up = [[] for i in range(n)]
down= [[]for i in range(n)]
for i in range(n+m-1):
    a,b = map(int,input().split())
    a -=1
    b -=1
    up[b].append(a)
    down[a].append(b)

res = [-1]*n
root = -1

for i in range(n):
    if len(up[i])==0:
        res[i] = 0
        root = i
        break

#0なら不使用
used = [0]*n
used[root]=1

#yの親に不使用が一つも存在しなければTrue
def g(y):
    for pe in up[y]:
        if used[pe]==0:
            return False
    return True
    
#zの下のusedとresを埋める
def f(z):
    for e in down[z]:
        if used[e]==0 and g(e):
            res[e]=z+1
            tank2.append(e)
            usedtank.append(e)
c = 1
tank = deque([root])
tank2 = deque([root])
usedtank = []
while c != n:
    tank = tank2
    tank2 = deque([])
    usedtank = []
    while len(tank)!=0:
        f(tank.popleft())
    for usede in usedtank:
        used[usede]=1
    c += len(tank2)
    
for i in range(n):
    print(res[i])
a,b,c=map(int,input().split())
print(min(abs(b-a)+abs(c-b),abs(c-a)+abs(b-c),abs(a-b)+abs(c-a),abs(c-b)+abs(a-c),abs(a-c)+abs(b-a),abc(b-c)+abs(a-b)))

### FIXED CODE ###

a,b,c=map(int,input().split())
print(min(abs(b-a)+abs(c-b),abs(c-a)+abs(b-c),abs(a-b)+abs(c-a),abs(c-b)+abs(a-c),abs(a-c)+abs(b-a),abs(b-c)+abs(a-b)))
from math import gcd
from functools import reduce
from itertools import product
from itertools import combinations
import numpy as np

def resolve():
  N, M, X = map(int, input().split(" "))

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books)

  books_index_pattarns = [list(x) for i in range(1, N) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)][:,:1]
  if len(books_result) == 0:
    print("-1")
    return True
  else:
    print(books_result.min())
    return True

if __name__ == "__main__":
    resolve()

### FIXED CODE ###

from itertools import product
from itertools import combinations
import numpy as np

def resolve():
  N, M, X = map(int, input().split(" "))

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books)


  if N == 1:
    if np.all(books[:, 1:] >= X):
      print(books[0][0])
    else:
      print(-1)
    return True
  books_index_pattarns = [list(x) for i in range(1, N+1) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)]

  if len(books_result) == 0:
    print(-1)
    return True
  elif len(books_result) == 1:
    print(books_result[0][0])
    return True
  else:
    # print(books_result)
    print(books_result[:,:1].min())
    return True

if __name__ == "__main__":
    resolve()