Harryxun/stf_run huggingface dataset:
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], 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 ###

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 i in range(1 << N):
    t = [0] * M
    c = 0
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        c += C[j]
        a = A[j]
        for k in range(M):
            t[k] += a[k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)
#coding: utf-8
import math
import heapq

MOD = 10**9+7

def combination(n, r):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % MOD
        denom = denom * i % MOD
    return numer * pow(denom, MOD-2, MOD) % MOD


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

if (X+Y)%3!=0:
    print(0)
else:
    a = (2*X-Y)/3
    b = (2*Y-X)/3
    if a<0 or b<0:
        print(0)
    else:
        print(combination(a+b, a))


### FIXED CODE ###

#coding: utf-8
import math
import heapq

MOD = 10**9+7

def combination(n, r):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % MOD
        denom = denom * i % MOD
    return numer * pow(denom, MOD-2, MOD) % MOD


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

if (X+Y)%3!=0:
    print(0)
else:
    a = (2*X-Y)//3
    b = (2*Y-X)//3
    if a<0 or b<0:
        print(0)
    else:
        print(combination(a+b, a))
N, Q = map(int, input().split())
ki = [[[],0] for i in range(N)]
result = [0]*N

def dfs(i, parent):
    if parent != -1:
        ki[i][1] += ki[parent][1]
    result[i] = ki[i][1]
    if not ki[i][0]:
        return
    for j in ki[i][0]:
        if j == parent:
            continue
        dfs(j, i)
    return

for i in range(N-1):
    a, b = map(int, input().split())
    ki[a-1][0].append(b-1)
    ki[b-1][0].append(a-1)

for i in range(Q):
    p, x = map(int, input().split())
    ki[p-1][1] += x

dfs(0, -1)
print(*result)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
n,q=[int(_) for _ in input().split()]
ki=[[] for _ in range(n)]
ans=[0]*n
 
def dfs(numQ,parent):
    for child in ki[numQ]:
        if child==parent:
            continue
        ans[child]+=ans[numQ]
        dfs(child,numQ)
 
for i in range(n-1):
    a,b=[int(_) for _ in input().split()]
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
 
for i in range(q):
    p,x=[int(_) for _ in input().split()]
    ans[p-1]+=x
 
dfs(0,-1)
print(*ans)
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
from itertools import combinations
s=list(range(n))
ans=10**10
array=[0]*n
res=0
for ii in range(1,n+1):
    for i in combinations(s,ii):
        for j in i:
            res+=ca[j][0]
            for k,l in enumerate(ca[j][1:]):
                array[k]+=l
        if min (array)>=x:
            ans=min(ans,res)
        res=0
        array=[0]*m

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

### FIXED CODE ###

n,m,x=map(int,input().split())
cc=[list(map(int,input().split())) for _ in range(n)]
ans=float('inf')
for b in range(1<<n):
    a=[0]*(m+1)
    for i in range(n):
        if b&(1<<i)==0:
            continue
        for k,l in enumerate(cc[i]):
            a[k]+=l
        if min(a[1:])>=x:
            ans=min(ans,a[0])
    a=[0]*(m+1)
if ans==float('inf'):
    print(-1)
else:
    print(ans)
import math
n, x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list.sort()
dis_list = []
for i in range(n):
    dis_list.append(x_list[i+1]-x_list[i])

gcd = dis_list[0]
for i in range(n):
    gcd = math.gcd(dis_list[i],gcd)

print(gcd)

### FIXED CODE ###

from fractions import gcd

n, x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list.sort()
dis_list = []

for i in range(n):
    dis_list.append(x_list[i+1] - x_list[i])

ans = dis_list[0]
for i in range(n):
    ans = gcd(dis_list[i],ans)

print(ans)
#-*- coding:utf-8 -*-

if __name__ == "__main__":
    A, B, C = list(map(int, liput().split()))
    if (A + B) >= C:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

#-*- coding:utf-8 -*-

if __name__ == "__main__":
	A, B, C = list(map(int, input().split()))
	if A+B >= C:
		print("Yes")
	else:
		print("No")
