main = do
    [n,m,k] <- map read . words <$> getLine :: IO [Int]
    as <- zip [0..] . takeWhile (<=k) . scanl (+) 0 . map read . words <$> getLine
    bs <- zip [0..] . takeWhile (<=k) . scanl (+) 0 . map read . words <$> getLine
    print $ as
    print $ (reverse bs)
    print $ maximum $ solve as (reverse bs) k

solve [] [] km = []
solve [] _ km = []
solve _ [] km = []
solve (a:as) (b:bs) km = [solveSub  a (b:bs) km] ++ solve as (b:bs) km 

solveSub a [] km = 0
solveSub a (b:bs) km | (sum . map snd) [a,b] <= km = (sum . map fst)[a,b]
                     | otherwise = solveSub a bs km
