import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  n <- unsafeSignedDecimal <$> T.getLine :: IO Int
  (a1 : as) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  bs <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    abs = zip as bs
    k = fst . foldl step (0, a1) $ abs
    step (q, r) (a, b) = if r + a <= b then (q + r + a, 0) else if r <= b then (q + b, r + a - b) else (q + b, a)
  print k

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
