peterverebics/CodeNet_Python_118 huggingface dataset:
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
AB = A + B
AB.sort()

x = 0
for i in range(N + M):
    if AB[i] <= K:
        x = x + 1
        K = K - AB[i]
        if K <= 0:
            break
        
print(x)
import itertools
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

max = 0

for i in range(1, n + 1):
    for j in range(1, m + 1):
        if (sa[i] + sb[j] <= k):
            if i + j > max:
                max = i + j
        else:
            break
print(max)
n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
SA, SB = [0], [0]
for i in range(n):
    SA.append(SA[i] + A[i])
for j in range(m):
    SB.append(SB[j] + B[j])
ans, tmp = 0, m
for i in range(n + 1):
    if SA[i] > k:
        break
    for j in range(tmp, 0, -1):
        if SA[i] + SB[j] <= k:
            ans = max(ans, i + j)
            break
    tmp = j
print(ans)
n,m,k = map(int,input().split())

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

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


c = [0]
d = 0
for i in range(n):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


ans = 0
j = m
for i in range(n):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)
from collections import deque
n,m,k=map(int,input().split())
a=deque(list(map(int,input().split())))
b=deque(list(map(int,input().split())))
cost=0
ans=0
while (a and cost+a[0]<=k) or (b and cost+b[0]<=k):
	if a and b:
		if a[0]<b[0]:
			cost+=a[0]
			ans+=1
			a.popleft()
		else:
			cost+=b[0]
			ans+=1
			b.popleft()
	elif a:
		cost+=a[0]
		ans+=1
		a.popleft()
	else:
		cost+=b[0]
		ans+=1
		b.popleft()
print(ans)
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
A.reverse()
B.reverse()
cnt=0
for i in range(N+M):
    if len(A)>0 and len(B)>0:
        if A[-1] > B[-1]:
            K -= B.pop()
        else:
            K -= A.pop()
    elif len(A)>0:
        K-=A.pop()
    elif len(B)>0:
        K-=B.pop()
    if(K<0):
        break
    cnt += 1
print(cnt)
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
for j in range(n+1):
    if k-suma[j] < 0:
        break
    for l in range(m+1):
        if k-suma[j]-sumb[l] < 0:
            res.append(j+l-1)
            break
print(max(res))
from itertools import accumulate
import bisect
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=list(accumulate(A))
b=list(accumulate(B))
diff=2*10**9
count=0
for i in range(N):
    j=bisect.bisect_right(b,K-a[i])-1
    if 0<=K-(a[i]+b[j])<=diff:
        diff=K-(a[i]+b[j])
        count=max(count,(i+1)+(j+1))
print(count)
x = input().split()
y = input().split()
z = input().split()
s = 0

for nn in range(400000):
    if int(x[2]) < 0:
        break
    if int(y[0]) <= int(z[0]) :
        x[2] = int(x[2]) - int(y[0])
        del y[0]  
        y.append(1000000001) 
        s += 1
    else:
        x[2] = int(x[2]) - int(z[0])
        del z[0]
        z.append(1000000001)
        s += 1
print(s-1)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.extend(b)
ab = sorted(a)

book = 0
time = 0
for i in ab:
    time += i
    if time > k:
        print(book)
        exit()
    elif time == k:
        book += 1
        print(book)
        exit()
    else:
        book += 1
from itertools import accumulate

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


As = list(accumulate(A))
Bs = list(accumulate(B))

ans = 0
if Bs[M-1] <= K:
    ans = max(ans, M)
idx = M-1
for i in range(N):    
    while idx != -1 and As[i] + Bs[idx] > K:
        idx -= 1
    num = i + idx + 2
    if As[i] > K:  
        num = 0
    ans = max(ans, num)

print(ans)
N, M, K = map(int, input().split())

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

ans = 0

while K >= 0:
    if len(A) > 0 & len(B) > 0:
        if A[0] <= B[0]:
            k = A.pop(0)
        else:
            k = B.pop(0)
    elif A:
        k = A.pop(0)
    elif B:
        k = B.pop(0)
    else:
        break
    K -= k
    if K >= 0:
        ans += 1
    
print(ans)
from collections import deque

n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A,B = deque(A),deque(B)
count = 0
a = A.popleft()
b = B.popleft()
while k>=a or k>=b:
    if a<b:
        k -= a
        count+=1
        if A: a = A.popleft()
        else: a = 10**10
    else:
        k -= b
        count+=1
        if B: b = B.popleft()
        else: b = 10**10
