let rec fold_for a b v f = if a > b then v else fold_for (a+1) b (f a v) f
let () =
  Scanf.scanf "%d" @@ fun n ->
  let w = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  fold_for 0 (n-2) 10101010 (fun i v ->
    let s1 = fold_for 0 i 0 (fun i v -> v + w.(i)) in
    let s2 = fold_for (i+1) (n-1) 0 (fun i v -> v + w.(i)) in
    min v (abs (s1 - s2)))
  |> Printf.printf "%d\n"
