import Data.String

readInt :: IO Int
readInt = readLn

readInts :: IO [Int]
readInts = do
  s <- getLine
  return $ map read (words s)

main = do
  n <- readInt
  k <- readInt
  xs <- readInts
  let result = go2 n k xs
  putStrLn $ show result

go x y = x^2 - y

go2 :: Int -> Int -> [Int] -> Int
go2 n k xs = sum $ map (\x -> 2 * (min x (abs $ x-k))) xs