program main
    implicit none
    integer(8) n,m,k
    integer(8), allocatable, dimension(:) :: a, b
    integer(8) i, j, time, na, nb, c, cmax

    read(*,*) n,m,k
    allocate(a(n))
    read(*,*) a
    allocate(b(m))
    read(*,*) b

    time = 0
    do i = 1, n
        time = time + a(i)
        if(time > k) then
            time = time - a(i)
            na = i-1
            c = i-1
            exit
        end if
        if(i == n) then
            na = n
            c = n
        end if
    end do


    do i = 1, m
        time = time + b(i)
        if(time > k) then
            time = time - b(i)
            nb = i-1
            exit
        end if
        c = c + 1
    end do


    cmax = c

    if (c == (n+m)) then
        write(*,*) c
    else
        do i = 0, na-1
            time = time - a(na-i)
            c = c - 1
            do j = nb+1, m
                time = time + b(j)
                if(time > k) then
                    time = time - b(j)
                    nb = j-1
                    exit
                end if
                c = c + 1
            end do
            if(c > cmax) then
                cmax = c
            end if
        end do

        write(*,*) cmax
    end if


end program
