candyline (x:xs) all@(y:ys)
 | sum xs == 0 && sum all == 0 =  x
 | sum xs >= sum all           = x + candyline xs ys
 | otherwise                   = x + sum all

main = do
 n <- readLn :: IO Int
 candy1 <- map read . words <$> getLine
 candy2 <- map read . words <$> getLine
 print $ candyline candy1 candy2