{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  n <- readLn
  k <- readLn
  xs <- getInts
  print $ solve n k xs

solve :: Int -> Int -> [Int] -> Int
solve n k xs = 2 * sum costs where
  costs = map cost xs
  cost x = min x . abs $ k - x

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine
