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

if abs(x) // d + 1 > k:
    print(abs(x) - k*d)
else:
    y = abs(x) // d
    if y % 2 == 0:
        if k % 2 == 0:
            print(abs(x) - y*d)
        else:
            print(abs(abs(x) - (y+1)*d))
    else:
        if k % 2 == 1:
            print(abs(x) - y*d)
        else:
            print(abs(abs(x) - (y+1)*d))
x,k,d = map(int,input().split())
max_d = k*d
if( abs(x) < abs(max_d) ):
    tmp = x%d
    min_move = (x-tmp)//d
    if( (k-min_move) % 2 == 0 ):
        ans = tmp
    else:
        ans = abs(d-tmp)
else:
    ans = abs(x) - max_d
print(ans)
x, k, d = map(int, input().split())
x = abs(x)
p_n = x % d
p_n_num = x//d

m_n = p_n - d
ans = ""
if x == 0:
    if k % 2 == 0:
        ans = 0
    else:
        ans = k
else:
    if k <= p_n_num:
        ans = x - (k*d)
    else:
        if (p_n_num - k) % 2 == 0:
            ans = p_n
        else:
            ans = m_n
print(abs(ans))
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    X, K, D = read_ints()
    if X < 0:
        X = -X
    closest_K = X // D
    if K <= closest_K:
        return abs(X-K*D)
    if (K-closest_K)%2 == 0:
        return abs(X-closest_K*D)
    return abs(X-(closest_K+1)*D)


if __name__ == '__main__':
    print(solve())
x,k,d = map(int,input().split())
ans = 0
if abs(x) >= k*d:
    ans = min(abs(x-k*d),abs(x+k*d))
else:
    b = abs(x)%d
    c = abs(x)//d
    if (k-c) %2 == 0:
        if x < 0:
            ans = b
        else:
            ans = b
    else:
        if x < 0:
            ans = abs(b-d)
        else:
            ans = abs(b-d)
print(ans)
x, k, d = [int(x) for x in input().split()]
if x < 0: x = -x
jmps = x//d
if (jmps >= k):
    x = x - d*k
    print(x)
