We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.
It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).
Consider the following action:
 - Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.
How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

-----Constraints-----
 - 1 \leq N, M \leq 200000
 - 1 \leq K \leq 10^9
 - 1 \leq A_i, B_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

-----Output-----
Print an integer representing the maximum number of books that can be read.

-----Sample Input-----
3 4 240
60 90 120
80 150 80 150

-----Sample Output-----
3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.
We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.
 - Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.
 - Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.
 - Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Difficulty: introductory

Starter code:

Solutions:
def solve():
  N,M,K = map(int, input().split())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  ret = 0

  A_cusum = [0]
  A_border_index = 0 # 超えるときのindex
  for a_ in A:
    A_end = A_cusum[-1]
    if A_end+a_ > K:
      break

    A_cusum.append(A_end+a_)
    
  A_border_index = len(A_cusum)-1
  ret = A_border_index

  B_cusum = [0]
  B_border_index = 0
  
  while A_border_index >= 0 and B_border_index < M:

    while B_border_index < M:
      B_end = B_cusum[-1]
      b_ = B[B_border_index]

      if A_cusum[A_border_index]+B_end+b_ > K:
        break

      B_cusum.append(B_end+b_)
      B_border_index += 1

    ret = max(ret, A_border_index+B_border_index)
    A_border_index -= 1

  print(ret)
  
solve()

n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]

ca,cb=[0],[0]
for i in range(n):
  ca.append(ca[i]+a[i])
for i in range(m):
  cb.append(cb[i]+b[i])

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

print(ans)

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])
# print(a)
# print(b)
# print(a[3])
ans=0
j = 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)

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(accumulate(map(int, input().split())))
    b = tuple(accumulate(map(int, input().split())))
    r = bisect(b, k)

    for i1, ae in enumerate(a):
        if k < ae:
            break
        r = max(r, bisect(b, k - ae) + i1 + 1)
    print(r)

def __starting_point():
    main()
__starting_point()

from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB
A.insert(0, 0)

for i in range(1,len(A)):
  A[i] += A[i-1]
for i in range(1, len(B)):
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time >= 0:
    numb = bisect_right(B, rest_time)
    anstmp = i + numb 
    ans = max(ans, anstmp)
print(ans)

import bisect
n, m, k = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
sum_a = [0] * (n + 1)
sum_b = [0] * (m + 1)

for i in range(n):
    sum_a[i + 1] = sum_a[i] + aaa[i]

for j in range(m):
    sum_b[j + 1] = sum_b[j] + bbb[j]

ans = 0
for i in range(n + 1):
    if sum_a[i] > k:
        break
    tmp = bisect.bisect_right(sum_b, k - sum_a[i])
    ans = max(ans, i + tmp - 1)
print(ans)

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

sum_a = [0]
sum_b = [0]

counta = 0
for x in a:
    counta += x
    if counta <= k:
        sum_a.append(counta)
    else:
        break

countb = 0
for y in b:
    countb += y
    if countb <= k:
        sum_b.append(countb)
    else:
        break


n = len(sum_b)

ans = 0

for i in range(len(sum_a)):
    for j in reversed(range(n)):
        if sum_a[i] + sum_b[j]<= k:
            ans = max(ans,i+j)
            n = j+1
            break
    else:
        break


print(ans)

def binary_search(arr, num):
  left = 0
  right = len(arr)-1
  while right-left > 0:
    mid = (left+right) // 2
    if arr[mid] > num:
      right = mid
    else:
      left = mid + 1
  if arr[left] > num:
    return left
  else:
    return len(arr)

def main():
  n, m, k = map(int , input().split())
  a_books = list(map(int , input().split()))
  b_books = list(map(int , input().split()))
  a_cum_sum = [0] * (n+1)
  b_cum_sum = [0] * (m+1)

  for i in range(n):
    a_cum_sum[i+1] = a_cum_sum[i] + a_books[i]
  for i in range(m):
    b_cum_sum[i+1] = b_cum_sum[i] + b_books[i]
  ans = 0
  for i in range(n+1):
    if a_cum_sum[i] > k:
      break
    rest = k - a_cum_sum[i]
    index = binary_search(b_cum_sum, rest)
    ans = max(ans, i+index-1)
  print(ans)

def __starting_point():
  main()
__starting_point()

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

cnt=i=0
for ai in a:
  if cnt+ai>k: break;
  cnt+=ai; i+=1; 

j=0
for bi in b:
  if cnt+bi>k: break;
  cnt+=bi; j+=1;
  
ans=s=i+j
for i in reversed(range(i)):
  s-=1; cnt-=a[i];
  while cnt+b[j]<=k:
    s+=1; cnt+=b[j]; j+=1;
  ans=max(ans,s)
  
print(ans)

