import Control.Monad
import Data.Function
import Data.Char
import Data.List
import Text.Read
import Text.ParserCombinators.ReadPrec

import Data.Ratio

newtype Pair a b = Pair { getPair :: (a, b) }

instance (Read a, Read b) => Read (Pair a b) where
  readPrec = Pair `dot` (,) <$> readPrec <* get <*> readPrec

instance (Show a, Show b) => Show (Pair a b) where
  show (Pair (a, b)) = show a ++ " " ++ show b

readPair :: IO (Int, Int)
readPair = getPair <$> readLn

infixr 8 `dot`
dot :: (c -> d) -> (a -> b -> c) -> a -> b -> d
dot = ((.).(.))

main :: IO ()
main = do
  [x, k, d] <- map read . words <$> getLine
  print $ solve x k d

solve :: Int -> Int -> Int -> Int
solve x k d
  | abs x > k * d = abs x - k * d
  | even (k - k0) = (abs x0) `min` (abs (x0 + 2*d))
  | otherwise     = (abs (x0 - d)) `min` (abs (x0 + d))
 where
  k0 = ceiling $ (abs x) % d
  -- = minimum [ k | abs x <= k * d ]
  x0 = abs x - k0 * d
  -- <= 0
  
