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())

def judge():
    l = x if x > 0 else -x
    i = l//d
    r = l%d

    if (k - i)%2 == 0:
        print(r)
    else:
        print(d - r)
    '''
    if x > 0:
        for r in range(d):
            if (x - r)/d == (x - r)//d:
                i = (x - r)//d
                if (k - i)%2 == 0:
                    print(r)
                else:
                    print(d-r)
                exit()
    else:
        l = -x
        for r in range(d):
            if (l - r)/d == (l - r)//d:
                i = (l - r)//d
                if (k - i)%2 == 0:
                    print(r)
                else:
                    print(d-r)
                exit()
    '''

if x == 0:
    if k%2 == 0:
        print(0)
    else:
        print(d)
elif x < 0:
    if k*d + x > 0:
        judge()
    else:
        print(abs(k*d + x))
else:
    if x - k*d < 0:
        judge()
    else:
        print(abs(x - k*d))

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

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

Solution (Python):


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

x = abs(x)

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

k -= x // d
x %= d

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

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


main()

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

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

print(ans)

Solution (Python):


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

moves = abs(x) // d

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

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

Solution (Python):

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

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

Solution (Python):
X, K, D = map(int,  input().split())
X = abs(X)
if K%2 == 1:
  K -= 1
  X -= D
  
K_ = K // 2

min_Y = X - K_ * (2 * D)

if min_Y > 0:
  print(min_Y)
else:
  min_Y_p = X % (2 * D)
  min_Y_m = 2 * D - X % (2 * D)
  print(min(min_Y_p, min_Y_m ))

Solution (Python):
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()



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

if X<0:
    X*=-1


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

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

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

else:
  ans=abs(X)-K*D
    
print(abs(ans))

Solution (Python):
import math

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

if X != 0:
  if X < 0:
    X = -X
  if K * D <= X:
    print(X - K * D)
  else:
    R = math.ceil(X / D)
    K -= R
    X -= D * R
    if K % 2 == 0:
      print(-X)
    else:
      print(X + D)  
else:
  if K % 2 == 0:
    print("0")
  else:
    print(D)

Solution (Python):
x,k,d=map(int,input().split())
if x<0:
    x*=(-1)
z=x//d
ans_p=x-z*d
ans_n=-(ans_p-d)
if k<z:
    ans=x-k*d
elif k==z:
    ans=ans_p
else:
    num=k-z
    if num%2==1:
        ans=ans_n
    else:
        ans=ans_p
print(ans)

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

if K*D <= X:
    X -= K*D
else:
    K %= 2
    for i in range(K):
        if X > 0:
            X -= D
        else:
            X += D
print(abs(X))

Solution (Python):
x,k,d = [int(x) for x in input().split()]
if x < 0:
  x *= -1
def f():
  c = 0
  if x - (k * d) > 0:
    c = x - (k * d)
    return True
  return False

def check():
  l = 0
  r = k
  while l <= r:
    m = (r + l) // 2
    p = x - d * (2 * m - k)
    
    if p > d:
      l = m + 1
    elif p < -1 * d:
      r = m - 1
    else:
      return m
  return m

if f():
  print(x - (k * d))
else:
  m1 = check()
  t = x - d * (2 * m1 - k)
  print(abs(t))

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

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

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

if K%2 == 0:
    print(X)
else:
    print(D-X)

Solution (Python):
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    X,K,D = i_map()
    if X<=0:
        X = -X
    tmp1 = X//D
    tmp2 = X-(tmp1 * D)
    if(tmp1 < K):
        if((K-tmp1)%2 == 0):
            print(tmp2)
        else:
            print(D-tmp2)
    else:
        print(X - K * D)

    return

if __name__ == '__main__':
    main()

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

if X>=D and D*K<=X:
  ans = X - D*K
if X>=D and D*K>X:
  K=K-int(X/D)
  X=X%D
  if K%2==0:
    ans=X
  else:
    ans = abs(X-D)
if X<D:
  if K%2==0:
    ans = X
  else:
    ans = abs(X-D)

print(ans)

