main = do
    _ <- getLine
    k <- fmap read getLine :: IO Int
    xs <- fmap (map read . words) getLine :: IO [Int]
    print $ solve k xs

solve :: Int -> [Int] -> Int
solve k = (* 2) . foldl (\acc x -> acc + min (abs x) (abs (k - x))) 0
