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

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 6 2 4
-- 2
-- >>> solve 7 4 3
-- 1
-- >>> solve 10 1 2
-- 8
-- >>> solve 1000000000000000 1000000000000000 1000000000000000
-- 1000000000000000
--
-- prop> solve x k d == solve (-x) k d
--
-- prop> solve x 0 1 == abs x
--
solve :: Int -> Int -> Int -> Int
solve x k d
  | k < 0 || d < 1           = -1
  | x < 0                    = solve (-x) k d
  | x > k * d                = x - k * d
  | even (k - kr) && xr >= 0 = xr
  | even (k - kl) && xl <  0 = abs xl
 where
  kr = floor $ x % d
  kl = kr + 1
  xr = x - kr * d
  xl = x - kl * d
