peterverebics/CodeNet_Python_118 huggingface dataset:
X,K,D = map(int, input().split())
if K*D <= X:
    print(X - K*D)
else:
    q, mod = divmod(X, D)
    if q % 2 == 0 and K % 2 == 0:
        print(abs(X - D * q))
    elif q % 2 == 0 and K % 2 == 1:
        print(abs(X - D * (q+1)))
    elif q % 2 == 1 and K % 2 == 1:
        print(abs(X - D * q))
    elif q % 2 == 1 and K % 2 == 0:
        print(abs(X - D * (q+1)))
[x, k, d] = list(map(int, input().split()))
howMany = x // d
remainder = x % d
stepLeft = k - howMany
if k < howMany:
    print((howMany - k) * d)
elif stepLeft % 2 == 0:
    print(remainder)
elif stepLeft % 2 == 1:
    print(d - remainder)
X, K, D = map(int, input().split())

q, r = divmod(X, D)

if X >= K*D:
    print(X-K*D)
elif abs(K-q) % 2 == 0:
    print(r)
else:
    print(abs(r-D))
x,k,d = map(int, input().split())
ans=0
p=x//d
if abs(x)>=k*d:
    ans=abs(x)-k*d
elif abs(x)<=d:
    if k%2==0:
        ans=abs(x)
    else:
        if x<=0:
            ans=x+d
        else:
            ans=d-x
else:
    if (k-p)%2==0:
        ans=abs(x)-p*d
    else:
        ans=abs(abs(x)-p*d-d)        
print(ans)
x,k,d = map(int,input().split())
a = 0

if x < 0:
    a = abs(x)//d
    if k < a:
        x += k*d
        k = 0
    else:
        x += a*d
        k -= a
else:
    a = x//d
    if k < a:
        x -= k*d
        k = 0
    else:
        x -= a*d
        k -= a

b = abs(x-d)
c = abs(x+d)

if 0 < k and k % 2 == 1:
    x = min(b,c)

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

cent = x % d
num = x // d

if d / 2 > cent and cent != 0:
    cent = d - cent
    num += 1

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

rem = k - num

if rem % 2 == 0:
    print(cent)
    exit(0)
else:
    print(d - cent)
x,k,d=map(int,input().split())

cnt=abs(x)//d

if cnt>k:
    cnt=k


if x>=0:
    p=x-d*cnt
else:
    p=x-d*cnt

k-=cnt

if p==0 and k%2==1:
    print(d)
else:
    print(p)
import sys,collections,math,random,fractions,bisect,itertools;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]
 
x,k,d = I()
if x/d >= k:
    print(x-k*d)
else:
    if (k - math.floor(x/d))%2 == 0:
        print(abs(x%d))
    else:
        print(abs(x%d-d))
x,k,d = map(int,input().split())
ans = 0

