program c175

implicit none
integer(16) :: x, k, d, a, s, l, t

read *, x, k, d

a = int(abs(x) / d)
s = abs(x) - a * d

if(abs(s) > abs(s-d)) then
 s = abs(s-d)
 l = abs(s)
 t = 1
else
 s = abs(s)
 l = abs(s-d)
 t = 0
end if

!print *, s, l

a = k - int(abs(x) / d) - t

if(abs(x) > d * k) then
 print *, abs(x) - d * k
else if(mod(a, 2) == 0) then
 print *, s
else if(mod(a, 2) == 1) then
 print *, l
end if

end program c175