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

main = breadIs >>= main'
    where
        main' [n, _, a, b] = breadIs >>= print . solve n a b

solve :: Int -> Int -> Int -> [Int] -> Int
solve n a b qs = run calc ([min a b, max a b], qs)

calc :: Memoizer ([Int], [Int]) Int -> Memoizer ([Int], [Int]) Int
calc f ([a, b], x : xs) = min <$> ((+ abs (a - x)) <$> f ([min x b, max x b], xs)) <*> ((+ abs (b - x)) <$> f ([min x a, max x a], xs))
calc _ _ = return 0

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

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.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.Map.insert x))) return
