(defn create-data [s]
  (map #(Long/parseLong %) (.split s " ")))

(defn sum [xs]
  (reduce + xs))

(defn zipWith [xs ys]
  (map vector xs ys))

(defn addCandy [[summ restY1 restY2] [y1 y2]]
  (cond (and (> restY1 restY2) (zero? (- restY1 y1))) [(+ summ y1 y2) (- restY1 y1) (- restY2 y2)]
        (and (> restY1 restY2) (<= (- restY1 y1) (- restY2 y2))) [(+ summ y1 y2) (- restY1 y1) (- restY2 y2)]
        (> restY1 restY2) [(+ summ y1) (- restY1 y1) (- restY2 y2)]
        (and (<= restY1 restY2) (zero? summ)) [(+ summ y1 y2) (- restY1 y1) (- restY2 y2)]
        :else [(+ summ y2) (- restY1 y1) (- restY2 y2)]
        ))
  
(defn candies [n ys1 ys2]
  (->> (reduce addCandy [0 (sum ys1) (sum ys2)] (zipWith ys1 ys2))
       (first)))

(def a (read))
(def b (read-line))
(def c (read-line))
(println (candies a (create-data b) (create-data c)))