from numpy import*

n,m,k,*a=int_(open(0).read().split())

c=cumsum

b=c([0]+a[:n])

print((max(list(range(len(b:=b[b<=k])))+searchsorted(c(a[n:]),k-b+1))))
n,m,k,*a=list(map(int,open(0).read().split()))

s=sum(a[:n])

x=i=j=n

a+=k,

while~i:

 while s+a[j]<=k:s+=a[j];j+=1

 if s<=k:x=max(x,i+j)

 i-=1;s-=a[i]

print((x-n))
from numpy import *

n, m, k, *a = int_(open(0).read().split())
c = cumsum
b = c([0] + a[:n])
print((max(list(range(len(b := b[b <= k]))) + searchsorted(c(a[n:]), k - b + 1))))

n, m, k, *a = list(map(int, open(0).read().split()))
s = sum(a[:n])
x = i = j = n
a += (k,)
while ~i:
    while s + a[j] <= k:
        s += a[j]
        j += 1
    if s <= k:
        x = max(x, i + j)
    i -= 1
    s -= a[i]
print((x - n))

-from numpy import * - -n, m, k, *a = int_(open(0).read().split()) -c = cumsum -b = c([0] + a[:n]) -print((max(list(range(len(b := b[b <= k]))) + searchsorted(c(a[n:]), k - b + 1)))) +n, m, k, *a = list(map(int, open(0).read().split())) +s = sum(a[:n]) +x = i = j = n +a += (k,) +while ~i: +    while s + a[j] <= k: +        s += a[j] +        j += 1 +    if s <= k: +        x = max(x, i + j) +    i -= 1 +    s -= a[i] +print((x - n))