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

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

(defn addCandy2 [summ xs ys]
   (cond
     (empty? ys) summ
     (>= (sum xs) (sum ys)) (recur (+ summ (first xs)) (rest xs) (rest ys))
     :else (recur (+ summ (first ys)) [] (rest ys))))

(defn candies2 [n ys1 ys2]
  (let [ys1' (drop 1 ys1) ys2' (drop-last ys2)]
    (->>
     (addCandy2 (first ys1) ys1' ys2')
     (+ (last ys2)))))

(println (candies2 (Long/parseLong (read-line)) (create-data (read-line)) (create-data (read-line))))
