import Control.Monad
import Control.Applicative
import Data.List


  
main :: IO ()
main = do
  input <- getLine
  let uuu = map read (words input ) :: [Integer] 
  putStrLn (solve (abs (head uuu)) (head (tail uuu)) (head (tail (tail uuu))))



--solve :: Integer -> Integer -> Integer  -> String

solve qX qK qD = show (max (min ((((qK*qD)-qX)) `mod` (qD+qD)) (qD+qD-((((qK*qD)-qX)) `mod` (qD+qD))))  (qX-(qK*qD)))




