let inf = 10101010101010
let n = Scanf.scanf "%d" (fun x -> x)
let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) |> Array.to_list
let sum = List.fold_left (+) 0 a
let f (v, s) (i, a) = if i = n-1 then v, s else min v (abs @@ sum - 2*(s+a)), s+a
let () =
  a |> List.mapi (fun i e -> i, e)
  |> List.fold_left f (inf, 0)
  |> fst |> Printf.printf "%d\n"