let () = Scanf.scanf "%d" @@ fun n ->
  let ws = Array.init n @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- acc.(i) + ws.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left min max_int @@
  Array.init n @@ fun i -> abs (acc.(n) - 2 * acc.(i))