peterverebics/CodeNet_Python_118 huggingface dataset:
x,k,d = map(int, input().split())

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

else:
    y = abs(x)//d 
    if (k - y) % 2 ==0:
        print(abs(x)% d)
    else:
        print((y+1)*d-abs(x))
import math

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

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

if 0 <= 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))
elif 0 > KL:
    print(abs(X+K*D))
else:
    print(abs(X-K*D))
#X:座標
#K：試行回数
#D：移動距離

X,K,D=map(int,input().split())
b=0
Xabs=abs(X)
J=Xabs%D
N=Xabs//D

if N>K:
    b=Xabs-K*D

else:
    if (K-N)%2==0 :
        b=J
   
    #取れる数字はXをKで割った時のあまり(J)or(K-J)
    #残りは試行回数でどうなるか
    
    else:
        b=D-J
        

print(b)
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    x, k, d = _ia()
    x = abs(x)
    xm = x % d
    n = (x-xm)//d

    if k >= n:
        if n % 2 == k % 2:
            return xm
        else:
            return -xm + d
    else:
        return x - k * d


if __name__ == "__main__":
    print(main())
x,k,d = map(int, input().split())
if x>=0:
  a = x//d
  if a>=k:
    ans = x-k*d
  elif (k-a)%2==0:
    ans = x-a*d
  else:
    ans = x-(1+a)*d
else:
  y = 0-x
  a = y//d
  if a>=k:
    ans = x+k*d
  elif (k-a)%2==0:
    ans = x+a*d
  else:
    ans = x+(a+1)*d
if ans>0:
  print(ans)
else:
  print((-1)*ans)
x, k, d = [int(x) for x in input().split()]
ab = abs(x)
if ab-k*d>=0:
    print(ab-k*d)
else:
    t = ab//d
    k -= t
    ab -= d*t
    k %= 2
    if k==1:
        ab -= d
    print(abs(ab))
import sys
input = sys.stdin.readline
X, K, D = map(int, input().split())
if abs(X) >= K * D:
  print(abs(X) - K * D)
  exit(0)
a = abs(X) // D
b = -(-abs(X) // D)
res = float("inf")
if (K - a) % 2:
  res = min(res, abs(X) % D + D, abs(abs(X) % D - D))
else: res = min(res, abs(X) % D)
print(res)
x,k,d=map(int,input().split())
mini=0
if abs(x)>=k*d:
 mini=abs(x)-k*d
 print(mini)
else:
 q=abs(x)//d
 s=abs(x)%d
 if (k-q)%2==0:
  print(s)
 else:
  print(abs(s-d))
x,k,d=list(map(int,input().split()))
#print(x,k,d)
result=abs(x)-k*d
swithn=0

if result<0:
    if k%2==1:
        x-=d
    result=min(x%(2*d),-x%(2*d))
print(result)
X, K, D = map(int, input().split())
if X > 0:
	X *= -1
ans = 0
if -X > K*D:
	ans = -X - K*D
else:
	X += K*D
	X %= 2*D
	ans = min(X, 2*D-X)

print(ans)
X, K, D = map(int, input().split())
 
q, r = divmod(X, D)
 
if abs(X) >= K*D:
    print(abs(X)-K*D)
elif abs(K-q) % 2 == 0:
    print(r)
else:
    print(abs(r-D))
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)
x, k, d = map(int, input().split())
x = abs(x)
ans = 1000000000000000
m = x // d
if m > k:
    print(abs(x-k*d))
else:
    if (k%2==0 and m%2==1) or (k%2==1 and m%2==0):
        m += 1
    ans = min(ans,x-m*d)
    """
    if m+2 <= k:
        ans = min(ans,ans+2*d)
        ans = min(ans,ans-2*d)
        """
    print(abs(ans))
import sys
input = sys.stdin.readline
x,k,d=map(int,input().split())
x=abs(x)
if x<d:
    if k&1==0:
        print(x)
    else:
        print(abs(x-d))
    sys.exit()

val = x//d

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

x-=(val*d)
k-=val
if k&1==0:
    print(x)

else:
    ans = min(x+d,abs(x-d))
    print(ans)