Solution (Python):
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    X,K,D = i_map()
    if X<=0:
        X = -X
    tmp1 = X//D
    tmp2 = X-(tmp1 * D)
    if(tmp1 < K):
        if((K-tmp1)%2 == 0):
            print(tmp2)
        else:
            print(D-tmp2)
    else:
        print(X - K * D)

    return

if __name__ == '__main__':
    main()

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

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

M=X//D
Q=X%D

if M%2 == K%2:
    print(Q)
else:
    print(D-Q)

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

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

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

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

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

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

Solution (Python):
x, k, d = [int(x) for x in input().split(' ')]
x = abs(x)

q = x // d
r = x % d

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

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

ans = 0

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

print(ans)

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

X = abs(X)

candidate1 = abs(X - K*D)
candidate2 = abs(X % D)
candidate3 = candidate2 - D

count2 = (X - candidate2)//D
if (K - count2) % 2==0:
    count2ok = True
else:
    count2ok = False


count3 = (X - candidate3)//D
if (K - count3) % 2==0:
    count3ok = True
else:
    count3ok = False

candidate3 = abs(candidate3)

if abs(X) - K*D > 0:
    print(candidate1)
elif count2ok == True and count3ok == True:
    print(min([candidate1, candidate2, candidate3]))
elif count2ok == True:
    print(min([candidate1, candidate2]))
elif count3ok == True:
    print(min([candidate1, candidate3]))
else:
    print(candidate1)

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

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

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

Solution (Python):
x,k,d = list(map(int, input().split()))
amari = abs(x) % d
shou = abs(x) // d

amari_ = abs(amari - d)
if k < shou:
  print(abs(x) - d * k)
else:
  if (k - shou) % 2 == 0:
    print(amari)
  else:
    print(amari_)

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

Solution (Python):

x, k, d = map(int,input().split())
x=abs(x)
t=x-k*d
if t>=0:
    ans=t
else:
    l=x//d
    p=x%d
    if (k-l)%2==0:
        ans=p
    else:
        ans=min(abs(p+d), abs(p-d))
print(ans)

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

X = abs(X)

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

