X,K,D=list(map(int,input().split()))



X=abs(X)

a=min(K,X//D)

X-=a*D

K-=a

#print(X,K)

if K%2:

    X=abs(X-D)

ans=X

print(ans)

X,K,D=list(map(int,input().split()))



X=abs(X)

a=min(K,X//D)

ans=X-a*D

if (K-a)%2:

    ans=D-ans



print(ans)

X, K, D = list(map(int, input().split()))
X = abs(X)
a = min(K, X // D)
X -= a * D
K -= a
# print(X,K)
if K % 2:
    X = abs(X - D)
ans = X
print(ans)

X, K, D = list(map(int, input().split()))
X = abs(X)
a = min(K, X // D)
ans = X - a * D
if (K - a) % 2:
    ans = D - ans
print(ans)

-X -= a * D -K -= a -# print(X,K) -if K % 2: -    X = abs(X - D) -ans = X +ans = X - a * D +if (K - a) % 2: +    ans = D - ans