xkd = input().split()
X = int(xkd[0])
K = int(xkd[1])
D = int(xkd[2])

X = abs(X)
ans = 0
times = int(X/D)
oneMore = False
if X%D > abs(D-X%D):
    times+=1

if times > K:
    ans = X - (D*K)
else:
    if (times%2) == (K%2):
        ans = min(X%D, (D-X%D))
    else:
        ans = max(X%D, (D-X%D))

print(ans) xkd = input().split() xkd input().split() ().split () input split X = int(xkd[0]) X int(xkd[0]) int xkd[0] xkd 0 K = int(xkd[1]) K int(xkd[1]) int xkd[1] xkd 1 D = int(xkd[2]) D int(xkd[2]) int xkd[2] xkd 2 X = abs(X) X abs(X) abs X ans = 0 ans 0 times = int(X/D) times int(X/D) int X/D X D oneMore = False oneMore False if X%D > abs(D-X%D):
    times+=1 X%D > abs(D-X%D) X%D X D abs(D-X%D) abs D-X%D D X%D X D times+=1 times 1 if times > K:
    ans = X - (D*K)
else:
    if (times%2) == (K%2):
        ans = min(X%D, (D-X%D))
    else:
        ans = max(X%D, (D-X%D)) times > K times K ans = X - (D*K) ans X - (D*K) X D*K D K if (times%2) == (K%2):
        ans = min(X%D, (D-X%D))
    else:
        ans = max(X%D, (D-X%D)) (times%2) == (K%2) times%2 times 2 K%2 K 2 ans = min(X%D, (D-X%D)) ans min(X%D, (D-X%D)) min X%D X D D-X%D D X%D X D ans = max(X%D, (D-X%D)) ans max(X%D, (D-X%D)) max X%D X D D-X%D D X%D X D print(ans) print ans ans = 0 0 ans oneMore = False False oneMore X = int(xkd[0]) int(xkd[0]) X K = int(xkd[1]) int(xkd[1]) K ans = max(X%D, (D-X%D)) max(X%D, (D-X%D)) ans xkd = input().split() input().split() xkd times+=1 1 times ans = X - (D*K) X - (D*K) ans times = int(X/D) int(X/D) times D = int(xkd[2]) int(xkd[2]) D X = abs(X) abs(X) X ans = min(X%D, (D-X%D)) min(X%D, (D-X%D)) ans
xkd = input().split()
X = int(xkd[0])
K = int(xkd[1])
D = int(xkd[2])

X = abs(X)
ans = 0
times = int(X/D)
oneMore = False
if X%D > abs(D-X%D):
    times+=1

if times > K:
    ans = X - (D*K)
else:
    if (times%2) == (K%2):
        ans = min(X%D, (D-X%D))
    else:
        ans = max(X%D, (D-X%D))

print(ans)