if x>0:
  if x-k*d>0:
    ans = x-k*d
  else:
    if (k-(x//d))%2 == 0: #右
      ans = x-(x//d)*d    
    else:
      ans = abs(x-(x//d+1)*d)  
else:
  if x<0 and x+k*d>0:
    ans = x+k*d
  else:
    if (k-(-x//d))%2 == 1: #左
      ans = abs(x-(x//d+1)*d)
    else:
      ans = x-(x//d)*d          
print(ans)
def mini(X, K, D):
    for i in range(K):
        X -= D
        if X <= 0:
            K -= i
            break
        if i == K-1:
            return abs(X)
    if K%2 == 0:
        return abs(X + D)
    else:
        return abs(X)

if __name__ == '__main__':
    X, K, D = map(int, input().split())
    print(mini(X, K, D))
x,k,d=map(int,input().split())
n=(k*d-x)//(2*d)
print(min(abs(x+2*n*d-k*d),abs(x+2*(n+1)*d-k*d)))
X, K, D = map(int, input().split())

d = int(abs(X)/D)
if X > 0:
    r = X - d*D
    if abs(r-D) < abs(r):
        r = r-D
else:
    r = X + d*D
    if abs(r+D) < abs(r):
        r = r+D

min_count = int((X-r)/D)

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

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

    print(abs(-(k % 2)*d + x))


if __name__ == '__main__':
    main()
s = input()
x, k ,d = s.split(" ")
x, k ,d = int(x), int(k), int(d)
score = abs(x)
t = 1
if x-d>0:
    while(t<=k and x-t*d>0):
        t+=1
        score = min([score, x-t*d])
    score = min([score, abs(x-(t+1)*d)])
elif x+d<0:
    while(t<=k and x+t*d<0):
        t+=1
        score =min([score,x+t*d])
    score =min([score, abs(x+(t+1)*d)])
else:
    score =min([score, abs(x-d), abs(x+d)])
x, k, d = map(int,input().split())
if (x >= k*d):
  print(x - k*d)
else:
  nokori = k - x//d
  if (nokori%2 == 0):
    print(abs(x%d))
  else:
    print(abs(x%d - d))
X, K, D = map(int, input().split())

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

if K > 0:
    if K%2 == 1:
        A = A - D

print(abs(A))
X,K,D = map(int, input().split())
ans = 0

if K%2 == 0:
    ans = abs(X-(D*2))
    print(ans)
    exit()
else:
    ans = abs(X-D)
    for i in range(2, K+1):
        num = abs(X-(D*i))
        if ans >= num:
            ans = num
        else:
            break
    print(ans)
    exit()
import sys
input = sys.stdin.readline
x,k,d=map(int,input().split())
val = x//d
if val>0:
    if val>k:
        x-=(k*d)
    
    if val<=k:
        x-=(val*d)
    print(x)
    sys.exit()
else:
    print(x)
X,  K,  D = list(map(int, input().split()))
L = X + D * K
 
if L >= 0:
   if K == 1 or D == 1:
      print(abs(X - D*K))
      exit()
   if L / (2 * D) - int(L / (2 * D)) > 0.5:
      a = L // (2 * D) + 1
   else:
      a = L // (2 * D)
 
elif L < 0:
   if L / (2 * D) - int(L / (2 * D)) < -0.5:
      a = int(L / (2 * D)) - 1
   else:
      a = int(L / (2 * D)) 
print(abs(X-2*D*a+D*K))
x,k,d=map(int,input().split())
x=abs(x)
if x-k*d>=0 and x>0:print(x-k*d)
else:
    num1,num2=x%d,d-x%d
    if num1==num2:print(num1)
    else:
        A,B=(x//d)%2,k%2
        if A==0 and B==0:
            print(num1)
        elif A==1 and B==1:
            print(num2)
        elif A==1 and B==0:
            print(num1)
        else:print(num2)
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 * (D - 1)))
x,k,d = map(int, input().split())

y = x % d
l = x // d
m = k - l

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

print(abs(ans))
X,K,D = map(int, input().split())
L = 0
M = 0
N = 0
S = 0
if(K %2 ==1):
  K =K-1
  if(X >0):
    X = X-D
  else:
    X = X+D
L = D*2
N = int(K/2)
M = int(abs(X)/L)
S = min(abs(abs(X)-M*N*2),abs(abs(X)-M*2*(N+1)))
if(M+1 <= N):
  print(S)
else:
  print(abs(abs(X)-K*D))
X, K, D= list(map(int, input().split()))
a, b = X // D, X % D
ans = X
if a < 0:
    a = abs(a)
if a > K:
    if X < 0:
        ans = X + K * D
    else:
        ans = X - K * D
elif K % 2 == a % 2:
    ans = b
else:
    ans = abs(b - D)
print(ans)
x, k, d = map(int, input().split())
x = abs(x)

tmp1 = x - d * (x // d)
tmp2 = tmp1 + d

if x >= k * d:
    print(x - k * d)
elif x == 0 and k % 2 == 0:
    print(0)
elif x == 0 and k % 2 == 1:
    print(d)
elif x == d and k % 2 == 0:
    print(x)
elif x == d and k % 2 == 1:
    print(0)
elif k % 2 == 0:
    print(min(abs(tmp1), abs(tmp2)))
else:
    print(max(abs(tmp1), abs(tmp2)))
x, k, d = map(int, input().split())
x0 = x
if k%2 == 0 and abs(x)==abs(d):
  print(abs(x))
  exit()

for i in range(k):
  """if abs(x - d) <= abs(x + d):
      x = x - d
  else:
      x = x + d"""
  if abs(x) > abs(x - (d*i) + d*(k-i)):
    x = x - (d*i) + d*(k-i)
    #print(x)
if abs(x0) > abs(x - d*k):
    x = x - (d*k)
print(abs(x))
x,k,d=map(int,input().split())
print(min(abs(x-k*d),abs(x+2*d-k*d)))
X, K, D = map(int, input().split())

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

a = X // D
b = X % D

remain_count = K - a

if remain_count < 0:
    ans = X - K * D
else:
    if remain_count % 2 == 0:
        ans = min(b, abs(b - D))
    else:
        ans = max(b, abs(b - D))
    
print(ans)
x,k,d = map(int, input().split())
r = x//d
s = 0
ans = 0
if r>k:
    ans = abs(abs(x)-abs(k*d))
else:
    l = (k-r)%2
    if l==0:
        ans = abs(abs(x)-abs(d*r))
    else:
        ans = abs(abs(x)-abs(d*(r+1)))
print(ans)
x,k,d = map(int,input().split())

if x < 0:
    x *= -1

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

if x-k*d < 0:
    if (k-(round(x/d)))%2 == 0:
        print(x%d)
    else:
        print(abs(x%d-d))
else:
    print(abs(x-k*d))
x, k, d = [int(i) for i in input().split()]
l = abs(k * d - abs(x))
print(min([abs(l % (2*d)), abs(l % (2*d) - 2*d)]))
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))
A = list(map(int,input().split()))
X,K,D = A[0], A[1], A[2]

if abs(X) >= K*D:
    print(abs(X)-K*D)
elif X == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
else:
    d = abs(X) // K
    amari = abs(X) % K
    hantai = K - amari
    
    if K - d % 2 == 0:
        print(amari)
    else:
        print(hantai)
x, k, d = map(int, input().split())
if abs(x) >= k * d:
    if x >= 0:
        print(x - k * d)
    else :
        print(-(x + k * d))
    exit()
if x < 0:
    x = -x
a = x // d
if a % 2 == k % 2:
    ans = min(x % d, d - x % d)
else:
    ans = max(x % d, d - x % d)
print(ans)
x, k, d = map(int, input().split())

# print(x,k,d)

x = abs(x)
if x < d:
    if k%d:
        print(d-x)
    else:
        print(x)
    exit()

c = min(x//d, k)
x = abs(x-d*c)
k = k-c
# print(k,c,x)
if x == 0:
    if k%2==0: # even
        print(0)
    else: # odd
        print(d)

else: # +
    print(x)
x,k,d=map(int,input().split())
a=divmod(abs(x),d)
if a[0]<k:
  if a[0]%2!=0:
    if a[1]<=d//2:
      print(a[1])
    else:
      print(d-a[1])
  else:
    print(a[1])
else:
  print(abs(x)-d*k)
x,k,d=map(int,input().split())
x=abs(x)
s=0
e=k 
ans=x
if(k%2!=0):
    ans=abs(x-d)
while(s<=e):
    mid=(s+e)//2
    if abs(x-mid*d)<=ans:
        ans=min(ans,abs(x-mid*d))
        s=mid+1
    else:
        e=mid-1
print(ans)
X,K,D = map(int, input().split())
L = 0
M = 0
N = 0
S = 0
if(K %2 ==1):
  K =K-1
  if(X >0):
    X = X-D
  else:
    X = X+D
L = D*2
N = int(K/2)
M = int(abs(X)/L)
S = min(abs(abs(X)-K*N),abs(abs(X)-M*(K+2)))
if(M < N):
  print(S)
else:
  print(abs(abs(X)-K*D))
x, k, d = map(int, input().split())
if abs(x) > k * d:
    print(abs(x) - k * d)
else:
    a = abs(x) % d
    b = a - d
    if a == 0 and (k - (abs(x) // d)) % 2 == 1:
        print(abs(abs(x) % d - d))
    else:
        print(min(abs(a), abs(b)))
a = input().split()
x, k, d = abs(int(a[0])), int(a[1]), int(a[2])
if x > 0:
    while x > 0 and k > 0:
        x -= d
        k -= 1
    if x <= 0:
        if k % 2:
            print(x + d)
        else:
            print(abs(x))
    else:
        print(x)
x, k, d = map(int, input().split())

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

print(ans)
# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
x = abs(x)
x_ = x % d
k_ = x // d
if(x_ == 0):
  x_ = x_ + d

if(k < k_):
  x_ = x - (k * d)

print(x_)
X,K,D=map(int,input().split())
def solve(X,K,D):
  if abs(X)>D:
    a=abs(X)//D
    if K>a:
      X=X%D
      K-=a
    else:
      return abs(abs(X)-D*K)
  if K%2==0:
    return X
  else:
    return abs(abs(X)-D)
print(solve(X,K,D))
li=  list(map(int,input().split()))	       
X, K, D=li[0], li[1], li[2]
if X>K*D:
    print(X-K*D)
else:
    N=X//D
    Min=10**16
    n=0
    for i in range(N-1, N+2):
        M=X-i*D
        if M<Min:
            Min=M
            n=i
    if (K-n)%2==0:
        print (abs(Min))
    else:
        print(min(abs(Min+D), abs(Min-D)))
x,k,d = map(int,input().split())
jud = x//d

if(jud == 0):
  if((k)%2 == 1):
    print(abs(abs(x)-d))
  else:
    print(abs(x))
    
else:
  jud += 1
  if(k<=jud):
    print(abs(abs(x)-d*k))
  else:
    if((k-jud)%2 == 1):
      print(abs(abs(x)-(jud-1)*d))
    else:
      print(abs(abs(x)-(jud)*d))
import math
X, K, D = map(int,input().split())
X = math.fabs(X)
ans = 0
E = X//D
if X - K*D > math.fabs(X- (K+1)*D):
    ans = X - K * D
elif K%2 == X//D%2:
    ans = X-E*D
else:
    ans = -X+(E+1)*D
print(ans)
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 15 17:44:21 2020

@author: Paras
"""

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

moves = abs(x)//d
if moves>k:
    print(abs(x)-(k*d))
    
elif moves==k:
    print("0")
    
else:
    closest = abs(x)-moves*d
    if closest==0:
        leftmoves = k-moves
        if leftmoves%2==0:
            print("0")
        else:
            print(closest+d)
    else:
        print(closest)
X, K, D = list(map(int, input().split()))

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

q = X // D
mod = X % D

if q > K:
    ans = abs(abs(X)-K*D)
elif q==K:
    ans = mod
else:
    if (K-q)%2 == 1:
        a1 = mod - D
        a2 = mod + D
        ans = min(abs(a1),abs(a2))
    else:
        ans = mod

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

cent = x % d
num = x // d

if d / 2 > cent:
    cent = d - cent
    num += 1

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

rem = k - num

if rem % 2 == 0:
    print(cent)
    exit(0)
else:
    print(d - cent)
X, K, D = map(int, input().split())
X = abs(X)
point = X % D
q = X / D
remain = K - q
if q >= K:
    print(X-D*K)
    exit(0)
if remain % 2 == 0:
    print(point)
    exit(0)
else:
    print(D-point)
X, K, D = [int(x) for x in input().split()]

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

if K<=X//D:
  print(X-K*D)
else:
  Z=X-D*(X//D)
  K-=X//D
  if K%2==0:
    print(Z)
  else:
    print(abs(Z-D))
import sys

array = list(map(int, input().strip().split()))
x = array[0]
k = array[1]
d = array[2]
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))
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

l = li()
x, k, d = l[0], l[1], l[2]
calc = x // d
mi = min(k, calc)
k -= mi
x -= mi * d

if k % 2 == 0:
	print(x)
else:
	print(abs(x-d))
X, K, D = map(int, input().split())

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

m = X % D
if m != 0:
    a = X // D
    if (K - a) % 2 == 0:
        print(m)
    else:
        print(D - m)
else:
    a = X // D
    if (K - a) % 2 == 0:
        print(0)
    else:
        print(D)
x,k,d=map(int,input().split())

x=abs(x)

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

x = abs(x)

decim = x/d

if (decim > k):
    print(abs(x - k*d))
    exit(0)
else:
    if (x % d == 0):
        print(0)
    else:
        lower = x // d
        upper = lower + 1
        print(min(abs(x - lower*d), abs(x - upper*d)))
X, K, D = map(int, input().split())

X = abs(X)

quotient = X // D
rest = X % D

if quotient <= K:
  if quotient == 1 and rest == 0 and K % 2 == 0:
    tmp = X
  elif quotient == 1 and rest == 0 and K % 2 != 0:
    tmp = X - D
  elif quotient == 0 and rest == X and K % 2 == 0:
    tmp = X
  elif quotient == 0 and rest == X and K % 2 != 0:
    tmp = X - D
  else:
    tmp = X - quotient * D
else:
  tmp = X - K * D 

print(abs(tmp))
import math

start, kai, step = map(int, input().split(" "))

if start >= 0:
    if 0 <= start - (kai * step):
        print(abs(start) - (kai * step))
        exit()
else:
    if 0 > start - (kai * step):
        print(abs(start) - (kai * step))
        exit()

ans1 = start % step
ans2 = abs(ans1 - step)
if (kai - abs(start // step)) % 2 == 0:
    print(abs(ans1))
else:
    print(abs(ans2))
from sys import stdin
input = stdin.readline

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

m = X % D
l = X // D

if l > K:
    print(abs(abs(X) - D * K))
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)
x,k,d=map(int, input().split())
if d*k>=x:
	f=x//d
	x=x-d*f
	if f%2==0:
		ans=x
	else:
		ans=-(x-d)
else:
	ans=x-(d*k)
	
print(ans)
# -*- coding: utf-8 -*-
X,K,D=map(int,input().split())

ii=int(X/D)
if K>=ii and X>0:
    X-=ii*D
elif K>=ii and X<0:
    X+=ii*D
elif (K-ii)%2==0 and X>0:
    X-=K*D
elif (K-ii)%2==0 and X<0:
    X+=K*D
elif X>0:
    X-=(K+1)*D
else:
    X+=(K+1)*D

print(abs(X))
X,K,D = [int(x) for x in input().split()]

if abs(X) >= K * D:
    print(abs(X) - K * D)
else:
    K = K - int(abs(X) / D)
    X = int(abs(X) % D)
    if int(abs(X) % D) >= int(D / 2):
        if K % 2 == 0:
            print(X)
        else:
            print(D - X)
    else:
        print(X)
X, K, D = map(int,input().split())
res = 0
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))
x,k,d = map(int,input().split())

init = 10**16
count =0
while True:
    if count == k:
        break
    count += 1
    next1 = abs(x)+d
    next2 = abs(x)-d
    next = min(abs(next1),abs(next2))
    if abs(x) <= abs(next):
        break
    else:
        x=next

if (k-count) % 2:
    print(abs(x))
elif k==count:
    print(abs(x))
else:
    print(abs(abs(x)-abs(d)))
X, K, D = map(int, input().split())
X=abs(X)
if D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif D<X and K*D<X:
    ans=X-K*D
else:
    ans=min(X,K*D-X)%D
    for i in range(0,K):
        ans=ans-1
        if ans<0 and (K-i)%2==0:
            ans=(ans+1)*D
            break
        elif ans<0 and (K-i)%2==1:
            ans=(-ans)*D
            break
print(ans)
x, k, d = map(int, input().split())
x = abs(x)
if x == d:
    if k % 2:
        print(abs(x - d))
    else:
        print(abs(x))
else:
    a = x // d
    b = x % d
    if a <= k:
        print(b)
    else:
        print(x - (d * k))
line = input()

strL = line.split()
X = int(strL[0])
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    if X > 0:
        ans = abs(X - K * D)
    else:
        ans = abs(X + K * D)
    
elif (K - div) % 2 != 0:
    if mod > 0:
        ans = mod - D
    else:
        ans = mod + D
else:
    ans = mod

print(int(abs(ans)))
X, K, D = map(int, input().split())
scnt = abs(X) // D
if K <= scnt:
    if X > 0:
        print(X - K * D)
    else:
        print(X + K * D)
else:
    if abs(X) % D == 0:
        if (K - scnt) % 2 == 0:
            print(0)
        else:
            print(D)
    else:
        if (K - scnt) % 2 == 0:
            print(X - scnt * D)
        else:
            print(abs(X - (scnt + 1) * D))
x, k, d = map(int, input().split())
if abs(x) // d >= k:
    if x > 0:
        print(x - k * d)
    else:
        print(abs(k * d + x))
    exit()
div = abs(x) // d
k -= div
if x > 0:
    x -= div * d
else:
    x += div * d
if k % 2 == 0:
    print(abs(x))
else:
    print(abs(x - d))
import math

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

KL = (X+K*D)/(2*D)

if KL < K:
    ans1 = X - math.floor(KL)*D + (K-math.floor(KL))*D
    ans2 = X - math.ceil(KL)*D + (K-math.ceil(KL))*D
    if abs(ans1) < abs(ans2):
        print(abs(ans1))
    else:
        print(abs(ans2))
else:
    print(abs(X-K*D))
i = list(map(int, input().split()))
x=(abs(i[0]))

if x>=i[1]*i[2]:
    print(x-i[1]*i[2])
else:
    if ((x%i[2]>=(i[2]-x%i[2]))^((i[1]-x//i[2])%2==1)):
        print(i[2]-x%i[2])
    else:
        print(x%i[2])
A = list(map(int, input().split())) 

x = A[0]
k = A[1]
d = A[2]

if (k - 1) % 2 == 0:
  plus = x + d
  minus = x - d
  if abs(plus) > abs(minus):
    x = minus
  else:
    x = plus
else:
  for i in range(2):
    plus = x + d
    minus = x - d
    if abs(plus) > abs(minus):
      x = minus
    else:
      x = plus

print(abs(x))
def resolve():
    P, N, D = map(int, input().split())
    if P // D > 0:
        P = P % D
        N = P // D

    for n in range(N % 2):
        P = min(P + D, P - D)
    print(abs(P))
X,K,D=map(int,input().split())

def valid(value1, value2, diff):
    if diff%2==0:
        return value1
    else:
        return value2

tmp = [X]
min_score = abs(X)
for i in range(K):
    if abs(X-D)>abs(X+D):
        X = X+D
    else:
        X = X-D
    if min_score > abs(X):
        min_score=abs(X)
    a = min([abs(X-D), abs(X+D)])
    if X in tmp:
        min_score = valid(a, min_score, K-i)
        break
    tmp.append(min_score)
print(min_score)
X, K, D = map(int, input().split())

x = X
for k in range(1, K+1):
  tmp_down, tmp_up = abs(x - D), abs(x + D)
  if tmp_down > tmp_up:
    x = tmp_up
  elif tmp_down < tmp_up:
    x = tmp_down
  elif tmp_down == tmp_up:
    x = tmp_down
    break
print(abs(x))
x,k,d = map(int, input().split())

if x > 0:
    kaisu = x//d
    if x//d <= k:
        k -= kaisu
        x -= kaisu*d
    else:
        x -= k*d
        k = 0
else:
    kaisu = -(x//d) 
    if x//d <= k:
        k -= kaisu
        x += kaisu*d
    else:
        x += k*d
        k = 0

if k%2 == 0:
    print(abs(x))
else:
    print(abs(x-d))
x,K,D = list(map(int, input().split()))

if x < 0 :
  x = -x

l = x // D

if K > l:
  if abs(x - D*l) < abs(x - D*(l+1)) :
    if (l % 2) == (K % 2):
      print(abs(x - D*l))
    else:
      print(abs(x - D*(l+1) ))
  else:
    if (l % 2) == (K % 2) :
      print(abs(x - D*(l+1) ))
    else:
      print(abs(x - D*l ))
else:
  print(abs(x - D*K))
x, k, d = map(int,input().split())

if (x // d) > k:
  print(x - k*d)
else:
  if (k - (x // d)) % 2 == 0:
    print(x % d)
  else:
    print(d - (x % d))
position,moves,distance=[int(x) for x in input().split()]
if position>=distance*moves:
	print(abs(position-distance*moves))
else:
	variable=moves-position//distance
	if variable%2==0:
		print(abs((position-distance*(position//distance))))
	else:
		print(abs(position-distance*((position//distance) + 1)))
x, k, d = map(int, input().split())

x = abs(x)
ans = 0

if 2 * x < d:
    ans = x
elif x < d:
    if k % 2 == 0:
        ans = x
    else:
        ans = x - d
else:
    t = x // d
    if k > t + 1:
        if (k - t) % 2 == 0:
            ans = abs(x - t * d)
        else:
            ans = abs(x - (t + 1) * d)
    else:
        ans = min(abs(x - k * d), abs(x - (k - 2) * d))

print(ans)
X,K,D = map(int,input().split())
A = abs(X)
ans = A
if A >= D*K:
    A = A - (D * K)
    K = 0
else :
    A = A - (A//D)*D
    K = K - (A//D)

if K > 0:
    if K%2 == 1:
        A = A - D
print(abs(A))
x,k,d=map(int,input().split())
m=min(k,x//d)
x-=d*m
k-=m
k%=2
x-=d*k
print(abs(x))
X, K, D = map(int, input().split())

x = X
done = False
while K:
    K -= 1
    pre = x
    if x >= 0:
        x -= D
    else:
        x += D
    if pre * x <=0:
        if K % 2 == 0:
            ans = abs(x)
        else:
            ans = abs(pre)
        done = True
        break

if not done:
    ans = x

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

#直線のみに進行すればいい場合の回数
s = x//d

#最短回数よりも移動可能回数の方が少ない場合
if s >= k:
    print(abs(x) - abs(k*d))

#最短経路回数よりも多く移動する場合
else:
    if (k-s) %2 == 0:
        print(abs(x) - s*d)
    else:
        print(d-(abs(x) - abs(k*d)))
x, k, d = map(int, input().split())

# print(x,k,d)

x = abs(x)
c = min(x//d, k)
x -= d*c
k = max(0, k-c)
# print(k,c,x)
if x == 0:
    if k%2==0: # even
        print(0)
    else: # odd
        print(d)

else: # +
    print(x)