print(count)
n,m,k = map(int,input().split())
a = [int(i) for i in input().split()][::-1]
b = [int(i) for i in input().split()][::-1]
ans = 0
cnt = 0
while True:
    if a and b:
        if a[-1] < b[-1]: nxt = a.pop()
        else: nxt = b.pop()
    elif a: nxt = a.pop()
    elif b: nxt = b.pop()
    else: break
    if cnt + nxt > k: break
    else:
        cnt += nxt
        ans += 1
print(ans)
n, m, k = map(int, input().split())

l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))

l = l1 + l2
l.sort()

tmp = 0
ans = 0
if l[0] <= k:
    ans += 1
for i in range(1, n + m):
    l[i] += l[i-1]
    if l[i] <= k:
        ans += 1

print(ans)
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min = 0
cnt = 0
for i,k in enumerate(b):
    min += k
j = i
for i in range(N):
    while(j > 0 and min > K):
        j -= 1
        min -= b[j]
    if(min > K):
        break
    cnt = max(cnt, i + j)
    if(i == N):
        break
    min += a[i]
print(cnt)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
i=0
j=0
t=0
A.append(1000000001)
B.append(1000000001)
while t < K:
    if A[i]>=B[j] and t+B[j]<=K:
        t+=B[j]
        j+=1
    elif A[i]<B[j] and t+A[i]<=K:
        t+=A[i]
        i+=1
    else:
      	break
print(i+j)
n, m, k = [int(i) for i in input().split()]
book_list = [int(i) for i in input().split()]
book_list.extend([int(i) for i in input().split()])

book_list.sort()

times = 0
book_num = 0
for i in book_list:
    if times + i > k:
        break

    times += i
    book_num += 1

print(book_num)
import sys
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=A+B
d=0
C.sort()
if sum(C)<=K :
    print(len(C))
    sys.exit()
for i in range(len(C)) :
    d=d+C[i]
    if d>K :
        print(i+1)
        sys.exit()
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M): 
    b.append(b[i] + B[i])
print(a)
print(b)
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
N, M, K = map(int, input().split())
A_N = list(map(int, input().split()))
B_M = list(map(int, input().split()))
 
A_ind = 0
B_ind = 0
count = K
ans = 0
 
for i in range(N+M): 
  if A_N[0] < B_M[0]:
    if count >= A_N[0]:
      count -= A_N.pop(0)
      ans += 1
      if len(A_N) == 0:
        A_N.append(1000000001)
  else:
    if count >= B_M[0]:
      count -= B_M.pop(0)
      ans += 1
      if len(B_M) == 0:
        B_M.append(1000000001)

print(ans)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
sort_array = b + c
sort_array.sort()

num = a[2]

print(sort_array)
for i in range(0,len(sort_array)):
    num -= sort_array[i]
    if num >= 0:
        count += 1


print(count)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b_sum = sum(B)
for i in range(M - 1, -1, -1):
    b_sum -= B[i]
    if b_sum <= K:
        j = i
        break
else:
    j = -1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)
import bisect
N,M,K = map(int, input().split())
A= list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,len(A)):
    A[i]+=A[i-1]
for i in range(1,len(B)):
    B[i]+=B[i-1]

honn=bisect.bisect(B,K)
print(honn)
for i in range(len(A)):
    s=K-A[i]
    if s>=0:
        
        a=bisect.bisect(B,s)
        #print(s)
        if i+1+a>honn:
            honn=i+1+a
print(honn)
from bisect import bisect
from itertools import accumulate
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n):
    if a[i] > k:
        break
    ans = max(ans, i+1+bisect(b, k-a[i]))
print(ans)
from collections import deque

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

time = 0
count = 0
while A or B:
    if A and B:
        desk = A if A[0] < B[0] else B
    else:
        desk = A if A else B
    time += desk.popleft()

    if time > K:
        break
    else:
        count += 1

print(count)
import itertools


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


accA = list(itertools.accumulate(a))
accB = list(itertools.accumulate(b))


cnt = 0
ans = 0
for i in range(len(accA)):
    for j in range(len(accB)):
        if k >= accA[i]+accB[j]:
            cnt = i+j
        
        ans = max(cnt, ans)


print(ans)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ac = 0
bc = 0
ans = 0
t = 0
while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
    else:
      t+= a[ac]
      ac+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    print(t)
  elif bc == m and ac<=n-1:
    t+= a[ac]
    ac+=1
  else:
      break
  ans+=1