X,K,D = map(int,input().split())
# 原点に近い位置までの移動回数を求める
count = abs(X) // D
ans = 0
if count>K:
    ans = abs(X) - D * K
else:
    if (K-count)%2==0:
        ans = abs(X) % D
    else:
        ans = abs(abs(X) % D - D)
print(ans)
x, k, d = map(int, input().split())

x = -x if x <= 0 else x

if x - d * k >= 0:
    print(x - d * k)
else:
    a = x // d
    b = a + 1
    rest_cnt = k - a
    if rest_cnt % 2 == 0:
        print(abs(x - d * a))
    else:
        print(abs(x - d * b))
X,K,D = map(int,input().split())
m = 0
s = 0
X = abs(X)
if X >= K * D:
    m = X - (K * abs(D))
else:
    l = X // D
    K -= l
    X -= l * D
    m = X
    if K % 2 == 1:
        X -= D
        m = X
       


       

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

X = abs(X)

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

ax = abs(x)
t = k * d

if t == ax:
    print(0)
elif t < ax:
    print(ax - t)
else:
    a = ax % d
    b = d - a
    f = ax // d

    if k % 2 == f % 2:
        print(a)
    else:
        print(b)
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)
x,k,d=map(int, input().split()) 
tmp = k

ans = abs(x)%d
k = k - int(abs(x)/d)

if k < 0:
    ans = abs(x)
    ans = ans - (tmp * d)
    print(ans)
    exit()

for i in range(k):
    if abs(ans) <= d and (k-i)%2 == 0:
        print(abs(ans))
        exit()
    elif ans >= 0:
        ans = ans - d
    elif ans < 0:
        ans = ans + d

print(abs(ans))
x,k,d = map(int,input().split())
X = abs(x)
n = X//d
if n > k:
    print(abs(X-k*d))
elif (k - n)%2 == 0:
    print(abs(X-n*d))
else:
    print(abs(X-(n+1)*d))
x,k,d = map(int,input().split(" "))
if k * d <= abs(x):
    print(abs(x) - k * d)
