import Data.List
import Control.Applicative

main :: IO ()
main = do
    n <- readLn
    xs <- map read . words <$> getLine
    print $ solve n xs

fstsplit :: Int -> [Int] -> [([Int],[Int])]
fstsplit n xs = map (flip splitAt xs) [2..(n-2)]

sndsplit :: [Int] -> (Int,Int)
sndsplit xs = minimumBy (\(x1,y1) (x2,y2) -> compare (abs (x1-y1)) (abs (x2-y2))) ys
    where ys = map ((\(l,r) -> (sum l, sum r)) . flip splitAt xs) [1..(length xs -1)]

mymin :: ((Int,Int),(Int,Int)) -> Int
mymin ((a,b),(c,d)) = maximum as - minimum as
    where as = [a,b,c,d]

solve :: Int -> [Int] -> Int
solve n = minimum . map (mymin . (\(xs, ys) -> (sndsplit xs, sndsplit ys))) . (fstsplit n)