print(ans)
alen,blen,k = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
max = 0

for acount in range(0,alen):
    bcount = 0
    asum = sum(alist[:acount])
    while asum + sum(blist[:bcount+1]) < k and bcount <= blen:
        bcount += 1
    if acount + bcount > max and asum + sum(blist[:bcount])<=k:
        max = acount + bcount

print(max)
N,M,K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())

sa = {-1: 0}
for i, val in enumerate(A):
  sa[i] = sa[i-1] + val

sb = {-1: 0}
for i, val in enumerate(B):
  sb[i] = sb[i-1] + val

max_num = 0

for i in range(N):
  for j in range(M):
    if(sa[i]+sb[j]<=K):
      max_num = max(max_num,i+j+2)
      
      
print(max_num)
N,M,K=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A+=[10**10]
B+=[10**10]
a,b = 0,0
while K >= A[a] or K >= B[b] :
    if A[a]>B[b]:
        K -= B[b]
        b+=1
    else:
        K -= A[a]
        a+=1
    #print(a,b)
        
print(a+b)
from collections import deque
N,M,K = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
ans = 0
time = 0

while len(A) > 0 or len(B) > 0:
    if len(A) == 0:
        time += B.popleft()
    elif len(B) == 0:
        time += A.popleft()
    elif A[0] < B[0]:
        time += A.popleft()
    else:
        time += B.popleft()
    if time > K:
        break
    ans += 1

print(ans)
a = input().split()
a = [int(a)for a in a]
lis = []

b = input().split()
b = [int(b)for b in b]
c = input().split()
c = [int(c)for c in c]

for i in b:
    lis.append(i)

for i in c:
    lis.append(i)

lis.sort()

count = 0
time = a[2]
honn = 0

while time >= lis[count] and count <= len(lis)-1 :
    time = time - lis[count]

    if  count >= len(lis)-1 :
        honn += 1

        break

    else:
        count += 1
        honn += 1

print(honn)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=a+b
c.sort()
i=0
sum=0
flag=0
while i<(n+m):
  sum=sum+c[i]
  i=i+1
  if sum<=k:
    flag=flag+1
  else:
    break
print(flag)
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

A = [0]
B = [0]
for i in range(N):
  A.append(A[i] + a[i])
for i in range(M):
  B.append(B[i] + b[i])
  
ans = 0
j = M
for n in range(N + 1):
  while True:
    time = A[n] + B[j]
    if time <= K or j == 0:
      ans = max(ans, n + j)
      break
    else:
      j -= 1
print(ans)
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]
B=[0]
for i in range(n):
    A.append(A[-1]+a[i])
for i in range(m):
    B.append(B[-1]+b[i])
ans=0
for i in range(n+1):
    index=bisect.bisect_right(B,k-A[i])-1
    index=max(0,index)
    ans=max(ans,i+index)
print(ans)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+1):
  tmp = 0
  for j in range(i):
    if a[j]+b[i-j] < K:
      tmp = i
      ans = max(ans,tmp)
      break
  if tmp ==0:
    break

print(ans)
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right,bisect
n,m,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
b=list(map(int,stdin.readline().split()))
prea=[]
ans=0
for i in a:
    ans+=i 
    prea.append(ans)
final=0
temp=0
for i in range(m):
    temp+=b[i]
    if(temp>k):
        break
    temp2=bisect(prea,k-temp)
    final=max(final,temp2+i+1)
print(final)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
time = 0
ares = 0
bres = 0
bsatu = int()
time2 = 0
res = []
for i in range(0,n): #Aで最高何冊読めるか
    if sum(a[n-i:]) < k and k <= sum(a[n-i-1:]):
        ares = i
for i in range(0,ares+1): #0からaresまで
    asatu = ares - i
    bsatu = 0
    time2 = sum(a[n-asatu:])
    bsatu += i
    if time >= k:
        break
    res += [asatu + bsatu]
print(max(res))
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
k=0
ans=0
a=0
b=0
for i in range(N+M+1):
  if a==N and b==M:
    break
  elif a==N:
    k+=B[b]
    b+=1
  elif b==M:
    k+=A[a]
    a+=1
  else:
    if A[a]>=B[b]:
      k+=B[b]
      b+=1
    else:
      k+=A[a]
      a+=1
  if k<=K:
    ans+=1
  else:
    break
