open Batteries
open Printf

let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let rev_cumsum l =
    let rec aux last res = function
      | [] -> res
      | hd :: tl -> 
        let last = last + hd in
        aux last (last::res) tl
    in
    aux 0 [] l
  in

  let l = List.rev (rev_cumsum a_lst) in
  let arr = Array.of_list l in

  let rec aux arr i init =
    let len = Array.length arr in
    let last = arr.(len-1) in
    let cur = arr.(i) in
    let next = arr.(i+1) in
    if i < len-2 then
      if abs((last - cur) - (cur - init)) > abs((last - next) - (next - init)) then
        aux arr (i+1) init
      else i, (cur - init), (last - cur)
    else i, (cur - init), (last - cur)
  in

  let ans = ref max_int in
  let rec loop i arr left_i right_i =
    let len = Array.length arr in
    if i < len-1 then 
      let left = Array.sub arr 0 i in
      let right = Array.sub arr i (len-i) in
      let left_i,s1,s2 = aux left left_i 0 in
      let right_i,s3,s4 = aux right right_i arr.(i-1) in
      let tmp =
        List.max [s1;s2;s3;s4] - List.min [s1;s2;s3;s4] 
      in
      if !ans < tmp then () else ans := tmp;
      let right_i = if right_i = 0 then 0 else right_i-1 in
      loop (i+1) arr left_i (right_i)
    else ()
  in
  loop 2 arr 0 0;
  printf "%d\n" !ans;