import itertools
import bisect
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=[0]+list(itertools.accumulate(a))
cb=[0]+list(itertools.accumulate(b))
ans=0
for i in range(n+1):
  if k<ca[i]:
    break
  j=bisect.bisect(cb,k-ca[i])
  ans=max(i-1+j,ans)
print(ans)


def main():
    n, m, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    s = sum(B)
    ans = 0
    i, j = 0, m - 1
    while i < n:
        if s <= k:
            ans = max(ans, i + j + 1)
            s += A[i]
            i += 1
        else:
            if j < 0:
                break
            s -= B[j]
            j -= 1

    if s <= k:
        ans = max(ans, n + j + 1)

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

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])
    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())
lsA = list(map(int,input().split()))
lsB = list(map(int,input().split()))

lsAN = [0]
sumA = 0
for i in range(N):
    sumA += lsA[i]
    lsAN.append(sumA)
lsBN = [0]
sumB = 0
for i in range(M):
    sumB += lsB[i]
    lsBN.append(sumB)
j = M
ans = 0
for i in range(N+1):
    if lsAN[i] > K:
        break
    while lsBN[j] > K - lsAN[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

# author:  Taichicchi
# created: 15.09.2020 21:14:18

import sys

N, M, K = list(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 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=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])

#print(a)
#print(b)

ans=0
j=M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    #print(i,j)
    ans=max(ans,i+j)
print(ans)

from collections import deque
from itertools import accumulate
n,m,k = map(int,input().split())
a_list = list(accumulate(list(map(int,input().split()))))
a_list = [0]+a_list
b_list = list(accumulate(list(map(int,input().split()))))
b_list = [0]+b_list+[float('inf')]
cnt_list = []

for i in range(len(a_list)) :
    t = k
    cnt = 0
    a = a_list[i]
    if t < a :
        continue
    t -= a
    cnt += i

    ok = 0
    no = m+2
    while no != ok+1 :
        center = (ok+no)//2

        if t >= b_list[center] :
            ok = center
        if t < b_list[center] :
            no = center
    cnt += ok
    cnt_list.append(cnt)

ans = max(cnt_list)
print(ans)

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0]
B = [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])
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while(A[i] + B[j] > k):
        # print('i: {}, j: {}'.format(i, j))
        j -= 1
    ans = max(ans, i + j)
print(ans)


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

Asum=[0]
Bsum=[0]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    
m=0
j=M

for i in range(len(Asum)):
    if Asum[i]>K:
        break
    while Asum[i]+Bsum[j]>K:
        j-=1
    if m<i+j:
        m=i+j
        
print(m)

n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))

acum1=[0]
for i in range(n):
  acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
  acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
  if acum1[i]>k:
    break
  while acum2[j]>k-acum1[i] and j>0:
    j-=1
  ans=max(ans,i+j)
print(ans)

from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int,input().split())
A = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))
B = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))
ans = 0
for i in range(N+1):
    left = K-A[i]
    if left < 0:
        break
    j = bisect_right(B, left)
    ans = max(ans, i+j-1)
print(ans)

def getval():
    n,m,k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    a = [A[0]]
    b = [B[0]]
    for i in range(0,n-1):
        a.append(a[i]+A[i+1])
    for i in range(0,m-1):
        b.append(b[i]+B[i+1])
    return n,m,k,a,b

def main(n,m,k,a,b):
    idxa = 0
    ans = 0
    t = 0
    while a[idxa]<=k and idxa<n:
        idxa += 1
        if idxa==n:
            break
    ans = idxa
    idxa -= 1
    t = a[idxa]
    for i in range(m):
        t = a[idxa] + b[i]
        if t<=k:
            ans = max(ans,idxa+i+2)
        else:
            flag = False
            while t>k:
                idxa -= 1
                if idxa<0:
                    a.append(0)
                    break
                t = a[idxa]+b[i]
            ans = max(ans,idxa+i+2)

    print(ans)

def __starting_point():
    n,m,k,a,b = getval()
    main(n,m,k,a,b)
__starting_point()

import bisect
import itertools
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=[0]+list(itertools.accumulate(a))
cb=[0]+list(itertools.accumulate(b))
ans=0
for i in range(n+1):
  bk=ca[i]
  if bk<=k:
    j=bisect.bisect(cb,k-bk)
    ans=max(ans,i+j-1)
  else:
    break
print(ans)

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[-1]+a[i])
for i in range(m):
    bsum.append(bsum[-1]+b[i])
ans=0
for i in range(n+1):
    if asum[i]>k:
        break
    while asum[i]+bsum[m]>k and m>0:
        m-=1
    ans=max(ans,i+m)
print(ans)

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])

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 = list(map(int, input().split()))
B = list(map(int, input().split()))

