(def N (read))

(defn scan [^long i ^long s ^long v]
  (cond
  (>= i N)
    v
  (and (>= i 0) (<= v 0))
    (recur (inc i) -1 -1)
  (< s 0)
    (recur (inc i) -1 -1)
  :else
    (let [a (int (read))
          r (- s a)
          s2 (* 2 r)
        #_ #_  s2 (- st a)
          v2 (+ v s2)]
      (recur (inc i) s2 v2))))

(println
  (scan -1 1 0))