else:
    x = abs(x)
    k -= x // d
    x %= d 
    if min(x,abs(x-d)) != x:
        k -= 1
    x = min(x,abs(x-d))
    if k % 2 == 0:
        print(x)
    else:
        print(d - x)
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)
x,k,d=map(int,input().split())
x=abs(x)
i=min(x//d,k) if (k-x//d)%2==0 else min(x//d+1,k)
print(abs(x-d*i))
X, K, D = [int(i) for i in input().split()]
# K = int(input())
X = abs(X)
rem = X % D
count = (X - rem) // D
if count <= K:
  if (K - count) % 2 == 0:
    print(rem)
  else:
    print(abs(rem-D))
else:
  print(X - D * K)
X, K, D = map(int, input().split())

Xa = abs(X)
Xs = Xa // D
Xm = Xa % D

if (K <= Xs):
    print(abs(Xa-D*K))
elif (K-Xs) % 2 == 0:
    print(abs(Xm))
else:
    print(abs(D-Xm))
X, K, D = map(int, input().split())

p = abs(X) // D
if (p >= K):
    print(abs(abs(X) - (K * D)))
else:
    re = K - p
    if (re % 2 == 0):
        print(abs(abs(X) - (D * p)))
    else:
        print(abs(abs(X) - (D * (p + 1))))
x,k,d = list(map(int, input().split()))
x = abs(x)
a,b = divmod(x, d)
a = min(a, k)
x -= a * d
#print('a=',a)
#print('x=',x)
#print('ka=',k-a)
x -= d * ((k-a) % 2)
print(abs(x))
x, k, d = [int(i) for i in input().split()]
x = abs(x)
moves_to_base_without_exceeding = x // d
if(x - k * d >= 0):
    print(x - k * d)
elif(((moves_to_base_without_exceeding - k) % 2 == 0)):
    print(x % d)
else:
    print(d - (x % d))
X,K,D=map(int,input().split())
X=abs(X)
a=X//D
if a>=K:
  print(X-K*D)
else:
  if (K-a)%2 == 0:
    print(X-a*D)
  else:
    print((a+1)*D-X)
X, K, D = map(int, input().split())

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

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

print(ans)
X,K,D=map(int,input().split())
x=abs(X)
a=x//D
b=x%D
c=abs(b-D)
if a%2==0:
    even=b
    odd=c
else:
    odd=b
    even=c
if a>K:
    print(abs(X)-K*D)
elif K%2==0:
    print(even)
else:
    print(odd)
x, k, d = map(int, input().split())

x = abs(x)
div = min(x//d, k)
if (k - div) % 2 == 0:
    ans = abs(x - d * div)
else:
    ans = abs(x - d * div - d)
print(ans)
import math
def main():
  X, K, D = map(int, input().split())
  if abs(X) >= K * D:
    print(abs(X)-K*D)
  else:
    Y = math.ceil(abs(X) / D)
    if (K-Y) % 2 == 0:
      print(D*Y-abs(X))
    else:
      Z = abs(X)-D*(Y-1)
      print(Z)
main()
x, k, d = map(int, input().split())
x=abs(x)
if x-d*k > 0:
    print(x-d*k)
else:
    n=x//d
    x-=n*d
    if (k-n)%2==0:
        print(x)
    else:
        print(abs(x-d))
x, k, d = map(int, input().split())
if k % 2 == 1:
    x = abs(x) - d
    k -= 1
else:
    x = abs(x)
if abs(x) - d * k <= 0:
    temp = x % (d * 2)
    print(min(temp, d * 2 - temp))
else:
    print(abs(x) - d * k)
m,K,D = input().split()
m = int(m)
K = int(K)
D = int(D)
if K < 0 or D < 0:
  print('error')
if m < 0:
  m *= -1
a = (m - m % D) / D
if a > K:
  m -= D*K
  K = 0
else:
  K -= a
  if K % 2 == 0:
    m %= D
  else:
    m = (m % D - D) * -1
print(m)
x, k, d = map(int, input().split())
r = x % d
q = (x - r) // d
if abs(x) >= k*d:
  if x>0:
    ans = x-k*d
  else:
    ans = abs(x+k*d)
elif k%2 == q%2:
  ans = r
else:
  ans = d - r
print(ans)
import sys
input = sys.stdin.readline


def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    step = x // d
    if step >= k:
        ans = x - d * k
        print(ans)
        return

    k -= step
    x = x - step * d
    k %= 2
    ans = abs(x - d*k)
    print(ans)


if __name__ == "__main__":
    main()
X, K, D = map(int,input().split())
a = abs(X) // D
b = abs(X) % D

if K <= a:
    print(abs(X) - D * K)
else:
    if (K - a) % 2 == 0:
        print(b)
    else:
        print(D - b)
X, K, D = map(int, input().split())
div, mod = divmod(abs(X), D)
if K <= div:
  print(abs(X) - K*D)
elif (K-div) % 2:
  print(D-mod)
else:
  print(mod)
x,k,d = map(int,input().split())

tmp = abs(x) % d
cal = abs(x) // d
if tmp > abs(tmp - d):
    cal += 1
    tmp = abs(tmp - d)

if cal == k:
    print(tmp)
elif cal > k:
    print(abs(x) - k*d)
else:
    if (k - cal) % 2 == 0:
        print(tmp)
    else:
        print(min(abs(tmp-d),abs(tmp+d)))
def solve(string):
    x, k, d = map(int, string.split())
    x = abs(x)
    if k % 2:
        x = min(x - d, x + d, key=abs)
        k -= 1
    k, d = k // 2, d * 2
    return str(min(x % d, abs((x % d) - d))) if x < k * d else str(x - k * d)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
n, k, d = map(int, input().split())
n = abs(n)
ok = n // d
if k < ok:
  print(n - (k*d))
else:
  left = k - (ok)
  if left % 2:
  	print(d - (n%d))
  else:
    print(n%d)
X,K,D=map(int,input().split())
X=abs(X)

a=X//D
b=X%D

if K<=a:
    ans=X-K*D
elif (K-a)%2==0:
    ans=b
else:
    ans=D-b
print(ans)
#print(3.0/2)
#print(3.0%2)
inp=map(int,input().split())
X,K,D=map(abs,inp)

goal=X-K*D
y1=X%D
y2=y1-D

if y1<=goal:
    print(int(goal))
else:
    if y1<=abs(y2):
        L=(X-y1)/D
    else:
        L=(X-y2)/D
    if (K-L)%2==0:
        print(int(min(y1,abs(y2))))
    else:
        print(int(max(y1,abs(y2))))
x, k, d = list(map(int,input().split()))
x =abs(x)
d =abs(d)
ans = 0
if x >= k * d:
  ans = x - k * d
else:
  ans = x - (x // d) * d
  if (k - x // d) % 2 == 1:
    ans = ans - d
print(abs(ans))
X,K,D = map(int,input().split())

X = abs(X)

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

if x < 0:
    x = -x

p = (x + d - 1) // d

if p <= k:
    if p % 2 == k % 2:
        print(-(x - p * d))
    else:
        print(x-(p-1)*d)
else:
    print(x-k*d)
X,K,D=map(int,input().split())
def solve(X,K,D):
  X=abs(X)
  if X>D:
    a=X//D
    if K>a:
      X=X%D
      K-=a
    else:
      return abs(X-D*K)
  if K%2==0:
    return X
  else:
    return abs(X-D)
print(solve(X,K,D))
x,k,d = map(int, input().split())
n = abs(x)//d 
if n > k:
    ans = abs(x)-k*d
else:
    # print(n)
    rest = n - k
    x_now = abs(x) - n*d
    ans = abs(x_now - d*(rest%2))
print(ans)
#!/usr/bin/python3
# -*- coding:utf-8 -*-

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

if __name__=='__main__':
  main()
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

def main(X, K, D):
    L = X - D * K
    R = X + D * K
    if L >= 0:
        return L
    if R < 0:
        return -R
    t = (-L) // (D + D)
    ans = -L
    for i in range(t - 10, t + 10):
        x = L + (D + D) * i
        if L <= x <= R:
            ans = min(ans, abs(x))
    return ans

print(main(X, K, D))
import math
X, K, D = map(int,input().split())

max_x = X + K * D
min_x = X - K * D

res = 0

if max_x <= 0:
  res = abs(max_x)
  print(res)
  exit()
elif min_x >= 0:
  res = abs(min_x)
  print(res)
  exit()

a = (K*D -X) / (2*D)

max_x = 2 * math.ceil(a) * D + min_x
min_x = 2 * math.floor(a) * D + min_x
res = min(abs(max_x), abs(min_x))
print(res)
# coding: utf-8

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()
X, K, D = map(int, input().split())
X = abs(X)
if X - K * D >= 0:
  print(X - K * D)
else:
  k = X // D
  if (K - k) % 2 == 0:
    print(X - k * D)
  else:
    print(abs(X - (k + 1) * D))
X, K, D = map(int, input().split())
abs_x = abs(X)
hikukazu = abs(X) // D
count = K - (hikukazu)
if K > hikukazu:
    if count % 2 == 0:
        hikukazu = hikukazu
    else:
        hikukazu = hikukazu + 1
else:
    hikukazu = K


# for i in range(hikukazu):
    
#     abs_x = abs_x - D
abs_x = abs_x - (D*hikukazu)
    # print(X)

print(abs(abs_x))
import sys
X, K, D = map(int, input().split())
X = abs(X)
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)
x, k, d = map(int,input().split())
x = abs(x)

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

if X < 0: X = -X

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

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

X = abs(X)

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

elif X // D < K:
  K = K - X // D
  if K % 2 == 0:
    print (X % D)
  else:
    print (abs(D - X % D))
else:
  print(X)
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

n = x // d
x = x - n * d
k -= n

if k % 2 ==0:
    print(x)
else:
    print(abs(x - d))
x,k,d=input().split()
k=int(k)
x=int(x)
d=int(d)
x=int(abs(x))
if((k*d)<=x):
    print(x-(k*d))
else:
    k-=int(x/d)
    x%=d
    if(k%2):
        print(d-x)
    else:
        print(x)
x,k,d=map(int,input().split())
x=abs(x)
ans=0
if x>k*d:
    print(x-k*d)
else:
    a=x//d
    p=x-d*a
    q=abs(x-d*a-d)
    print(q if (k-a)%2 else p)
X, K, D = map(int, input().split())
if X < 0:
    X = -X
k = X // D
if k >= K:
    X -= K * D
    print(abs(X))
else:
    X -= k * D
    K -= k
    if K % 2 == 0:
        print(abs(X))
    else:
        print(abs(X - D))
X, K, D = map(int, input().split())
if X > 0 and X - K * D >= 0:
  print(X - K * D)
elif X < 0 and X + K * D <= 0:
  print(abs(X + K * D))
elif K % 2:
  print(min((X+D) % (2*D), abs((X+D) % (2*D)-2*D)))
else:
  print(min(X % (2*D), abs(X % (2*D)-2*D)))
X,K,D = map(int,input().split())
X = abs(X)
s = X//D
if s == K:
    print(X%D)
elif s > K:
    print(abs(X-D*K))
elif (K-s) % 2 == 0:
    print(X%D)
else:
    print(abs(X%D-D))
from sys import stdin
input = stdin.readline
X, K, D = map(int, input().split())
A=int((K-X/D)/2)
if 0<=A and A<=K:print(min(abs(-K*D+2*A*D+X),abs(-K*D+2*(A+1)*D+X)))
else:print(min(abs(X+K*D),abs(X-K*D)))
l = list(map(int, input().split()))
x, k, d = map(abs, l)
if x - k*d > 0:
    print(x - k*d)
else:
    cnt = x//d
    val1 = x%d
    val2 = d-val1
    if (k-cnt)%2 == 0:
        print(val1)
    else:
        print(val2)
# author:  Taichicchi
# created: 15.09.2020 21:22:26

import sys

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

X = abs(X)

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

    if k % 2:
        print(abs(x - D))
    else:
        print(x)
X,K,D = map(int,input().split())
X = max(X,X*(-1))
plusmin = X%D
minusmin = -plusmin+D
totalmin = min(plusmin,minusmin)
if totalmin == plusmin:
    num = X//D
else:
    num = X//D+1
    
if K<num:
    answer = X-D*K
elif K==num+1:
    answer = max(plusmin,minusmin)
elif K%2==num%2:
    answer = totalmin
else :
    answer = max(plusmin,minusmin)
    
print(answer)
x, k, d = map(int, input().split())

lo = 0
hi = k

while (lo < hi) :
  mid = lo + (hi - lo) // 2 + 1
  if (x >= 0) :
    if (x - mid * d >= 0) : 
      lo = mid;
    else :
      hi = mid - 1
  else :
    if (x + mid * d <= 0) :
      lo = mid;
    else :
      hi = mid - 1;

if (x >= 0) :
  x -= d * hi
else :
  x += d * hi

k -= hi;

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

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

else:
    t=x//d
    r=x-t*d
    l=x-(t+1)*d
    if (k-t)%2==1:
        print(abs(l))
    else:
        print(abs(r))
x, k, d = map(int, input().split())

x = abs(x)
m = min(k, x // d)
k -= m
x -= m * d

if k % 2 == 0:
    print(x)
else:
    print(d - x)
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))
import math
X, K, D = map(int,input().split())
X = math.fabs(X)
ans = 0
E = X//D
if E > K:
    ans = X - K * D
elif K%2 == E%2:
    ans = X-E*D
else:
    ans = -X+(E+1)*D
print(int(ans))
X, K, D = map(int, input().split())

if X < 0:
    X = -1 * X

x = X % D
N = X // D

if N > K:
    print(X - D * K)
else:
    judge = (K - N) % 2
    if judge == 0:
        print(x)
    else:
        print((x-D)*-1)
X, K, D = list(map(int, input().split()))
X = abs(X)
n = X//D
if K <= n:
    print(abs(X-K*D))
elif (K-n)%2==1:
    print(abs(X-(n+1)*D))
else:
    print(abs(X-n*D))
import decimal    

data = input().split()
X = decimal.Decimal(data[0])
K = decimal.Decimal(data[1])
D = decimal.Decimal(data[2])
if X < 0:
    X *= -1
if X/D-X//D > 0.5:
    y = X//D + 1
else:
    y = X//D
if y > K:
    y = K
X -= y * D

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

mv = K * D
if mv <= X:
    ans = X - mv
    print(ans)
    exit()

need = (X + D - 1) // D

X -= need * D
K -= need

if K % 2 == 0:
    ans = abs(X)
    print(ans)
else:
    X += D
    print(X)
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

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

if x < 0: x = -x

q,r = x//d,x%d

if q >= k:
    print(x-k*d)
else:
    k -= q
    if k%2==0:
        print(r)
    else:
        print(abs(r-d))
X, K, D = map(int, input().split())
if X < 0:
    X = -X
steps, res = divmod(X, D)
if steps >= K:
    print(X - D * K)
else:
    K -= steps
    if K % 2 == 0:
        print(res)
    else:
        print(min(res + D, abs(res - D)))
x,k,d=map(int,input().split())
x=abs(x)
v=x//d
if v>=k:
    print(x-k*d)
else:
    f=x-d*v
    s=x-d*(v+1)
    f=abs(f)
    s=abs(s)
    if f<s:
        if (k-v)%2==0:
            print(f)
        else:print(s)
    else:
        if (k-(v+1))%2==0:
            print(s)
        else:
            print(f)
x, k, d = map(int, input().split())

if x < 0:
  x *= -1

r = x % d
q = x // d

if q <= k:
  if (k - q) % 2 == 0:
    print(r)
  else:
    print(d - r)
  
else:
  print(r + (q - k) * d)
x,k,d=map(int,input().split())

x=abs(x)

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

X = abs(X)

cuts = X//D

if cuts>=K:
    print(X-(K*D))
else:
    remainingcuts = K-cuts
    r = X-cuts*D

    if remainingcuts%2 == 1:
        print(abs(r-D))
    else:
        print(r)
import sys
input=sys.stdin.readline

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

y=abs(x)
t=y//d
if k<t:
    print(y-d*k)
else:
    s=t-k
    if s%2==0:
        print(y-d*t)
    else:
        print(abs(y-d*(t+1)))
import sys
X,K,D=map(int, sys.stdin.readline().split())
X=abs(X)
a,b=X/D,X%D
if a<K:
    K-=a
    if K%2==0:
        print b
    else:
        print abs(b-D)
else:
    print X-D*K
x,K,D=map(int, input().split())

X=abs(x)
n=X//D

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


# 2darray [[0] * 4 for i in range(3)]
# import itertools
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

x,k,d = inpl()
x = abs(x)
if x - k*d >= 0:
    print(x - k*d)
    quit()
res1 = x - x//d*d
res2 = abs(x - (x//d+1) *d)
if (k-x//d)%2:
    print(res2)
else:
    print(res1)
X, K, D = map(int, input().split())

g = abs(X) % D

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

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

if k%2==1:
    x=x-d

kaisu=int(x/(2*d))
ans=abs(x-kaisu*d*2)
if ans >=d:
    ans=2*d-ans

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

if x >0:
  cnt = x // d
  if cnt <= k:
    if (k - cnt) % 2 == 0:
      ans = x%d
    else:
      ans = abs(x%d - d)
  else:
    ans = abs(x - k*d)
elif x < 0:
  cnt = abs(x) // d
  if cnt <= k:
    if (k - cnt) % 2 == 0:
      ans = abs(x + d*cnt)
    else:
      ans = abs(x + d*(cnt+1))
  else:
    ans = abs(x + k*d)
else:
  if k%2 == 0:
    ans = 0
  else:
    ans = d
print(ans)
x,k,d = map(int,input().split())
result = 0
if abs(x) > k * d:
    result = abs(x) - k*d
else:
    g = abs(x) // d
    if (k - g) % 2 == 0:
        result = abs(x) - d*g
    else:
        result = d*(g+1) - abs(x)
print(result)
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-X//D*D)
    else:
        print((X//D+1)*D-X)
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))
# -*- coding: utf-8 -*-
# 標準入力を取得
X, K, D = list(map(int, input().split()))

# 求解処理
ans = int()
C = int(abs(X) / D)
if C >= K:
    if X < 0:
        ans = X + K * D
    else:
        ans = X - K * D
else:
    if X < 0:
        ans = -1 * (abs(X) % D) + ((K - C) % 2 == 1) * D
    else:
        ans = (abs(X) % D) - ((K - C) % 2 == 1) * D
ans = abs(ans)

# 結果出力
print(ans)