C, D = [0], [0]
for i in range(N):
    C.append(C[-1] + A[i])
for i in range(M):
    D.append(D[-1] + B[i])

ans = 0
for i in range(N + 1):
    T = K - C[i]
    l, r = 0, M + 1
    while r - l > 1:
        m = (l + r) // 2
        if D[m] <= T: l = m
        else: r = m
    if T >= 0: ans = max(ans, i + l)
print(ans)

import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

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()]

tmp = sum(A)
cnt = len(A)
res = 0

A = deque(A)
B = deque(B)

while True:
    if tmp <= k:
        res = max(res, cnt)
        if len(B) <= 0:
            break
        b = B.popleft()
        tmp += b
        cnt += 1
    else:
        if len(A) <= 0:
            break
        a = A.pop()
        tmp -= a
        cnt -= 1

print(res)


import numpy as np
import bisect
N,M,K= list(map(int, input().split()))
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print((0));return

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  
  else:break
    
Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
  else:break
    #AAsum=[]
#for i in range(len(Asum)):
#  AAsum.append(K-Asum[i])

#print(Asum)
#print(AAsum)
#print(Bsum)

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)

#print(Asum)
#print(AAsum)
#print(Bsum)
#print(C)
print((max(C)))
#176882


n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)

n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]

c=[0]
for i in range(n):
  if c[i]+a[i]<=k:
    c.append(c[i]+a[i])
  else:
    break

d=[0]
for i in range(m):
  if d[i]+b[i]<=k:
    d.append(d[i]+b[i])
  else:
    break

e=0
f=len(d)-1
for i in range(len(c)):
  for j in range(f,-1,-1):
    if c[i]+d[j]<=k:
      if i+j>e:
        e=i+j
      f=j
      break
print(e)

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,N):
  A[i] += A[i-1]
for i in range(1,M):  
  B[i] += B[i-1]
ma = bisect.bisect(A,K)
for m in range(0,M):
  if B[m]>K:
    break  
  n = bisect.bisect(A,K-B[m])
  if  ma < n + m + 1:
    ma = n + m + 1 
print(ma)

def main():
    line1 = input()
    line2 = input()
    line3 = input()
    n, m, k = list(map(int, line1.split()))
    a = [0] + list(map(int, line2.split()))
    b = [0] + list(map(int, line3.split()))
    mark1, mark2 = 0, 0
    for i in range(1, len(a)):
        a[i] += a[i-1]
        if a[i] > k:
            mark1 = i
            break
    for i in range(1, len(b)):
        b[i] += b[i-1]
        if b[i] > k:
            mark2 = i
            break
    if mark1:
        a = a[:mark1]
    if mark2:
        b = b[:mark2]
    ans = 0
    for i in range(len(a)):
        target = k - a[i]
        tmp = 0
        low, high = 0, len(b)
        while low < high:
            mid = (low + high) // 2
            if b[mid] <= target:
                tmp = mid
                low = mid + 1
            else:
                high = mid - 1
        ans = max(ans, i + tmp)
    print(ans)
    return

def __starting_point():
    main()
__starting_point()

import sys
input = sys.stdin.readline # for speed up
sys.setrecursionlimit(10**7)

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

aa=[0]*(len(a)+1)
bb=[0]*(len(b)+1)

for ii in range(len(a)):
  aa[ii+1]=aa[ii]+a[ii]
for ii in range(len(b)):
  bb[ii+1]=bb[ii]+b[ii]
"""
print(a)
print(aa)
print(b)
print(bb)
"""
r=0
jmax=len(bb)-1
for ii in range(len(aa)):
  if aa[ii]>k:
    break
  for jj in range(jmax,-1,-1):
    if bb[jj]>k-aa[ii]:
      pass
    else:
      r=max(r,ii+jj)
      #print(r,ii,jj)
      jmax=jj
      break
print(r)


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

curr = 0
A_index = 0
B_index = 0
while curr + A[A_index] <= K:
    curr += A[A_index]
    A_index += 1
    if A_index == N:
        break

while curr + B[B_index] <= K:
    curr += B[B_index]
    B_index += 1
    if B_index == M:
        break

ans = A_index + B_index

while A_index:
    A_index -= 1
    curr -= A[A_index]
    if B_index == M:
        break
    while curr + B[B_index] <= K:
        curr += B[B_index]
        B_index += 1
        if B_index == M:
            break
    ans = max(ans, A_index + B_index)

print(ans)

from bisect import bisect_right

n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
a_cum = [0] * (n + 1)
b_cum = [0] * (m + 1)

for i in range(n):
    a_cum[i+1] = a_cum[i] + a[i]
for i in range(m):
    b_cum[i+1] = b_cum[i] + b[i]

