program c172
 
implicit none
integer :: n, m, k, g, h, i, j, l, x, y, z, p, s, t
integer, allocatable :: a(:), b(:)

read *, n, m, k
 
allocate(a(0:n))
allocate(b(0:m))
 
read *, a(1:n)
read *, b(1:m)

a(0) = 0
b(0) = 0
z = 0
x = 0
y = 0
p = 0
s = 0
j = 0

do h = 1, n
 x = x + a(h)
 if (x > k) then
  exit
 end if
end do

x = 0

do g = 0, h-1
 do i = 0, g
  x = x + a(i)
 end do
 
 s = k - x
 
 roop: do l = z, 0, -1
  do j = 0, l
   y = y + b(j)
  end do
  
  if(s >= y) then
   z = l
   exit roop
  end if
   
  end do roop

print *, g, z

if (p < g + z) then
 p = g + z
end if

x = 0
y = 0
s = 0
end do

!print *, p
 
end program c172