PROGRAM C
  IMPLICIT NONE
  INTEGER(8) :: x,k,d,i
  INTEGER(8) :: a=1000000000000000
  INTEGER(8),allocatable :: tmp(:)
  READ *, x,k,d
  allocate(tmp(0:k))
  tmp(0:k)=1000000000000000

  DO i=0,k
    tmp(i)=d*(-k+2*i)
    IF(ABS(x+tmp(i))<a) a=ABS(tmp(i))
  END DO

  deallocate(tmp)
  PRINT *, a
END PROGRAM C
