peterverebics/CodeNet_Python_118 huggingface dataset:
x,K,D = list(map(int, input().split()))

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())
a = 0
b = k + 1
mid = 0
if x < 0:
    x *= -1
while b - a > 1:
    mid = (a + b) >> 1
    if x - d * mid >= 1:
        a = mid
    else:
        b = mid

ans = x - a * d
if a < k:
    y = abs(x - d)
    if y >= 1 and y < abs(x - a * d):
        ans = y
print(ans)
#  a = (kd - x)/2d


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


pos = (k - (x//d))//2

if pos < 0:
    pos = 0
ans = x + pos * d - (k-pos) * d
fa = abs(ans) 


pos = ((x//d) - k)//2 
if pos < 0:
    pos = 0
ans = x + pos * d - (k-pos) * d 
fa = min(fa, abs(ans)) 

print(fa)
x, k, d = map(int, input().split())
 
if (x - k*d > 0 and x > 0) or (x + k*d < 0 and x < 0):
    print(abs(x) - k*d )
else:
    if (x % d == 0) and (k % 2 == 0):
        print(abs(x))
    elif (x % d == 0) and (k % 2 == 1):
        print(0)
    elif (x - (x % d)) % d == k % 2:
        print(x % d)
    else:
        print(d - x % d)
X,K,D=map(int, input().split())
n=(K*D-X)//(2*D)
if n<0:
    ans=abs(X-K*D)
else:
    ans1=abs(X+(2*n-K)*D)
    ans2=abs(X+(2*(n+1)-K)*D)
    ans=min(ans1,ans2)
print(ans)
X,K,D = map(int,input().split())

c = X

if c > 0:
  if c//D > K:
    c = c - D * K
    print(c)
    exit()
  else:
    c = c - D * (c//D)
    if (K - c//D) % 2 == 0:
      print(c)
      exit()
    else:
      print(max(c,abs(c-D)))
x,k,d = map(int,input().split())
y = k*d
if x >= 0 and x-y >= 0:
    print(x-d*k)
elif x < 0 and x+y <= 0:
    print(abs(x+d*k))
else:
    a = abs(x%d)
    b = abs(x%d-d)
    c = abs(x%d+d)
    d = abs(x%d-d)
    if (k-x%d)%2 == 1:
        print(min(a,b))
    else:
        print(min(c,d))
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:
      if X>0:
        return X-D*K
      else:
        return -1*(X+D*K)
  if K%2==0:
    return X
  else:
    if X>0:
      return X-D
    else:
      return -1*(X+D)
print(solve(X,K,D))
x, k, d = [int(i) for i in input().split()]

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

if abs(x)//d < k:
  #最小までいく。
  if (k-abs(x)//d)%2==0:
    if x>=0:
      print(abs(x-(x//d)*d))
    else:
      print(abs(x+(x//d)*d))
  else:
    if x>=0:
      print(abs(x-(x//d)*d-d))
    else:
      print(abs(x+(x//d)*d+d))
else:
  if x>=0:
    print(abs(x-k*d))
  else:
    print(abs(x+k*d))
#from math import abs
x,k,d=input().split()
x=int(x)
k=int(k)
d=int(d)
if(x<=0):
    if(x+k*d<=0):print(x+k*d)
    else:
        res=x%d
        k-=abs(res-x)//d
        if(k%2):print(res-d)
        else:print(res)
else:
    if(x-k*d>=0):print(x-k*d)
    else:
        res=x%d
        k-=abs(res-x)//d
        if(k%2):print(res-d)
        else:print(res)
x, k, d = map(int, input().split())
abs(x)

if x >= d*k:
    print(x-d*k)
else:
    if (k-x//d) % 2 == 0:
        print(x-d*(x//d))
    else:
        print(abs(x-d-d))
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:
    if k >= x/d:
        ans = (x % d)
    else:
        ans = abs(x - d*k)

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

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

for i in range(k):
    if abs((x + d)) > abs((x - d)):
        x = abs(x - d)
    elif abs((x - d)) > abs((x + d)):
        x = abs(x + d)
    if mina > x:
        mina = x
    else:
        cnt += 1
    if cnt >= 5:
        break

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

first=X//D
if K>first:
    if X>0:
        X=X-first*D
        if K-first%2==0:
            pass
        else:
            if X>0:
                X=X-D
            else:
                X=X+D
    else:
        X=X+first*D
else:
    if X>0:
        X=X-K*D
    else:
        X=X+K*D

print(X)
x, k, d = map(int, input().split())
a = 0
b = k + 1
if d < 0:
    d *= -1
mid = 0
while b - a > 1:
    mid = (a + b) >> 1
    if x - d * mid >= 1:
        a = mid
    else:
        b = mid
print(x - a * d)
X,K,D=map(int,input().split())
if K%2==0:
  if abs(2*D)>=abs(X):
    print(X)
  else:
    p=K*D
    q=abs(X-p)
    r=min(q%D,abs(q%D-D))
    print(r)   
else:
  if K==1:
    print(min(X,min(X+D,X-D)))
  else:
    if abs(D)>=abs(X):
      print(X)
    else:
      p=K*D
      q=abs(X-p)
      r=min(q%D,abs(q%D-D))
      print(r)
x,k,d=map(int,input().split())
print(max(abs(x)-k*d,(x%d,-x%d)[k-x//d&1]))
import math
x, k, d = map(int, input().split())

if(abs(x) - k*d >= 0):
    print(abs(x) - k*d)
else:
    num = x // d
    rest = x % d
    if(num % 2 == 0):
        print(rest)
    else:
        print(d-rest)
x,k,d=map(int,input().split())
xa=abs(x)
kz=xa//d
xz=xa-kz*d
if xz*2>d:
  xzz=d-xz
  kz+=1
else:
  xzz=xz
rest=k-kz
if rest%2==0:
  print(xzz)
else:
  print(d-xzz)
x, k, d = map(int, input().split())
abs(x)

if x >= d*k:
    print(x-d*k)
else:
    if (k-x//d) % 2 == 0:
        print(x-d*(x//d))
    else:
        print(abs(x-d*(x//d)-d))
x,k,d = map(int,input().split())
init = 10**15
count =0
if abs(x)//abs(d) >= k:
    print(abs(x)-abs(d)*k)
    exit()

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

total = K*D
if(total > X):
    ans = (total-X-1) 
    ans -= D
elif total < X:
    ans = X - total
else:
    ans = X
print(ans)
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())
dist = abs(X)
rem = K
count = min(int(X/D),K)
dist = dist - count*D
rem = K - count
if rem % 2 == 1:
  dist = dist - D
ans = abs(dist) 
print(ans)
x,k,d=map(int,input().split())
if abs(0-x)>=d*k:
    print(abs(0-x)%d)
else:
    c=abs(0-x)//d
    k-=c
    if x<=0:
        if k%2==0:
            print(abs(x+d*c))
        else:
            print(abs(x+d*(c+1)))
    else:
        if k%2==0:
            print(abs(x-d*c))
        else:
            print(abs(x-d*(c+1)))
x, k ,d = map(int, input().split())
if k*d <= x:
    print(x-k*d)
else:
    xx = x
    x -= min(k, x//d)*d
    k -= min(k, xx//d)
    if k % 2 != 0:
        ans = min(abs(x-d),abs(x+d))
    else:
        ans = min(abs(x), abs(x-2*d))
    print(ans)
x,k,d=map(int,input().split())
a=divmod(abs(x),d)  
if a[0]<k:
  if a[1]==0 and a[0]%2==1:
    print(d)
  elif a[1]==0 and a[0]%2==0:
    print(0)
  elif a[1]!=0 and a[0]%2!=0:
    if a[1]<=abs(d-a[1]):
      print(a[1])
    else:
      print(abs(d-a[1]))
  else:
    print(a[1])
else:
  print(abs(x)-d*k)
x,k,d = list(map(int, input().split(' ')))

if k*d<=x:
    print(x-k*d)
elif -k*d>=x:
    print(x+k*d)
else:
    rem = x%(d)
    div = x//d
    if (k-div)%2==0:
        print(rem)
    else:
        print(d-rem)
x,k,d=map(int, input().split())
if x>d*k:
	ans=x-k*d
else:
	k=k-x//d
	if k%2==0:
		ans=x%d
	else:
		ans=abs(x%d-d)
print(ans)
x,k,d=map(int,input().split())
a=k*d
b=k//2
c=10**17
for i in range(b):
  c=min(c,abs(c-b))
  b-=2*d
print(c)
import collections


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


if __name__ == '__main__':
    main()
import math
X, K, D = list(map(int, input().split()))

a = (K * D - X) / (2*D)
a1, a2 = math.floor(a), math.ceil(a)

left = 0
right = K
def f(a):
    return X - K * D + 2 * a * D

mid = None
flag = 0
while left < right:
    mid = (left + right) // 2

    if f(mid) == 0:
        flag = 1
        break
    elif f(mid) < 0:
        left = mid + 1
    else:
        right = mid - 1

if flag:
    print(abs(X - K * D + 2 * mid * D))
else:
    print(abs(X - K * D + 2 * left * D))
x, k, d = map(int, input().split())
num = 0
s = x

while k>0:
    s = s-d
    num += 1
    k -= 1
    if abs(s)>=abs(x):
        break
    x = s

if k == 0:
    print(abs(s))
    exit()

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

else:
    ans = x - k*d

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

num = X - K*D
if 0<num:
  print(num)
  sys.exit(0)

k2 = X//D
if (K-k2)%2==0:
  print(X - k2*D)
elif K<k2+1:
  print(X - (k2-1)*D)
else:
  print((k2+1)*D - X)
import math
x, k, d = map(int, input().split())

if(abs(x) - k*d >= 0):
    print(abs(x) - k*d)
else:
    print(math.gcd(abs(x), d))
X,K,D = map(int, input().split())

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

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

print((abs(abs(X)-K*D)/D)%2)
if abs(X) >= K*D:
    print(abs(X-K*D))
elif (abs((abs(X)-K*D)/D))%2 == 0:
    print(0)
elif (abs((abs(X)-K*D)/D))%2 <= 0.5:
    print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D-1))))
elif (abs((abs(X)-K*D)/D))%2 <= 1.5:
    print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D+1))))
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
x,k,d  =ma()
if abs(x) > k*d:
    ans = x-k*d
else:
    if x<0:
        x*=-1
    t1 = x%d
    t2 = abs(x%d-d)
    pal = (x-t1)//d
    if pal%2==k%2:
        ans = t1
    else:
        ans=t2
print(ans)
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):
        print(rest)
    else:
        print(d-rest)
x,k,d=map(int, input().split())

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

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

def solve():
    if X // D >= K:
        return X - D*K
    if ((X//D)%2 == 0) ^ (K%2 == 0):
        return D - (X - D*(X//D))
    else:
        return X - D*(X//D)


if __name__ == "__main__":
    print(solve())
def resolve():
    x, k, d = list(map(int, input().split()))
    ans = 10 * 15
    cnt = 0
    now = x
    mem = set()
    while True:
        if now > 0:
            now -= d
        else:
            now += d

        ans = min(ans, abs(now))

        cnt += 1
        if cnt >= k:
            break
    print(ans)

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

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

    else:
        if K- X//D >= 2:
            print(Y)
        else:

            a = abs(D)+Y
            b = abs(Y-D)
            print(min(a,b))
s = input().split()
x = int(s[0])
k = int(s[1])
d = int(s[2])
ans = 0
x = abs(x)
if x > 0:
    if k*d < x:
        ans = x - (k*d)
    else:
        con = x/d
        rem = k - con
        if rem%2 == 1:
            ans = d - x%d
        else:
            ans = x%d

elif x == 0:
    if k%2 == 0:
        ans = 0
    else:
        ans = d

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

k = (D*K-X)//(2*D)
ans = min(abs(X+D*K), abs(X-D*K))
for i in range(k-10, k+10):
  if 0<=k<=K:
    ans = min(ans, abs(X+k*D-(K-k)*D))
print(ans)
X,K,D = map(int,input().split())
ans = [X]
for i in range(K):
  if X-(i+1)*D<=0:
    break
  ans.append(X-(i+1)*D)
  
print(min(ans))
from math import floor
import decimal
x,k,d=map(int,input().split())
if x==0:
	if k%2==0:
		print(0)
	else:
		print(d)
t=floor(decimal.Decimal(abs(x))/decimal.Decimal(d))
if (k<=t):
	if (x>0):
		print(x-k*d)
	else:
		print(x+k*d)
	exit(0)
else:
	if (x>0):
		x=x-t*d
		k-=t
		if k%2==0:
			print(abs(x))
		else:
			print(abs(x-d))
	else:
		x=x+t*d
		k-=t
		if k%2==0:
			print(abs(x))
		else:
			print(abs(x+d))
# cook your dish here
# your code goes here
a, b, c = input().split()
x=int(a)
k=int(b)
d=int(c)
val=(k*d-x)/(2*d)
fs=int(val)
# print(fs)
if fs<0:
	ans=abs(x-k*d)
elif fs==0:
	ans1=abs(x-k*d)
	ans2=abs(x-k*d+2*d)
	ans=min(ans1,ans2)
else:
	ans1=abs(x-k*d+2*(fs-1)*d)
	ans2=abs(x-k*d+2*fs*d)
	ans3=abs(x-k*d+2*(fs+1)*d)
	ans=min(ans1,ans2,ans3)
print(ans)
x, k, d = map(int, input().split())
x_d = x//d
if k<=x_d:
    ans = abs(x)-k*d
else:
    if k%2==1:
        ans = min(abs(abs(x)-x_d*d-d), abs(x)-x_d*d+d)
    else:
        ans = abs(x)-x_d*d
print(ans)
x,k,d=[int(i) for i in input().split()]

min=x

smin,smax=x-k*d,x+k*d
if abs(smin)>x:
    smin=-x
if abs(smax)>x:
    smax=x
for t in range(smin,smax,d*2):
    tt=abs(t)
    if tt<min:
        min=tt
print(min)
X,K,D = map(int,input().split())
tmp = X -K*D
if tmp >= 0:
    ans = tmp
else:
    if X < 0:
        X *= (-1)
    dif  = X//D
    buf = X - D*dif
    if (K-dif) % 2  == 0:
        ans = abs(buf)
    else:
        ans = abs(buf - D)
print(ans)
X, K, D = map(int, input().split())

ans = 0
count = X // D

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

if ans < 0:
    ans = ans * (-1)

print(ans)
xkd = list(map(int,input().split()))
xkd[0] = abs(xkd[0])
x = xkd[0] // xkd[2]
x = abs(x)
xkd[0] -= xkd[2] * x
xkd[1] -= x
if xkd[1] < 1:
  xkd[0] += abs(xkd[1]) * xkd[2]
  print(xkd[0])
else:
    ans = xkd[0]
    if xkd[1] % 2 != 0:
        ans -= xkd[2]
        if ans > xkd[0] + xkd[2]:
            ans += xkd[2] * 2
            print(abs(ans))
x, k, d = map(int, input().split())
i = 1

if k*d <= x:
    print(x-k*d)
else:
    while(d*i < x):
        i += 1
    if (k-i)%2 == 0:
        print(abs(x-d*i))
    else:
        print(x-d*(i-1))
import sys
input=lambda: sys.stdin.readline().rstrip()
x,k,d=map(int,input().split())
if k%2==1:
  if x>0:
    x-=d
  else:
    x+=d
k-=1
ans=min(x%(2*d),2*d-x%(2*d))
if abs(x)>k*d:
  print(abs(x)-k*d)
else:
  print(ans)
x, k, d = map(int, input().split())

r = x%d
l = r-d

lc = abs(x-l)//d
rc = abs(x-r)//d

ans = abs(x-d*k)
if(k>=lc):
    if((k-lc)%2): ans = min(ans, min(abs(l+d), abs(l-d)))
    else: ans = min(ans, abs(l))
if(k>=rc):
    if((k-rc)%2): ans = min(ans, min(abs(r+d), abs(r-d)))
    else: ans = min(ans, abs(r))
print(ans)
x,k,d = map(int, input().split())
for n in range(k):
  if x > 0:
    if x > d:
      x = x - d
    elif x <= d:
      if (k-n) % 2 == 0:
        print(x)
      else:
        print(-(x-d))
  elif x < 0:
    if -x < -d:
      x = x + d
    elif x >= d:
      if (k-n) % 2 == 0:
        print(-x)
      else:
        print(x+d)
x, k, d = map(int, input().split())
x=abs(x)
if x-d*k > 0:
    print(x-d*k)
else:
    print(x+d*k)
import math
def main():
  X, K, D = map(int, input().split())
  if abs(X) > K * D:
    print(X-K*D)
  else:
    Y = math.ceil(X / D)
    if (K-Y) % 2 == 0:
      print(D*Y-abs(X))
    else:
      Z = abs(X)-D*(Y-1)
      print(Z)
main()
import math
import sys
x, k, d = map(int, input().split())

l = math.floor(x / d)
if(l > k):
    x -= k*d
    print(abs(x))
    sys.exit()
else:
    x -= l*d
k = k-l

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

if K*D<X:
  if X<0:
    print(abs(X+K*D))
  else:
    print(abs(X-K*D))
else:
  if X%D==0:
    ans = [0,D]
    if X//D%2==0:
      print(ans[K%2])
    else:
      print(ans[1-K%2])
  else:
    ans = [-X%D,X%D]
    if X//D%2==X%D:
      print(ans[K%2])
    else:
      print(ans[1-K%2])
X,K,D=map(int,input().split())
X_min=pow(10,16)
if X<K*D:
    if (K-X//D)%2==0:
        X_min=X%D
    else:
        X_min=abs(X%D-D)
else:
    for i in range(K):
        if X>=0:
            X=X-D
        else:
            X=X+D
        if X_min>abs(X):X_min=abs(X)
print(X_min)
X, K, D = map(int,input().split())
ans = X
for i in range(K):
    if abs(ans) >= D:
        ans -= D
    elif abs(ans) < D and ans >= 0:
        ans -= D
    else:
        ans += D
print(abs(ans))
x,k,d=map(int,input().split())

if x==k and x==d:
  print(x)
  exit()

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

for i in range(k):
  tmp=x
  x-=d
  if abs(x) >= abs(tmp):
    if (k-i)%2==0:
      print(abs(tmp))
      exit()
    else:
      print(abs(x))
      exit()
  else:
    pass
else:
  print(abs(x))
x, k, d = map(int, input().split())
t = abs(x)//d
if k*d <= abs(x):
    print(abs(x) - k*d)
else:
    print(abs(d*(max(0, k-t)%2) - (x-t*d)))
x, k, d = map(int, input().split())
ml = min(x//d, k)
mu = min(ml+1, k)
if abs(x-ml*d) < abs(x-mu*d):
    if ml%2 == k%2:
        print(abs(x-ml*d))
    else:
        print(abs(x-mu*d))
else:
    if mu%2 == k%2:
        print(abs(x-mu*d))
    else:
        print(abs(x-ml*d))
X, K, D = map(int, input().split())

if abs(X) < abs(X) % D:
    if K % 2 == 0:
        print(abs(X))
    else:
        print(min(abs(X - D), abs(X + D)))
else:
    if int(K - int(abs(X) / D)) % 2 == 0:
        print(abs(X) % D)
    else:
        print(min(abs(abs(X) % D - D), abs(abs(X) % D + D)))
X, K, D  = map(int, input().split())
shou = X//D
amari = X%D 

if D * K <= X:
    print(X - (D*K) + 2)
else:
    nokori = K - shou
    if nokori % 2 == 0:
        print(amari)
    else:
        print(abs(amari - D))
x,k,d = map(int,input().split())
a = 0

if x < 0:
    a = abs(x)//d if abs(x)%d == 0 else abs(x)//d+1
    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

if k != 0 and k % 2 == 1:
    b = abs(x-d)
    c = abs(x+d)
    x = min(b,c)

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

if abs(x) - k * d >= 0:
    print(abs(x) - k * d)
elif (k - ((x - x % d) / d)) % 2 == 0:
    if x % d == 0:
        print(0)
    else:
        print(abs(x) % d)
else:
    if x % d == 0:
        print(d)
    else:
        print((abs(x)+d) % d)
# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())

if(k * d < abs(x)):
  x_ = x -(k * d) if x > 0 else x + (k * d) 

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

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

print(ans)
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def f(d, x, b):
    return abs(2 * d * x - b)

def main():
    x, k, d = ril()
    b = - x + k * d
    if b <= 0:
        ans = -b
    elif b % (2 * d) == 0:
        ans = 0
    else:
        x1 = b // (2 * d)
        x2 = x1 + 1
        ans = min(f(d, x1, b), f(d, x2, b))
    print(ans)



if __name__ == '__main__':
    main()
def main():
    x,k,d = list(map(int,input().split()))
    ln = abs(x)//d
    if abs(x)%d > d//2:
        ln += 1

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

    print(ans)

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

if x == k and x == d:
    print(abs(x))
    exit()
elif x == d and k % 2 == 1:
    print(0)
    exit()
else:
    if x >= k*d:
        print(abs(x-k*d))
        exit
    else:
        for i in range(k):
            if x >= 0:
                x -= d
            else:
                x += d
    
print(abs(x))
li=  list(map(int,input().split()))	       
X, K, D=li[0], li[1], li[2]
if abs(X)>K*D:
    print(min(abs(X-K*D), abs(X+K*D)))
else:
    N=X//D
    Min=10**16
    n=0
    X=abs(X)
    for i in range(N-1, N+2):
        M=abs(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)))
def C():
    X, K, D = map(int, input().split())
    if X//D >= K:
        return X - K*D

    pos1 = abs(X - (X//D)*D)
    pos2 = abs(X - (X//D+1)*D)

    if pos1 > pos2:
        K -= X//D+1
    else:
        K -= X//D
    
    if K % 2 == 0:
        return min(pos1, pos2)
    else:
        return abs(min(pos1, pos2) - D)

print(C())
X,K,D=map(int,input().split())
a=round(abs(X/D))
if K<a:
  print(abs(X-K*D))
elif (K-a)%2==0:
  l=[]
  l.append(abs(X-a*D))
  l.append(abs(X-(a+2)*D))
  l.append(abs(X-(a-2)*D))
  print(min(l))
elif (K-a)%2!=0:
  l=[]
  l.append(abs(X-(a+1)*D))
  l.append(abs(X-(a+3)*D))
  l.append(abs(X-(a-1)*D))
  print(min(l))
x,k,d=map(int,input().split())
if x==0:
	if k%2==0:
		print(0)
	else:
		print(d)
	exit(0)
t=abs(x//d)
if (k<=t):
	if (x>0):
		print(x-k*d)
	else:
		print(x+k*d)
	exit(0)
else:
	if (x>0):
		x=x-t*d
		k-=t
		if k%2==0:
			print(x)
		else:
			print(abs(x-d))
	else:
		x=x+t*d
		k-=t
		if k%2==0:
			print(abs(x))
		else:
			print(abs(x+d))
X,K,D = map(int, input().split())

if abs(X) > abs(D * K):
    print(abs(X-abs(D*K)))
else:
    if (K - (X // D) ) % 2 == 0:
        print(abs(X%D))
    else:
        print(abs(X%D-D))
#ABC175  C
x, k, d = map(int, input().split())
num = abs(x) // d
if num >= k:
  if x>=0:
    print(abs(x-k*d))
  else:
    print(abs(x+k*d))
else:
  temp = x - num*d
  k -= num
  if k % 2 == 0:
    print(abs(temp))
  else:
    if abs(temp+d) < abs(temp-d):
      print(abs(temp+d))
    else:
      print(abs(temp-d))