for i in range(n+1):
    a_cnt = i
    rest = k - a_cum[i]
    if rest < 0:
        break
    b_cnt = bisect_right(b_cum,rest) - 1    
    cnt = max(cnt, a_cnt + b_cnt)

print(cnt)

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0]*(N+1), [0]*(M+1)
for i in range(N):
	a[i+1] = a[i] + A[i] 
for i in range(M):
	b[i+1] = b[i] + B[i]
 
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,B=eval("[0]+[*map(int,input().split())],"*2);s=t=x=0;j=m
for i in range(n+1):s+=A[i];A[i]=s
for i in range(m+1):t+=B[i];B[i]=t
for i in range(n+1):
  if A[i]>k:break
  while B[j]>k-A[i]:j-=1
  x=max(x,i+j)
print(x)

n,m,k = list(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])
 
num,x = 0,m
 
for i in range(len(A)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)


N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA =[0]
SB =[0]
for i in range(len(A)):
  SA.append(SA[i] + A[i])
for j in range(len(B)):
  SB.append(SB[j] + B[j])

l = M
ans = 0
for k in range(N+1):
  if SA[k] > K:
    break
  while SA[k] + SB[l] > K:
    l -= 1
  ans = max(ans, k + l)
print(ans)

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])
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)

from itertools import accumulate
import bisect

N, M, K = map(int, input().split())
A=[0]+list(accumulate(map(int,input().split())))
B=[0]+list(accumulate(map(int,input().split())))

X = 0
Y_num = [0]*(N+1)

for i in range(N+1):
    if A[i] <= K:
        X = bisect.bisect_right(B, K-A[i])
        Y_num[i] = i + X - 1

print(max(Y_num))


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

RA = [0]
RB = [0]

tmp = 0
for i in range(N):
    tmp += A[i]
    RA.append(tmp)

tmp = 0
for i in range(M):
    tmp += B[i]
    RB.append(tmp)
#print(RA)
#print(RB)

ans = 0
best = M
for i in range(N+1):
    if RA[i]>K:
        break
    while RB[best] > K - RA[i]:
        best -= 1
    ans = max(ans, i + best)

print(ans)


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])

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 = 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])
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)

def getmax(x,y):
    if x>y:
        return x
    else:
        return y
N,M,K = list(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[i]にはAの本をi冊読んだ時の時間がそれぞれ保存されている．
    a.append(a[i]+A[i])  #計算量を減らすため，a[i]（1冊前までにかかる時間）を用いる
for i in range(M):
    b.append(b[i]+B[i])

ans,j = 0,M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j] > K-a[i]:    #Bの本を読んだ場合の処理はここで実行される．
        j -=1
    ans = max(ans, i+j)
print(ans)


import sys
input = sys.stdin.readline # for speed up
sys.setrecursionlimit(10**7)

n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]*(len(a)+1)
bb=[0]*(len(b)+1)

for ii in range(len(a)):
  aa[ii+1]=aa[ii]+a[ii]
for ii in range(len(b)):
  bb[ii+1]=bb[ii]+b[ii]
  
ii=0
jmax=0
r=0
for jj in range(len(aa)):
  if aa[jj]>k:
    break
  else:
    r=ii+jj
    jmax=jj
    
for ii in range(len(bb)):
  for jj in range(jmax,-1,-1):
    if bb[ii]>k-aa[jj]:
      pass
    else:
      jmax=jj
      r=max(r,ii+jj)
      break
"""
for ii in range(m+1):
  print(c[ii])
"""  

print(r)


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

sum_as = [0]
sum_bs = [0]

for i in range(n):
    sum_as.append(sum_as[i]+a[i])
for i in range(m):
    sum_bs.append(sum_bs[i]+b[i])

ans = 0
i = 0
j = m

while i<=n and sum_as[i] <= k:
    while sum_bs[j] > k-sum_as[i]:
        j -= 1
    ans = max(ans, i+j)
    i += 1
print(ans)


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(1, N+1):
    A[i] += A[i-1]

i = N
total = 0
ans = 0
for j in range(M+1):
    total += B[j]
    while i >= 0 and A[i]+total > K:
        i -= 1
    if A[i]+total <= K:
        ans = max(ans, i+j)

print(ans)

n, m ,k = list(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])

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=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])
 
#print(a)
#print(b)
 
ans=0
j=M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    #print(i,j)
    ans=max(ans,i+j)
print(ans)

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])

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)

from bisect import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i+1] = SA[i] + A[i]
for i in range(M):
    SB[i+1] = SB[i] + B[i]
result = 0
for x in range(N+1):
    if SA[x] > K:
        break
    y = bisect(SB, K - SA[x]) - 1
    result = max(result, x + y)
print(result)

import bisect

N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sum1=[0]
sum2=[0]
for i in range(N):
    sum1.append(sum1[-1]+A[i])