if (K-X//D)%2:
    print(D-X%D)
else:
    print(X%D)

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

def sgn(x):
  if x > 0:
    return 1
  if x < 0:
    return -1
  return 0

if x > 0:
  x1 = x - k * d
else:
  x1 = x + k * d

if sgn(x) == sgn(x1):
  print(abs(x1))
  exit()
  
xright = x % d
xleft = x % d - d

xr = (abs(x - xright) // d) % 2
if k % 2 == xr:
  print(abs(xright))
elif k % 2 != xr:
  print(abs(xleft))

Solution (Python):
import sys

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

if k <= x // d:
    ans = x - k*d
    print(ans)
    sys.exit()

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

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

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

x -= d*g
k -= g

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

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

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

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

y = abs(X)//D

if K<=y:
    print(abs(abs(X)-K*D))

else  :
    a = (abs(X)-y*D)
    b = (abs(X)-(y+1)*D)
    
    C = abs(a)
    D = abs(b)
    
    if (K-y)%2==0:
        print(C)
    else:
        print(D)

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

if (X < 0):
	lo, hi = 0, K
	while (lo < hi):
		mid = int(lo+ (hi - lo) / 2)
		if (X + mid*D >= 0):
			hi = mid;
		else:
			lo = mid + 1;
	if (X + hi*D < 0):
		p1 = hi
		if (abs(X + p1*D) < result):
			result = abs(X + p1*D)
	else:
		p1 = lo
		rem1 = K - p1
		if (rem1%2 == 1):
			result = min((result, abs(X + p1*D + D), abs(X + p1*D - D)))
		p2 = lo - 1
		rem2 = K - p2
		if (rem2%2 == 1):
			result = min((result, abs(X + p2*D + D), abs(X + p2*D - D)))
	print(result)
elif (X > 0):
	lo, hi = 0, K
	while (lo < hi):
		mid = int(lo+ (hi - lo) / 2)
		if (X - mid*D <= 0):
			hi = mid;
		else:
			lo = mid + 1
	if (X - hi*D > 0):
		p1 = hi;
		if (abs(X - p1*D) < result):
			result = abs(X - p1*D)
	else:
		p1 = lo
		rem1 = K - p1
		if (rem1%2 == 1):
			result = min((result, abs(X - p1*D - D), abs(X - p1*D + D)))
		p2 = lo - 1;
		rem2 = K - p2
		if (rem2%2 == 1):
			result = min((result, abs(X - p2*D - D), abs(X - p2*D + D)))
	print(result)
else:
	if (K%2 == 1):
		print(D)
	else:
		print(0)

Solution (Python):
x, k, d = 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)

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

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

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

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

print(ans)

Solution (Python):
X, K, D = map(int,input().split())
X = abs(X)
T = X//D
if K < T:
    print(X-K*D)
else:
    X -= T*D
    K -= T
    if K&1:
        print(D-X)
    else:
        print(X)

Solution (Python):
x,k,d = map(int,input().split())
y = abs(x)//d
if y >= k:
        ans = abs(abs(x)-d*k)

else:
        if (k-y)% 2 == 0:
                ans = abs(abs(x)-d*y)
        else:
                ans = min(abs(abs(x)-d*y+d),abs(abs(x)-d*y-d))
print(ans)

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

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

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

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

k -= a
x -= a * d

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

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

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

Solution (Python):

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



if __name__ == "__main__":
    main()

Solution (Python):

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

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

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

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

Solution (Python):
def resolve():
    import math
    x, k, d = list(map(int, input().split()))
    ans = abs(x)
    x = abs(x)
    if x - d * k >= 0:
        ans = x - d * k
    else:
        k -= math.floor(x / d)
        x -= math.floor(x / d) * d
        if k % 2 == 1: x = abs(x - d)
        ans = x
    print(ans)


resolve()

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

x = abs(x)
c = x // d

k_r = k - c

ans_2 = x - d * c


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

x_l = x - d * c


if k_r % 2 == 0:
    print(ans_2)
    exit()
else :
    x_l -= d
    x_l =abs(x_l)
    print(x_l)

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

x = abs(x)

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

Solution (Python):
def main():
    x, k, d = map(int, input().split())
    l = 0
    r = k
    ans = abs(x + k * d)
    while l <= r:
        mid = int((l + r)/2)
        nw = x - mid*d + (k - mid)*d
        ans = min(abs(nw), ans)
        if nw < 0:
            r = mid - 1
        else:
            l = mid + 1
    print(ans)

main()

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

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


print(ans)

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

        
N=int(X/D)

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

Solution (Python):
a,c,b = list(map(int, input().split()))

a = abs(a)
b = abs(b)
c = abs(c)

if b*c <= a:
  print(a - (b*c))
else:
  c -= a//b
  a = a%b
  
  if c%2==0:
    print(a)
  else:
    print(abs(a-b))

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

Solution (Python):
x,k,d=[int(i) for i in input().strip().split(" ")]

x=abs(x) if x<0 else x

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

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

X = abs(X)


r = X%D

q = X//D



if K <= q:
    print(X-D*K)
else:
    
    rem = K - q

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

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

X = abs(X)
if X >= K * D:
  ans = X - K * D

else:
  n, d = divmod(X, D)
  ans = d
  if (K - n) % 2:
    ans = D - d


print(ans)

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

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

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

x-=first_move*d
x=abs(x)
k-=first_move
print(abs(x-d) if k&1 else x)

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

Solution (Python):
x, k, d = map(int, input().split(' '))
b = x + k * d;
if b > 0:
    a = int(b / (2 * d))
    if a <= k:
        print(min(b-a*2*d, -(b-(a+1)*2*d)))
    else:
        print(b-k*2*d)
else:
    print(-b)

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

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

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

if x >= k*d:
    print(x-k*d)
else:
    t = x//d
    t -= int(t%2 ^ k%2)
    print(min(x-d*t, abs(x-d*(t+2))))

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

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

Solution (Python):
x,k,d=[int(i) for i in input().strip().split(" ")]
x=abs(x) if x<0 else x
if x//d>=k:
    print(x-d*k)
else:
    if (k-x//d)%2==0:
        print(x%d)
    else:
        print(d-(x%d))

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

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

X = abs(X)

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

    if K % 2 == 1:
        X = abs(X-D)

    print(X)

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

value = abs(X)

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

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

x=abs(x)

a=x//d

if a>=k:
    ans=x-k*d

elif (k-a)%2==0:
    ans=x-d*a

else:
    ans=x-d*a-d

print(abs(ans))

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    x, k, d = map(int, input().split())
    desired = abs(x) // d
    if k <= desired:
        if x < 0:
            x += k * d
        else:
            x -= k * d
        print(abs(x))
        return
    if x < 0:
        x += desired * d
    else:
        x -= desired * d
    if (k - desired) % 2 == 0:
        print(abs(x))
        return
    if x == 0:
        print(d)
    elif x > 0:
        x -= d
        print(abs(x))
    elif x < 0:
        x += d
        print(abs(x))


if __name__ == '__main__':
    main()

Solution (Python):

import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')


REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn


TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        X, K, D = map(int, self.input_data().split())
        if abs(X) > K * D:
            result = abs(X) - K * D
        else:
            if int(abs(X) / D) % 2 == K % 2:
                result = abs(X) - int(abs(X) / D) * D
            else:
                result = (int(abs(X) / D) + 1) * D - abs(X)

        print(str(result))


solver = Solver(REL_PATH)
solver.exec_resolve()

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

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

print(ans)

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

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

x = abs(x)

m = x // d

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

elif (k-m) % 2 == 0:
    ans = x - (d*m)

else:
    ans = x - (d*m) - d

print(abs(ans))

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

n=math.ceil(X/D)
m=math.floor(X/D)

n_moveto0=0

if abs(X-n*D) <= abs(X-m*D):
  n_moveto0=abs(n)
  x_min=X-n*D
else: 
  n_moveto0=abs(m)
  x_min=X-m*D


if n_moveto0>=K:
  print(min([abs(X-D*K),abs(X+D*K)]))
else:
  if (K-n_moveto0)%2==0:
    print(abs(x_min))
  else:
    print(min([abs(x_min+D),abs(x_min-D)]))

Solution (Python):


def walk(X, K, D):
  abX = abs(X)
  if abX >= K*D:
    return abX - K*D
  itr = round(abX/D)
  ret = K - itr
  res = abs(abX - D*itr)
  if (ret % 2) == 0:
    return res
  return abs(res - D)

if __name__ == "__main__":
  inputs = list(map(int, input().split()))
  print(walk(inputs[0], inputs[1], inputs[2]))

Solution (Python):
X, K, D = map(int, input().split())
if X < 0:
    X = -X
step = X//D
X -= D*step
K -= step

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
from itertools import product
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]

def array2d(N, M, initial=0):
    return [[initial]*M for _ in range(N)]

def copy2d(orig, N, M):
    ret = array2d(N, M)
    for i in range(N):
        for j in range(M):
            ret[i][j] = orig[i][j]
    return ret


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


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

    
    d, m = divmod(X, D)
    cand = (m, m-D)

    if X >= 0:
        if K <= d:
            print(X-K*D)
            return
        else:
            rest = (K-d)
            if rest % 2 == 0:
                print(cand[0])
                return
            else:
                print(-cand[1])
                return
    else:
        if K <= -d-1:
            print(abs(X+K*D))
            return
        else:
            rest = K-(-d-1)
            if rest % 2 == 0:
                print(-cand[1])
                return
            else:
                print(cand[0])
                return
    return


if __name__ == '__main__':
    main()

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

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

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

absX = abs(X)
a = absX - K * D
minX = absX % D

if a > 0:
    print(a)

elif a <= 0:

    Kmin = (absX - minX) / D
    Krem = K - Kmin

    if Krem % 2 == 0:
        print(min(abs(minX), abs(minX - 2 * D)))
    else:
        print(min(abs(minX + D), abs(minX - D)))

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

x = abs(x)

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

print(ans)

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

x = abs(x)








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





p = x%d
rem = k - x//d
if rem%2 == 0:
   print(p)
else:
    print(abs(p -d))

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