let _ =
    let _ = read_line () in
    let (hd::tl) = List.map int_of_string (Str.split (Str.regexp " ") (read_line ())) in
    let (sum::spls) = List.fold_left (fun (h::t) x -> (h+x)::h::t) [hd] tl in
    print_int (List.fold_left (fun m x -> min (abs (x*2-sum)) m) max_int spls)