peterverebics/CodeNet_Python_118 huggingface dataset:
x,K,D = map(int,input().split())
X = abs(x)
total_distance = D * K
if X >= total_distance:
    print(X - total_distance)
else:
    to_zero_times = X // D #0に近付くまでに使った回数
    from_zero_distance1 = X % D #０になるべく近付いた時の０からの距離
    from_zero_distance2 = D - from_zero_distance1
    left_times = K - to_zero_times #残り回数
    if left_times % 2 == 0:
        print(from_zero_distance1)
    else:
        print(from_zero_distance2)
x, k, d = map(int, input().split())

if abs(x) >= k * abs(d):
  print(min(abs(x - k * d),abs(x + k * d)))
else:
  n = abs(x) // abs(d)
  if (k - n) % 2 == 1:
    n += 1
  print(min(abs(x - n * d),abs(x + n * d)))
x,k,d = map(int,input().split())
x = abs(x)
if k*d <= x:
    print(x - k*d)
else:
    if (k - x//d) %2 == 0:
        print(x%d)
    else:
        print(abs(x%d-d))
import sys

input = sys.stdin.readline


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

    X = abs(X)
    q, r = divmod(X, D)
    if K <= q:
        ans = (q - K) * D + r
    else:
        if (K - q) % 2 == 0:
            ans = r
        else:
            ans = D - r

    print(ans)


if __name__ == "__main__":
    main()
x,k,d=map(int,input().split())
print(max(abs(x)-k*d,(x%d,d-x%d)[k-x//d&1]))
X, K, D = map(int, input().split())

XX = abs(X)

if XX > K*D:
    print(XX - K*D)
else:
    if (K - X//D)%2 == 0:
        print(X%D)
    else:
        print(abs(X%D -D))
#!/usr/bin/env python3

x, k, d = map(int, input().split(' '))
m = (k * d - x) / (2 * d)
ans = 0

def score(c):
    return abs(x - k * d + 2 * d * c)

if m > k:
    ans = k
else:
    if m < 0:
        ans = 0
    else:
        ans = int(m)
    if score(ans) > score(ans+1):
        ans += 1

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

X = abs(X)

if X//D <= K:
    K -= X//D
    X %= D

    X -= D*(K%2)

    print(abs(X))
else:
    print(X - D*K)
x, k, d = map(int, input().split())
x = abs(x)
if k * d < x:
    print(x - k * d)
    exit()

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

move_count = 0
D = abs(D)
X = abs(X)

q = X // D
mod = X % D
vi = X //2
if q > K:
  print(X - D*K)
else:
  if (K-q) % 2 == 0:
    print(X- D*q)
  else:
    print(abs(X-D*(q+1)))
X,K,D=input().split(' ')
x,k,d=abs(int(X)),int(K),int(D)

x_par=x%d
x_num=int((x-x_par)/d)

s=0
if x_num<=k:
  x_div=x-x_num*d
  k-=x_num
  if k%2==0:
    s=abs(x_div)
  else:
    s=x_div-d
else:
  s=x-d*k
print(abs(s))
x,k,d = map(int,input().split())

num = abs(x)//d

dist = abs(x) - min(num,k)*d

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

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

p_min_cnt = x//d
rem = k - p_min_cnt
p_min = x%d

if rem%2 == 0:
    print(p_min)
else:
    m_min = abs(p_min-d)
    print(m_min)
def main():
    x, k, d = list(map(int, input().split(" ")))
    dk = d*k
    if abs(x) < dk:
        div_count = abs(x)//d
        if (k - div_count)%2==0:
            ans = abs(x)%d
        else:
            ans = d - abs(x)%d
    else:
        ans = abs(dk - abs(x))
    print(ans)

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

if least>=K:
    ans = X - K*D
elif (K-least)%2==0:
    ans = X - least*D
elif (K-least)%2==1:
    ans = -1*(X-(least+1)*D)

print(ans)
import math


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


Y = abs(X) // D

Mm = abs(X) - Y*D
Mp = (Y+1)*D - abs(X)

if (Mm <= Mp):
    M0 = Mm
    M1 = Mp
    Z = Y
else:
    M0 = Mp
    M1 = Mm
    Z = Y + 1

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

if x<0:
  x *= -1

if x>=0 and x-k*d>=0:
  print(x-k*d)
else:
  tmp = x//d
  if tmp%2==k%2:
    print(x%d)
  else:
    print(d-x%d)
X, K, D = map(int, input().split())
X = abs(X)
if X > D*K:
    print(X-D*K)
else:
    n, c = divmod(X, D)
    if n%2:
        if K%2:
            print(c)
        else:
            c = D-c
            print(c)
    else:
        if K%2:
            c = D-c
            print(c)
        else:
            print(c)
X,K,D=map(int,input().split())
X=abs(X)
if K*D<X:
    print(X-K*D)
else:
    K-=X//D
    X%=D
    if K%2==0:
        print(X)
    else:
        print(D-X)
X,K,D=map(int,input().split())
if abs(X)<K*D:
    a=X//D
    K-=a
    X-=D*a
    if K%2:
        print(abs(X-D))
    else:
        print(X)
else:
    print(abs(X)-K*D)
x, k, d = map(int, input().split())
x = abs(x)
if x >= k*d:
    print(x-k*d)
else:
    mv = int(x/d)
    x -= mv*d
    k -= mv
    if k % 2 == 0:
        print(x)
    else:
        print(abs(x-d))
x,k,d=map(int,input().split())
print(max(abs(x)-k*d,[x%d,d-x%d][(k-x//d)%2]))
X,K,D=map(int,input().split())
min_=X-D*K
max_=X+D*K
if min_>=0:
  print(min_)
elif max_<=0:
  print(-max_)
else:
  c1=max_%(2*D)
  c2=c1-2*D
  print(min(abs(c1), abs(c2)))
x, k, d = map(int, input().split())

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

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

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

if cal > k:
    ans = abs(x) - k*d
else:
    if (k - cal) % 2 == 1:
        ans = min(abs(ans-d),abs(ans+d))

print(ans)
#coding:utf-8

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

X = abs(X)

ans = 0
kan = X // D

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

print("{}".format(ans))
X, K, D = map(int, input().split())
tmp = abs(X) // D
if tmp >= K:
    print(abs(X) - K * D)
    exit()
X = abs(X) - tmp * D
K -= tmp
Kp = K - 1
Xp = abs(X - D)
K %= 2
Kp %= 2
if K:
    X = abs(X - D)
if Kp:
    Xp = abs(Xp - D)
print(min(X, Xp))
X,K,D=map(int, input().split())
X = abs(X)
if X > K*D:
    print(abs(X)-K*D)
else:
    n = X // D
    r = K-n
    m = X - D * n
    if r % 2 == 0:
        print(m)
    else:
        print(D-m)
x,k,d=map(int,input().split())

minx=x-k*d
maxx=x+k*d
targetx=minx%(2*d)
if targetx>d:
    targetx-=2*d
if targetx==d:
    if x<0:
        targetx-=2*d

if minx>targetx:
    print(abs(minx))
    exit()
if maxx<targetx:
    print(abs(maxx))
    exit()
print(abs(targetx))
import sys
X, K, D = map(int, input().split())
X = abs(X)
if X // D >= K:
    print(X - K*D)
    sys.exit()
K = K - (X // D)
A = X - X//D*D
if K % 2 == 0:
    print(A)
else:
    print(abs(A - D))
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

    X = abs(X)
    div, mod = X // D, X % D
    if K <= div:
        print(X - K * D)
    else:
        print(abs(mod - D * ((K - div) % 2 == 1)))


if __name__ == "__main__":
    main()
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))
x,k,d = map(int,input().split())
x = abs(x)
if x - k*d > 0:
    print(x-k*d)
else:
    rest = k - x//d
    if rest%2==0:
        print(x-d*(x//d))
    else:
        print(abs(x-d*(x//d+1)))
x, k, d = map(int, input().split())
x = abs(x)
if d * k < abs(x):
    ans = abs(x - d * k)
elif (k - (x // d)) % 2 == 0:
    ans = x % d
else:
    ans = abs(x % d - d)
print(ans)
X, K, D = map(int, input().split())
X = abs(X)


if X == 0:
    if K % 2 == 0:
        print(0)

    else:
        print(D)

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

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

if __name__ == "__main__":
    main()
import os

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

x = abs(x)

if x//d>k:
    print(x-k*d)
else:
    if (k-x//d)%2==0:
        print(x%d)
    else:
        print(abs(x%d-d))
def main():
    X, K, D = map( int, input().split())
    if X < 0:
        X = -X
    c = min(X//D, K)
    X -= c*D
    K -= c
    if K%2 == 0:
        print(X)
    else:
        print(D-X)
    
if __name__ == '__main__':
    main()
def WalkingTakahashi():
    
    data = list(map(int,input().split()))
    
    position = abs(data[0])
    
    m = min(data[1], position//data[2])
    
    position = position - data[2]*m
    
    data[1] = data[1] - m
    
    data[1] %= 2
    
    position = position - data[2]*data[1]
    
    print(abs(position))
    
if __name__ == '__main__':
    WalkingTakahashi()
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    x, k, d = ril()
    a = 2 * d
    b = - x + k * d
    f = lambda i : a * i - b
    if b <= 0:
        ans = -b
    elif a * k < b:
        ans = -f(k)

    elif b % a == 0:
        ans = 0
    else:
        x1 = b // a
        x2 = x1 + 1
        ans = min(-f(x1), f(x2))
    print(ans)

if __name__ == '__main__':
    main()
x, k, d = map(int, input().split())
neg = (x < 0)
x = abs(x)
if x // d > k: ans = (x - k * d)
else:
    if (x // d) % 2 == k % 2: ans = x - x // d * d
    else: ans = x - x // d * d - d
print(abs(ans))
X, K, D = map(int, input().split())
p = (abs(X)+D-1)//D
if p >= K:
    print(abs(abs(X)-K*D))
    exit()
K -= p
if X > 0:
    X = X-p*D
else:
    X = X+p*D
plus, minus = 0, 0
if X > 0:
    plus = K//2
    minus = (K+1)//2
else:
    plus = (K+1)//2
    minus = K//2
# print(X, plus, minus)
print(abs(X+plus*D-minus*D))
#template
def inputlist(): return [int(j) for j in input().split()]
#template
X,K,D= inputlist()
count = abs(X)//D +1
if K < count:
    print(min(abs(X-D*K),abs(X+D*K)))
    exit()
d_odd = 0
d_even = 0
if X >= 0:
    d_odd = X - D*(count-1)
    d_even = X-D*count
if X < 0:
    d_odd = X + D*(count-1)
    d_even = X + D*count
K -=count
if K % 2 == 0:
    print(abs(d_even))
else:
    print(abs(d_odd))
X,K,D=map(int,input().split())

if abs(X)>=K*D:
  print(abs(X)-K*D)
  exit()
  
q,r=divmod(X,D)

if K%2 == q%2:
  print(r)
else:
  print(abs(r-D))
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

X,K,D = LI()
X = abs(X)
sho = X // D
amari = X % D

if (sho>=K):
    saigo = X - (K*D)
    print(abs(saigo))
else:
    nokori = K - abs(sho)
    if nokori % 2 == 0:
        print(abs(amari))
    else:
        ans = min(amari+D,amari-D)
        print(abs(ans))
X,K,D = map(int,input().split())
 
if X<0:
    X *= -1
n = X//D
m = min(K,n)
 
X -= m*D
K -= m
if K%2:
    print(abs(X-D))
else:
    print(X)
X,K,D=map(int, input().split())
d=abs(X)//D
if d>=K:
	if X<0:ans=X+K*D
	else:ans=X-K*D

else:
	if X<0:
		temp=X+d*D
		if (K-d)%2==0:
			ans=temp
		else:
			ans=temp+D
	else:
		temp=X-d*D
		if (K-d)%2==0:
			ans=temp
		else:
			ans=temp-D

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

pm = 1 if x > 0 else -1
a = abs(x) // abs(d)
if abs(x-pm*d*a) > abs(x-pm*d*(a+1)):
    a = a + 1
if k <= a:
    print(abs(x-pm*d*k))
elif (k-a) % 2 == 0:
    print(abs(x-pm*d*a))
else:
    print(min(abs(x-pm*d*(a+1)), abs(x-pm*d*(a-1))))
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)))
import os

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

x = abs(x)

ri=x//d
if ri <= k:
    nkr = k-ri
    if nkr%2==0:
        print(abs(x - ri*d))
    else:
        riso_a = abs(x-ri*d)
        print(min(abs(riso_a+d), abs(riso_a-d)))
elif ri > k:
   print(x - k*d)
a = input().split()
x, k, d = abs(int(a[0])), int(a[1]), int(a[2])
a, b = x // d, x % d
c = d - b
if a > k:
    print(x - k * d)
elif a == k:
    print(b)
else:
    t = k - a
    if t % 2:
        print(c)
    else:
        print(b)
x,k,d=map(int,input().split())
x=abs(x)
syou=x//d
if k<=syou:
  print(x-k*d)
else:
  k=k-syou
  x=x%d
  if k%2==0:
    print(x)
  else:
    print(abs(x-d))
X,K,D=map(int,input().split())
res = X
n = abs(int(X/D))
rest = 0
if n >= K:
  if X < 0:
    res = X+K*D
  else:
    res = X-K*D
else:
  if X < 0:
    res = X+n*D
  else:
    res = X-n*D
  rest = K-n
  if rest % 2 == 1:
    if res < 0:
      res = res+D
    else:
      res = res-D
  else:
    pass
res = abs(res)
print(res)
X,K,D = map(int, input().split())
X = abs(X)
if K*D <= X:
    print(X-K*D)
else:
    tempK = X//D
    if (K-tempK)%2==0:
        print(X-D*tempK)
    else:
        print(abs(X-D*tempK-D))
X, K, D = list(map(int, input().split()))

if X < 0:
    X = -X

if X - K*D > 0:
    print(X-K*D)
else:
    K_min = int(X/D)
    if (K - K_min)%2 == 0:
        print(X - K_min*D)
    else:
        print((K_min+1)*D -X)
def main():
    X, K, D = map(int, input().split())
    answer = solve(X, K, D)
    print(answer)


def solve(X, K, D):
    if abs(X) >= D * K:
        return abs(X) - (D * K)

    least_hops = abs(X) // D

    hops_left = K - least_hops
    dst = abs(X) - (D * (least_hops + hops_left % 2))

    return abs(dst)


if __name__ == "__main__":
    main()
def abs(x):
    if x < 0:
        return -x
    return x


def main():
    xkd = [int(_x) for _x in input().split()]
    x = xkd[0]
    k = xkd[1]
    d = xkd[2]
    ax = abs(x)
    if ax-k*d > 0:
        print(ax-k*d)
        return

    i = int(ax/d)
    if (k-i) % 2 == 0:
        print(ax-d*i)
        return
    else:
        print(abs(ax-d*i-d))
        return
    # N = int(input())


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

x = abs(x)

wari = x//d
amari = k-wari
p = x - (d*wari)

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

        print(abs(d-(x-d*(x//d))))
X,K,D=map(int,input().split())
P = X-D*K
Q = 2*D
if X-D*K<=0<=X+D*K:
    U=(X-D*K)%(Q)
    print(min(U,Q-U))
    
elif 0<X-D*K:
    print(X-D*K)
    
    
elif X+D*K<0:
    print(-X-D*K)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def li():
    return [int(x) for x in input().split()]


X, K, D = li()

if X < 0:
    X *= -1

ans = 0
if K * D < X:
    #print("A")
    ans = X - K * D
else:
    over_K = X // D + 1
    #print(over_K)
    if (K - over_K) % 2 == 1:
        #print("B")
        ans = X % D
    else:
        #print("C")
        ans = D - (X % D)

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):
        if(k%2==0): print(rest)
        else: print(d-rest)
    else:
        if(k%2==1): print(rest)
        else: print(d-rest)
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)))
x,k,d=[int(x) for x in input().split()]
if k<(abs(x)/d):
  print(abs(abs(x)-d*k))
else:
  if x%d==0:
    if (k-(abs(x)/d))%2==0:
      print(0)
    elif (k-(abs(x)/d))%2==1:
      print(d)
  else:
    n=int(abs(x)/d)+1
    if (k-n)%2==0:
      print(abs(abs(x)-d*n))
    elif (k-n)%2==1:
      print(abs(abs(x)-d*(n-1)))
x,k,d=map(int,input().split())
x=abs(x)
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())

cnt = abs(x) // d
x = abs(x)
if k % 2 == cnt % 2:
    ans = min(abs(x - d * min(k,cnt)), abs(x + d * min(k,cnt)))
elif k % 2 != cnt % 2:
    ans = min(abs(x - d * min(k,(cnt + 1))), abs(x - d * min(k,(cnt + 1))))
print(ans)
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))
X, K, D = map(int, input().split())

mod = abs(X) % D
ura = D - mod
if mod <= ura:
  if abs(X)-D*K > mod:
    ans = abs(X)-D*K
  else:
    n = (abs(X)-mod) // D
    if (K-n) % 2 == 0:
      ans = mod
    else:
      ans = ura
else:
  if D*K-abs(X) < ura:
    ans = abs(X)-D*K
  else:
    n = (abs(X)+ura) // D
    if (K-n) % 2 == 0:
      ans = ura
    else:
      ans = mod
print(ans)
x, k, d = map(int, input().split())
x = abs(x)
z = x//d
if x-k*d >= 0:
    print(x-k*d)
else:
    if (k-z)%2 == 0:
        print(x-z*d)
    else:
        print(abs(x-z*d-d))
x,k,d = map(int,input().split())
a = 0
if abs(x) // d > k:
    print(abs(abs(x) - k * d))
else:
    a = abs(abs(x) - (abs(x) // d) * d)
    k = k - (abs(x) // d)
    if k % 2 == 0:
        print(a)
    else:
        print(abs(a - d))
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x,k,d = mi()
x = abs(x)

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

if k % 2 == 0:
    print(x)
else:
    print(d-x)
X,K,D = [int(i) for i in input().split()]
X = abs(X)
M = X//D
if K <= M:
    print(X - K*D)
    exit()
X = X - M*D
K -= M
if K%2 == 0:
    print(X)
else:
    print(abs(X-D))
x,k,d=map(int,input().split())
if x<=0:
  x*=-1
mi=x//d
if mi>=k:
  print(x-k*d)
  exit()
else:
  if (mi-k)%2==0:
    print(x-mi*d)
  else:
    print(abs(x-mi*d-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 = b
    else:
        ans = abs(b - D)
    
print(ans)
X, K, D = map(int, input().split())

X = abs(X)

n = X // D
m = K - n

A1 = abs(X - n*D)
A2 = abs(X - (n+1)*D)

Ans = A2

if m > 1:
    if A1 <= A2:
        if m % 2 == 0:
            Ans = A1
    else:
        if m % 2 == 0:
            Ans = A1
else:
    Ans = abs(X - K*D)

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

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

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

elif (k - abs(x)//d)%2 == 0:
    print(abs(x)%d)
    
elif (k - abs(x)//d)%2 == 1:
    print(abs(abs(x)%d - d))
X, K, D = map(int, input().split())
q, r = divmod(X, D)
if X < 0:
    q += 1
    q *= -1
    r -= D
if q >= K:
    if X >= 0:
        print(abs(X - K * D))
    else:
        print(abs(X + K * D))
else:
    if (K - q) % 2 == 0:
        print(abs(r))
    else:
        print(min(abs(r - D), abs(r + D)))
x,k,d=list(map(int, input().split()))
y=abs(x)
if y>k*d:
    print(y-k*d)
else:
    if k%2==0:
        e=y//(2*d)
        f=min(abs(y-2*e*d),abs(y-(2*e+2)*d))
        print(f)
    elif k%2==1:
        e=(y+d)//(2*d)
        f=min(abs(y-(2*e-1)*d),abs(y-(2*e+1)*d))
        print(f)
X, K, D = map(eval, input().split())

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

print(abs(X))
x,k,d = map(int,input().split())
x = abs(x)
n = x//d
if n <= k :
    x -= d*n
    count = k-n+2
    if count % 2 == 0 :
        now = x
    else :
        now = d-x
else :
    now = x - k*d

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

#できるだけ0に近づける(K1:正の値ギリギリ K2:負の値ギリギリ)
X = abs(X)

K1 = X // D
K2 = K1 + 1

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

first_step = min(X // D, K)

X -= first_step * D
K -= first_step

if K % 2 == 0:
    print(abs(X))
else:
    X -= D
    print(abs(X))
x,k,d = map(int,input().split(' '))
a = abs(x) % d 
b = -(a - d)
if abs(x) // d > k:
    ans = abs(x) - k * d
else:
    if a == b:
        ans = a
    else:
        if a < b:
            n1 = a
            n2 = b
        if b < a:
            n1 = b
            n2 = a
        if k % 2 == (abs(x) // d) % 2:
            ans = a
        else:
            ans = b
print(ans)
X, K, D = map(int, input().split())
#  何回で0をまたぐか、その時いる場所
if X < 0:
    X = X * (-1)
times = X // D + 1
place = X - D * (times)
if times <= K:
    #  残った移動回数
    K = K - times
    if K % 2 == 0:
        place = place
    else:
        place = place + D
else:
    place = X - D * K

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

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


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

    if K < cnt:
        ans = x - (K * D)
    else:
        ans = x - (cnt * D)
        if (K - cnt) % 2:
            ans -= D
    print(abs(ans))


if __name__ == "__main__":
    resolve()
x,k,d=map(int,input().split())
if x<0:
    x=-x
t=x//d
if k<=t:
    print(int(x-(d*k)))
else:
    if (k-t)%2==1:
        print(int(abs(x-(d*t)-d)))
    else:
        print(int(x-(d*t)))
x, k, d = map(int, input().split())
x = abs(x)
a = x//d
if a>=k:
    ans = x-k*d
else:
    if (k-a)%2==0:
        ans = x-d*a
    else:
        ans = abs(x-(a+1)*d)
    

print(ans)
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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


def solve(X, K, D):
    X = abs(X)

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


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

Abs_X = abs(X)
step  = Abs_X // D

if step < K:
    if (K - step) % 2 == 0:
        answer = min(abs(X + step*D), abs(X - step*D))
    else:
        answer = min(abs(X + (step+1)*D), abs(X - (step+1)*D))
else:
    answer = min(abs(X + D*K), abs(X - D*K))

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

if abs(x // d) >= k:
    ans = min(abs(x - k*d), abs(x + k*d))
else:
    k -= x // d
    x -= x // d * d
    if min(abs(x - d), abs(x + d)) <= abs(x):
        if k % 2 == 1:
            ans = min(abs(x - d), abs(x + d))
        else:
            ans = abs(x)
    else:
        if k % 2 == 0:
            ans = abs(x)
        else:
            ans = min(abs(x - d), abs(x + d))
print(ans)
X, K, D = [int(x) for x in input().split()]
if(D*K+X)>0:
  if(X-D*K)>=0:
    print(X-D*K)
  else:
    x = int((D*K+X) // (2*D))
    ans0 = abs(-2*D*(x-1)+(D*K+X))
    ans1 = abs(-2*D*x+(D*K+X))
    ans2 = abs(-2*D*(x+1)+(D*K+X))
    ans3 = abs(-2*D*(x+2)+(D*K+X))
    print(min(ans0, ans1, ans2, ans3))
elif(D*K+X)<=0:
  print(abs(D*K+X))
x,k,d = map(int,input().split())
x = abs(x)
if x > d:
	if x - k*d >= 0:
		print(x - k*d)
	else:
		if (k-(x//d))%2 == 0:
			print(x%d)
		else:
			print(min(x%d + d,abs(x%d - d)))
if x <= d:
	if k%2 == 0:
		print(min(abs(x - 2*d),x))
	else:
		print(min(d-x,x+d))