let n = int(stdin.ReadLine())
let a = stdin.ReadLine().Split(' ') |> Array.map int
let sump (s,t) = Array.sub a s t |> Array.sum

seq {
for i in [1 .. n-3] do
for j in [i+1 .. n-2] do
for k in [j+1 .. n-1] do
yield [(0, i); (i, j-i); (j, k-j); (k, n-k)]
}
|> Seq.map (fun x -> x |> List.map sump)
|> Seq.map (fun x -> List.max(x) - List.min(x))
|> Seq.min
|> stdout.WriteLine
