main = do
    getLine
    d <- readLn
    ns <- getLine
    print $ sum $ map (f d) $ map read (words ns)
      where
        f :: Int -> Int -> Int
        f ds p
          | (ds - p) < (p - 0) = 2 * (ds - p)
          | otherwise          = 2 * p