for i in range(M):
    sum2.append(sum2[-1]+B[i])

ans=0
for i in range(N+1):
    if sum1[i]>K:
        break
    ans=max(ans,i+bisect.bisect_right(sum2,K-sum1[i])-1)
print(ans)


# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
n, m, k = list(map(int, input().split()))
A = list(accumulate(list(map(int, input().split()))))
B = list(accumulate(list(map(int, input().split()))))
A=[0]+A
B=[0]+B
ans = []
for i in range(n+1):
    c = bisect_right(B, k-A[i])-1
    if c!=-1:
        ans.append(c+i)
print((max(ans)))


import itertools
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ca=[0]+list(itertools.accumulate(a))
cb=[0]+list(itertools.accumulate(b))
ans=0
for i in range(n+1):
  wk=ca[i]
  if wk>k:
    break
  else:
    j=bisect.bisect(cb,k-ca[i])
    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()))

sum_a = [0]
sum_b = [0]

counta = 0
for x in a:
    counta += x
    if counta <= k:
        sum_a.append(counta)
    else:
        break

countb = 0
for y in b:
    countb += y
    if countb <= k:
        sum_b.append(countb)
    else:
        break


n = len(sum_b)

ans = 0

for i in range(len(sum_a)):
    for j in reversed(range(n)):
        if sum_a[i] + sum_b[j]<= k:
            ans = max(ans,i+j)
            n = j+1
            break
    else:
        break


print(ans)

from bisect import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i+1] = SA[i] + A[i]
for i in range(M):
    SB[i+1] = SB[i] + B[i]

result = 0
y = M
for x in range(N+1):
    if SA[x] > K:
        break
    while y >= 0 and SA[x] + SB[y] > K:
        y -= 1
    result = max(result, x + y)
print(result)

from itertools import accumulate as a
N,M,K=map(int,input().split());l=[0]
P=l+list(a(map(int,input().split())))
Q=l+list(a(map(int,input().split())))
i=j=0
f=lambda:P[i]+Q[j]<=K
while(i<=N)and f():i+=1
while i>=0:
 i-=1
 while(j<=M)and f():j+=1 
 l+=[i+j-1]
print(max(l))

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = np.zeros(n + 1, np.int64)
    ba = np.zeros(m + 1, np.int64)
    aa[1:] = a.cumsum()
    ba[1:] = b.cumsum()
    aa = aa[aa <= k]
    ba = ba[ba <= k]
    rs = np.searchsorted(ba, k - aa, side='right') - 1
    rs += np.arange(len(aa))
    r = rs.max()
    print(r)

def __starting_point():
    main()
__starting_point()

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_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list(accumulate(b))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)

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 j in range(M):
    b.append(b[j] + B[j])
ans = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i+j)
print(ans)

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

readtime_a = [0]
readtime_b = [0]
for i in range(n):
    readtime_a.append(readtime_a[i]+a[i])
for i in range(m):
    readtime_b.append(readtime_b[i]+b[i])

#print(readtime_a)
#print(readtime_b)

cnt = [0]
import bisect

for i in range(n+1):
    if readtime_a[i] > k:
        continue
    else:
        #print(i,bisect.bisect(readtime_b,k-readtime_a[i])-1,k-readtime_a[i])
        
        cnt.append(i-1 + bisect.bisect(readtime_b,k-readtime_a[i]))

print((max(cnt)))


N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
ASum, BSum = [0] * (N + 1), [0] * (M + 1)
ASum[0], BSum[0] = A[0], B[0]
AOver, BOver = -1, -1
for i in range(1, N + 1):
    ASum[i] = ASum[i-1] + A[i]
    if AOver == -1 and ASum[i] > K: AOver = i - 1
for i in range(1, M + 1):
    BSum[i] = BSum[i-1] + B[i]
    if BOver == -1 and BSum[i] > K: BOver = i - 1
if AOver == -1: AOver = N
if BOver == -1: BOver = M
ans = 0
import bisect
for i in reversed(range(AOver + 1)):
    if i + BOver <= ans: break
    time = K - ASum[i]
    ans = max(ans, i + bisect.bisect_right(BSum, time) - 1)

print(ans)

n, m, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
ans, j = 0, m
for i in range(n + 1):
    if a[i] > k: 
        break
    while a[i] + b[j] > k:
        j -= 1
    if i + j > ans:
        ans = i + j
print(ans)



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

b = 0
tb = 0

for i in range(M):
    if tb + B[i] > K:
        break
    tb += B[i]
    b = i+1

ans = [0, b]
m = b
a = 0
ta = 0

for i in range(N):
    if ta + A[i] > K:
        break
    a = i+1
    ta += A[i]
    while True:
        if ta + tb > K:
            if b == 0:break
            b -= 1
            tb -= B[b]
        else:
            if a + b > m:
                m = a + b
                ans = [a, b]
            break

