import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m,k] <- getIntList
    as <- getIntList
    bs <- getIntList
    let sa = reverse $ takeWhile (<k) $ scanl (+) 0 as
        sb = takeWhile (<k) $ scanl (+) 0 bs
        ans = zipWith (\a i -> i + length (takeWhile (< k-a) sb)) sa [0..]
    print . maximum $ solve k (length sa - 1) sa sb
    
solve k l [] _ = [0]
solve k l _ [] = [0]
solve k l (a:sa) (b:sb)
    | a + b <= k = l : solve k (l+1) (a:sa) sb
    | a + b > k = solve k (l-1) sa (b:sb)                    
