import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad.State (State, evalState, gets, modify)
import Data.Map.Strict (Map, lookup, insert, empty)
import Data.Maybe (maybe)

main :: IO ()
main = breads >>= main'
    where
        main' [n, z, w] = breads >>= print . solve z w

solve :: Int -> Int -> [Int] -> Int 
solve z w xs = run calc (True, xs, w)

type Key = (Bool, [Int], Int)

calc :: Memoizer Key Int -> Memoizer Key Int
calc f (b, x : y : zs, w) = cmpf b <$> f (b, y : zs, w) <*> f (not b, y : zs, x)
calc _ (_, x : _, w) = return . abs $ x - w

cmpf :: Bool -> Int -> Int -> Int
cmpf b 
    | b = max
    | otherwise = min

type Memoizer a b = a -> State (Map a b) b

run :: (Ord a) => (Memoizer a b -> Memoizer a b) -> a -> b
run f = flip evalState empty . memoizeFix f

memoizeFix :: (Ord a) => (Memoizer a b -> Memoizer a b) -> Memoizer a b
memoizeFix f x = gets (Data.Map.Strict.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.Map.Strict.insert x))) return

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

