awk -M '\
function abs(x){
    return x > 0 ? x : -x
}
{
    X=$1; K=$2; D=$3
    if(K*D <= abs(X)){
        ans = abs(X) - K*D
        if(X<0)ans*=-1
        print ans;
        exit
    }
    tmp = int(abs(X)/D)
    if(X>0){
        X -= tmp*D
    }else{
        X += tmp*D
    }
    K -= tmp
    b = X
    while(1){
        S[X]++
        if(S[X]>1){
            a = X
            break
        }
        if(K==0){
            print abs(X);
            exit
        }
        b = X
        if(X>0){
            X -= D
        }else{
            X += D
        }
        K--
    }
    if(K%2==0){
        print abs(a)
    }else{
        print abs(b)
    }
    exit
}'