let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let x = Array.make (n-1) 0 in
  x.(0) <- a.(0);
  for i = 1 to n - 2 do
    x.(i) <- x.(i-1) + a.(i);
  done;
  let y = Array.make (n - 1) 0 in
  y.(0) <- a.(n-1);
  for i = 1 to n - 2 do
    y.(i) <- y.(i-1) + a.(n-1-i);
  done;
  let ans = ref max_int in
  for i = 0 to n - 2 do
    let t = abs (x.(i) - y.(n-2-i)) in
    if t < !ans then ans := t;
  done;
  Printf.printf "%d\n" !ans