import numpy as np

inpt = input()
inpt_list = inpt.split(" ")
X, K, D = [int(x) for x in inpt_list]

X_abs = np.abs(X)
num = X_abs // D
rem = K - num
if rem < 0:
    out = X_abs - D*K
else:
    if rem%2==0:
        out = X_abs - num*D
    else:
        out = np.abs(X_abs - num*D - D)
print(out) import numpy as np numpy inpt = input() inpt input() input inpt_list = inpt.split(" ") inpt_list inpt.split(" ") inpt.split inpt split " " int(x) for x in inpt_list for x in inpt_list x inpt_list for x in inpt_list int(x) int x X, K, D = [int(x) for x in inpt_list] X [int(x) for x in inpt_list] K D X_abs = np.abs(X) X_abs np.abs(X) np.abs np abs X num = X_abs // D num X_abs // D X_abs D rem = K - num rem K - num K num if rem < 0:
    out = X_abs - D*K
else:
    if rem%2==0:
        out = X_abs - num*D
    else:
        out = np.abs(X_abs - num*D - D) rem < 0 rem 0 out = X_abs - D*K out X_abs - D*K X_abs D*K D K if rem%2==0:
        out = X_abs - num*D
    else:
        out = np.abs(X_abs - num*D - D) rem%2==0 rem%2 rem 2 0 out = X_abs - num*D out X_abs - num*D X_abs num*D num D out = np.abs(X_abs - num*D - D) out np.abs(X_abs - num*D - D) np.abs np abs X_abs - num*D - D X_abs - num*D X_abs num*D num D D print(out) print out inpt_list = inpt.split(" ") inpt.split(" ") inpt_list K, D = [int(x) for x in inpt_list] [int(x) for x in inpt_list] K out = np.abs(X_abs - num*D - D) np.abs(X_abs - num*D - D) out rem = K - num K - num rem D = [int(x) for x in inpt_list] [int(x) for x in inpt_list] D inpt = input() input() inpt X, K, D = [int(x) for x in inpt_list] [int(x) for x in inpt_list] X num = X_abs // D X_abs // D num X_abs = np.abs(X) np.abs(X) X_abs out = X_abs - num*D X_abs - num*D out out = X_abs - D*K X_abs - D*K out
import numpy as np

inpt = input()
inpt_list = inpt.split(" ")
X, K, D = [int(x) for x in inpt_list]

X_abs = np.abs(X)
num = X_abs // D
rem = K - num
if rem < 0:
    out = X_abs - D*K
else:
    if rem%2==0:
        out = X_abs - num*D
    else:
        out = np.abs(X_abs - num*D - D)
print(out)