print((ans[0]+ans[1]))




from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect_right
from itertools import accumulate

n,m,k=nii()
a=lnii()
b=lnii()
ar=[0]+list(accumulate(a))
br=list(accumulate(b))

ans=0
for i in range(n+1):
  time=ar[i]
  if time>k:
    break
  t_ans=i
  inx=bisect_right(br,k-time)
  t_ans+=inx
  ans=max(ans,t_ans)
print(ans)

from itertools import accumulate
from bisect import bisect_left

ri = lambda S: [int(v) for v in S.split()]


def rii():
    return ri(input())


N, M, K = rii()
A = rii()
B = rii()

i = j = 0

pA = [0] + list(accumulate(A))
pB = [0] + list(accumulate(B))

ans = 0
for i, a in enumerate(pA):
    br = 0
    if K >= a:
        r = K - a
        br = i
    
    if r:
        j = bisect_left(pB, r)
        if j != len(pB):
            if pB[j] > r:
                j -= 1
            br += j
    
    ans = max(ans, br)

print(ans)

import itertools
n,m,k=map(int,input().split())
a=list(itertools.accumulate(list(map(int,input().split()))))
b=list(itertools.accumulate(list(map(int,input().split()))))
a.insert(0,0)
a=[a[-i-1] for i in range(n+1)]
b.insert(0,0)
j=0
ans=0
for i in range(n+1):
  if a[i]<=k and j!=m+1:
    while a[i]+b[j]<=k:
      j+=1
      if j==m+1:
        break
    ans=max(ans,n-i+j-1)
print(ans)

n,m,k = list(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])

num,x = 0,m

for i in range(n+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)




n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
import itertools as it
sa = [0] + list(it.accumulate(a))
sb = [0] + list(it.accumulate(b))
maxi = 0
j = m 
for i in range(n+1):
    if sa[i] <= k:
        while sa[i] + sb[j] > k:
            j -= 1
        maxi = max(maxi, i + j)

print(maxi)






n,m,k = map(int,input().split())
shelfA = list(map(int,input().split()))
shelfB = list(map(int,input().split()))
prodA = [0]*(n+1)
prodB = [0]*(m+1)
for i in range(1,n+1):
    prodA[i] = prodA[i-1] + shelfA[i-1]
for i in range(1,m+1):
    prodB[i] = prodB[i-1] + shelfB[i-1]

ans = -1
j = m
for i in range(n+1):
    if(prodA[i]>k):
        break
    while(prodB[j] > k - prodA[i]):
        # print(prodB[j],j,k-prodA[i])
        j-=1
    # print(ans)
    ans = max(ans,i+j)



print(ans)

def binary_search(arr, num):
  left = 0
  right = len(arr)-1
  while right-left > 0:
    mid = (left+right) // 2
    if arr[mid] > num:
      right = mid
    else:
      left = mid + 1
  if arr[left] > num:
    return left
  else:
    return len(arr)

def main():
  n, m, k = map(int , input().split())
  a_books = list(map(int , input().split()))
  b_books = list(map(int , input().split()))
  b_cum_sum = [0] * (m+1)
  for i in range(m):
    b_cum_sum[i+1] = b_cum_sum[i] + b_books[i]
  current = 0
  ans = 0
  for i in range(n+1):
    if i > 0:
      current += a_books[i-1]
    if current > k:
      break
    rest = k - current
    index = binary_search(b_cum_sum, rest)
    ans = max(ans, i+index-1)
  print(ans)

def __starting_point():
  main()
__starting_point()

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumsum_a = [0] * (N + 1)
cumsum_b = [0] * (M + 1)

for i in range(1, N + 1):
    cumsum_a[i] = cumsum_a[i - 1] + A[i - 1]

for i in range(1, M + 1):
    cumsum_b[i] = cumsum_b[i - 1] + B[i - 1]

ans = 0
bi = M
for i in range(N+1):
    for j in range(bi, -1, -1):
        t = cumsum_a[i] + cumsum_b[j]
        if t <= K:
            ans = max(ans, i + j)
            bi = j
            break

print(ans)


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

s = sum(B)
ans = 0
i, j = 0, M - 1
while i < N:
    #print(s, i, j)
    if s <= K:
        ans = max(ans, i + j + 1)
        s += A[i]
        i += 1
    else:
        if j < 0: break
        s -= B[j]
        j -= 1
if s <= K:
    ans = max(ans, N + j + 1)
print(ans)

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])
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)

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    r = np.searchsorted(ba, k, side='right')    
    for i1, aae in enumerate(aa):
        if k < aae:
            break
        r = max(r, np.searchsorted(ba, k - aae, side='right') + i1 + 1)
    print(r)