print(ans)
n,m,k=map(int,input().split())
a=sorted(map(int,input().split()))
b=sorted(map(int,input().split()))[::-1]
x=sum(a)
z=n
ans=0
while a and x>k:
  c=a.pop()
  x-=c
  z-=1
  if x>k:continue
  ans=max(ans,z)
while a:
  while b and b[-1]+x<=k:
    c=b.pop()
    x+=c
    z+=1
  ans=max(ans,z)
  c=a.pop()
  x-=c
  z-=1
  if x>k:continue
  ans=max(ans,z)
print(ans)
N, M, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

v = 0
ans = 0
for i in range(N):
    if v + A[i] <= K:
        v += A[i]
    else:
        mi = i-1
        break
else:
    mi = N-1

for j in range(M):
    while mi > -1 and v + B[j] > K:
        v -= A[mi]
        mi -= 1
    v += B[j]
    if v <= K:
        ans = max(ans, mi+1+ j+1)
        
print(ans)
import numpy as np
from bisect import bisect_right

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

ans = 0
for a_num, time in enumerate(a):
    if time > k:
        continue
    b_num = bisect_right(b, k - time)
    num = a_num + b_num + 1
    if num > ans:
        ans = num
print(ans)
from itertools import accumulate
from bisect import bisect_left
 
n,m,k=map(int,input().split())
a=list(accumulate([0]+list(map(int,input().split()))))
b=list(accumulate([0]+list(map(int,input().split()))))
#print(b)
mx=0
for i in range(n+1):
  if a[i]>k:continue
  #print('a[i];'+str(a[i]))
  idx=max(bisect_left(b,k-a[i])-1, 0)
  #print(idx)
  if a[i]+b[idx]>k:continue
  mx=max(mx,i+idx)
print(mx)
from collections import deque

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

count = 0
for i in range(N + M):
  if len(A) == 0:
    book = B[0]
    B.popleft()
  elif len(B) == 0:
    book = A[0]
    A.popleft()
  else:
    if A[0] <= B[0]:
      book = A[0]
      A.popleft()
    else:
      book = B[0]
      B.popleft()
  
  if K >= book:
    count += 1
    K -= book
  else:
    break

print(count)
from queue import deque

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

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

count = 0

while 1:
    a = A.popleft() if A else 10**9+1
    b = B.popleft() if B else 10**9+1
    
    if min(a, b) <= K:
        count += 1
        K -= min(a, b)
        if a <= b:
            B.appendleft(b)
        else:
            A.appendleft(a)
    else:
        break

print(count)
N,M,K = list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.append(1000000001)
B.append(1000000001)
a=0
b=0
count=0
time=0
while True:
    if A[a]<B[b]:
        time+=A[a]
        a+=1
        if time>K:
            break
        count+=1
    else:
        time+=B[b]
        b+=1
        if time>K:
            break
        count+=1

print(count)
from bisect import bisect_left
n, m, k = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

list_AS = []
list_BS = []
a = 0
b = 0
for i in list_A:
    a += i
    list_AS.append(a)

for i in list_B:
    b += i
    list_BS.append(b)
ans = 0

for i in range(n):
    j = bisect_left(list_BS, k-list_AS[i])
    if list_AS[i] + list_BS[j-1] <= k:
        ans = max(ans, i+j+1)

print(ans)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(10000000000)
b.append(10000000000)
ans = 0
t = 0
a1,b1 = 0,0
while t<k:
    if t+min(a[a1],b[b1])>k: break
    if a[a1]<b[b1]:
        t+=a[a1]
        a1+=1
    else:
        t+=b[b1]
        b1+=1
    ans+=1
print(ans)
from collections import deque

N,M,K=map(int,input().split())
A_list=list(map(int,input().split()))
B_list=list(map(int,input().split()))
A=deque(A_list)
B=deque(B_list)
time = 0
cnt = 0
while time <= K:
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    tmp = B.popleft()
  elif len(B) == 0:
    tmp = A.popleft()
  elif A[0]<B[0]:
    tmp = A.popleft()
  else:
    tmp = B.popleft()
  time += tmp
  if time > K:
    break
  cnt += 1
#  print(time,A,B)
print(cnt)
##C
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
##print(A+B)
C = A+B
##print(C)
i = 0
j = 0
goukei = 0
if K >= sum(C):
    print(N+M)
