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

!print *, s

if(abs(s) > abs(s-d)) then
 l = abs(s)
 s = abs(s-d)
 t = 1
else
 s = abs(s)
 l = abs(s-d)
 t = 0
end if
 
!print '(3(I5))', a, 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