import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  k <- readLn :: IO Int
  xs <- fmap (\x -> read x :: Int) <$> words <$> getLine
  print $ 2 * $ sum $ fmap (\x -> min x (k - x)) xs