def __starting_point():
    main()
__starting_point()

#172 緑
from itertools import accumulate
N,M,K=map(int,input().split())
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
cumsum=list(accumulate(Alist))
ans=0
num=0
flag=0
flag1=0
for i in range(N):
    if cumsum[i]>K:
        suma=cumsum[i-1]
        break
else:
    flag1=True
    ans+=1
    num+=1
    suma=cumsum[i]
ans+=i #index注意
num+=i
k=0
while suma+Blist[k]<=K:
    suma+=Blist[k]
    k+=1
    num+=1
    if k==M:
        print(num)
        return
ans=max(ans,num)
for j in range(i+1):
    if flag1:
        suma-=Alist[i-j]
    else:
        suma-=Alist[i-1-j]
    num-=1
    while suma+Blist[k]<=K:
        suma+=Blist[k]
        k+=1
        num+=1
        ans=max(ans,num)
        if k>=M:
            flag=True
            break
    if flag:
        break
ans=max(ans,num)
print(ans)

import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n, m, k = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    A = list(accumulate(A))
    B = list(accumulate(B))
    ans = 0
    j = m
    for i in range(n + 1):
        if A[i] > k:
            break
        while A[i] + B[j] > k:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


def __starting_point():
    main()
__starting_point()

n, m, k = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]

for i in range(len(aa)):
    asum.append(asum[i]+aa[i])
for i in range(len(bb)):
    bsum.append(bsum[i]+bb[i])

j = len(bsum)-1
ans = 0
for i in range(len(asum)):
    while j >= 0:
        if k >= asum[i] + bsum[j]:
            ans = max(ans, i+j)
            break
        else:
            j -= 1


print(ans)


n,m,k = list(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])
 
num,x = 0,m
 
for i in range(len(a)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)
 


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


def get_integral(nums):
    integral = [0]
    for i in range(0, len(nums)):
        integral.append(integral[i] + nums[i])

    return integral


integral_a = get_integral(A)
integral_b = get_integral(B)

ans = 0
bestj = M
for i in range(N+1):
    ta = integral_a[i]
    if ta > K:
        break
    while ta + integral_b[bestj] > K:
        bestj -= 1

    best = i + bestj
    ans = max(best, ans)

print(ans)




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

from itertools import accumulate
import bisect
cumsum_a = list(accumulate(a))
cumsum_b = list(accumulate(b))

ans = 0
for i in range(1, n+1):
    if cumsum_a[i-1] > k:
        break
    
    cnt_b = bisect.bisect(cumsum_b, k - cumsum_a[i-1])
    ans = max(ans, i + cnt_b)

for i in range(1, m+1):
    if cumsum_b[i-1] > k:
        break
    
    cnt_a = bisect.bisect(cumsum_a, k - cumsum_b[i-1])
    ans = max(ans, i + cnt_a)

print(ans)

import bisect

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

A=[0]
for i in range(N):
  A.append(arr1[i]+A[-1])
B=[0]
for i in range(M):
  B.append(arr2[i]+B[-1])

ans=0
for i in range(N+1):
  if A[i]>K:
    break
  j=bisect.bisect_right(B,K-A[i])-1
  ans=max(ans,i+j)
print(ans)

from bisect import bisect_left
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i+1] = SA[i] + A[i]
for i in range(M):
    SB[i+1] = SB[i] + B[i]
result = 0
for x in range(N+1):
    if SA[x] > K:
        break
    y = bisect_left(SB, K - SA[x] + 1) - 1
    result = max(result, x + y)
print(result)

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])
 
#print(a)
#print(b)
 
ans=0
j=M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    #print(i,j)
    ans=max(ans,i+j)
print(ans)

def main(N, M, K, A, B):
    #print(f'K: {K}, A: {A}, B: {B}')

    Ai = [0]
    for i in range(N):
        Ai.append(Ai[i]+A[i])
    #print(f'Ai: {Ai}')

    Bj = [0]
    for j in range(M):
        Bj.append(Bj[j]+B[j])
    #print(f'Bj: {Bj}')

    ans = 0
    # len(A) = N+1, len(B) = M+1
    best_i = 0
    for j in range(M+1):
        tmp = 0
        for i in range(best_i, N+1):
            #print(f'i: {N-i}, j: {j}')
            #if Ai[N-i] + Bj[M-j] <= K:
            if Ai[N-i] + Bj[j] <= K:
                #tmp = N - i + M - j
                tmp = N - i + j
                best_i = i
                break
        #print(f'tmp: {tmp}')
        if tmp > ans:
            ans = tmp

    return ans
            

def __starting_point():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    print((main(N, M, K, A, B)))


__starting_point()

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,i,j=0,0,0
a.append(10**9+1)
b.append(10**9+1)
while x+a[i]<=k:
    x+=a[i]
    i+=1
