program tsundoku
  implicit none
  integer(16) :: n, m, k, x, y, z, i, j, max
  integer(16), allocatable :: a(:), b(:)

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

  x = 0
  if (sum(a) <= k ) then
     x = sum(a)
     y = n
  else
     do i = 1, n
        x = x + a(i)
        if (x > k) then
           x = x - a(i)
           y = i - 1
           exit
        end if
     end do
  end if
  
  max = y
  
  do i = y, 2, -1
     x = x - a(i)
     z = x
     do j = 1, m
        if ( z + sum(b) <= k ) then
           if (i + m > max) then
              max = i + m
           end if
        else
           z = z + b(j)
           if (z > k) then
              if ( i+j-1 > max ) then
                 max = i + j - 1
              end if
              exit
           end if
        end if
     end do
  end do

  if ( sum(b)<=k .and. m > max) then
     max = m
  end if

  write(*,'(i0)') max
  stop
end program tsundoku
  
