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

x = abs(X)

print((x-K*D if x > K*D else abs(x%D-(K-x//D)%2*D)))
x, k, d = list(map(int, input().split()))



t = min(abs(x)//d, k)

u = abs(x)-d*t

print((abs(u-d*((k-t)%2))))
X, K, D = list(map(int, input().split()))
x = abs(X)
print((x - K * D if x > K * D else abs(x % D - (K - x // D) % 2 * D)))

x, k, d = list(map(int, input().split()))
t = min(abs(x) // d, k)
u = abs(x) - d * t
print((abs(u - d * ((k - t) % 2))))

-X, K, D = list(map(int, input().split())) -x = abs(X) -print((x - K * D if x > K * D else abs(x % D - (K - x // D) % 2 * D))) +x, k, d = list(map(int, input().split())) +t = min(abs(x) // d, k) +u = abs(x) - d * t +print((abs(u - d * ((k - t) % 2))))