lm' [] = []
lm' x@(x0:[]) = x
lm' x@(x0:x1:xs) =
    if x1 < x0
    then lm' (x1:xs)
    else x

lm'' [] = []
lm'' x@(x0:[]) = x
lm'' x@(x0:x1:xs) =
    if x1 > x0
    then lm'' (x1:xs)
    else x

lm x = lm' $ lm'' x

maximum' [] = 0
maximum' x = maximum x

ans1 (x:[]) = 0
ans1 x = 
    let m = lm x
    in  
        if length m <= 1
        then 0
        else
            let min = head m
                max = maximum' $ drop 1 m
                p0  = max - min
                p1  = ans1 $ drop 1 m
            in
                maximum [p0,p1]

ans2 (x0:x1:[]) = x1 - x0
ans2 (x:xs) = 
    let min = x
        max = maximum xs
        p0  = max - min
        p1  = ans2 xs
    in
        maximum [p0,p1]

ans x@(x0:xs) =
    let m = lm x
        p1 = if length m <= 1
             then ans2 x
             else ans1 x
        p0 = (maximum xs) - x0
    in
      maximum [p0,p1]

main = do
    n <- getLine
    c <- getContents
    let i = map read $ lines c :: [Int]
        o = ans i
    print o