open Batteries
let x, k, d = Scanf.sscanf (read_line()) "%d %d %d" (fun x k d -> x, k, d)

let move = min (x / d) k
let new_x, used_k = 
  if k < (x / d) then x - (move * d), move else (
    if abs @@ x - ((move + 1) * d) < abs @@ x - (move * d) then (x - ((move + 1) * d), move + 1) else x - (move * d), move
  )

let new_k = k - used_k

let () = (
  if new_k mod 2 = 0 then Printf.printf "%d\n" new_x else (
    Printf.printf "%d\n" @@ min (abs @@ new_x + d) (abs @@ new_x - d)
  )
)
