program ABC175C
    implicit none
    integer(8)X,K,D
    read*,X,K,D
    X=abs(X)

    if(X/D>=K)then
        print'(i0)',abs(X-D*K)
    else
        if(mod(X/D,2)==mod(K,2))then
            print'(i0)',abs(X-D*(X/D))
        else
            print'(i0)',min(abs(X-D*(X/D-1)),abs(X-D*(X/D+1)))
        end if
    end if
end program ABC175C