-- 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
import qualified Test.QuickCheck as QC

naive :: Integer -> Integer -> Integer -> Integer
naive x k d = minimum $ map abs $ iterate (>>= oneStep) (pure x) !! fromInteger k
  where
    oneStep :: Integer -> [Integer]
    oneStep y = [y + d, y - d]

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

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

prop :: Int64 -> QC.Positive (QC.Small Int64) -> QC.Positive Int64 -> Bool
prop x (QC.Positive (QC.Small k)) (QC.Positive d) = fromIntegral (solve x k d) == naive (fromIntegral x) (fromIntegral k) (fromIntegral d)

runTest :: IO ()
runTest = QC.quickCheck $ QC.forAll (QC.choose (1,15)) $ \k -> \x d -> prop x (QC.Positive (QC.Small k)) d