def pixel_input(H,W,border="."):
    pixel = [[border]*(W+2)] + \
    [[border] + list(input()) + [border] for _ in range(H)] + \
    [[border]*(W+2)]
    return pixel
  
H,W=map(int,input().split())
A=pixel_input(H,W)

cnt=0
q,r=[],[]
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j]=="#":
            q.append((i,j))
if len(q)==H*W:
    print(0)
    sys.exit()
while(q):
    while(q):
        i,j=q.pop()
        if A[i-1][j]==".":
            if i-1!=0:
                A[i-1][j]="#"
                r.append((i-1,j))
        if A[i+1][j]==".":
            if i+1!=H+1:
                A[i+1][j]="#"
                r.append((i+1,j))
        if A[i][j-1]==".":
            if j-1!=0:
                A[i][j-1]="#"
                r.append((i,j-1))
        if A[i][j+1]==".":
            if j+1!=W+1:
                A[i][j+1]="#"
                r.append((i,j+1))
    q=[i for i in r]
    r=[]
    cnt+=1
print(cnt-1)

### FIXED CODE ###

H,W = list(map(int,input().split()))
A = [list(str(input())) for i in range(H)]
 
black = []
 
cnt = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            black.append([i,j])
 
length = len(black)
            
while (length < H*W):
    gray = []
    for l in black:
        if l[1] != 0:
            c1 = (l[0],l[1]-1)
            if A[c1[0]][c1[1]] == ".":
                gray.append(c1)
                A[c1[0]][c1[1]] = "#"
        if l[1] != W-1:
            c2 = (l[0],l[1]+1)
            if  A[c2[0]][c2[1]] == ".":
                gray.append(c2)
                A[c2[0]][c2[1]] = "#"
        if l[0] != 0:
            c3 = (l[0]-1,l[1])
            if  A[c3[0]][c3[1]] == ".":
                gray.append(c3)
                A[c3[0]][c3[1]] = "#"
        if l[0] != H-1:
            c4 = (l[0]+1,l[1])
            if  A[c4[0]][c4[1]] == ".":
                gray.append(c4)
                A[c4[0]][c4[1]] = "#"
    
    gray = list(set(gray))
    black = [l for l in gray]
    
    cnt += 1
    length += len(black)
    
