import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  [x, k, d] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    x' = abs x :: Int
    (q, r) = x' `divMod` d
    m = q - k :: Int
    n | 0 <= m    = x' - k * d
      | even m    = r
      | otherwise = d - r
  print n

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
