program walking_takahashi
  implicit none
  integer(16) :: x, k, d, m
  read(*,*) x, k, d
  if (k * d < abs(x)) then
    write(*,'(i0)') abs(merge(k * d + x, x - k * d, x < 0))
    stop
  end if
  m = abs(x) / d
  x = merge(m * d + x, x - m * d, x < 0)
  k = k - m
  if (mod(k, 2_16) == 0) then
    write(*,'(i0)') abs(x)
  else
    write(*,'(i0)') abs(merge(d + x, x - d, x < 0))
  end if
end program walking_takahashi