program tsundoku
  implicit none
  integer :: n, m, h = 0, i, j
  integer(8) :: k
  integer(8), dimension(0:200001) :: a = 0, b = 0, x = 0, y = 0
  read(*,*) n, m, k
  read(*,*) a(1:n)
  read(*,*) b(1:m)
  do i = 1, n
    x(i) = x(i - 1) + a(i)
  end do
  do i = 1, m
    y(i) = y(i - 1) + b(i)
  end do
  j = m
  do i = 0, n
    if (x(i) > k) exit
    do while (y(j) > k - x(i))
      j = j - 1
    end do
    h = max(h, i + j)
  end do
  write(*,'(i0)') h
end program tsundoku