else:
    A = A+[10**9]
    B = B+[10**9]
    while goukei <= K: 
        if A[i] <= B[j]:
            goukei += A[i]
            i += 1
        else:
            goukei += B[j]
            j += 1
    print(i+j-1)
'''ABC172 C'''
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
for i,ai in enumerate(a_c):
    n = np.searchsorted(b_c, k - ai, side = 'right')
    ans = max(i + n, ans)
print(ans)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
at=0
bt=0
al=[0]*n
bl=[0]*m
for i in range(n):
  at=at+a[i]
  al[i]=at
for j in range(m):
  bt=bt+b[j]
  bl[j]=bt
t=m-1
ans=0
i=0
while i<n:
  if al[i]+bl[t]<=k:
    ans=max(ans,i+t+2)
    i=i+1
  else:
    t=t-1
  if i==n or t==-1:
    break
print(ans)
n, m, k = (int(i) for i in input().split())

A = [0]
for i,a in enumerate(input().split()):
    A.append(A[i] + int(a))

B = [0]
for i,a in enumerate(input().split()):
    B.append(B[i] + int(a))

#print(A)
#print(B)
i,bestj,ans = 0,m,0
while A[i] < k:
    for j in range(bestj, -1, -1):
        if A[i] + B[j] <= k: break
    #print(i,j)
    ans = max(i+j, ans)
    bestJ = j
    
    i += 1
    if i == n+1: break

print(ans)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=sum(B)
a=A[0]
p=0
for i in range(N):
    while count>K:
        count-=B[M-1]
        M-=1
    if i!=N-1:
        count+=A[i+1]
        a+=A[i+1]
    p=max(p,i+M+1)
    if a>K:
        break
print(p)
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))

for i in range(N):
    A[i+1]+=A[i]
for i in range(M):
    B[i+1]+=B[i]

idx=N
ans=0
for i in range(N):
    if A[i]>K:
        idx=i-1
        break

idx2=0
for i in range(idx,-1,-1):
    while idx2<M and A[idx]+B[idx2+1]<=K:
        idx2+=1
    ans=max(ans,i+idx2)

print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(10**10)
B.append(10**10)

L = []
for i in range(N+M):
  if A[0] >= B[0]:
    L.append(B[0])
    B.pop(0)
  else:
    L.append(A[0])
    A.pop(0)

ans = 0
for i in range(N+M):
  ans += L[i]
  if ans > K:
    print(i)
    break
    
if ans <= K:
  print(N+M)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumnum = 0
count = 0

B.reverse()
AB = A + B

while 1:
    if len(AB) == 0:
        break

    elif AB[0] < AB[-1]:
        tmp = sumnum + AB[0]
        AB.pop(0)

    else:
        tmp = sumnum + AB[-1]
        AB.pop(-1)

    if tmp > K:
        break

    else:
        sumnum = tmp
        count = count + 1


print(count)
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
temp = [[0] * M] * N

result = 0
count = 0
for i in range(0, len(A)):
    temp[i][0] = A[i]
    if temp[i][0] <= K:
        result = max(result, temp[i][0])
        count = i + 1
    for j in range(1, len(B)):
        temp[i][j] = temp[i][j-1] + B[j]
        if temp[i][j] <= K:
            result = max(result, temp[i][j])
            count = i + j + 2
print(count)
n, m, k = map(int, input().strip().split())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
i=j=0

time=0
while j<m:
    time+=B[j]
    if time >k:
        time-=B[j]
        break
    j += 1
j-=1
rem=k-time
ans=j+1
cnt=ans
while j>=0:
    while i<n and rem-A[i]>=0:
        rem-=A[i]
        i+=1
        cnt+=1
    ans=max(ans,cnt)
    
    rem+=B[j]
    j-=1
    cnt-=1

print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.reverse()
B.reverse()

ans = 0
total_time = 0
while A or B:
    if not A:
        t = B.pop()
    elif not B:
        t = A.pop()
    else:
        if A[-1] < B[-1]:
            t = A.pop()
        else:
            t = B.pop()
    total_time += t
    if total_time <= K:
        ans += 1
    else:
        break
print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))


maxNum = 0
cnt = 0


for i in a:
    if k - i > 0:
        k -= i
        cnt += 1
    else:
        break

    for i in b:
        if k - i > 0:
            k -= i
            cnt += 1
        else:
            break
    
    maxNum = max(maxNum, cnt)


print(maxNum)