(* 横一列のn個の整数の入力を、配列に格納する *)
let i_inp_array : 'a array -> int -> unit = fun a n ->
  let rec loop i =
    if i = n then ()
    else
      (a.(i) <- (Scanf.scanf " %d" (fun x -> x));
       loop (i + 1))
  in loop 0

let floop init_v init_i condition acc body =
  let rec loop i v =
    if condition i then loop (acc i) (body i v)
    else v
  in
  loop init_i init_v
   
(* ocamlc str.cma main.ml でコンパイルできる *)
let () =
  let n = Scanf.sscanf (input_line stdin) "%d" (fun a -> a) in
  let a = Array.make n 0 in
  let () = i_inp_array a n in
  let b = Array.make n 0 in
  let sum = floop 0 0 (fun i -> i < n) (fun i -> i + 1) (fun i v -> v + a.(i)) in
  for i = 0 to (n - 1) do
    if i = 0 then b.(i) <- a.(i)
    else
      b.(i) <- b.(i - 1) + a.(i)  
  done;
  let l = floop [] 0 (fun i -> i < n) (fun i -> i + 1) (fun i v -> (abs (b.(i) - (sum - b.(i)))) :: v) in
  let ans = List.fold_right min l 100000000 in
  print_int ans;
  print_newline ()
