program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,s,t,l,u
    
    integer(8),allocatable :: a(:),b(:)
  
    read(*,*)n,m,k
    allocate(a(n),b(m))
    read(*,*)a
    read(*,*)b


    
    do i=1,n
        s=s+a(i)
        if (s>k)then
            
            s=s-a(i-1)
            t=k-s
            s=i-1
            exit
        end if
    end do
    if(s>=0)then
        t=k-s
        s=n
    end if
    l=s
    u=s
    do i=1,m
        
        do while(b(i)>t)
            t=t+a(l)
            l=l-1
            u=u-1
        end do
        u=u+1
       
        if (u>s)then
            s=u
        end if
        t=t-b(i)
    end do
    
    write(*,*)s
       




    
  
    stop
end program sample
  

