module Main where

import Control.Applicative
import Control.Monad
import Data.List

f1 :: Int -> Int -> Int
f1 k x = (* 2) $ min x (abs $ x - k)

main :: IO ()
main = do
    getLine
    k <- readLn
    xs <- fmap read . words <$> getLine :: IO [Int]
    let ans = sum $ fmap (f1 k) xs
    print ans