{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List
import Control.Arrow (second)

solve :: Int -> [Int] -> [Int] -> Int
solve a xs ys = go 0 a a xs ys
  where
    go !c l r [] [] = c
    go !c l r (x:xs) []
        | abs (l - x) == mx = go (c + abs (l - x)) x r xs []
        | abs (r - x) == mx = go (c + abs (r - x)) l x xs []
      where
        mx = maximum [abs (l - x), abs (r - x)]
    go !c l r [] (y:ys)
        | abs (l - y) == mx = go (c + abs (l - y)) y r [] ys
        | abs (r - y) == mx = go (c + abs (r - y)) l y [] ys
      where
        mx = maximum [abs (l - y), abs (r - y)]
    go !c l r (x:xs) (y:ys)
        | abs (l - x) == mx = go (c + abs (l - x)) x r xs (y:ys)
        | abs (r - x) == mx = go (c + abs (r - x)) l x xs (y:ys)
        | abs (l - y) == mx = go (c + abs (l - y)) y r (x:xs) ys
        | abs (r - y) == mx = go (c + abs (r - y)) l y (x:xs) ys
      where
        mx = maximum [abs (l - x), abs (r - x), abs (l - y), abs (r - y)]

main :: IO ()
main = do
    n <- readLn
    (a:as) <- fmap sort $ replicateM n readLn :: IO [Int]
    let (xs, ys) = second reverse $ splitAt (n `div` 2) as
    print $ solve a xs ys