import Control.Monad
import Data.List

getInt = read <$> getLine :: IO Int
getInts = ((map read) . words) <$> getLine :: IO [Int]

f k x = 2 * min x (k-x)

main = do
    n <- getInt
    k <- getInt
    xs <- getInts
    print $ sum $ map (f k) xs