else:
    k -= (x//d)
    x = x - (x//d)*d

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

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

if k%2==0:
  print(x)
else:
  print(d-x)
#import numpy as np
#import collections
#import math

#f = open('./input_C.txt')
#
#X,K,D=map(int, f.readline().split())

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

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


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

x, cnt = abs(x), abs(x) // d
ans = abs(x - d * min(k, cnt + (k % 2 != cnt % 2)))
print(ans)
# -*- coding: utf-8 -*-

def dbg(s):
    # print(s)
    pass


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

k_steps = abs(X)//D
x = absX - K*D
mod = abs(X) % D
if k_steps >= K:
    print(x)
    exit()

remain_steps = K - k_steps

if remain_steps % 2 == 0:
    x = mod
else:
    x = D - mod
print(x)
X,K,D=map(int,input().split())
if X>=0:
    if X-K*D>X%D:
        print(abs(X-K*D))
    else:
        if (K-X//D)%2==0:
            print(X%D)
        else:
            print(abs(X%D-D))
else:
    if X+K*D<X%D:
        print(abs(X+K*D))
    else:
        if (K+X//D)%2==0:
            print(X%D)
        else:
            print(abs(X%D-D))
x, k, d = map(int, input().split())
l = x - k * d
r = x + k * d
if l <= 0 <= r:
  y = r % (2 * d)
  print(min(y, 2 * d - y))
elif r <= 0:
  print(-r)
else:
  print(l)
x,k,d=map(int, input().split())
x=abs(x)
if x-k*d>=0:
  print(x-k*d)
elif x==0:
  if k%2==0:
    print(0)
  else:
    print(k)
else:
  m=x//d
  if (k-m)%2==0:
    print(x-m*d)
  else:
    print(abs(x-(m+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(abs(x) - d))
x, k, d = map(int, input().split())

k_i = abs(x)//d

if k >= k_i+1:
    if k%2==0:
        if k_i%2==0:
            print(abs(abs(x)-d*k_i))
        else:
            print(abs(abs(x)-d*(k_i+1)))
    else:
        if k_i%2==0:
            print(abs(abs(x)-d*(k_i+1)))
        else:
            print(abs(abs(x)-d*k_i))
else:
    print(abs(x)-k*d)
x,k,d=map(int,input().split())
x=abs(x)
if k>x//d:
    X=x%d
    X-=(k-x//d)%2*d
else:
    X=x-k*d
       
print(abs(X))
X,K,D=map(int, input().split())
X=abs(X)
if X-K*D>0:
  print(X-K*D)
else:
  if K%2==0:
    s=X-2*D*int(X/(2*D))
    t=-(s-2*D)
    print(min(abs(s),t))
    
  else:
    s=X-2*D*int((X-D)/(2*D))-D
    t=-(s-2*D)
    
    print(min(abs(s),t))
x, k, d = map(int, input().split())
n1 = abs(x) - d * k
if n1 >= 0:
  print(n1)
else:
  m = abs(x) // d
  if (m - k) % 2 == 0:
    print(abs(x) - m * d)
  else:
    print(abs((abs(x) - (m + 1) * 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=X%d
    if (X-ans)%2!=K%2:
        ans=d-ans
print(ans)
X, K, D = map(int, input().split())
A = abs(X)//D
if K>=A and (K-A)%2==0:
  print(abs(X)%D)
elif K>=A and (K-A)%2==1:
  print(abs(abs(X)%D-D))
else:
  print(abs(X)-K*D)
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

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

m = Decimal(str(x/d)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
m = abs(m)
if k < m:
    m = k

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

#print("m=",m," k=",k, "x=",x)

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

if __name__ == "__main__":
    main()
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))))
import math

x,k,d=map(int, input().split())
if abs(x) > k*d:
    Ans = abs(x)-k*d
    print(Ans)
else:
    move = math.floor(abs(x) / d)
    oufuku = k - move
    if oufuku % 2 == 0:
        Ans =abs(abs(x)-d*move)
    else:
        Ans=abs(abs(x)-d*(move+1))
    print(Ans)
x,k,d = map(int,input().split())

kk = k % 2
y = (x + d*kk) % (2*d)

z = abs(x) // d

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

X=abs(X)
if X>=K*D:
    print(abs(X-K*D))
else:
    print(abs(X-(abs(X)//D+(K-abs(X)//D)%2)*D))
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

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

if k % 2 == 0:
    print(x - a * d)
else:
    print(abs(x - a * d - d))
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

x = abs(x)

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

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

if x<0:
  x=-x
#print(x,k,d)

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

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


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
x, k, d = map(int, input().split())

x = abs(x)

n = x // d

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

kk = k - n

if kk % 2 == 0:
    print(x - (d * n))
else:
    print(abs(x - (d * (n+1))))
X, K, D = map(int, input().split())
T = abs(X) // D
if T > K:
    print(abs(abs(X) - K*D))
else:
    if (K - T) % 2 == 0:
        print(abs(abs(X) - T*D))
    else:
        print(abs(abs(X) - (T+1)*D))
# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
x = abs(x)
a = x // d
b = x % d
ans = 0
# 0を超えない
if k - a < 0:
  ans = x - k * d
else:
  if (k - a) % 2 == 0:
    ans = b
  else:
    ans = abs(b - d)

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

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

k-=c
print(d-x%d if k%2 else x%d)
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

x,k,d = inintm()
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(abs(min(x-(x//d)*d + d, x-(x//d)*d - d)))
def solve():
    X = abs(x)
    a = X//D
    if a <= K:
        if (K-a)%2 == 0:
            ans = X%D
        else:
            ans = min(abs((X%D)+D), abs((X%D)-D))
    else:
        ans = min(abs(X-K*D), abs(X+K*D))
    print(ans)

if __name__ == "__main__":
    x,K,D = list(map(int, input().split()))
    solve()
x, k, d = map(int, input().split())
x = abs(x)
q = x // d
r = x % d

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

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

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

x = abs(x)
m = x//d

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

if x==0:
  if k&1:
    print(d)
  else:
    print(0)
  exit()

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

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

print(ans)
x, k, d = map(int, input().split())
x = abs(x)
ml = min(x//d, k)
mu = min(ml+1, k)
diff_ml = k - ml
diff_mu = k - mu
print(x-ml*d if diff_ml%2 == 0 else mu*d-x)
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

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

x = abs(x)
a = x % d
b = x % d - d
ans = abs(x - k * d)
if (x - a) // d <= k and ((x - a) // d - k) % 2 == 0:
    ans = min(ans, a)
if (x - b) // d <= k and ((x - b) // d - k) % 2 == 0:
    ans = min(ans, -b)
print(ans)
x, k, d = map(int,input().split())
if x < 0:
    x = (-1)*x
if x >= k*d:
    print(x-k*d)
else:
    deg = int(x/d)
    r = k-deg
    if r % 2 == 0:
        print(x-deg*d)
    else:
        print((x-(deg+1)*d)*(-1))
#!/usr/bin/env python3
import math

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

x = abs(x_org)
ans = 0 

def a(n):
    global x
    global d
    ret = x-d*(n-1)
    return ret 

n = x//d
l = math.floor(n)
r = l+1 

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

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

if k < x // d:
    print(x - d * k)
    exit(0)
if (k - x // d) % 2 == 0:
    print(x % d)
else:
    print(d - x % d)
x, k, d = map(int, input().split())
time = x // d
if abs(time) > k:
    print(min(abs(x - d * k), abs(x + d * k)))
    exit()
k -= time
x -= d * time
if k % 2 == 0:
    print(abs(x))
else:
    print(min(abs(x - d), abs(x + d)))
import sys
import numpy as np
X, K, D = list(map(int, input().split()))
x = int(X)
D = int(D)
j = 0
j = abs(X//D)

if j > K:
    j = K


if x > 0:
    x = x - (D*j)
else:
    x = x + (D*j)

j = (K-j) % 2

if j==0:
    print(abs(x))
else:
    if x > 0:
        x = x - D
    else:
        x = x + D
    print(abs(x))
X, K, D = [int(a) for a in list(input().split())]
X = abs(X) 
q = X//D
r = X%D
if q >= K:
    print(X - D*K)
    exit()
rem = K - q
if rem % 2 == 0:
    print(r)
else:
    print(abs(D-r))
X,K,D=map(int,input().split())
X=abs(X)
y=X//D
if K<y:
    y=K
X=X-(D*y)
K=K-y

if K%2==1:
    X=abs(X-D)
    
print(X)
x,k,d = map(int, input().split())
if k*d <= abs(x):
  print(abs(x)-k*d)
else:
  a = abs(x)%d
  b = abs(a-d)
  if (k-(abs(x)//d))%2 == 0:
    print(a)
  else:
    print(b)
x, k, d = map(int, input().split())
ans = 0
if abs(x) <= k * d:
  if (abs(x) // d) % 2 == k % 2:
    ans = abs(x) % d
  else:
    ans = d - abs(x) % d
else:
  ans = abs(x) - k * d
print(ans)
#!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

q, mod = divmod(X, D)

if q < K:
    # print("if")
    X = X - (q * D)
    if (K - q) % 2 == 0:
        ans = X
    else:
        ans = X - D
else:
    # print("else")
    ans = X - (K * D)
print(abs(ans))
X, K, D = list(map(int, input().split()))
X = abs(X)
syo = X // D
#print(syo, amari)
if X <= K * D:
    K -= syo
    X -= D * syo
    if K % 2 == 0:
        print(X)
    else:
        print(abs(X - D))
else:
    print(X - K * D)
X, K, D = [int(x) for x in input().split(" ")]

result = 0
if abs(X) > K * D:
    result = abs(X) - K * D
else:
    y = int(round(abs(X) / D))
    resX = abs(abs(X) - D * y)
    resK = K - y
    if resK % 2 == 1:
        result = abs(resX - D)
    else:
        result = resX
print(result)
x, k, d = map(int, input().split())
if x < 0:
    x *= -1
if x - k*d > 0:
    print(x - k*d)
else:
    print(d - x%d if (x//d - k) % 2 else x%d)
X,K,D = map(int,input().split())
if K*D<=abs(X):
    print(abs(X)-K*D)
    exit()

move_num_before = abs(X)//D
move_num_after = move_num_before+1
if (K - move_num_after)%2 == 0:
    print(abs(abs(X)-move_num_after*D))
    exit()
print(abs(X)-move_num_before*D)
#!/usr/bin/env pypy3

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

    if X - K * D >= 0:
        print(X - K * D)
    elif X + K * D <= 0:
        print(-D * K - X)
    else:
        y = (D * K - X) // (2 * D)
        yy = (D * K - X + 2 * D) // (2 * D)
        print(min(abs(2 * D * y + X - D * K), abs(2 * D * yy + X - D * K)))
main()
X,K,D=map(int,input().split())
if abs(X) >= K*D:
    print(abs(X)-K*D)
else:
    y = abs(X)//D
    z = K-y
    X = abs(X) - (y*D)
    if z%2 == 0:
        print(abs(X))
    else:
        print(abs(X-D))
def resolve():
    '''
    code here
    '''
    X, K, D = [int(item) for item in input().split()]

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

        if temp % 2 == 1:
            print(D - X%D)
        else:
            print(X%D)
    else:
        print(abs(X) - K*D)


if __name__ == "__main__":
    resolve()
x ,k ,d = map(int,input().split())

x = abs(x)
c = x // d
# 必要な移動回数
k_r = k - c
# 移動した後の残りの移動回数
ans_2 = x - d * c
#残り移動回数が偶数のときのｘからの距離

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

x_l = x - d * c
#ｘまでの残りの距離

if k_r % 2 == 0:
    print(ans_2)
    exit()
else :
    x_l -= d
    x_l =abs(x_l)
    print(x_l)
x, k, d = map(int, input().split())
prev = 0
r = min(abs(x) // d, k)
x = x - (r*d) if x > 0 else x + (r*d)
k -= r
while k != 0:
  prev = x
  x = x-d if abs(0-(x-d)) < abs(0-(x+d)) else x+d
  k -= 1
  if prev * x < 0 or x == 0:
    k %= 2
print(abs(x))
x,k,d = map(int, input().split())
lists = []
x = abs(x)
 
step = int(x/d) 
 
if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = min(abs(x % d - d), abs(x % d + d))
 
print(answer)
x, k, d = map(int, input().split())
abs_x = abs(x)
kd = k * d 
ans = 0
if abs_x > kd:
  ans = abs_x - kd
else:
  div, mod = divmod(abs_x, d)
  ans = abs(mod - (k - div) % 2 * d)

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

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

x=abs(x)
kai=x//d
if kai==k:
    print(x%d)
elif kai>k:
    print(x-k*d)
else:
  right=x%d
  left=abs(x%d-d)

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

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

else:
    x = abs(x)
    sho = x//d
    amari = x%d
    if sho >= k:
        print(x-k*d)
    else:
        if (k-sho)%2==0:
            print(amari)
        else:
            print(abs(amari-d))
x, k, d = map(int, input().split())
x = abs(x)
if x >= d * k:
    print(x - d * k)
elif (k - x // d) % 2 == 0:
    print(x - d * (x // d))
else:
    print(abs(x - d * (x // d + 1)))
x,k,d = map(int, input().split())
ans=0
p=abs(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());xx=abs(x)
tmp=xx;tmp=(xx//d);cc=min(tmp,k)
xx-=d*cc;k-=cc;k&=1;xx-=d*k
print(abs(xx))
x,k,d=map(int,input().split())

x=x if x>0 else -x

if k*d<x:
    print(x-k*d)
else:
    rma=(k*d-x+2*d-1)//(2*d)
    rmi=(k*d-x)//(2*d)

    print(min(abs(x-(k-2*rmi)*d),abs(x-(k-2*rma)*d)))
x, k, d = map(int, input().split())

x = abs(x)

cnt = x//d
amari = x%d

nokori = k-cnt

if nokori < 0:
  ans = x - d*k
else:
  if nokori%2 == 0:
    ans = amari - d + d
  else:
    ans = amari - d

print(abs(ans))
x, k, d = map(int, input().split())
x_abs = abs(x)
if x_abs >= k * d:
  print(x_abs - k * d)
else:
  n = x_abs // d
  if (k - n) & 1:
    print((n + 1) * d - x_abs)
  else:
    print(x_abs - n * d)
x,k,d=map(int,input().split())
x=abs(x)
if x>=k*d:
  print(x-k*d)
else:
  if x%d==0:
    t=0
  else:
    t=x%d
  c=k-(x-t)//d
  if c%2==0:
    print(x%d)
  else:
    print(d-x%d)
#!/usr/bin/env python3
# input
X, K, D = map(int, input().split())
DIV = (X + K * D) // (2 * D)

if X + K * D < 0:
    ans = -(X + K * D)
elif X - K * D > 0:
    ans = X - K * D
else:
    ans = min(X + K * D - DIV * D * 2, -(X + K * D - (1 + DIV) * D * 2))
print(ans)
# coding: utf-8
# Your code here!
X,K,D=map(int,input().split())

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

if move==K:
    print(ans)
else:
    if (K-move)%2==0:
        print(ans)
    else:
        print(abs(ans-D))
l = list(map(int,input().split()))
x = abs(l[0])
k = l[1]
d = l[2]
prev = 0

n = x//d

if k%2 == 0 and n%2 == 1:
  n += 1
elif k%2 == 1 and n%2 == 0:
  n += 1

if n>k:
  n = k
ans = abs(x-n*d)
print(ans)
#ABC 175 C
x, k, d = map(int, input().split())

x = abs(x)
syou = x // d
amari = x % d

if k <= syou:
    ans = x - (d * k)

else:
    if (k - syou) % 2 == 0: #残りの動ける数が偶数
        ans = amari

    else:#残りの動ける数が奇数
        ans = abs(amari - d)

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


def f(x):
    return X + (2 * x - K) * D


if f(0) >= 0:
    print(f(0))
    exit()

if f(K) <= 0:
    print(-f(K))
    exit()

left = 0
right = K
while right - left > 1:
    mid = int((right + left) / 2)
    if f(mid) < 0:
        left = mid
    else:
        right = mid

print(min(-f(left), f(right)))
X,K,D = map(int, input().split())

if abs(X) > K*D:
    X = abs(X) - K*D
else:
    # とりあえず同方向に移動できるところまでいく
    # 移動回数
    T = abs(X)//D
    # 移動先の座標
    Y = abs(X)%D
    
    # 残りは往復の2択
    X = abs(Y - ((K-T)%2)*D)   
    
print(X)
x,k,d=map(lambda x:abs(int(x)),input().split())

p = x//d
m = k - p
ans = 0
if k<p:
    ans = x - d*k
else:
    ans = x - d*p
    k = k - p
    if (k%2 ==1):
        ans = abs(ans) - d
print(abs(ans))
X, K, D = map(int, input().split())
dis = 0

if X < 0:
    X *= -1

quotient = X // D

if quotient >= K:
    dis = X - K * D
else:
    remainder = X % D
    if remainder < D - remainder:
        dis = remainder
        if (K - quotient) % 2 != 0:
            dis = D-remainder
    else:
        dis = D - remainder
        if (K - quotient) % 2 == 0:
            dis = remainder

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

x = abs(x)

num = x // d 

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

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

a,b = divmod(x,d)
if a <= k:
    if (k-a) % 2 == 0:
        print(b)
    else:
        print(min(abs(b-d),abs(b+d)))
else:
    print(x - k*d)
x,k,d = map(int, input().split())
if x < 0:
    x = -x
x_min = x
if x//d >= k:
    x_min -= k * d
else:
    x_min -= x//d * d
    k -= x//d
    if k % 2 == 1:
        x_min = abs(x_min - d)
print(x_min)
#xが更新されてる！！
n,k,d=map(int,input().split())
n=abs(n)
q=n//d
r=n%d
if(k<=q):
    print(n-k*d)
else:
    rem=k-q
    if(rem%2==0):
        print(r)
    else:
        print(min(abs(r-d),abs(r+d)))
from math import *
import sys,bisect,copyreg,copy,statistics,os
def inp(): return sys.stdin.readline().strip()
def IIX(): return (int(x) for x in sys.stdin.readline().split())
def II(): return (int(inp()))
def LI(): return list(map(int, inp().split()))
def LS(): return list(map(str, inp().split()))
def L(x):return list(x)
def out(var): return sys.stdout.write(str(var))


x,k,d=LI()

x=abs(x)

if (x//d>=k) :  out(x-k*d)
else:
    k-=x//d
    x-=(x//d) *d
    if k % 2==0:    out(x)
    else:   out(abs(x-d))
# coding: utf-8
# Your code here!
X,K,D=map(int,input().split())

move=min(X//D,K)
ans=X-move*D

if move==K:
    print(ans)
else:
    if (K-move)%2==0:
        print(ans)
    else:
        print(abs(ans-D))