import bisect

from itertools import*

n,m,k,*x=[int(v)for l in open(0) for v in l.split()];a=accumulate([0]+x[:n]);b=[*accumulate(x[n:])];print((max(i+bisect.bisect(b,k-v)for i,v in enumerate(a)if v<=k)))
from bisect import*

from itertools import*

n,m,k,*x=list(map(int,open(0).read().split()));c=accumulate;a=c([0]+x[:n]);b=[*c(x[n:])];print((max(i+bisect(b,k-v)for i,v in enumerate(a)if v<=k)))
import bisect
from itertools import *

n, m, k, *x = [int(v) for l in open(0) for v in l.split()]
a = accumulate([0] + x[:n])
b = [*accumulate(x[n:])]
print((max(i + bisect.bisect(b, k - v) for i, v in enumerate(a) if v <= k)))

from bisect import *
from itertools import *

n, m, k, *x = list(map(int, open(0).read().split()))
c = accumulate
a = c([0] + x[:n])
b = [*c(x[n:])]
print((max(i + bisect(b, k - v) for i, v in enumerate(a) if v <= k)))

-import bisect +from bisect import * -n, m, k, *x = [int(v) for l in open(0) for v in l.split()] -a = accumulate([0] + x[:n]) -b = [*accumulate(x[n:])] -print((max(i + bisect.bisect(b, k - v) for i, v in enumerate(a) if v <= k))) +n, m, k, *x = list(map(int, open(0).read().split())) +c = accumulate +a = c([0] + x[:n]) +b = [*c(x[n:])] +print((max(i + bisect(b, k - v) for i, v in enumerate(a) if v <= k)))