open Str

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let () =
  let n = read_int () in
  let al = read_list int_of_string in
  let rec iter sn ar mx = function
      x :: [] -> mx
    | x :: xs -> let sn' = sn + x in
                 let ar' = ar - x in
                 iter sn' ar' (min (abs (sn' - ar')) mx) xs
    | _ -> failwith "splitting_pile"
  in
  let sn = List.hd al in
  let ar = List.fold_left (+) 0 (List.tl al) in
  iter sn ar (abs (sn - ar)) (List.tl al) |> string_of_int |> print_endline
