program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: x,k,d,n

    read*, x,k,d
    x = abs(x)

    if (x/d >= k) then
        print*, x-k*d
    else
        n = x/d
        if (mod(n,2_8) == mod(k,2_8)) then
            print*, mod(x,d)
        else
            print*, -(mod(x,d)-d)
        end if
    end if
end program main