Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.
More specifically, in one move, he can go from coordinate x to x + D or x - D.
He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.
Find the minimum possible absolute value of the coordinate of the destination.

-----Constraints-----
 - -10^{15} \leq X \leq 10^{15}
 - 1 \leq K \leq 10^{15}
 - 1 \leq D \leq 10^{15}
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
X K D

-----Output-----
Print the minimum possible absolute value of the coordinate of the destination.

-----Sample Input-----
6 2 4

-----Sample Output-----
2

Takahashi is now at coordinate 6. It is optimal to make the following moves:
 - Move from coordinate 6 to (6 - 4 =) 2.
 - Move from coordinate 2 to (2 - 4 =) -2.
Here, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.

Difficulty: introductory

Starter code:

Solutions:
x, k, d = map(int, input().split())
if x < 0:
    x *= -1
cnt = min(k, x//d+1)
x -= cnt * d
if abs(x) < x+d:
    x += d
    cnt -= 1
    x -= d * ((k-cnt)%2)
else:
    x += d * ((k-cnt)%2)
print(abs(x))

import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

x, k, d = [int(i) for i in input().split()]

tmp = 0
res = 0

x = abs(x)
tmp = min(k, x // d)
res = x - tmp * d
if (k - tmp) % 2 == 1:
    res = abs(res - d)

print(res)


x, k, d = map(int, input().split())
cur = abs(x)
rem = k
cnt = min(cur // d, k)
cur -= d * cnt
rem -= cnt
if rem > 0:
    if rem % 2 == 1:
        cur = cur - d

ans = abs(cur) 
print(ans)

def main():
    x,k,d = map(int,input().split(" "))

    if abs(x) % d == 0:
        exceed_num = (abs(x) // d)
    else:
        exceed_num = (abs(x) // d) + 1


    if k <= exceed_num :
        print(abs( abs(x) - (d*k) ))
    else:
        if (k - exceed_num) % 2 == 0:
            print(abs( abs(x) - (d*exceed_num) ))
        else:
            print(abs( abs(x) - (d*(exceed_num-1) )))



def __starting_point():
    main()
__starting_point()

X,K,D=map(int,input().split())
X=abs(X)
r=X//D
if r>=K:
  print(X-K*D)
  return
if (K-r)%2==0:
  print(X-r*D)
else:
  print(abs(X-D*r-D))

# 175 C
X, K, D = list(map(int, input().split()))
div = abs(X)//D
mod = abs(X)%D
if abs(X) > K*D:
    print(abs(X) - K*D)
elif (K-div)%2 == 0:
    print(mod)
else:
    print(D-mod)

x,k,d = map(int,input().split())
an = x

if x < 0:
    x = -x

if k <= x/d:
    an = x-d*k
else:
    if (k-x//d)%2==0:
        an = x-d*(x//d)
    else:
        an = x-d*(x//d)-d
        
print(abs(an))

import sys
X, K, D = map(int, input().split())
if K * D < abs(X):
    print(abs(X) - K * D)
    return

tmp = X//D
X -= tmp * D
K -= tmp
if K%2 == 0:
    print(abs(X)%D)
else:
    print(abs(X-D))

x, k, d = map(int, input().split())

x = abs(x)

if x - k*d >= 0:
    print( x - k*d )
    return

k -= x // d
if k % 2:
    print ( d - x % d )
else:
    print ( x % d )

import math

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

if K < X//D:
    ans = (X - K*D)
else:
    dis = X - D * (X // D)
    if (K-X//D)&1:
        ans = (dis-D)
    else:
        ans = (dis)

print((int(math.fabs(ans))))


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

X = abs(X)

count = X // D
ans = 0

if count >= K:
  ans = X - (K * D)
else:
  if (K - count) % 2 == 0:
    ans = X - (count * D)
  else:
    ans = X - (count + 1) * D

print((abs(ans)))


x,k,d=list(map(int, input().split()))
if abs(x)//d>=k:
    #print("ひ")
    print((abs(x)-d*k))
elif (k-abs(x)//d)%2==0:
    #print("fu")
    print((abs(x)%d))
else:
    #print("mi")
    print((d-abs(x)%d))



X, K, D = map(int, input().split())
par = K%2
if X < -K*D:
    print(-X-K*D)
elif X > K*D:
    print(X-K*D)
else:
    if par ==0:
        if X%(2*D) < D:
            print(X%(2*D))
        else:
            print(2*D-X%(2*D))
    else:
        if (X-D)%(2*D) < D:
            print((X-D)%(2*D))
        else:
            print(2*D-(X-D)%(2*D))

x, k, d = map(int, input().split())
x = abs(x)
l = x // d

if k <= l:
    print(abs(x - k * d))
else:
    print(abs(abs(x - d * l) - d * ((k - l) % 2)))

X,K,D = list(map(int,input().split()))
X = abs(X)
if X-D*K>=0:
  print((X-D*K))
else:
  r = X//D
  print((abs(X-D*(r+(r+K)%2))))


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

# X > 0 として良い
X = abs(X)

# 原点に向かう
c = min(K, X//D)
K -= c
X -= D * c

# 移動できなければ終了
if K == 0:
    print(X)
else:
    # 行ったり来たりする
    if K%2:
        print((abs(X-D)))
    else:
        print(X)


def c175(x, k, d):

    x = abs(x)
    ans = 0
    if x - k * d > 0:
        return x - k * d

    if x%d <= d-(x%d):
        ans = x%d if (k - int(x//d))%2 == 0 else d-(x%d)
    else:
        ans = d-(x%d) if (k - 1 - int(x//d)) %2 == 0 else x%d

    return ans

def main():
    x, k, d = map(int, input().split())
    print(c175(x, k, d))

def __starting_point():
    main()
__starting_point()

x, k, d = map(int, input().split())

cur  = abs(x)
rem = k

cnt = min(cur // d, k)
cur = cur - d * cnt
rem = rem - cnt

if rem  > 0:
        if rem % 2 == 1:
                cur = cur - d
                
ans = abs(cur)
print(ans)

X, K, D = map(int, input().split())
X = abs(X)
cnt = X // D
if cnt >= K:
  print(X - D * K)
  return
if (K - cnt) % 2 == 0:
  print(X - D * cnt)
else:
  print(abs(X - D * cnt - D))

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

if X<0:
    X=-X

if K*D<X:
    print((X-K*D))
else:
    k = K - int(X/D)
    x = X % D
    if k%2:
        print((abs(x-D)))
    else:
        print(x)


X,K,D=map(int,input().split())
X=abs(X)
r=X//D
if r>=K:
  print(X-K*D)
  return
if (K-r)%2==0:
  print(X-r*D)
else:
  print(abs(X-r*D-D))

a=input().split(" ")
b=[x,k,d]= [int(a[0]),int(a[1]),int(a[2])]  
ans = 0
if x - k*d > 0:
  ans = x - k*d
elif x + k*d < 0:
  ans = - k*d -x
else:
  if k%2==0:
    ans= x%(2*d)
    if d<x%(2*d):
      ans= 2*d-x%(2*d)
  elif k%2==1:
    ans= (x+d)%(2*d)
    if d<(x+d)%(2*d):
      ans= 2*d-(x+d)%(2*d)
print(ans)

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

if(X<0):
  X = -1*X
if(K%2==1):
  K-=1
  X-=D
A = X-K*D

#if(A>=-1*D):
#  print(abs(A))
#else:
low = 0
high = K//2
while low<=high:
  mid = (low+high)//2
  A = X-mid*2*D
  #print('low:'+str(low)+',mid:'+str(mid)+',high:'+str(high)+',A:'+str(A))
  if(abs(A)<=D):
    #print(A)
    break
  elif(A>D):
    low = mid+1
  else:
    high = mid-1
print(abs(A))

from bisect import bisect_left, bisect_right

def main():
    s = [int(x) for x in input().split()]
    x, k, d = s[0], s[1], s[2]
    tmp = abs(x) // d
    if(tmp >= k):
        mini = abs(x)-d*k
    else:
        mini = abs(abs(x) - tmp * d)
        if ((k - tmp) % 2 == 1):
            mini = abs(mini - d)
    print(mini)

def __starting_point():
    main()
__starting_point()

x, k, d = map(int, input().split())

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = cur - d

ans = abs(cur)  # 絶対値を出力することに気をつけてください
print(ans)

x,k,d = list(map(int, input().split()))
x = abs(x)

if x < k*d:
	step = x//d
	k -= step
	x -= step*d
	ans = x
	if k%2 == 1:
		ans = abs(x-d)
else:
	x -= k*d
	ans = x

print(ans)


def main(X, K, D):
    ans = 0
    X = abs(X)
    # 0に近づける回数を獲得
    time = round(X//D)
    #print(f'time: {time}')
    if time > K:
        time = K
    #print(f'time: {time}')
    if time == 0:
        # Xとabs(X-D)のどちらがより0に近いのか
        if X <= abs(X-D):
            time = 0
        else:
            time = 1
    #print(f'time: {time}')
    # それ以外の回数は単に往復する
    ans = X-time*D
    if (K-time)%2 != 0:
        ans = abs(ans) - D
    return abs(ans)

def __starting_point():
    X, K, D = list(map(int, input().split()))
    ans = main(X, K, D)
    print(ans)


__starting_point()

x,num,dis = map(int,input().split())

if x < 0:
    x = x*-1
n =  x//dis + 1

if num < n:
    print(abs(x-num*dis))
elif (num - n) % 2 == 0:
    print(abs(x-dis*n))
else:
    print(abs(x-dis*(n-1)))

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

if abs(X) > K * D:
    print(abs(X) - K * D)
    return

y = abs(X) // D
X_ = abs(X) - y * D
z = K - y
if z % 2 == 0:
    ans = X_
else:
    ans = abs(X_ - D)

print(ans)

x, k, d = list(map(int, input().split()))

x = -x if x <= 0 else x

if x - d * k >= 0:
    print((x - d * k))
else:
    a = x // d
    b = a + 1
    rest_cnt = k - a
    if rest_cnt % 2 == 0:
        print((abs(x - d * a)))
    else:
        print((abs(x - d * b)))


def main():
	X, K, D = input().split(" ")
	sign = "+"
	if X[0] == "-":
		sign = "-"
		X = X[1:]
	if bigint_compare(X, bigint_multiply(K, D)) >= 0:
		print((bigint_minus(X, bigint_multiply(K, D))))
		return 0
	div = bigint_divide(X, D)
	tmp_p0 = bigint_minus(X, bigint_multiply(D, div))
	tmp_k = bigint_minus(K, div)
	tmp_p1 = bigint_minus(D, tmp_p0)
	if int(tmp_k[-1]) % 2 == 0:
		print(tmp_p0)
	elif int(tmp_k[-1]) % 2 == 1:
		print(tmp_p1)

def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if "." in n:
		l = n.find(".")
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == "0":
			head_zeros += 1
		else:
			break

	return n[head_zeros:]

# compare a, b
# a, b: int or string
def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	else:
		if a > b:
			return 1
		elif a < b:
			return -1
		else:
			return 0

# calculate a + b
# a, b: int or string
def bigint_plus(a, b):
	a = str(a)
	b = str(b)

	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b

	ans = ""
	carry = 0
	for i in range(d):
		s = int(a[-i-1]) + int(b[-i-1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans

	return ans

# calculate a - b
# a, b: int or string
def bigint_minus(a, b): 
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ""

	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = "-"
	m = '0' * (len(M) - len(m)) + m

	ans = ""
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i-1]) - int(m[-i-1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans

	return sign + delete_head_zeros(ans)

# calculate a * b
# a, b: int or string
def bigint_multiply(a, b):
	a = str(a)
	b = str(b)

	md = []
	for j in range(len(b)):
		carry = 0
		mj = ""
		for i in range(len(a)):
			m = int(a[-i-1]) * int(b[-j-1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)

	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + "0" * k, ans)

	return ans


# calculate a / b to d digits after decimal point
# a, b, d: int or string
def bigint_divide(a, b, d = 0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0

	ans = ""
	r = ""
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += "."
			r += "0"
		else:
			r += "0"

		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)

	return delete_head_zeros(ans)

main()


import sys

# x = abs(int(input()))
# k = int(input())
# d = int(input())

array = list(map(int, input().strip().split()))
x = abs(array[0])
k = array[1]
d = array[2]
if (d == 0):
    amari = abs(x)

else:
    move_cnt = int(x / d)
    if (move_cnt <= k):
        k -= move_cnt
        amari = x - move_cnt * d

    else:
        amari = x - k * d
        k = 0

    if (k > 0):
        if (k % 2 == 1):
            if (amari > 0):
                amari -= d
            else:
                amari += d

print(abs(amari))

x, k, d = map(int, input().split())

x = abs(x)
straight = min(k, x//d)
k -= straight
x -= straight*d

if k%2 == 0:
  print(x)
else:
  print(d-x)

X,K,D=map(int,input().split())
X=abs(X)
r=X//D
if r>=K:
  print(X-K*D)
  return
if (K-r)%2==0:
  print(X-D*r)
else:
  print(abs(X-D*r-D))

import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

X, K, D = ri_()
x = abs(X)

if K * D <= x:
    ans = x - K * D
else:
    if K % 2 == 0:
        ans = min(x % (2 * D), abs(x % (2 * D) - 2 * D))
    else:
        ans = min(x % (2 * D) + D, abs(x % (2 * D) - D))
print(ans)

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

N = X // D
if K < abs(N):
    ans = abs(abs(X) - K * D)
else:
    if (K - abs(N)) % 2 == 0:
        ans = abs(X - N * D)
    else:
        ans = abs(X - (N+1) * D)

print(ans)


X, K, D = map(int, input().split())
X = abs(X)
div, mod = divmod(X, D)
if X > D * K:
    ans = X - D * K
elif (K - div) % 2 == 0:
    ans = mod
else:
    ans = D - mod
print(ans)

X,K,D=list(map(int,input().split()))
X=abs(X)
if K*D<X:
    print((X-K*D))
else:
    K-=X//D
    X%=D
    if K%2==0:
        print(X)
    else:
        print((D-X))


#今Xにいる、K回 D移動する
[X, K, D] = [int(i) for i in input().split()]
#正負で答え変化しないので、正に変える
X = abs(X)
if X - K*D > 0:
#原点に到達しないとき
    print(X-K*D)
#原点に到達するとき
else:
    #往復始める正の位置を求める
    time = int(X/D)
    start = X - D * time
    #残り移動回数を計算
    time_re = K - time
    #残り回数の偶奇で場合分け
    if time_re % 2 == 0:
        print(start)
    else:
        print(abs(start-D))

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

if abs(X) >= K * D:
    print((abs(X) - K * D))
else:
    n = abs(X) // D
    p = abs(X) % D
    if (K-n) % 2 == 0:
        print(p)
    else:
        print((D-p))



X,K,D=map(int,input().split())
ans=float('inf')
X=abs(X)
before_0_cnt=X//D
if before_0_cnt>=K:
  print(X-K*D)
  return
if (before_0_cnt%2)^(K%2)==0:
  print(X-before_0_cnt*D)
else: # odd
  print(abs(X-before_0_cnt*D-D))

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

    X = abs(X)
    q = X // D
    if q >= K:
        X -= K * D
    else:
        X -= q * D
        if (K - q) % 2 == 1:
            X = abs(X - D)

    print(X)
    return


def __starting_point():
    main()

__starting_point()

x, k, d = map(int, input().split())
ans = 0

if x < 0:
  x *= -1

if k*d <= x:
  ans = x - k*d
elif x < k*d:
  k -= x//d
  x -= (x//d) * d
  ans = x if k%2==0 else x-d

print(ans if 0<= ans else -ans)

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

cur = abs(X)
cnt = min(cur//D,K)
cur -= cnt*D
K = K - cnt

if K > 0 :
  if K%2 == 1:
    cur = cur - D
 
print(abs(cur))

x,k,d = map(int,input().split())

if x >= 0 :
    a = abs(x//d)
    if a <= k :
        if (k - a) % 2 == 0 :
            print(abs(x-a*d))
        else :
            print(abs(x-(a+1)*d))
    else :
        print(abs(x-k*d))
else :
    if x%d == 0 :
        a = abs(x//d)
    else :
        a = abs(x//d+1)

    if a <= k :
        if (k - a) % 2 == 0 :
            print(abs(x+a*d))
        else :
            print(abs(x+(a+1)*d))
    else :
            print(abs(x+k*d))

# まず極力原点に近づく。
# 原点を超えた場合は、切り返す
# シミュレートは遅いので、短絡させる。

x,k,d=list(map(int,input().split()))
absx=abs(x)
step1= absx // d
if step1 >= k:
  print((absx-(d*k)))
else:
  step2=k-step1
  absx-=(d*step1)
  if step2 % 2==0:
    print(absx)
  else:
    print((abs(absx-d)))


X,K,D = map(int,input().split())
ans = 0
if X == 0:
    if K % 2 == 0:
        ans = 0
    else:
        ans = D
if X > 0:
    if K*D <= X:
        ans = X - K*D
    else:
        n = X // D
        if X % D != 0:
            n += 1
        if (K - n) % 2 == 0:
            ans = abs(X-D*n)
        else:
            ans = abs(X-D*(n-1))
if X < 0:
    if K*D + X <= 0:
        ans = abs(K*D+X)
    else:
        n = -X // D
        if -X % D != 0:
            n += 1
        if (K-n) % 2 == 0:
            ans = abs(X+n*D)
        else:
            ans = abs(X+(n-1)*D)

print(ans)

import sys
X, K, D = map(int, input().split())
X = abs(X)
if X // D >= K:
    print(X - K*D)
    return
K = K - (X // D)
A = X - X//D*D
if K % 2 == 0:
    print(A)
else:
    print(abs(A - D))

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


X = abs(X)
a = K*D
if X >= a:
    result = X-a
else:
    b = X//D
    c = (X-b*D)
    d = abs(X-(b+1)*D)
    if c < d:
        if b%2==K%2:
            result = c
        else:
            result = d
    else:
        if (b+1)%2==K%2:
            result=d
        else:
            result=c

print(result)

# author:  Taichicchi
# created: 15.09.2020 21:22:26

import sys

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

X = abs(X)

if X >= K * D:
    print((X - (K * D)))
else:
    k = K - X // D
    x = X - D * (X // D)

    if k % 2:
        print((abs(x - D)))
    else:
        print(x)


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



# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return list(map(int, input().split()))


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    X, K, D = input_to_int_map()

    temp = abs(X) // D

    if K < temp:
        return int(abs(X) - (K * D))

    if (K - temp) % 2 == 0:
        return int(abs(X) - (D * temp))

    return int(abs(abs(X) - (D * temp) - D))


def __starting_point():
    print((main()))

__starting_point()

X, K, D = map(int, input().split())
X = abs(X)
cnt = X // D
if cnt >= K:
  print(X - D * K)
  return
if (cnt % 2) ^ (K % 2) == 0:
  print(X - D * cnt)
else:
  print(abs(X - D * cnt - D))

x, k, d = [int(s) for s in input().split()]
x = abs(x)
q, m = divmod(x, d)
if q >= k:
    x -= k * d
else:
    x = m
    if (k - q) & 1:
        x = d - x
print(x)

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

x, k, d = map(int, input().split())

print(abs(abs(abs(x)-min((abs(x)//d), k)*d)-((k-min(abs(x)//d,k))%2)*d))

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


def sign(x):
    return 1 if x >= 0 else -1


if abs(X) >= D * K:
    ans = X - sign(X) * D * K
else:
    l = abs(X) // D
    mod = abs(X) % D

    residual = K - l

    if residual % 2 == 0:
        ans = mod
    else:
        ans = mod - sign(mod) * D

print((abs(ans)))




X,K,D=list(map(int,input().split()))
if X<0:
    X=-X
if X-K*D>=0:
    print(X-K*D)
else:
    N=X//D
    if (K-N)%2==0:
        print(X-N*D)
    else:
        print((N+1)*D-X)

import sys

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

c = min(K, X // D)
K -= c
X -= D * c
if K % 2 == 0:
    print(X)
else:
    print((abs(X - D)))


x, k, d = map(int, input().split())
x = abs(x)

if x >= k*d:
    ans = x - k*d
else:
    c = x // d
    x %= d
    k -= c
    if k%2 == 0:
        ans = x
    else:
        ans = abs(x-d)

print(ans)

X,K,D=map(int,input().split())
ans=float('inf')
X=abs(X)
before_0_cnt=X//D
if before_0_cnt>=K:
  print(X-K*D)
  return
rest=K-before_0_cnt
if rest%2==0:
  print(X-before_0_cnt*D)
else: # odd
  print(abs(X-before_0_cnt*D-D))

import math
import collections
import itertools

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

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

    ans=0
    if(abs(X)-K*D<0):
        tmp=X//D
        if((K-tmp)%2==0):
            ans=abs(X-D*tmp)
        else:
            ans=abs(X-D*(tmp+1))
    else:
        ans=abs(X)-K*D

    print(ans)
resolve()


x, k, d = map(int, input().split())
x = abs(x)
if x > k * d:
  ans = x - k * d
else:
  a = x // d
  b = x % d
  k -= a
  if k % 2 == 0:
    ans = b
  else:
    ans = abs(b-d)
print(ans)

def main():
    X, K, D = map(int, input().split())
    X = abs(X)
    rem = K
    
    cnt = min(X // D, K)
    X -= D*cnt
    rem -= cnt
    
    if rem > 0:
        if rem % 2 == 1:
            X = X - D
            
    print(abs(X))
    
    
    
    
def __starting_point():
    main()
__starting_point()

X,K,D=map(int,input().split());X=abs(X)-K%2*D;E=D*2;print(max(min(X%E,-X%E),X-D*(K-K%2)))

x, k, d = list(map(int, input().split()))
x = abs(x)
if k * d < x:
    ans = x - k * d
else:
    if (k - x // d) % 2 == 0:
        ans = x % d
    else:
        ans = abs(x % d - d)
print(ans)


import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    X, K, D = list(map(int, input().split()))
    if abs(K * D) < abs(X):
        print((abs(X) - abs(K * D)))
    else:
        m = X // D
        x = X - m * D
        k = K - m
        if k % 2 == 0:
            print((abs(x)))
        else:
            print((abs(x - D)))


def __starting_point():
    main()

__starting_point()

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

if X >= K*D:
  ans = X - K*D
else:
  l = X // D
  if (K-l) % 2 == 0:
    ans = abs(X - D*l)
  else:
    ans = abs(X - D*(l+1))
print(ans)

x,k,d = map(int,input().split())

if x < 0:
    x *= -1
    
m = x // d

if k <= m:
    print(x - k*d)
    
else:
    x %= d
    y = abs(x-d)
    
    print([x,y][(k-m)%2])

x,k,d = list(map(int,input().split()))

ax = abs(x)

kd = k*d

if(ax>kd):
    print((ax-kd))
else:
    num = ax//d
    if((num%2)==(k%2)):
        print((ax-(d*num)))
    else:
        if(num==k):
            print((ax-d*num))
        else:
            print((abs(ax-d*num-d)))

    


x,k,d = map(int,input().split())
x = abs(x)
s = min(k,x//d)
k -= s
x -= s * d
if k % 2 == 0:
    print(x)
else:
    print(d-x)

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


cnt=min(abs(X)//D,K)
c_K=K

c_K-=cnt
rem=abs(X)-D*cnt

if c_K%2==0:
  print(rem)
else:
  print(abs(rem-D))

x, k, d = list(map(int, input().split()))

if x < 0:
    if x + k * d < 0:
        print((-x - k * d))
    else:
        a = -x // d
        x += a * d
        if (k - a) % 2 == 0:
            print((-x))
        else:
            print((x + d))
            
else:
    if x - k * d > 0:
        print((x - k * d))
    else:
        a = x // d
        x -= a * d
        if (k - a) % 2 == 0:
            print(x)
        else:
            print((d - x))


#C問題
import numpy as np
X,K,D = map(int, input().split())
ans = 0
if X >= 0 :
    if int(X/D)<=K:
        if int(X/D)%2==K%2:
            ans = X%D
        else:
            ans = D-X%D
    else:
        ans = abs(X-K*D)       
if X < 0 :
    if abs(int(X/D))<=K:
        if abs(int(X/D))%2==K%2:
            ans = abs(X)%D
        else:
            ans = D-abs(X)%D
    else:
        ans = abs(X+K*D)          
print(ans)

def solve():
    x, k, d = map(int, input().split())

    x = abs(x)

    a = x // d
    b = x % d

    p = x - d * k
    
    if p > b:
        print(p)
        return

    q = x - a * d
    if (k-a) % 2 == 0:
        print(abs(q))
    else:
        print(abs(q-d))

solve()

x, k, d = list(map(int, input().split()))
x = abs(x)
ans = 0
if x // d > k:
    ans = x - d * k
else:
    e = x // d
    k -= e
    x -= e * d
    if (k % 2 == 1):
        x = abs(x - d)
    ans = x
print(ans)


x,k,d = map(int, input().split())
lists = []
x = abs(x)
 
step = int(x/d) 
 
if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = min(abs(x % d - d), abs(x % d + d))
 
print(answer)

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

if X > K*D:
  print(X-K*D)
else:
  greed = X//D
  if (K - greed)%2 == 0:
    print(X-greed*D)
  else:
    print((1+greed)*D -X)

x,k,d=map(int,input().split())
q=abs(x)//d
if q>=k:
    print(abs(x)-k*d)
else:
    now=abs(x)-q*d
    r=k-q
    if r%2==0:
        print(now)
    else:
        print(d-now)

import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x,k,d = mi()
x = abs(x)

count = min(k,x//d)
k -= count
x -= d*count

if k % 2 == 0:
    print(x)
else:
    print(d-x)

#abc175c
x,k,d=list(map(int,input().split()))
x=abs(x)
t=x//d
if k<t:
 print((x-k*d))
else:
 print((abs(x%d-(k-t)%2*d)))


def pm(x):
  if x>=0:
    return 1
  else:
    return -1
X,K,D=map(int,input().split())
if (abs(X))<D :
  if K%2==0:
    print(int(abs(X)))
  else:
    a=X-pm(X)*D
    print(int(abs(a)))
else:
  if abs(X)//D>=K:
    a=X-(pm(X))*D*K
    print(int(abs(a)))
  else:
    K=K-int(abs(X)//D)
    X=X-(pm(X))*D*int(abs(X)//D)
    if (abs(X))<D :
      if K%2==0:
        print(int(abs(X)))
      else:
        a=X-(pm(X))*D
        print(int(abs(a)))

x, k, d = map(int, input().split())

count = 0
local = x

def odd_or_eaven(x, d, k):
  if k % 2 == 0:
    print(abs(x))
  else:
    print(abs(x - d))
    
if abs(x) < abs(d):
  odd_or_eaven(x, d, k)
elif abs(x) - abs(k * d) > abs(d):
  print(abs(abs(x) - abs(k * d)))
else:
  mod = x % d
  temp = k - x // d
  odd_or_eaven(mod, d, temp)

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

def sign(x):
    return 1 if x >= 0 else -1


ans = abs(X) - K * D

if abs(X) - K * D < 0:
    divs = abs(X) // D
    mods = abs(X) % D
    nums = K - divs

    ans = abs(mods - (nums%2) * D)

print(ans)


# ans = min([abs(X+D*i) for i in range(-K, K+1, 2)])
# 
# print(ans)


#n = int(input())
x, k, d = list(map(int, input().split()))
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
x = abs(x)
if x//d >= k:
    ans = x-d*k
else:
    mnmove = x//d
    k -= mnmove
    x -= mnmove*d
    if k % 2 == 0:
        ans = x
    else:
        ans = abs(x-d)

print(ans)


#今Xにいる、K回 D移動する
[X, K, D] = [int(i) for i in input().split()]
#正負で答え変化しないので、正に変える
X = abs(X)
if X - K*D > 0:
#原点に到達しないとき
    print(X-K*D)
#原点に到達するとき
else:
    #往復始める正の位置を求める
    time = int(X/D)
    start = X - D * time
    #残り移動回数を計算
    time_re = K - time
    #残り回数の偶奇で場合分け
    if time_re % 2 == 0:
        print(start)
    else:
        print(abs(start-D))

x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) >= abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = int(abs(x)/d)
    k_2 = k - kaisuu
    if k_2%2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = abs((abs(x) - d*kaisuu) - abs(d))
print(int(ans))

X,K,D = map(int,input().split())
a = abs(X)//D
b = abs(X)%D
ans = 0
if a>K :
    ans = abs(X)-D*K
elif (K-a)%2==0:
    ans = b
else:
    ans = abs(b-D)
print(ans)

#c
x,k,d=map(int,input().split())
x=abs(x)
x1=x//d
if k<=x1:
    ans=x-k*d
else:
    if (k-x1)%2==0:
        ans=x%d
    else:
        ans=d-x%d

print(ans)

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


x,k,d=list(map(int,input().split()))

X=abs(x)
if k*d<X:
    ans=X-k*d
else:
    t=X//d  #絶対値Xを何回D移動すると0になるか
    t_a=k-t #0に到達したあとの回数

    if t_a%2==0:
        ans=X%d #0に到達したあと偶数ならば往復できるのでその位置から変わらない

    else:
        ans= abs((X%d)-d) 
print(ans)


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

XX = abs(X)

if XX > K*D:
    print((XX - K*D))
else:
    if (K - X//D)%2 == 0:
        print((X%D))
    else:
        print((abs(X%D -D)))



X, K, D = list(map(int, input().split()))
if abs(X) > D * K:
    abso = abs(X) - D * K
    print(abso)
    return
div = abs(X)//D
mod = abs(X)%D #+側の最小値
if (K - div)%2 == 0: #K-div:+側での絶対値の最小値までたどり着く回数
    print(mod)
else:
    print((D-mod))


import sys
readline = sys.stdin.readline

X,K,D = map(int,readline().split())

X = abs(X)

if X - K * D > 0:
  print(X - K * D)
else:
  cnt = X // D
  point = X % D
  if (K - cnt) % 2 == 1:
    print(abs(point - D))
  else:
    print(point)

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

if X - K * D >= 0:
    ans = abs(X - K * D)
elif X + K * D <= 0:
    ans = abs(X + K * D)
else:
    n = int(abs(X - K * D) / (2 * D))
    ans = min(abs(X - K * D + n * 2 * D), abs(X - K * D + (n + 1) * 2 * D))
    
print(ans)

x,k,d=list(map(int,input().split()))
if x<0:
  x=-1*x
if x>=k*d:
  print((x-k*d))
else:
  ans=(x-k*d)%(2*d)
  if ans>d:
    print((2*d-ans))
  else:
    print(ans)


x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)

X, K, D = list(map(int, input().split()))
X = abs(X)
if X - K * D >= 0:
    print((X - K * D))
    return
else:
    n = X // D
    x = X - n * D
    if (K - n) % 2 == 0:
        print(x)
    else:
        print((min(x + D, D - x)))


x, k, d=map(int,input().split())
x=abs(x)
#k回すべて戻っても0に達せない場合  k-x//d
if x//d>=k:
  print(x-k*d)
elif (k-x//d)%2==0:
  print(x%d)
else:
  print(abs(x-x//d*d-d))