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 n = n-1 in
  let len = Array.length arr in

  let ans = ref max_int in
  let rec loop i j k arr cnt =
    if k < n then (
      let tmp =
        List.max [arr.(i); (arr.(j)-arr.(i)); (arr.(k)-arr.(j)); (arr.(len-1)-arr.(k));] -
        List.min [arr.(i); (arr.(j)-arr.(i)); (arr.(k)-arr.(j)); (arr.(len-1)-arr.(k));] in
      if !ans < tmp then () else ans := tmp;
      loop i j (k+1) arr (cnt+1)
    ) else (
      if j < n-1 then (
        loop i (j+1) (j+2) arr cnt
      ) else (
        if i < n-1 then (
          loop (i+1) (i+2) (i+3) arr cnt
        ) else (
          ()
        )
      )
    )
  in
  loop 0 1 2 arr 0;
  printf "%d\n" !ans
