import qualified Data.ByteString.Char8 as C
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as U
import Data.Vector.Unboxed ((!))

main = sol <$> get <*> get <*> get >>= print

get = U.unfoldr (C.readInt . C.dropWhile (<'0')) <$> C.getLine

sol nmk a b = snd $ U.foldr' f ((n',0),n') sa
  where
  n = nmk!0
  k = nmk!2
  sa = U.takeWhile (<= k) $ U.scanl' (+) 0 a
  sb = U.takeWhile (<= k) $ U.scanl' (+) 0 b
  n' = U.length sa-1
  m' = U.length sb-1
  f s ((i,j),c) = ((i-1,j'),c')
    where
    j' = pred . fromMaybe (m'+1) $ find ((> k-s) . (sb!)) [j..m']
    c' = max c (i+j')