let n = Scanf.scanf " %d" (+) 0
let ws = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let s = Array.fold_left (+) 0 ws
let _ = Array.fold_left (fun (m, s1) w -> min m @@ abs @@ s1 + w - (s - (s1 + w)), s1 + w) (max_int, 0) ws |> fst |> Printf.printf "%d\n"