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

    read*, x,k,d

    if (x>=0) then
        if (log10(dble(k))+log10(dble(d)) <= 18) then
            if (x-k*d > 0) 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
        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
    else
        if (log10(dble(k))+log10(dble(d)) <= 18) then
            if (x+k*d < 0) 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
        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 if
end program main