program main
    use iso_fortran_env
    implicit none
    integer(int32) :: n, m, k
    integer(int32), allocatable :: a(:), b(:)
    integer(int32), allocatable :: at(:), bt(:)
    integer(int32) :: i, j, tmp, ans

    read *, n, m, k
    allocate(a(n))
    allocate(b(m))
    allocate(at(0:n), source = 0)
    allocate(bt(0:m), source = 0)

    read *, (a(i), i = 1, n)
    read *, (b(i), i = 1, m)

    do i = 1, n
        at(i) = at(i-1) + a(i)
    enddo

    do i = 1, m
        bt(i) = bt(i-1) + b(i)
    enddo

    i = 0
    ans = 0
    do while( ( k - at(i) ) >= 0 )
        tmp = k - at(i)
        j = maxloc( (bt(:) - tmp), 1, mask = ((bt(:) - tmp) <= 0) ) - 1
        if ( ans < (i+j) ) ans = i + j
        i = i + 1
        if ( i > n ) exit
    enddo

    print *, ans

end program main