let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- as_.(i) + acc.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left min max_int @@
  Array.init n @@ fun i ->
    let sum = acc.(n) in
    let l = acc.(i) in
    let r = sum - l in
    abs (r - l)

