import Data.Ratio

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

-- |
-- >>> solve 6 2 4
-- 2
--
-- >>> solve 7 4 3
-- 1
--
-- >>> solve 10 1 2
-- 8
--
-- >>> solve 1000000000000000 1000000000000000 1000000000000000
-- 1000000000000000
--
-- prop> k >= 1 && d >= 1 ==> solve x k d >= 0
--
-- prop> k >= 1 && d >= 1 ==> solve (-x) k d == solve x k d
--
solve :: Integer -> Integer -> Integer -> Integer
solve x k d
  | x < 0     = solve (-x) k d
  | x0 >= 0   = x0
  | k == 0    = x
  | k == 1    = abs (x - d)
  | otherwise = solve (x - k0 * d) (k0 `mod` 2) d
 where
  x0 = x - k * d
  k0 = floor (x % d)
