import scala.io.StdIn._
object Main {
  def main(args:Array[String]) {
    val read = readLine().split(' ').map(_.toLong)
    val move = read(0) / read(2)
    if(move < read(1)) {
      val vibration = read(1) - move
      if(vibration % 2 == 0) println(math.abs(read(0) % read(2)))
      else println(math.abs((read(0) % read(2)) - read(2)))
    }else {
      if(0 <= read(0)) println(math.abs(read(0) - (read(1) * read(2))))
      else println(math.abs(read(0) + (read(1) * read(2))))
    }
  }
}