-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

-- 愚直解
naive :: Integer -> Integer -> Integer -> Integer
naive x k d = minimum $ map abs $ iterate (concatMap oneStep) [x] !! fromInteger k
-- iterate (\m -> m >>= oneStep) (pure x) !! fromInteger k
{- do
  let loop 0 t = pure t
      loop i t = do
        u <- oneStep t
        loop (i - 1) u
  loop k x
-}
  where
    oneStep :: Integer -> [Integer]
    oneStep t = [t - d, t + d]

solve :: Int64 -> Int64 -> Int64 -> Int64
solve x k d = let (q,r) = abs x `quotRem` d
              in if q <= k then
                   min r (abs (r - d))
                 else
                   x - k * d

main = do
  [x,k,d] <- map fromInteger . unfoldr (BS.readInteger . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve x k d
