Problem:
 Score : 300 points    Problem Statement 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 1 6 2 4      Sample Output 1 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.       Sample Input 2 7 4 3      Sample Output 2 1  Takahashi is now at coordinate 7 . It is optimal to make, for example, the following moves:   Move from coordinate 7 to 4 .  Move from coordinate 4 to 7 .  Move from coordinate 7 to 4 .  Move from coordinate 4 to 1 .   Here, the absolute value of the coordinate of the destination is 1 , and we cannot make it smaller.       Sample Input 3 10 1 2      Sample Output 3 8       Sample Input 4 1000000000000000 1000000000000000 1000000000000000      Sample Output 4 1000000000000000  The answer can be enormous.

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

if x > k*d or -x > k*d:
    print(abs(abs(x) -k*d))
else:
    num = abs(x) // d
    rest = k - num
    if rest%2 == 1:
        print(abs(abs(x)%d -d))
    else:
        print(abs(abs(x)%d))

Solution (Python):
X, K, D = map(int, input().split())
first = 0
if X < 0:
    first = -1
elif X > 0:
    first = 1
ans = 0
X = abs(X)
judge = 0 
if first == 0:
    if D % 2 == 1:
        ans = D
    else:
        ans = 0
else:
    if K < X // D:
        ans = X - (K * D)
    else:
        judge = (X // D) % 2
        if judge == 0:
            if K % 2 == 0:
                ans = X % D
            else:
                ans = X % D - D
        else:
            if K % 2 == 0:
                ans = X % D - D
            else:
                ans = X % D
print(abs(ans))

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

Solution (Python):
def resolve():
    x,k,d = map(int, input().split())
    x=abs(x)
    if abs(x)>=k*d:
        print(abs(x-k*d))
    else:
        m=x//d
        n=abs(x)%d
        if (m-k)%2==0:
            print(n)
        else:
            print(abs(n-d))
resolve()

Solution (Python):

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

q, mod = divmod(X, D)

if q < K:
    
    X = X - (q * D)
    if (K - q) % 2 == 0:
        ans = X
    else:
        ans = X - D
else:
    
    ans = X - (K * D)
print(abs(ans))

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

x=abs(x)

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

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



xxx=x//d

yyy=x%d

zzz=k-xxx

if zzz%2==0:
  print(yyy)

else:
    print(abs(yyy-d))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

x = abs(x)

if x - (k * d) >= 0:
    print(x - (k * d))
    sys.exit(0)
else:
    remain = k - (x // d)
    p_min = x % d
    n_min = abs(p_min -d)
    if remain % 2 == 0:
        print(p_min)
    else:
        print(n_min)

Solution (Python):
"""MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWO:,'..'xXWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO. .:kOo.,kNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO. .lNWWo..lXMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MNOxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMMMMWKxoloxKWNc  .:xxd;  ,dxxxkXMXkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMM
MKc''''''''''''''''.  ..'''''.   .''''.  .''MMMWx..,:. .xXo''.  .''.  ..'';kMk;'''''.  .'.''.  .''''''.  ..''.   .''MM
MWNXNNNNNNNNNNNNNNNO' ;KNNNNNKo. cKNNNd. lXNMMMK; ,0Wx. :NWXXl .dNNO' ;KNNNWMWNNNNNXc .kNNNNx. cXNNNNNO' ;KNN0; 'ONNMM
MMMMMMMMMMMMMMMMMWM0' :NMMMMWMX: .OMWWx. oWMMMMWx. ';. .dNMWWo .xMM0' :NWWMMMMMMMMWWl .OMMMWk. lWWMMWM0' ;XMMX: ,KMMMM
MMMMMMWMWkccccccccc;. :NMWNNNKd. :XMMWx. oWMMMWKo. .',. .,ldx; .dMM0' :NMMMMMMMNNWMWl .OMMMWk. lWMMMMM0' ;XMMX: ,0MMMM
MMWXKNWMWxcc,. .;cc;. :XMk,''..'lKWMMWx. oWMNx:. .lONNKxl.     .xMM0' :NMMMMMM0:,oKO' ,KMMMMk. lWWNkoc,. .;::;. ,KMMMM
MMXc.lXMMWWWNd..xWM0' :NM0;  ;kXWMMMWNl  oWMK:.;xXWWMWXx:. ,c' .dMM0' :NMMMMMMKc. ...;kWMMMMk. lWWc .:;. .clc:. ,KMMMM
MWWx. lXMWMMMK, lWM0' :NMMNx'.,ldxxoc'   oWMWNKNWWWN0o' .:kNWo .dMM0' :NMMMMMMMNO;  ,OWWWMMMk. lWM' lXx. lNMMX: ,KMMMM
MMMWk'.,xKNX0c..kWM0' :NMMMMNkl;,'',:l:  oWMMMMMWMWO' 'l0WMWWo .xMM0' :NMMMMMMMMMNd. .oXWMMMk. lWMd.....;0WMMX: ,KMMMM
MMMMWKo'...'..:kWMM0' :NMMMMMMMWWNNWWWx. oWMMMMMMMMWOxXWMWMWWo .xMM0' :NMMMMMMMMMMMKl. ,kNMMk. lWMWKkxx0NMWMMX: ,KMMMM
MMMMMMMN0kxk0XNWMMWKl;xNMMMMMMMMMMMMWM0c;kWMMMMMMMMMMMWWMMMMWk;:OMMXl,dNMMMMMMMMMMMMWO; .dNM0c;kWWMMMMMMMMMMMNd,oXMMMM
MMMMMMMMWWMWMMMMMMMMMWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWMMWWMMWMMMMMMMMMMMMMMNkxKWMMWWMMMMMMMMMMMMMMWMMWMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"""





import math;   		from collections import *
import sys;   		from functools import reduce
import time;   		from itertools import groupby



def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]







x, k, d = get_ints()
x = abs(x)
el_facto = min(k, (x + d-1) // d)
moves = []
if k & 1:
	if el_facto & 1:
		moves.append(el_facto)
		el_facto -= 2
		if (el_facto > 0 and el_facto <= k) :
			moves.append(el_facto)
		if el_facto + 4 <= k:
			moves.append(el_facto + 4)
	else:
		el_facto -= 1
		moves.append(el_facto)
		el_facto -= 2
		if (el_facto > 0 and el_facto <= k) :
			moves.append(el_facto)
		if el_facto + 4 <= k:
			moves.append(el_facto + 4)
else:
	if not (el_facto & 1):
		moves.append(el_facto)
		el_facto -= 2
		if (el_facto > 0 and el_facto <= k) :
			moves.append(el_facto)
		if el_facto + 4 <= k:
			moves.append(el_facto + 4)
	else:
		el_facto -= 1
		moves.append(el_facto)
		el_facto -= 2
		if (el_facto > 0 and el_facto <= k) :
			moves.append(el_facto)
		if el_facto + 4 <= k:
			moves.append(el_facto + 4)
ans = float('inf')
x = abs(x)

for i in moves:
	ans = min(ans, abs(x - i * d))
print(ans)

Solution (Python):
def solve():
    X,K,D = map(int,input().split())
    close_zero = None

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


if __name__ == '__main__':
    solve()

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

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

Solution (Python):
import math

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

if X - K*D >= 0:
    print(X - K*D)
    exit()

z_cnt = math.ceil(X/D)
if K%2 == z_cnt%2:
    print(math.ceil(X/D)*D-X)
else:
    print(X - (math.ceil(X / D)-1) * D)

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

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

Solution (Python):
import sys

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

if K*D <= abs(X):
    if 0 <= X:
        print(X - K*D)
    else:
        print(abs(X + K*D))
else:
    dist = abs(X)
    a = dist // D
    
    r = K - a
    if 0 <= X:
        pos1 = X - a * D
        pos2 = pos1 - D
    else:
        pos1 = X + a * D
        pos2 = pos1 + D

    if r % 2 == 1:
        print(abs(pos2))
    else:
        print(abs(pos1))

Solution (Python):
x, k, d = map(int, input().split())
x = abs(x)
if x > d * k:
    print(x - d * k)
else:
    re_k = x // d
    if (k - re_k) % 2 == 0:
        print(x - re_k * d)
    else:
        print((re_k + 1) * d - x)

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

x = abs(x)

cnt = x//d
amari = x%d

nokori = k-cnt

if nokori < 0:
  ans = x - d*k
else:
  if nokori%2 == 0:
    ans = amari - d + d
  else:
    ans = amari - d

print(abs(ans))

Solution (Python):
X,K,D=map(int,input().split())
X=abs(X)
if X-K*D>0:
    print(X-K*D)
else:
    kaisu=int(X/D)
    gi1=X-kaisu*D
    gi4 = abs(gi1)
    if (K - kaisu) % 2 == 0:
        print(gi4)
    else:
        gi2=abs(gi1-D)
        gi3=abs(gi1+D)
        kot=gi2
        if gi3<kot:
            kot=gi3
        print(kot)

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

ma = D * K
ans = 0
if abs(X) >= ma:
    ans = abs(X) - ma
    print(ans)
else:
    div,mod = divmod(X,D)
    if (div - K) % 2 == 0:
        print(mod)
    else:
        tmp = (div + 1) * D
        print(abs(X - tmp))

Solution (Python):


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

main()

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

kk = k % 2
y = (x + d*kk) % (2*d)

z = abs(x) // d

if z >= k:
    print(abs(x) - (k*d))
else:
    if d >= y:
        print(y)
    else:
        print((2*d)-y)

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

Solution (Python):
X,K,D=map(int,input().split())
count=X//D
ans=0
if abs(count)>=K and X>0:
    ans=abs(X-D*K)
elif abs(count)>=K and X<0:
    ans=abs(X+D*K)
else:
    if K%2==count%2:
        ans=abs(X-D*count)
    else:
        ans=abs(X-D*(count+1))
print(ans)

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

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

n = x // d

if abs(n) > k:
    if x < 0:
        print(abs(x+k*d))
        exit()
    elif x > 0:
        print(x-k*d)
        exit()

if abs(x-d*n) > abs(x-d*(n+1)):
    a = abs(x-d*(n+1))
    b = n+1
else:
    a = abs(x-d*n)
    b = n

if (k-b) % 2 == 0:
    print(a)
else:
    print(min(abs(a-d),abs(a+d)))

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

min_abs = 10**15
min_step = X // D
if K <= min_step:
    min_abs = X - D*K
else:
    lowest_plus = X - D*min_step
    highest_minus = abs(lowest_plus - D)
    if (K - min_step) % 2 == 0:
        min_abs = lowest_plus
    else:
        min_abs = highest_minus

print(min_abs)

Solution (Python):
import math
x,k,d = map(int,input().split())

def f( x, k, d, left):
	return abs(x + left*(-d) + (k-left)*d)


l = 0
r = k
res=10000000000000000;
while(r - l >2):
	
	m1 = l + (r - l) // 3
	m2 = r - (r - l) // 3
	
	f1 = f(x,k,d,m1)
	f2 = f(x,k,d,m2)
	
	res=min(res,f1)
	res=min(res,f2)
	
	if (f1 < f2):
		r = m2
	else:
		l = m1


for _i in range(l,r+1):
	cur = f(x,k,d,_i)
	res=min(res,cur)


print(res)

Solution (Python):

import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


x, k, d = MI()

q, r = divmod(abs(x), d)

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

Solution (Python):
x, k, d = map(int, input().split())
if abs(x) > d:
    tmp = min(abs(x) // d, k)
    if x < 0:
        x += d * tmp
        k -= tmp
    else:
        x -= d * tmp
        k -= tmp

ans = x
if k > 0 and x >= 0:
    if k % 2 != 0:
        ans = x - d
    else:
        ans = x
elif k > 0:
    if k % 2 != 0:
        ans = x + d
    else:
        ans = x

print(abs(ans))

Solution (Python):


x, k, d = map(int, input().split())
if x < 0:
    x *= -1
t1 = x % d
t2 = t1 - d
n = (x - t1) // d
if k == n:
    print(t1)
elif k < n:
    print(x - k * d)
else:
    n = k - n
    if n % 2 == 0:
        print(t1)
    else:
        print(-t2)

Solution (Python):
X, K, D = [abs(int(i)) for i in input().split()]
ans = 0
if K*D < X:
    ans = X - K * D
elif X//D%2 == 0 and K%2 == 0 or X//D%2 * K%2 == 1:
    ans = X%D
else:
    ans = D - X % D

print(ans)

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

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

dist = abs(x)

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

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

if abs(X) - K * D > 0:
    print(abs(X) - K * D)
else:
    i = round((K * D - abs(X)) / (2 * D))
    print(abs(abs(X) - K * D + i * D * 2))

Solution (Python):
import sys
X,K,D=map(int,input().split())
Xa=abs(X)
Da=abs(D)
one=Xa//Da

if K < one:
    print(Xa-Da*K)
    sys.exit()


guki=(K-one)%2

if guki==0:
    print(abs(Xa-Da*one))
else:
    print(abs(Xa-Da*(one+1)))

Solution (Python):
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    X, K, D = readnums()
    if X > 0:
        if X // D >= K:
            print(X - K * D)
        else:
            a1 = X % D
            a2 = D - X % D
            if (K - X // D) % 2:
                print(a2)
            else:
                print(a1)
    else:
        X = -X
        if X // D >= K:
            print(X - K * D)
        else:
            a1 = X % D
            a2 = D - X % D
            if (K - X // D) % 2:
                print(a2)
            else:
                print(a1)


if __name__ == "__main__":
    main()

Solution (Python):
x,k,d=input().split(" ")
x=int(x)
k=int(k)
d=int(d)
x=abs(x)
if x>k*d:
    print(x-k*d)
else:
    t=x//d
    x=x%d
    k-=t
    if k%2==1:
        print(d-x)
    else:
        print(x)

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

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

Solution (Python):



def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))
x,k,d = mp()
x = abs(x)
if x - k*d >= 0:
    print(x-k*d)
else:
    u = x % d
    l = abs(u - d)
    if (k - x//d) % 2 == 0:
        print(u)
    else:
        print(l)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X, K, D = [int(x) for x in input().split()]

    kcnt = abs(X) // D

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

    ans1 = abs(X) % D
    ans2 = abs(ans1 - D)

    if (K - kcnt) % 2 == 0:
        print(ans1)
    else:
        print(ans2)


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
import math
x, k, d = map(int, input().split())
mx = x + k*d
mn = x - k*d
ans = min(abs(mx), abs(mn));
p = abs(x)//d

l = max(p-1, 0)
r = min(p+1, k)
for n in range(l, r+1):
	rem = k - n
	mx = x + n*d
	mn = x - n*d
	
	if rem % 2 == 0:
		
		ans = min(ans, abs(mx), abs(mn))
	else:
		ans = min(ans, abs(mx+d), abs(mn+d));
		ans = min(ans, abs(mx-d), abs(mn+d));
		ans = min(ans, abs(mx+d), abs(mn-d));
		ans = min(ans, abs(mx-d), abs(mn-d));

print(ans)

Solution (Python):
x, k, d = map(int, input().split())
val = abs(x)
cnt = val // d
ans = val % d
if cnt >= k: ans = val - d * k
else:
    if (k - cnt) % 2 != 0: ans = abs(ans - d)
print(ans)

Solution (Python):
X,K,D = map(int,input().split())
if K*D<=abs(X):
    print(abs(X)-K*D)
    exit()

move_num_before = abs(X)//D
move_num_after = move_num_before+1
if (K - move_num_after)%2 == 0:
    print(abs(abs(X)-move_num_after*D))
    exit()
print(abs(X)-move_num_before*D)

Solution (Python):

x,k,d=map(int,input().split())
l=0
r=k
while (l<r-1):
    m=l+(r-l)//2
    if(x-k*d+2*m*d>0): r=m
    else: l=m
ans1=x-k*d+2*l*d;
ans2=x-k*d+2*r*d;
print(min(abs(ans1),abs(ans2)))

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

a=abs(x)//d

if x<0:
  d=d*(-1)

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

Solution (Python):
X, K, D = map(lambda x: int(x), input().split(" "))

candidates = []

if abs(X) >= abs(K*D):
    candidates.append(abs(X - K * D))
    candidates.append(abs(X + K * D))
else:
    tmp = X // D  
    if tmp % 2 == K % 2:
        candidates.append(abs(X - tmp * D))
        candidates.append(abs(X + tmp * D))
    else:
        candidates.append(abs(X - (tmp+1) * D))
        candidates.append(abs(X + (tmp+1) * D))
        candidates.append(abs(X - (tmp-1) * D))
        candidates.append(abs(X + (tmp-1) * D))

print(min(candidates))

Solution (Python):
def main():
    X, K, D = map(int, input().split())
    X = abs(X)
    if X >= K * D:
        return X - K * D
    else:
        div = X // D
        mod = [X % D, abs(X % D - D)]
        return mod[(K - div) % 2]

if __name__ == '__main__':
    print(main())

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

d = abs(X) // D
if d >= K:
  if X >= 0:
    ans = X - K * D
  else:
    ans = X + K * D
  print(abs(ans))
  exit()

if X >= 0:
  ans = X - d * D
else:
  ans = X + d * D

n = K - d
if n % 2 == 1:
  if ans >= 0:
    ans -= D
  else:
    ans += D

print(abs(ans))

Solution (Python):
x,k,d=map(int,input().split())
if x==0:
    if k%2==0:
        print(0)
    else:
        print(d)
elif x>0:
    if x-k*d>=0:
        print(x-k*d)
    else:
        a=x//d
        x-=d*a
        k-=a
        if k%2==0:
            print(x)
        else:
            print(abs(x-d))
else:
    if x+k*d<=0:
        print(abs(x+k*d))
    else:
        a=(-x)//d
        x+=d*a
        k-=a
        if k%2==0:
            print(abs(x))
        else:
            print(abs(x+d))

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

print(ans)

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

cnt = int(x/d)

x -= d*min(cnt, k)

if x > d/2 and cnt < k:
  x = abs(x - d)
  cnt += 1

if (k-cnt) % 2 == 1 and cnt < k:
  x -= d

print(abs(x))

Solution (Python):


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


if k*d< abs(x):
     print(abs(x)-(k*d))

elif (k*d)==abs(x):
    print(0)

else:

    x=abs(x)

    r=(x//d)

    p=x-r*d

    q=abs(p-d)

    k=k-r

    if k%2==1:
        print(q)
    else:
      print(p)

Solution (Python):
x,k,d = map(int,input().split())
if k * d < abs(x):
    print(abs(x) - k * d)
    exit()

amari = x % d
syou = x // d
a = k - syou
if a % 2 == 0:
    print(amari)
else:
    print(abs(d-amari))

Solution (Python):
x,k,d=map(int,input('').split(' '))
if x<0:
    x=x*(-1)

if x>=k*d:
    print(x-k*d)
else:
    e=x//d
    f=x%d
    g=f-d
    if g<0:
        g=g*(-1)
    
    if (k-e)%2==0:
        print(f)
    else:
        print(g)

Solution (Python):

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


saidai = X + K * D
saisyou = X - K * D

if(saidai == 0):
    ans = 0
elif(saisyou == 0):
    ans = 0
else:
    if(saidai > 0 and saisyou > 0):
        ans = abs(saisyou)
    elif(saidai < 0 and saisyou < 0):
        ans = abs(saidai)
    else:
        L = X // D
        P = X - L * D
        
        if(L % 2 == K % 2):
            l = [abs(P-6*D), abs(P - 4*D), abs(P-2*D), abs(P), abs(P+2*D), abs(P+4*D), abs(P+6*D)]
        else:
            l = [abs(P-5*D), abs(P - 3*D), abs(P-D), abs(P+D), abs(P+3*D), abs(P+5*D)]
        ans = min(l)
            
        '''
        a = X - L * D
        b = a + D
        c = b + D
        d = a - D
        e = d - D
        l = [abs(a), abs(b), abs(c), abs(d), abs(e)]
        ans = min(l)
        '''
        

print(ans)

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

q = abs(x) // d

if q >= k:
    print(abs(x) - (d * k))
    exit()

mod = abs(x) % d


if (k - q) % 2 == 0:
    print(mod)
else:
    print(abs(d) - mod)

Solution (Python):





"""
"""

from collections import defaultdict
from itertools import combinations
import bisect

import sys
input = sys.stdin.readline

def solve(x,k,d):
    x = abs(x)
    a = x // d
    if k <= a:
        ans = x - k * d
    elif (k - a) % 2 == 0:
        ans = x % d
    else:
        ans = d - x%d
    print(ans)

            

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


if __name__ == "__main__":
    main()

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

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

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

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

s = x // d

if s > k:
  nx = x - k * d
  print(nx)

else:
  nx = x - s * d
  nk = k - s
  if nk % 2 != 0:
    nx = abs(nx - d)
  print(nx)

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

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

Solution (Python):

"""
@author: H_Hoshigi
"""
def main():
    X, K, D = map(int, input().split())
    X = abs(X)

    answer = int()
    if X > 0:
        if X >= D*K:
            answer = X-D*K
        else:
            if (X//D)%2 == K%2:
                answer = X%D
            else:
                answer = D-X%D
    elif X == 0:
        if D%2 == 0:
            answer = 0
        else:
            answer = D
    print(answer)

if __name__ == "__main__":
    main()

Solution (Python):
import math
x, k, d = map(int, input().split())

if(abs(x) - k*d >= 0):
    print(abs(x) - k*d)
else:
    num = abs(x) // d
    rest = abs(x) % d

    if(num % 2 == 0):
        if(k%2==0): print(rest)
        else: print(d-rest)
    else:
        if(k%2==1): print(rest)
        else: print(d-rest)

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

Solution (Python):
import sys
import copy
from collections import deque
import collections
import itertools
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

x, k, d = na()

r = 1
if x < 0:
    r = -1

a = abs(x)//d

if a > k:
    print(r*x-k*d)
else:
    res1 = r*x-a*d
    res2 = res1 - d
    if (k-a)%2==0:
        print(abs(res1))
    else:
        print(abs(res2))

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

x = abs(x)

n = x//d
if n > k:
    ans = x - (k*d)

else:
    if (k - n) % 2 == 0:
        ans = x - (n*d)
    else:
        ans = x - ((n+1)*d)

print(abs(ans))

Solution (Python):
import math
X,K,D=map(int,input().split())

if abs(X)>=K*D:
    if X>=0:
        print(abs(X-K*D))
    else:
        print(abs(X+K*D))
else:
    a=math.ceil(X/D)
    b=X-a*D
    K-=a
    if K%2==0:
        print(abs(b))
    else:
        print(abs(b+D))

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

Solution (Python):
import os

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

x = abs(x)

ri=x//d
if ri <= k:
    nkr = k-ri
    if nkr%2==0:
        print(abs(x - ri*d))
    else:
        riso_a = abs(x-ri*d)
        print(min(abs(riso_a+d), abs(riso_a-d)))
elif ri > k:
   print(x - k*d)

Solution (Python):
x, k, d = map(int, input().split())
x = abs(x)
a = x // d 
if k <= a:
  print(x - k * d)
  exit()
k -= a
eveng = x - d * a
oddg = abs(x - d * (a + 1))
if k % 2 == 0:
  print(eveng)
else:
  print(oddg)

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

if x - k * d >= 0:
    print(x - k * d)
elif x + k * d <= 0:
    print(abs(x + k * d))
else:
    dis = x % d
    dis_p = d - dis
    c = k - x // d

    if c % 2 == 0:
        print(dis)
    else:
        print(dis_p)

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

cnt = X // D
ans1 = X - cnt * D
ans2 = abs(ans1 - D)

if abs(cnt) < K:
  if (K - abs(cnt))%2 == 0:
    print(ans1)
  else:
    print(ans2)
else:
  if X >= 0:
    print(X - K * D)
  else:
    print(abs(X + K * D))

Solution (Python):
X,K,D=map(int,input().split())
if abs(X) >=K*D:
  if X>=0:
    print(abs(X-K*D))
  else:
    print(abs(X+K*D))
  exit(0)
k=abs(X)//D
if X>=0:
  if k%2==K%2:
    print(abs(X-D*k))
  else:
    print(abs(D*(k+1)-X))
else:
  if k%2==K%2:
    print(abs(X+D*k))
  else:
    print(abs(D*(k+1)+X))

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



px = x%d
mx = x%d - d

pc = abs(x - px) // d
mc = abs(x - mx) // d

if min(pc,mc) < k:
  if ( (k-pc) % 2) == 0:
    print( abs(px) )
  else:
    print( abs(mx) )
else:
  print( abs(x) - d * k )

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

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

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

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

Y = X

if X < 0:
    X = -X

i = 0
posA = X % D
posB = posA - D
i = X // D + 1

if K >= i:
    if K % 2 == i % 2:
        print(abs(posB))
    else:
        print(abs(posA))
else:
    print(abs(X-D*K))

Solution (Python):
x, K, D = [int(i) for i in input().split()]
x = abs(x)

if K * D < x:
  print(x - K * D)
  exit(0)

v = x // D 
x = x % D  

nokori = (K - v) % 2
if nokori:
  print(abs(x - D))
else:
  print(x)

Solution (Python):
x,k,d = map(int,input().split())
syoki = round((k*d-x)/(2*d))
if syoki < 0:
    syoki = 0
elif syoki > k:
    syoki = k
answer = x - k*d + 2*syoki*d
print(abs(answer))

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

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

Solution (Python):


import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def solve(X, K, D):

    X = abs(X)
    if X/K > D or X/D > K or X > K*D :
        print(X-K*D)
        return
    cnt = X//D
    X %= D
    ans1 = X
    ans2 = D-X
    K -= cnt
    if K % 2 == 1:
        print(ans2)
    else:
        print(ans1)




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

if __name__ == '__main__':
    main()


'''
cd ~/Desktop/Programming/AtCoder/contest/abc175/abc175_c && sh shellscripts/test_py.sh
cd ~/Desktop/Programming/AtCoder/contest/abc175/abc175_c && sh shellscripts/etest_py.sh
cd ~/Desktop/Programming/AtCoder/contest/abc175/abc175_c && sh shellscripts/submit_py.sh
'''

Solution (Python):
x,k,d=map(int, input().split())
if x-k*d>0:
    print(x-k*d)
elif x+k*d<0:
    print(-x-k*d)
else:
    if (k-x//d)%2==0:
        print(abs(x-(x//d)*d))
    else:
        print(abs(x-(x//d+1)*d))

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

ans = 0
if k * d < abs(x):
    if x >= 0:
        ans = x - k*d
    else:
        ans = x + k*d
    print(abs(ans))
    exit()
    
xd = x // (2*d)
if k % 2:
    tmp = x - 2*d*xd
    l = [abs(tmp-d), abs(tmp+d), abs(tmp+3*d)]
    ans = min(l)
else:
    tmp = x - 2*d*xd
    l = [abs(tmp-2*d), abs(tmp), abs(tmp+2*d)]
    ans = min(l)
print(ans)

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

X = abs(X)
a = X / D
b = round(a)

c = K - b
e = 0

if c < 0:
    print(X-(K*D))
    e = 1
elif c % 2 != 0:
    if a > b:
        b = b + 1
    else:
        b = b - 1
if e == 0:
    d = abs(X - (D*b))
    print(d)

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

    L = abs(X)

    r = L // D
    c = L % D

    if K < r:
        print(L - K * D)
    elif K == r:
        print(c)
    elif K == r + 1:
        print(D - c)
    else:  
        if K % 2 == r % 2:
            print(c)
        else:
            print(D - c)


if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil

x,k,d = map(int,input().split())
x = abs(x)
steps = ceil(x/d)
if k <= steps:
  x = x-d*k
  print(abs(x))
else:
  k -= steps
  x = x-d*steps
  if k&1:
    print(abs(x+d))
  else:
    print(abs(x))

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

if abs(x)>=k*d:
    print(abs(x)-k*d)
else:
    v=x//d
    w=x%d
    k-=v
    if k%2==0:
        print(w)
    else:
        print(abs(w-d))