Harryxun/stf_run huggingface dataset:
import math
N, M = list(map(int, input().split(" ")))
abc = [[0, 0, 0] for i in range(M)]
for i in range(M):
  abc[i][0], abc[i][1] = list(map(int, input().split(" ")))
  c = list(map(int, input().split(" ")))
  for j in range(N):
    cbits = (1 << j) * (j+1 in c)
    abc[i][2] |= cbits

dp = [0 if i == 0 else math.inf for i in range(2**N)]
for i in range(M):
  for j in range(2**N):
    dp[j|abc[i][2]] = min(dp[j]+abc[i][0], dp[j|abc[i][2]])
print(dp[-1] if dp[-1] != math.inf else -1)

### FIXED CODE ###

N, M = list(map(int, input().split(" ")))
abc = [[0, 0, 0] for i in range(M)]
for i in range(M):
  abc[i][0], abc[i][1] = list(map(int, input().split(" ")))
  c = list(map(int, input().split(" ")))
  for j in c:
    cbits = (1 << j-1) 
    abc[i][2] |= cbits

dp = [0 if i == 0 else float("inf") for i in range(2**N)]
for i in range(M):
  for j in range(2**N):
    if dp[j|abc[i][2]] > dp[j]+abc[i][0]:
      dp[j|abc[i][2]] = dp[j]+abc[i][0]
print(dp[-1] if dp[-1] != float("inf") else -1)
n = int(input())
a_list = list(map(int,input().split()))
import numpy as np
print(int(np.median(a_list)) - (a_list.index(int(np.median(a_list))) + 1))

### FIXED CODE ###

n = int(input())
a_list = list(map(int,input().split()))
ans_list = []
for i in range(len(a_list)):
    ans_list.append(a_list[i] - i - 1)
