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

main = do

   n <- readLn :: IO Int
   k <- readLn :: IO Int
   xn <- map read . words <$> getLine
   
   let ans = map (solve k) xn
   print (sum ans)
   


solve :: Int -> Int -> Int
solve k xi = if (k-xi) > xi
             then 2 * xi
             else 2 * (k-xi)