print(cnt)
n, k = map(int, input())
print(((n - 1) + (k - 2)) // (k - 1))


### FIXED CODE ###

from sys import stdin
n, k, *a = map(int, stdin.read().split())
print(((n - 1) + (k - 2)) // (k - 1))
n , k , q = map(int, input().split())
points = [k] * n
for i in range(q):
    x = int(input())
    points[x] += 1
for x in points:
    x -= q
    if x <= 0:
        print("No")
    else:
        print("Yes")






### FIXED CODE ###

n , k , q = map(int, input().split())
points = [k] * n


for i in range(q):
    x = int(input())
    points[x-1] += 1
for x in points:
    x -= q
    if x <= 0:
        print("No")
    else:
        print("Yes")
n = int(input())
brick = list(map(int, input().split()))
cnt = 0
def Break(brick, i):
    if len(brick) == 0:
        return
    else:
        if i not in brick:
            return
        else:
            j = brick.index(i)
            brick = [brick[k] for k in range(j+1, len(brick))]
            global cnt
            cnt += 1
            Break(brick, i + 1)
Break(brick, 1)
if cnt == 0:
    print(-1)
else:
    print(n - cnt)


### FIXED CODE ###

n = int(input())
brick = list(map(int, input().split()))
cnt = 0
i = 0
j = 1
while i < n:
    if brick[i] == j:
        cnt += 1
        j += 1
    i += 1
if cnt == 0:
    print(-1)
else:
    print(n - cnt)
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,x,d = list(map(int, input().split()))
if d<0:
    x = x + d*(n-1)
    d *= -1
    
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
if x!=0:
    g = gcd(x,d)
    l = x*d//g
    lx = l//x
    ld = l//d
d = {} # (要素数, 最大値)
for i in range(n):
    # iX+sD
    if x!=0:
        ii = i - (i//lx)*lx
    else:
        ii = 0
    jj = (i//lx)*ld
    print(ii,jj)
    if ii not in d:
        d[ii] = [0,None]
    nn, m = d[ii]
    num = ((2*n-1-i)*i//2 + jj) - max(i*(i-1)//2 + jj - 1, m if m is not None else -float("inf"))
    d[ii] = [d[ii][0]+num, (2*n-1-i)*i//2 + jj]
ans = sum(v[0] for k,v in d.items() if v[1] is not None)
print(ans+1)

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,x,d = list(map(int, input().split()))
if d==0:
    if x==0:
        ans = 1
    else:
        ans = n+1
else:
    if d<0:
        x *= -1
        d *= -1
#         x = x + d*(n-1)
#         d *= -1
    D = {} # (要素数, 最大値)
    for i in range(n+1):
        # iX+sD
        if x!=0:
            ii = i*x % d
            jj = (i*x-ii)//d
        else:
            ii = 0
            jj = 0
#         print(ii,jj)
        if ii not in D:
            D[ii] = []
        D[ii].append((i*(i-1)//2 + jj, (2*n-1-i)*i//2 + jj))
    ans = 0
    for k,v in D.items():
        v.sort()
        m = -float("inf")
        val = 0
        for l,r in v:
#             val += (r - (max(l-1, m)))
            val += max(r - (max(l-1, m)), 0)
            m = max(m, r)
        ans += val
                    
#         num = ((2*n-1-i)*i//2 + jj) - max(i*(i-1)//2 + jj - 1, m if m is not None else -float("inf"))
#         D[ii] = [D[ii][0]+num, (2*n-1-i)*i//2 + jj]
#         print(D)
#         if ii==0 and (2*n-1-i)*i//2 + jj >= 0 >= i*(i-1)//2 + jj:
#             zz = True
#     ans = sum(v[0] for k,v in D.items() if v[1] is not None) + (not zz)
# print(ans)
print(ans)
s = int(input())
a = [s]

while len(a) - len(set(a)) != 0:
  for i in range(1000000):
    m = i+1
    if a[i] % 2 == 0:
      a.append(int(a[i]/2))
    else:
      a.append(3*a[i] + 1)
      
print(m)

### FIXED CODE ###

s = int(input())
def f(n):
    if n % 2 == 0:
        return int(n/2)
    else:
        return 3*n + 1

def a(i):
    if i == 1:
        return s
    else:
        return f(a(i-1))

list = []
for i in range(1,1000000):
    list.append(a(i))
    if len(list) != len(set(list)):
        print(i)
        break
y = 0
for i in range(int(input())):
    x,u = input().split()
    y += int(x) if u == "JPY" else float(x)*380000
print(y)

### FIXED CODE ###

year, month, day = map(int, input().split("/"))
if year <= 2019 and month <= 4 and day <= 30:
    print("Heisei")
else:
    print("TBD")
# coding: utf-8
# Your code here!

n,k,*a=map(int,open(0).read().split())

MOD=10**9+7

a.sort()
# print(a)

if a[-1]<0: #all minus
    if k%2==1:
        ans=1
        for i in range(k):
            ans=ans*a.pop()
            ans=ans%MOD
        print(ans)
        exit()
    a=a[::-1]
    for i in range(k):
        ans=ans*a.pop()
        ans=ans%MOD
    print(ans)
    exit()

if n==k:
  ans=1
  for i in range(k):
    ans=ans*a[i]%MOD
  print(ans)
  exit()    
    
l=0
r=n-1
ans=1
cnt=0
while True:
    if cnt==k:
        break
    if a[l]*a[l+1]>a[r]:
        ans=ans*a[l]%MOD
        ans=ans*a[l+1]%MOD
        l+=2
        cnt+=2
    else:
        ans=ans*a[r]%MOD
        r-=1
        cnt+=1
print(ans)

### FIXED CODE ###

import sys

# after これ通る？コピペs


def solve(n, k, aaa):
    MOD = 10 ** 9 + 7

    if n == k:
        ans = 1
        for a in aaa:
            ans = ans * a % MOD
        return ans

    pos = []  # Strictly, Non-neg
    neg = []
    for a in aaa:
        if a >= 0:
            pos.append(a)
        elif a < 0:
            neg.append(a)

    if len(pos) == 0:
        if k % 2 == 1:
            neg.sort(reverse=True)
        else:
            neg.sort()
        ans = 1
        for a in neg[:k]:
            ans = ans * a % MOD
        return ans

    pos.sort()
    neg.sort(reverse=True)
    ans = 1
    r = k

    if r % 2 == 1:
        ans = ans * pos.pop() % MOD
        r -= 1

    while r > 0:
        if len(pos) <= 1:
            ans = ans * neg.pop() * neg.pop() % MOD
        elif len(neg) <= 1:
            ans = ans * pos.pop() * pos.pop() % MOD
        else:
            pm = pos[-1] * pos[-2]
            nm = neg[-1] * neg[-2]
            if pm > nm:
                ans = ans * pos.pop() * pos.pop() % MOD
            else:
                ans = ans * neg.pop() * neg.pop() % MOD
        r -= 2

    return ans


n, k, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, k, aaa))
n=list(map(int,input.split()))
for i in range(len(n)):
  if(n[i]==0):
    cout<<i+1
    break

### FIXED CODE ###

n=list(map(int,input().split()))
for i in range(len(n)):
  if(n[i]==0):
    print(i+1)
    break
n,m,*T=map(int,open(0).read().split());*S,=zip(T[::2],T[1::2]);s=lambda e:{*sum([s for s in S if e in s],())};print("IM"*(len(s(1)&s(n))<1)+"POSSIBLE")

### FIXED CODE ###

n,m,*T=map(int,open(0).read().split());*S,=zip(T[::2],T[1::2]);s=lambda e:set(s[e<2]for s in S if e in s);print("IM"*(len(s(1)&s(n))<1)+"POSSIBLE")
X = map(int, input().split())

number = X
flag = 0

if(number%2 == 0):
    number += 1
else:
    pass

while(True):
    for i in range(2, number):
        if number%i == 0:
            number += 2
            break

        elif i == (number-1):
            flag = 1
            print(number)
            break

        else:
            pass

    if flag == 1:
        break


### FIXED CODE ###

X = int(input())

number = X
flag = 0

if number == 2:
  	print(number)
elif number%2 == 0:
    number += 1
else:
    pass
  
if number != 2:
    while(True):
        for i in range(2, number):
            if number%i == 0:
                number += 2
                break

            elif i == (number-1):
                flag = 1
                print(number)
                break

            else:
                pass

        if flag == 1:
            break

else:
  pass
N=int(input())
S=0
A=list(map(int,input().split()))
for i in range(N):
  S += 1/i
print(1/S)

### FIXED CODE ###

N=int(input())
S=0
A=list(map(int,input().split()))
for i in A:S+=1/i
print(1/S)
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
	if a[i]-1 == count:
		count += 1
if count == 0:
	print(-1)
else:
	prin
	t(n-count)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
	if a[i]-1 == count:
		count += 1
if count == 0:
	print('-1')
else:
	print(n-count)
4
BRBR

### FIXED CODE ###

N = int(input())
print("Yes" if input().count("R") > N//2 else "No")
import sys
input_number = int(raw_input())
if __name__ == '__main__':
    print(str(input_number ** 3))



### FIXED CODE ###

import sys
input_number = int(input())
if __name__ == '__main__':
    print(str(input_number ** 3))
N = int(input())
list = list(map(int,input().split()))
#print(list)
sa_list = []
ai = max(list)
for i in range(N):
    sa2 = abs(( list[i] - ai/2 ) *2)
    
   #print(sa)
    sa_list.append(int(sa2))
#print(sa_list)
basyo = (sa_list.index(min(sa_list)))
ar = list[basyo]
if ai == ar:
    print(str(ai) + " " + str(ai - ar))
else:
    print(str(ai) + " " + str(ar))
    


### FIXED CODE ###

A,B,X = map(int, input().split())
if A + B >= X and A <= X:
    print("YES")
else:
    print("NO")
N=int(input())
count=0

for i in range(1,N+1):
    a=[]
    if i%2==0:
        continue
     for j in range(1,i+1):
         if i%j==0:
             a.append(j)

    if len(a)==8:
        count+=1

print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-

N = int(input())
count = 0

for i in range(1, N + 1):
    a = []
    if i % 2 == 0:
        continue

    for j in range(1, i + 1):
        if i % j == 0:
            a.append(j)

    if len(a) == 8:
        count += 1

print(count)
a,b,K = map(int,input().split())
List =[]
for i in range(a,b+1):
    List.append(i)
for i in range(K):
    print(List[i])
for i in range(b-a+1-K,len(List)):
    print(List[i])

### FIXED CODE ###

a,b,k = map(int,input().split())
List =[]

ans = []

for i in range(a,min(a+k,b+1)):
    ans.append(i)
for i in range(b,max(b-k,a),-1):
    ans.append(i)

ans = list(set(ans))
ans.sort()
for i in ans:
    print(i)
from bisect import bisect_left
INF = 10**18
A, B, Q = map(int, input().split())
als = [int(input()) for i in range(A)]
bls = [int(input()) for i in range(B)]
als = [-INF]+als+[INF]
bls = [-INF]+bls+[INF]

for i in range(Q):
  x = int(input())
  ai = bisect_left(x,als)
  bi = bisect_left(x,bls)
  res = INF
  for S in [als[ai], als[ai-1]]:
    for T in [bls[bi], bls[bi-1]]:
      d1, d2 = abs(S-x)+abs(T-S), abs(T-x)+abs(S-T)
      res = min(res,d1,d2)
  print(res)

### FIXED CODE ###

from bisect import bisect_left
INF = 10**18
A, B, Q = map(int, input().split())
als = [int(input()) for i in range(A)]
bls = [int(input()) for i in range(B)]
als = [-INF]+als+[INF]
bls = [-INF]+bls+[INF]

for i in range(Q):
  x = int(input())
  ai = bisect_left(als,x)
  bi = bisect_left(bls,x)
  res = INF
  for S in [als[ai], als[ai-1]]:
    for T in [bls[bi], bls[bi-1]]:
      d1, d2 = abs(S-x)+abs(T-S), abs(T-x)+abs(S-T)
      res = min(res,d1,d2)
  print(res)
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])#reverse
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    if wv[i][0]==w0:
        k=wv[i][1]+x[0][-1]
        l=len(x[0])
        if l*w0<=w:x[0].append(k)
    elif wv[i][0]==w0+1:
        k=wv[i][1]+x[1][-1]
        l=len(x[1])
        if l*(w0+1)<=w:x[1].append(k)
    elif wv[i][0]==w0+2:
        k=wv[i][1]+x[2][-1]
        l=len(x[2])
        if l*(w0+2)<=w:x[2].append(k)
    else:
        k=wv[i][1]+x[3][-1]
        l=len(x[3])
        if l*(w0+3)<=w:x[3].append(k)

ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
for i in range(l3):
    for j in range(l2)):
        for k in range(l1):
            d=w-(i*(w0+3)+j*(w0+2)+k*(w0+1))
            if d>=0:
                ma_sub=x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,len(x[0])-1)]
            ma=max(ma,ma_sub)
print(ma)


### FIXED CODE ###

n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    if wv[i][0]==w0:
        k=wv[i][1]+x[0][-1]
        l=len(x[0])
        if l*w0<=w:x[0].append(k)
    elif wv[i][0]==w0+1:
        k=wv[i][1]+x[1][-1]
        l=len(x[1])
        if l*(w0+1)<=w:x[1].append(k)
    elif wv[i][0]==w0+2:
        k=wv[i][1]+x[2][-1]
        l=len(x[2])
        if l*(w0+2)<=w:x[2].append(k)
    else:
        k=wv[i][1]+x[3][-1]
        l=len(x[3])
        if l*(w0+3)<=w:x[3].append(k)
#print(x)
ma=0
for i in range(len(x[0])):
    for j in range(len(x[1])):
        for k in range(len(x[2])):
            for l in range(len(x[3])):
                ma_sub=0
                if i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3)<=w:
                    ma_sub+=x[0][i]
                    ma_sub+=x[1][j]
                    ma_sub+=x[2][k]
                    ma_sub+=x[3][l]
                ma=max(ma,ma_sub)
print(ma)
from collections import deque

def main():
    N = int(input())
    edges = [[] for _ in range(N-1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges[a-1].append(b-1)
    
    K = max([len(g) for g in edges[1:]])
    K = max(K+1, len(edges[0]))
    init = [[node, i+1] for i, node in enumerate(sorted(edges[0]))]
    que = deque(init)
    colors = set([i for i in range(1, K+1)])
    ans = [i for n, i in init]
    while que:
        node, color = que.popleft()
        if node >= N-1:
            continue

        next_nodes = edges[node]
        next_nodes.sort()
        next_colors = list(colors - set([color]))
        
        for i in range(len(next_nodes)):
            ans.append(next_colors[i])
            que.append([next_nodes[i], next_colors[i]])

    print(K)
    print('\n'.join(list(map(str, ans))))

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque

def main():
    N = int(input())
    path = [[] for _ in range(N)]
    ab = []
    ans = {}
    visited = [False] * N
    visited[0] = True
    for _ in range(N-1):
        a, b = map(int, input().split())
        path[a-1].append(b-1)
        path[b-1].append(a-1)
        # ab.append(str(a-1)+str(b-1))
        ab.append((a-1, b-1))
    
    que = deque([(0, 0)])
    while que:
        # k = 1
        k = 0
        pre, c = que.popleft()
        for next_node in path[pre]:
            if visited[next_node]:
                continue
            k += 1
            if c == k:
                k += 1
            visited[next_node] = True
            # ans[str(pre)+str(next_node)] = k
            ans[(pre, next_node)] = k
            que.append((next_node, k))
            

    print(max(ans.values()))
    for key in ab:
        print(ans[key])

if __name__ == '__main__':
    main()
ans = 0

for i in range(k+1):
    l = min(i,n)
    for j in range(l+1):
        left_gain = jewel_list[:j]
        if l-j != 0:
            right_gain = jewel_list[-l+j:]
        else:
            right_gain = []
        
        gabage = sorted(left_gain+right_gain)[:k-i]

        total = sum(left_gain+right_gain)
        for p in gabage:
            if p < 0:
                total -= p
            else:
                break
        ans = max(ans,total)

print(ans)

### FIXED CODE ###

n, k = [ int(v) for v in input().split() ]
jewel_list = [ int(v) for v in input().split() ]

ans = 0

for i in range(k+1):
    l = min(i,n)
    for j in range(l+1):
        left_gain = jewel_list[:j]
        if l-j != 0:
            right_gain = jewel_list[-l+j:]
        else:
            right_gain = []
        
        gabage = sorted(left_gain+right_gain)[:k-i]

        total = sum(left_gain+right_gain)
        for p in gabage:
            if p < 0:
                total -= p
            else:
                break
        ans = max(ans,total)

print(ans)
from functools import reduce
import math


N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

def lcm_base(x, y):
    return (x * y // math.gcd(x, y))

def lcm_list(list):
    return reduce(lcm_base, list, 1)

lcm = lcm_list(T)

print(lcm)


### FIXED CODE ###

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return y


ans = T[0]
for i in range(1, N):
    ans *= T[i] // gcd(ans, T[i])

print(ans)
S, T= input().split()
A, B= map(int, input().split())
U= input().split()

if (S==U):
    print(A-1 B)
else:
    print(A B-1)

### FIXED CODE ###

S, T= input().split()
A, B= map(int, input().split())
U= input()
if (S == U):
    print(A-1,B)
elif (T == U):
    print(A,B-1)
else:
    print(A,B)