import numpy as np
if len(ans_list)% 2 == 0:
    ans_list1 = sorted(ans_list)
    number1 = ans_list1[n//2]
    number2 = ans_list1[n//2 + 1]
    
    ans1 = 0
    ans2 = 0
    for i in ans_list:
        ans1 += abs(i - number1)
        ans2 += abs(i - number2)
    print(min(ans1 , ans2))
else:
    cary = ans_list
    number = int(np.median(cary))
    ans = 0
    for i in ans_list:
        ans += abs(i - number)
    print(ans)
a=input()
b=input()
sum=0
a=int(a)
b=int(b)
 
if a>=b:
  sum+=a
  if a-1>=b:
  	sum+=a-1
  else:
    sum+=b
else:
  sum+=b
  if b-1>=a:
  	sum+=b-1
  else:
    sum+=a
    
print(sum)

### FIXED CODE ###

import numpy as np
 
a,b=(int(x) for x in input().split())
sum=0

 
if a>=b:
  sum+=a
  if a-1>=b:
  	sum+=a-1
  else:
    sum+=b
else:
  sum+=b
  if b-1>=a:
  	sum+=b-1
  else:
    sum+=a
    
print(sum)
n = int(input())

dp = [0 for i in range(n+1)]

for i in range(35):
    j = i // 9
    cand = []
    for k in range(j+1):
       _i = i
       _i -= 9*k
       l = _i // 6
       for m in range(l+1):
           __i = _i
           __i -= 6*m
           cand.append(k+m+__i)
    dp[i] = min(cand)
nine_list = [pow(9, i) for i in range(1, 6)]
six_list = [pow(6, i) for i in range(1, 7)]
for i in range(36, n+1):
    for j in range(len(nine_list)):
        if nine_list[j] > i:
            max_nine = nine_list[j-1]
            break
    for j in range(len(six_list)):
        if six_list[j] > i:
            max_six = six_list[j-1]
            break
    dp[i] = min(dp[i-max_nine]+1, dp[i-max_six]+1)

print(dp[n])

### FIXED CODE ###

n = int(input())

dp = [0 for i in range(max(n+1, 36))]

for i in range(35):
    j = i // 9
    cand = []
    for k in range(j+1):
       _i = i
       _i -= 9*k
       l = _i // 6
       for m in range(l+1):
           __i = _i
           __i -= 6*m
           cand.append(k+m+__i)
    dp[i] = min(cand)
nine_list = [pow(9, i) for i in range(1, 6)]
six_list = [pow(6, i) for i in range(1, 7)]
for i in range(35, n+1):
    max_nine = nine_list[len(nine_list) - 1]
    max_six = six_list[len(six_list) - 1]
    for j in range(len(nine_list)):
        if nine_list[j] > i:
            max_nine = nine_list[j-1]
            break
    for j in range(len(six_list)):
        if six_list[j] > i:
            max_six = six_list[j-1]
            break
    dp[i] = min(dp[i-max_nine]+1, dp[i-max_six]+1)

print(dp[n])
import math
a,b,x=map(int,input().split())

if a*b//2*a>=x:
  print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
  print(90-math.degrees(math.atan(a/(2*b-2*x/a/a))))

### FIXED CODE ###

import math
a,b,x=map(int,input().split())
 
if a*b//2*a>=x:
  print(90-math.degrees(math.atan(2*x/(a*b*b))))
else:
  if a*b*b==x:
    print(0)
  else:
    print(90-math.degrees(math.atan(a/(2*b-2*x/a/a))))
N, M = [int(i) for i in input().split()]
for j in range(M):
    a, b = [int(k) for k in input().split()]
    graph[a-1][b-1] = graph[b-1][a-1] = 1

nmax = 50
graph = [[0]*nmax for i in range(nmax)]

print(*graph)

### FIXED CODE ###

N, M = [int(i) for i in input().split()]
graph = [[0]*N for i in range(N)]
vstd = [0] * N

for i in range(M):
    a, b = [int(i) for i in input().split()]
    graph[a-1][b-1] = graph[b-1][a-1] = 1
#print(*graph, sep="\n")

def dfs(v):
    vstd[v] = 1
    for v2 in range(N):
        if graph[v][v2] == 0:
            continue
        if vstd[v2] == 1:
            continue
        dfs(v2)
 
ans = 0
for i in range(N):
    for j in range(N):
        if graph[i][j] == 0:
            continue
        graph[i][j] = graph[j][i] = 0
        for k in range(N):
            vstd[k] = 0
        dfs(0)
        bridge = False
        for k in range(N):
            if vstd[k] == 0:
                bridge = True
        if bridge == True:
            ans += 1
        graph[i][j] = graph[j][i] = 1

print(ans//2)
def main():
    from collections import deque
    S = input()
    Q = int(input())

    for _ in range(Q):
        query = deque(input().split())
        if query[0] == "1":
            S.reverse()
        elif query[1] == "1":
            S = query[2] + S
        elif query[1] == "2":
            S = S + query[2]

    print("".join(map(str, S)))

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])
a = input()
input_list = []
for k in a:
    input_list.append(int(k))
ans = []
fomul_list = []
for i in range(2 ** n):
    sum = input_list[0]
    fomul = str(input_list[0])
    for j in range(3):
        if (i >> j)&1:
            sum += input_list[j+1]
            fomul = fomul + "+" + str(input_list[j+1])
        else:
            sum -= input_list[j+1]
            fomul = fomul + "-" + str(input_list[j+1])
    bag.append(sum)
    fomul_list.append(fomul)
print(fomul_list[bag.index(7)])

### FIXED CODE ###

a = input()
input_list = []
for k in a:
    input_list.append(int(k))
n=3
bag = []
fomul_list = []
for i in range(2 ** n):
    sum = input_list[0]
    fomul = str(input_list[0])
    for j in range(3):
        if (i >> j)&1:
            sum += input_list[j+1]
            fomul = fomul + "+" + str(input_list[j+1])
        else:
            sum -= input_list[j+1]
            fomul = fomul + "-" + str(input_list[j+1])
    bag.append(sum)
    fomul_list.append(fomul)
print(fomul_list[bag.index(7)] + "=7")
x = input()
s = t = 0
for i in range(200000):
    if x[i] = "T":
        t += 1
    if x[-i-1] = "S":
        s += 1
print(max(s, t))

### FIXED CODE ###

x = input()

st_sub = 0
count = 0
for char in x:

    if st_sub < 0 and char == "S":
        st_sub = 1
    elif char == "S":
        st_sub += 1
    else:
        st_sub -= 1
    
    if st_sub < 0:
        count += 1
    
print(count * 2)
n = int(input())
a = list(map(int, input().split()))
b = set(a)
d = [0,0,0]
index = 0
if len(b) != 3 and len(n) % 3 == 0:
    print("No")
    exit()
for i in list(b):
    for j in a:
        if i == j:
            d[index] += 1
    index += 1
if d[0] == d[1] and d[1] == d[2]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
temp = a[0] ^ a[1]
for i in range(2,n):
    temp = temp ^ a[i]
if temp == 0:
    print("Yes")
else:
    print("No")
num_prob = int(input())
prob = input()
new = prob.split()
sum = 0
num_drinks = input()
for j in new:
  sum += j

for i in range(num_drinks):
  line = input()
  new_line = line.split()
  if new_line[1] != new[new_line[0]]:
    sum -= new[new_line[0]]
    sum += new_line[1]
  print(sum)
    


### FIXED CODE ###

num_prob = int(input())
prob = input()
new = prob.split()
sum = 0

for j in new:
  sum += int(j)

  
num_drinks = int(input())
for i in range(num_drinks):
  line = input()
  new_line = line.split()
  if int(new_line[1]) != int(new[int(new_line[0])-1]):
    temp = sum - int(new[int(new_line[0])-1]) + int(new_line[1])
    print(temp)
  else:
    print(sum)
import sys
from itertools import product
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
h, w, k = map(int, input().split())
CHOCO = [list(map(int, input())) for _ in range(h)]
INF = 10**5

it = ["01"]*(h-1)
ans = INF
for x in product(*it):
    cnt = sum(map(int, x))
    agg = [[0]*(w) for _ in range(cnt+1)]
    *ls, = map(int, x+('1',))
    for i in range(w):
        prev = c = 0
        for j, split in enumerate(ls):
            if split:
                agg[c][i] = prev+CHOCO[j][i]
                prev = 0
                c += 1
            else:
                prev += CHOCO[j][i]

    tmp = [0]*(cnt+1)
    for xyz in zip(*agg):
        cannot_split = False
        can_continue = True
        for i, x in enumerate(xyz):
            if x > k:
                cannot_split = True
                break
            if x+tmp[i] > k:
                can_continue = False
                break

        if cannot_split:
            break

        if can_continue:
            for i, x in enumerate(xyz):
                tmp[i] += x
                continue
        else:
            for i, x in enumerate(xyz):
                tmp[i] = x
            cnt += 1

    if cannot_split:
        continue

    ans = min(ans, cnt)
print(ans)


### FIXED CODE ###

from itertools import product
h, w, k = map(int, input().split())
CHOCO = [list(map(int, input())) for _ in range(h)]
INF = 10**5

it = ["01"]*(h-1)
ans = INF
for x in product(*it):
    cnt = sum(map(int, x))
    agg = [[0]*(w) for _ in range(cnt+1)]
    *ls, = map(int, x+('1',))
    for i in range(w):
        prev = c = 0
        for j, split in enumerate(ls):
            if split:
                agg[c][i] = prev+CHOCO[j][i]
                prev = 0
                c += 1
            else:
                prev += CHOCO[j][i]

    tmp = [0]*(cnt+1)
    cannot_split = False

    for xyz in zip(*agg):
        cannot_split = False
        can_continue = True
        for i, x in enumerate(xyz):
            if x > k:
                cannot_split = True
                break
            if x+tmp[i] > k:
                can_continue = False
                break

        if cannot_split:
            break

        if can_continue:
            for i, x in enumerate(xyz):
                tmp[i] += x
                continue
        else:
            for i, x in enumerate(xyz):
                tmp[i] = x
            cnt += 1

    if cannot_split:
        continue

    ans = min(ans, cnt)
print(ans)
import sys
inputs = sys.stdin.readlines()

n, q = list(map(int, inputs[0].split()))
edges = []
for i in range(n-1):
    edges.append(tuple(map(int, inputs[i+1].split())))
p_x_list = []
for i in range(q):
    p_x_list.append(tuple(map(int, inputs[n+i].split())))

from collections import deque, defaultdict

def dfs_generator(nodes, start):
    nexts = deque([start])
    while nexts:
        node = nexts.popleft()
        nexts.extend(nodes[node]['childs'])
        yield node

nodes = dict({1: dict({'val': 0, 'childs': []})})
for from_, to_ in edges:
    nodes[from_]['childs'].append(to_)
    nodes[to_] = dict({'val': 0, 'childs': []})

part_tree_roots = defaultdict(int)
for p, x in p_x_list:
    part_tree_roots[p] += x

part_tree = defaultdict(list)
for r in part_tree_roots:
    gen = dfs_generator(nodes, r)
    try:
        while True:
            part_tree[r].append(next(gen))
    except StopIteration:
        pass

for n, v in part_tree_roots.items():
    for i in part_tree[n]:
        nodes[i]['val'] += v

for i in range(n-1):
    print(str(nodes[i+1]['val']), end=' ')
print(str(nodes[i+2]['val']))


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,Q = map(int,readline().split())
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:N+N-2])
PX = iter(ABPX[N+N-2:])

