main :: IO ()
main = do
    [n, m, k] <- (map read) . words <$> getLine
    an <- (map read) . words <$> getLine
    bm <- (map read) . words <$> getLine
    print . maximum $ solve k an bm

solve :: Int -> [Int] -> [Int] -> [Int]
solve k an bm = f 0 0 an bm where
    f c i [] []     = [i]
    f c i _ _
      | c == k = [i]
      | c > k = [i - 1]
    f c i (a:an) [] = f (c + a) (i + 1) an []
    f c i [] (b:bn) = f (c + b) (i + 1) [] bn
    f c i ans@(a:an) bns@(b:bn) = f (c + a) (i + 1) an bns ++ f (c + b) (i + 1) ans bn