maxs=i
for c in range(n+m):
    if x+b[j]<=k:
        x+=b[j]
        j+=1
        maxs=max(maxs,i+j)
    else:
        if i>0:
          x=max(0,x-a[i-1])
          i-=1
print(maxs)

import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);return

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  
  else:break
Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
  else:break

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)
print(max(C))

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]
for i in range(N):
    a.append(a[i] + A[i])
ak = [i-K for i in a]
b = [0]
for i in range(M):
    b.append(b[i] - B[i])
import bisect
ans = 0
for i in range(M+1):
    k = bisect.bisect_right(ak,b[i])
    if k > 0:
        ans = max(k+i-1,ans)
print(ans)

# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 11:05:00 2020

@author: liang
"""

"""
片側を固定して、それぞれのケースに対して最適解を求める
それぞれのケースについて
index(b_i) =< index(b_i-1)
であるから、bの最大値bestを保存して探索することで重複探索を回避できる
"""
N, M, K = map(int, input().split())

A = [0] + [int(x) for x in input().split()]
B = [0] + [int(x) for x in input().split()]

s_b = 0
for i in range(M+1):
    s_b += B[i]
    if s_b > K:
        s_b -= B[i]
        best = i - 1
        break
else:
    best = M
res = best
#print(res)
s_a = 0
for i in range(N+1):
   # print("i", i)
    s_a += A[i]
    if s_a > K:
        break
    for j in reversed(range(best+1)):
        #print("j",j)
        if s_b <= K - s_a:
            if i + j > res:
                res = i + j
            best = j
            #print(i, j, s_a, s_b)
            break
        else:
            s_b -= B[j]
        
print(res)

import numpy as np
n, m, k = map(int, input().split())
li_a = np.array(list(map(int, input().split())))
li_b = np.array(list(map(int, input().split())))
a_i, b_i = np.hstack([np.array([0]),li_a.cumsum()]), np.hstack([np.array([0]),li_b.cumsum()])

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

n, m, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(1, n + 1):
    a[i] += a[i - 1]

for i in range(1, m + 1):
    b[i] += b[i - 1]

ans = 0

b_cnt = m

for a_cnt in range(n + 1):
    if a[a_cnt] > k:
        continue

    while a[a_cnt] + b[b_cnt] > k:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

print(ans)



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_c = [0] + list(accumulate(a))
b_c = [0] + list(accumulate(b))

result = []

for i in range(n+1):
    if k >= a_c[i]:
        k_temp = k - a_c[i]
        b_idx = bisect.bisect_left(b_c, k_temp+1)
        result.append(i + b_idx - 1)
    else:
        pass
result.append(0)
print(max(result))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#import sympy
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M, K = na()
A = na()
B = na()
now = 0
ct = 0
x = -1
y = 0
ans = 0
for i in range(N):
    if A[i] + now <= K:
        now += A[i]
        ct += 1
        x += 1
    else:
        break
res = K - now
ans = ct
while y < M:
    if res - B[y] >= 0:
        ct += 1
        ans = max(ct, ans)
        res -= B[y]
        y += 1
    elif res - B[y] < 0 and x >= 0:
        res += A[x]
        ct -= 1
        x -= 1
    else:
        break
print(ans)

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])

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())
tmp_a = list(map(int,input().split()))
tmp_b = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(n):
    a.append(a[i]+tmp_a[i])
for i in range(m):
    b.append(b[i]+tmp_b[i])
#print(a)
#print(b)
ans = 0
j = 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)

from itertools import accumulate
import bisect
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = list(accumulate(A, initial=0))
B = list(accumulate(B, initial=0))
ans = 0
for i, a in enumerate(A):
    remain = k - a
    if remain < 0:
        break
    tmp = i
    tmp += bisect.bisect_right(B, remain) - 1
    ans = max(ans, tmp)
print(ans)


n, m, k = list(map(int, input().split(" ")))
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
A = [0]
B = [0]
for i in a:
    if A[-1] > k:
        break
    A.append(A[-1] + i)
for i in b:
    if B[-1] > k:
        break
    B.append(B[-1] + i)

ans = 0
j = len(B) - 1

for i in range(len(A)):
    if A[i] > k:
        break
    while A[i] + B[j] > k:
        j -= 1
    ans = max(ans, i + j)

print(ans)


n, m, k = list(map(int, input().split()))
aArr = list(map(int, input().split()))
bArr = list(map(int, input().split()))

t = sum(bArr)
ans = 0
j = m

for i in range(n + 1):
  while j > 0 and t > k:
    j -= 1
    t -= bArr[j]
  if t > k:
    break
  ans = max(ans, i + j)
  if i == n:
    break
  t += aArr[i]

print(ans)