graph = [[] for _ in range(N+1)]
for a,b in zip(AB,AB):
    graph[a].append(b)
    graph[b].append(a)

val = [0] * (N+1)
for p,x in zip(PX,PX):
    val[p] += x

stack = [1]

parent = [0] * (N+1)
while stack:
    x = stack.pop()
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        val[y] += val[x]

print(' '.join(map(str,val[1:])))
n = int(input())
r = int(input())
if n<10 and -1<n:
  	print(r+100*(10-n))
elif n>=10:
    print(r)

### FIXED CODE ###

N,R = map(int,input().split())
plus=0
if N<10:
	plus=100*(10-N)
print(R+plus)
def num2alpha(num):
    if num<=26:
        return chr(97+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(97+num%26)

if __name__ == '__main__':
  n = int(input())
  print(num2alpha(n))

### FIXED CODE ###

no, sct = map(int, input().split(' '))
flut = list(map(int, input().split(' ')))
flut = sorted(flut, reverse=False)
sum_ = 0
for i in range(sct):
  sum_ += flut[i]
print(sum_)
import sys
sys.setrecursionlimit(500000)
K = int(input())

ans_list = []
def dfs(A):
    if len(A)!=0 and int("".join(A))<=10**6:
        ans_list.append(int("".join(A)))
    elif len(A)!=0 and int("".join(A))>10**6:
        return
    if len(A)==0:
        for i in range(1, 10, 1):
            A.append(str(i))
            dfs(A)
            A.pop()
        return

    for i in range(0, 10, 1):
        if abs(int(A[-1])-i)<=1:
            A.append(str(i))
            dfs(A)
            A.pop()
    return
dfs([])
ans_list.sort()
print(ans_list[K-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
K = int(input())

ans_list = []

def dfs(l):
    if len(l)==1 and l[0]!="0":
        ans_list.append(int("".join(l)))
    if l!=[] and l[0]=="0":
        return
    if l!=[] and int("".join(l))>3234566667:
        return
    for i in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
        l.append(i)
        #ここで絶対値1以下になるものだけdfs
        if len(l)==1:
            dfs(l)
            l.pop()
        elif abs(int(l[len(l)-2])-int(l[len(l)-1]))<=1:
            dfs(l)
            ans_list.append(int("".join(l)))
            l.pop()
        else:
            l.pop()

    return

dfs([])
ans_list.sort()
print(ans_list[K-1])
print(eval("("+input().replace(" ", "-1)(")+"-1)"))

### FIXED CODE ###

print(eval("("+input().replace(" ", "-1)*(")+"-1)"))
s = input()

s = s.sort()

if s == "abc":
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()

s = set(s)

if len(s) == 3:
  print("Yes")
else:
  print("No")
import math

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

def C(N,P):
    if N == 1: return P
    a=P
    N1=2
    while N >= N1:
        N1*=2
        a=math.sqrt(a)

    res=1
    for i in range(2,int(a)+2):
        if i**N > P : break
        if P % i**N == 0 : res = i

    return res

print(C(n,p))

### FIXED CODE ###

print(input().count("2"))
x, y=input().split()
m = 0 
for i in range(len(x)):
    if x[i] != y[i]:
        Y = y.replace(y[i], x[i]) 
        m+=1
print(m)    

### FIXED CODE ###

x=input()
y=input()
m = 0 
for i in range(len(x)):
    if x[i] != y[i]: 
        m+=1
print(m)
print(Christmas Eve *(25-int(input())

### FIXED CODE ###

n=int(input())
if n==25:
    print('Christmas')
if n==24:
    print('Christmas Eve')
if n==23:
    print('Christmas Eve Eve')
if n==22:
    print('Christmas Eve Eve Eve')
h,w = map(int, input().split())
# print(h,w)
row = []
for x in range(h):
    col = list(input())
    row.append(col)

out = "YES"

for x in range(h):
    for y in range (w):
        if row[x][y] == "#":
           #print(x,y)
            if  x > 0 and row[x-1][y] == "#":
                pass
            elif x < h-1 and row[x+1][y] == "#":
                pass
            elif y > 0 and row[x][y-1] == "#" :
                pass
            elif y < w-1  and row [x][y+1] == "#" :
                pass
            else:
                out = "NO"
                break
        pass

print(out)

### FIXED CODE ###

a,b = map (int , input().split())

if a <= b:
    print(a)
else:
    print(a-1)
N,K = map(int,input().split())
l = []
mod = 998244353
for i in range(K):
    L,R = map(int,input().split())
    l.append([L,R])
l.sort()

a = [0 for i in range(N+1)]
a[1] = 1
b = [0 for i in range(N+1)]
b[1] = 1
for i in range(2,N+1):
    for j in range(K):
        if l[j][0] < i:
            a[i] += (b[i-l[j][0]]-b[max(0,i-l[j][1]-1)])%mod
        else:
            break
    b[i] = (b[i-1]+a[i])%mod
mod = 998244353
print(a[N]%mod)

### FIXED CODE ###

S = input()
if S[-1] == "s":
    print(S+"es")
else:
    print(S+"s")
print(x*x*x)

### FIXED CODE ###

x = int(input())
print(x ** 3)
c = input()
s = 'abcdefghijklmnopqrstuvwxyz'
flg = True
while flg:
    if c == s[i] and c != 'z':
        print(s[i + 1])
        flg = False
    elif c == 'z':
        print('a')
        flg = False

### FIXED CODE ###

c = input()
s = "abcdefghijklmnopqrstuvwxyz"
flg = True
for i in range(len(s) + 1):
    if c == s[i] and c != "z":
        print(s[i + 1])
        break
    elif c == "z":
        print("a")
        break
from fractions import gcd
a,b,c=map(int,input().split())
print("NO"if c%gcd(a,b)!=0else"YES")

### FIXED CODE ###

x,y,z=map(str,input().split(' '))

if x[len(x)-1]==y[0] and y[len(y)-1]==z[0]:
    print('YES')
else:
    print('NO')
import sys
n = int(input())
a = []
ans = 0
lamp = 1
for _ in range(n):
  A = int(input())
  a.append(a)
  
for i in range(n):
  if lamp -1 == 1:
    print(i)
    sys.exit()
  lamp = a[lamp - 1]
print(-1)

### FIXED CODE ###

import sys
n = int(input())
a = [int(input()) for _ in range(n)]
lamp = 1
ans=0
for i in range(n):
    if lamp - 1 == 1:
        print(i)
        sys.exit()
    lamp = a[lamp - 1]
print(-1)
from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n-r,r )
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

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

r_cnt = N - K
b_cnt = K



for i in range(1, K+1):
    print(( cmb( r_cnt+1, i ) * cmb( b_cnt-1, i-1 )) % (10**9+7))

### FIXED CODE ###

from operator import mul
from functools import reduce
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

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

r_cnt = N - K
b_cnt = K

for i in range(1, K+1):
    print(( cmb( r_cnt+1, i ) * cmb( b_cnt-1, i-1 )) % (10**9+7))
N, K= map(int, input().split())
Nli = [int(x) for x in input().split()]
Nli.sort()
if N > K:print(sum(Nli[0:N-K]))
else: print(0)

### FIXED CODE ###

H, A = map(int, input().split())
times = H / A
if int(times) == times:
    print(int(times))
else:
    print(int(times) + 1)
list = map(int, input().split())
S = list[0]
W = list[1]
if W >= S: print("unsafe")
else: print("safe")

### FIXED CODE ###

list = list(map(int, input().split()))
S = list[0]
W = list[1]
if W >= S: print("unsafe")
else: print("safe")
n=int(input());s=input();print(max(len(set(s[:i])&set(s[i:]))for i in range(n)))
#copy code

### FIXED CODE ###

a,b=map(int,input().split())
s=[a+b,a-b,a*b]
print(max(s))
mod = 10**9+7
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

a = sorted(a, reverse=True)
b = sorted(b, reverse=True)

c = [0 for _ in range(n*m)]
for i in range(n):
    c[a[i]-1] += 1
    if c[a[i]-1] == 2:
        print(0)
        exit()

c = [0 for _ in range(n*m)]
for i in range(m):
    c[b[i]-1] += 1
    if c[b[i]-1] == 2:
        print(0)
        exit()

ans = 1

i = 0
j = 0

while i < n and j < m:
    if n*m > max(a[i], b[j]) + i*j:
        print(0)
        exit()
    if a[i] == b[i]:
        i += 1
        j += 1
    elif a[i] > b[j]:
        ans *= j
        ans %= mod
        i += 1
    else:
        ans *= i
        ans %= mod
        j += 1

res = n*m - min(n, m)

for i in range(1, res+1):
    ans *= i
    ans %= mod

print(ans)


### FIXED CODE ###

mod = 10**9+7
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

aa = [0 for _ in range(n*m)]
bb = [0 for _ in range(n*m)]

for i in range(n):
    if aa[n*m-a[i]] == 0:
        aa[n*m-a[i]] = 1
    else:
        print(0)
        exit()

for j in range(m):
    if bb[n*m-b[j]] == 0:
        bb[n*m-b[j]] = 1
    else:
        print(0)
        exit()

for i in range(n*m):
    if i == 0:
        continue
    aa[i] += aa[i-1]
    bb[i] += bb[i-1]

aa = aa[::-1]
bb = bb[::-1]

seta = set(a)
setb = set(b)

ans = 1

for x in range(1, n*m+1)[::-1]:
    if x in seta and x in setb:
        continue
    elif x in seta and x not in setb:
        ans *= bb[x-1]
        ans %= mod
    elif x not in seta and x in setb:
        ans *= aa[x-1]
        ans %= mod
    elif aa[x-1]*bb[x-1] - (n*m-x) > 0:
        ans *= aa[x-1]*bb[x-1] - (n*m-x)
        ans %= mod
    else:
        print(0)
        exit()

print(ans)
import sys

def syoki(k,skk,atk,):
    sks=ats=0
    for i in range(len(skk)):
        if skk[i]<=k:
            sks=i+1
        else:
            break
    for i in range(len(atk)):
        if atk[i]+skk[sks-1]<=k:
            ats=i+1
        else:
            break
    return(sks,ats)

def keisan(o,s,k,ok,sk,os,ss):
    swk=ss
    for i in range(os-2,-1,-1):
        while k> ok[i]+sk[swk]:
            swk+=1
            if swk<s:
                break
    return max(os+ss,i+swk)

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ak=[]
aa=0
for i in a:
    aa+=i
    ak.append(aa)
bk=[]
bb=0
for i in b:
    bb+=i
    bk.append(bb)

xa,xb=syoki(k,ak,bk)
yb,ya=syoki(k,bk,ak)
if xa+xb>yb>ya:
    ass=xa
    bs=xb
else:
    ass=ya
    bs=yb

wk=ass+bs

if wk==n+m:
    print(n+m)
    sys.exit()
if ass ==0 and bs==0:
    print(0)
    sys.exit()
if ass>bs:
    an=keisan(n,m,k,ak,bk,ass,bs)
else:
    an=keisan(m,n,k,bk,ak,bs,ass)

print(an)

### FIXED CODE ###

import numpy as np

n,m,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
b=np.array(list(map(int,input().split())))

ak=np.cumsum(a,dtype=np.int64)
bk=np.cumsum(b,dtype=np.int64)
ak=ak[ak<=k]
bk=bk[bk<=k]
lak=len(ak)
lbk=len(bk)

an=lak
j=0
for i in range(lak-1,-1,-1):
    while bk[j]+ak[i]<=k:
        an=max(an,i+j+2)
        j+=1
        if j>=lbk:
            j-=1
            break
an=max(an,lbk)

print(an)
n,l=map(int,input().split())

sum_ = 0
for i in range(n-1):
    sum_ = sum_ + (l + i - 1)

taste = [] 

for i in range(n):
    taste.append(sum_ - (l + i - 1))

min_sa = 0
sa = 0

for i in range(n):
    sa = sum_ - taste[i]
    if sa < min_sa:
        min_sa = sa

for i in range(n):
    if (sum_ - taste[i]) == min_sa:
        print(taste[i])
        break

### FIXED CODE ###

num = input()
#num = str(code)

if num[0] == num[1] or num[1] == num[2] or num[2] == num[3]:
    print('Bad')
else:
    print('Good')
a,b=map(int,intput().split())
print(a*b-a-b+1)

### FIXED CODE ###

a,b=map(int,input().split())
print(a*b-a-b+1)
def calc(x):
    global mount
    global list
    count=0
    for y in range(1,x+1):
        if mount[x] >= mount[x-y]:
            count+=1
    if x == count:
        list.append(x)

N=int(input())

mount=input().split()

list=[]

for z in range(1,len(mount)):
    calc(z)

print(1+len(list))

### FIXED CODE ###

A,B=map(int,input().split())

sum=0
for i in range(2):
    if A >= B:
        sum+=A
        A-=1
    else:
        sum+=B
        B-=1
print(sum)