import Control.Applicative

main :: IO ()
main = do
  n <- readLn :: IO Int
  k <- readLn :: IO Int
  xs <- map read . words <$> getLine

  print $ sum $ map (dist k) xs

dist :: Int -> Int -> Int
dist k x = 2*(x`min`(k-x))