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

C =[]
if X == K and K == D:
    print(X)

else:
    for i in range(K):
        if abs(X - D) >= abs(X + D):
            X = X + D
            C.append(X)
        #print(X)
        else:
            X = X - D
            C.append(X)
        #print(X)

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

i = 0

while X - D * i > 0 :
  i = i + 1
#  print('i', i)

if i-1 < K :
  X = X - D * (i-1)
  #print('X', X)
  K = K - (i-1)
  #print('K', K)

  if K % 2 == 0:
    print(X)
  else :
    print(X-D)

else :
  print(X-K*D)
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

x,k,d = readints()

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

print(x)
import math
x,k,d = map(int,input().split())
ans = float('inf')

if x/k < d:
    x = x - math.floor(x/d) *d
    for i in range(10**5):
        ans = min(abs(x-k), abs(x+k))
        if abs(x-k) < abs(x+k):
            x = x - k
        else:
            x = x + k
else:
    if x > 0:
        ans = x - k*d
    else:
        ans = x + k*d
print(ans)
x, k, d = map(int, input().split())

t = float(abs(x/d))
ans = 0

#print(t)
if k <= t:
    ans = abs(x - d*k)

else:
    if (k-t)%2 == 0:
        ans = abs(x - d*int(t))
    else:
        ans = abs(x - d*int(t) - d)
        
print(abs(ans))
import sys
input = sys.stdin.readline

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

x = abs(x)

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

X = abs(X)
a = X / D
b = round(a)

c = K - b

if c < 0:
    print(X-(K*D))
elif c % 2 != 0:
    if a > b:
        b = b + 1
    else:
        b = b - 1
    d = abs(X - (D*b))
    print(d)
X, K, D = map(int, input().split())
if abs(X) == D and K % 2 == 0:
    print(D)
    exit()
if abs(X) >=abs(K * D):
    if X >= 0:
        print(X - K * D)
    else:
        print(X + K * D)
else:
    if K%2 == 0:
        print(X % D)
    else:
        print(abs(X % D - D))
# cook your dish here
x,k,d = list(map(int, input().split()))
mod = x%d
div = x//d
ans = 0
if mod==0:
    if k%2==0:
        ans = x
    else:
        ans = x-d #x-d=0
else:
    if div<=mod:
        ans = x-k*d
    if div>mod:
        ans = mod
print(abs(ans))
A = list(map(int,input().split()))
X,K,D = A[0], A[1], A[2]

if abs(X) >= K*D:
    print(abs(X)-K*D)
else:
    d = abs(X) // K
    amari = abs(X) % K
    hantai = K - amari
    
    if K - d % 2 == 0:
        print(amari)
    else:
        print(hantai)
X,K,D = map(int,input().split())
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 = [int(x) for x in input().split()]
if X // D < K:
    rest = K - (X // D)
    if rest % 2:
        if X > 0:
            X -= D
        elif X < 0:
            X += D
    print(min(X%D, abs(X%D - D)))
else:
    if X < 0:
        print(abs(X + K*D))
    else:
        print(abs(X - K*D))
x, k, d = map(int, input().split())
t = x // d
a = []
a.append(t - 3)
a.append(t - 2)
a.append(t - 1)
a.append(t)
a.append(t + 1)
a.append(t + 2)
a.append(t + 3)
a.append(k)
a.append(k - 1)
a.append(-k)
a.append(-k + 1)

res = abs(x)
for i in a:
    if i % 2 == k % 2 and abs(i) <= k:
        res = min(res, abs(x - i * d))
print(res)
# C - Walking Takahashi

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

d = X // D
m = X % D

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


if x > k * d:
    print(x - k * d)
else:
    q = x // d
    mod = x % d
    x2 = x - q * d
    k2 = k - q
    r = abs(mod - d)
    if k2 % 2 == 0:
        print(mod)
    else:
        print(r)
b=list(map(int,input().split()))
X=int(b[0])
K=int(b[1])
D=int(b[2])
a=abs(X+D)
for i in range(K+1):
    if abs(X-D*i+D*(K-i))<a:
        a=X-D*i+D*(K-i)
print(a)
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 cnt % 2 != 0:
        ans -= D
print(abs(ans))
# -*- coding: utf-8 -*-
X,K,D=map(int,input().split())

X=abs(X)
ii=int(X/D)
if K<=ii:
    X-=K*D
else:
    X-=ii*D
if (K-ii)%2==1:
    X-=D

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

X = abs(X)

a = X % D

X -= min(a, K) * D
K -= min(a, K)

K %= 2
if K == 1:
    X -= D

result = abs(X)

print(result)
#ABC175  C
x, k, d = map(int, input().split())
num = x // d
if num >= k:
  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))
x, k, d = map(int, input().split())
r = x % d
q = (x - r) / d
if x - k*d >= 0:
  ans = x - k*d
elif k%2 == q%2:
  ans = r
else:
  ans = d - r
print(ans)
X,K,D = map(int,input().split())
A = abs(X)
if A > D:
    if K == 0:
        A = A
    elif 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))
import numpy as np

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

if x - k * d > 0:
	print(x - k * d)
elif x == d:
	if k % 2 == 0: print(x)
	else:print(0)
else:
	num1 = x % d
	num2 = num1 - d
	print(min(np.abs(num1),np.abs(num2)))
# ABC172　C - Walking Takahashi
X,K,D=map(int,input().split())

q=X//D
if q>K:
    print(abs(X)-K*D)
else:
    if (K-q)%2==0:
        print(abs(X)-q*D)
    else:
        print(abs(X)-(q+1)*D)
def resolve():
    '''
    code here
    '''
    X, K, D = [int(item) for item in input().split()]

    if K*D > 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())
anl = []
for i in range(k+1):
	anl.append(abs(d*k + x - 2*d*(i+1)))
print(min(anl))
x, k, d = map(int, input().split())
l = x-k*d
r = x+k*d
if l <= 0 and r >= 0:
    if int(abs(x)/d) % 2 == k % 2:
        print(x % d)
    else:
        print(d - x % d)
elif r < 0:
    print(abs(r))
else:
    print(abs(l))
X, K, D = map(int, input().split())
scnt = abs(X) // D
if K <= scnt:
    print(abs(X) - K * D)
else:
    if X % D == 0:
        if (K - scnt) % 2 == 0:
            print(0)
        else:
            print(D)
    else:
        if (K - scnt) % 2 == 0:
            print(min(abs(abs(X - scnt * D)), abs(abs(X) - (scnt + 1) * D)))
        else:
            print(abs(abs(X) - (scnt + 1) * D))
import sys
X, K, D = map(int, input().split())
K = int(K/D)+1
for _ in range(K):
    if abs(X+D) > abs(X-D):
        X -= D
    else:
        X += D

print(abs(X))
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580


def solve():
    x,k,d = map(int, input().split())
    move = k*d
    x = abs(x)
    if x > k*d:
        print(x -k*d)
    else:
        q = x//d
        if abs(q - k)/2 == 0:
            print(x%d)
        else:
            print(d - x%d)
            
if __name__ == '__main__':
    solve()
import math

X,K,D = map(int, input().split())
tm = round(X/D)
if K <= tm:
  print(abs(X-D*K))
else:
  if (K-tm)%2==1:
    if math.modf(X/D)[0]<0.5:
      print(abs(X-D*(tm+1)))
    else:
      print(abs(X-D*(tm-1)))
  else:
    print(abs(X-D*tm))
X,K,D=map(int,input().split())
L=min(X+D*K,X-D*K)
R=max(X+D*K,X-D*K)

if 0<=L:
    print(L)
elif R<=0:
    print(R)
else:
    X=L
    start=0
    end=K
    while end-start>1:
        test=(end+start)//2
        if X+test*2*D<=0:
            start=test
        else:
            end=test
    ans1=abs(X+2*D*start)
    ans2=abs(X+2*D*end)
    print(min(ans1,ans2))
X, K, D = map(int, input().split())

low = 0
high = K

while low <= high:
    mid = (low + high) //2
    i = mid
    j = K-mid
    ans_pre = (X + D*i - D*j)
    if ans_pre > 0:
        high = mid-1
    else:
        low = mid+1
        

if high < 0:
    high = 0

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

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

near0_X = X % D
after_K = K - X//D

if after_K % 2 == 0:
    print(near0_X)
else:
    print(D-near0_X)
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


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


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    x, k, d = MI()

    min_idou = x // d
    amari = x % d

    if min_idou >= k:
        print(min(abs(x - k*d), x))
        return

    k -= min_idou
    if k % 2 == 0:
        print(amari)
    else:
        print(-1*(amari - d))


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

mod1 = x % d
mod2 = mod1 - d
mod = min(mod1, abs(mod2))
modx = max(mod1, abs(mod2))
x1 = abs(x)

a = (x1-mod)/d

if mod1+k*d <= x1:
    print(x-k*d)
elif (k-a) % 2 == 0:
    print(mod)
else:
    print(modx)
X, K, D = list(map(int, input().split()))
X = abs(X)
if K * D >= X:
    cgoal = X % D
    fgoal = abs(abs(cgoal) - D)
    times2cgoal = (X - cgoal) // D
    print(cgoal, fgoal, times2cgoal)
    if times2cgoal % 2 == K % 2:
        print(min(cgoal, fgoal))
    else:
        if X >= 0:
            print(fgoal)
else:
    print(X - K * D)
X, K, D = map(int, input().split())

k1 = X // D
if k1 >= K:
    print(X - D * K)
    exit()
k = K - k1
x = X % D

while True:
    if abs(x) < D:
        if k % 2 == 0:
            print(abs(x))
        else:
            print(D-abs(x))
        exit()

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

    # print(X)

print(abs(X))
X,K,D = map(int,input().split())
X = abs(X)
 
if X <= K * D :
  if abs(X % D -D) < X % D :
    answer = abs(X % D - D)
  else :
    answer = X % D
else :
  answer = X - K * D
  
print(answer)
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(X)
else:
    print(abs(D-r))
X,K,D=map(int, input().split())

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

K2= K - (X // D)

X= X - abs(((K-K2)*D))

if K2 % 2 == 1:
    X= X -D


print(abs(X))
X,K,D = map(int,input().split()) 
if X >= K*D:
    print(X-K*D)
else:
    if (K-X//D) % 2 ==1:
        print(D-(X-X//D*D))
    else:
        print(X-X//D*D)
x,k,d=map(int, input().split())
if abs(k*d)>abs(x):
    if k%2==0:
        a=x%(2*d)
        print(min(abs(a),abs(a-2+d)))
    else:
        a=x%(2*d)
        print(min(abs(a-d),abs(a+d)))
else:
    print(abs(x)-abs(k*d))
def li():
    return [int(x) for x in input().split()]

x, k, d = li()

x = abs(x)

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

xr = x % d
xl = xr - d

r_parity = (x - xr) // d % 2
k_parity = k % 2
if r_parity == k_parity:
    print(xr)
else:
    print(xl)
t = list(map(int, input().split()))
X, K, D = t[0], t[1], t[2]
s = set([X])

if X < 0:
    X *= -1

d = X // D

if d <= K-1:
    s.add(X - D*d)
    s.add(D*(d+1) - X)
elif d == K:
    s.add(X - D*d)
else:
    s.add(X - D*K)

print(min(s))
n, k, d = input().split()

n = int(n)
k = int(k)
d = int(d)

# print(n, k, d)

x = (k*d - n)//(2*d);

# debug1(x);
x = max(0, x);
ans = abs(n+x*d - (k-x)*d);

if (x+1 <= k):
    x = x + 1
    ans = min(ans, abs(n+x*d - (k-x)*d));

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

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

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

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

for i in range(k):
    if x < 0:
        if i % 2 == 1:
            print(abs(x + d))
            exit()
        else:
            print(abs(x))
            exit()
    x -= d
print(abs(x))
import sys
sys.setrecursionlimit(10**9)
x, k, d=map(int, input().split(' '))
if x - k*d >= 0:
  print(x - k*d)
else:
  l=0
  for i in range(k):
    if i*d > x:
      l=i
      break
  if (k-l) % 2 == 0:
    x = -x + l*d
  else:
    x = -(l-1)*d + x
  if x < 0:
    x = -x
  print(x)
x,k,d = [int(x) for x in input().split()]

s = x/d
if s >= k:
    if x > 0:
        print(x-k*d)
    else:
        print(x+k*d)
else:
    circa0 = x-s*d
    if s % 2 == k % 2:
        print(abs(circa0))
    else:
        print(min(abs(circa0-d),abs(circa0+d)))
x,k,d=map(int,input().split())
a=divmod(abs(x),d)
if a[0]<=k:
  if a[0]%2!=0:
    if a[1]<=d//2:
      print(a[1])
    else:
      print(d-a[1])
  else:
    print(a[1])
else:
  print(a[1])
x, k, d = [int(i) for i in input().split()]
if x >= d:
  t = abs(x)//d
  if k >= t:
    if (k - t) % 2 ==0:
      print(abs(x) % d)
    else:
      print(d - (abs(x) % d))
  else:
    print(abs(x) - k*d)
else:
  if k % 2 == 0:
    print(abs(x))
  else:
    print(abs(abs(x) - d))
x, k, d = map(int, input().split())
if x == d:
    if k % 2 == 0:
      print(x)
    else:
      print(0)
else:
  for i in range(k):
    if x > d:
      x = x - d
    else:
      x = d - x 
  print(x)
def Qc():
    x, k, d = map(int, input().split())
    x = abs(x)
    all_minus = abs(x) - (k * d)
    if 0 <= all_minus:
        ans = all_minus
    else:
        point = abs(all_minus) // d
        k2 = k - point
        all_minus += d * point
        ans = abs(all_minus)
        if k2 % 2 != 0:
            ans = min(abs(all_minus - d), abs(all_minus + d))
    print(ans)


if __name__ == '__main__':
    Qc()
x,k,d = map(int,input().split())
if abs(x) >= k*d:
  print(abs(x)-k*d)
  exit()
x = abs(x)
r = x%d
if (x-r)%2 == k%2:
  print(r)
else:
  print(abs(r-k))
import math
X,K,D=map(int,input().split())

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

mini = math.ceil(X/D)

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

n = X // D
if K <= n: print(X - K * D)
else:
  X -= n * D
  K -= n
  if K % 2 == 0: print(X)
  else:
    if X >= 0: print(-X + D)
    else: print(X + D)
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]


def solve(x,k,d):
    di = int(x//d)
    if di >= k: 
        return abs(x - (k*d))
    x = x - (di*d)
    k -= di
    if k % 2 == 0:
        return abs(x)
    else:
        return abs(x - d)

x,k,d = ip()
print(solve(x,k,d))
def resolve():
    x,k,d = map(int, input().split())
    if abs(x)>=k*d:
        print(abs(x-k*d))
    else:
        m=x//d
        n=abs(x)%d
        if (m-k)%2==0:
            print(n)
        else:
            print(abs(n-d))
resolve()
X,K,D=map(int,input().split())
if X<K*D:
    if (K-X//D)%2==0:
        X=X%D
    else:
        X=abs(X%D-D)
else:
    X=X-K*D
print(X)
# -*- coding: utf-8 -*-

x, k, d = map(int, input().split())
x = abs(x)
for i in range(1,k+1):
    if abs(x) >= abs(x-d):
        x -= d
    else:
        if (k-i+1) % 2 != 0:
            x += d
        break
print(abs(x))
X, K, D = map(int, input().split())

k = round(X / D)

if k > K:
    if k == 1:
        print(abs(abs(X) - K * D))
    else:
        print(min(abs(abs(X) - K * D), abs(abs(X) - (K - 1) * D)))

else:
    if k % 2 == K % 2:
        print(min(abs(abs(X) - k * D), abs(abs(X) - (k + 2) * D), abs(abs(X) - (k - 2) * D)))

    else:
        print(min(abs(abs(X) - (k + 1) * D), abs(abs(X) - (k - 1) * D), abs(abs(X) - (k + 3) * D), abs(abs(X) - (k - 3) * D)))
a,b,c=map(int,input().split())

if abs(a)>=abs(b*c):
    print(abs(abs(a)-abs(b*c)))
    exit()

n=abs(a)
m=n//c
if abs(a)-abs(c*m)>abs(a)-abs(c*(m+1)):
    m=m+1
print(m)
if (b-m)%2==0:
    print(abs(a)-abs(c*m))
else:
    print(min(abs(abs(a)-abs(c*(m+1))),abs(abs(a)-abs(c*(m-1)))))
X,K,D = list(map(int,input().split()))

if X / D == K:
    print(0)
else:
    nokori = abs(X - (K * D)) #残りマス
    q = abs(X // D) #商
    p = X % D #余り
    nokorik = K-q #残り回数
    if K < q:
        print(nokori)
    else:
        if nokorik % 2 == 0:
            print(p)
        else:
            print(abs(p-D))
x,k,d = map(int,input().split())
cnt = x//d
mod = x%d
min = 0

if k < cnt:
    print(x-(d*k))
    exit()

if mod > abs(mod-d):
    min = abs(mod-d)
    cnt += 1
else:
    min = mod

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

plus=0
minus=k
ans=10**15+1
for i in range(k//2+1):
    a=x+plus*d+minus*(-d)
    a=abs(a)
    ans=min(ans,a)
    plus+=i
    minus=k-i

print(ans)
X,K,D = map(int,input().split())
A = abs(X)
ans = 0
if A >= D*K:
    ans = A - (D * K)
else :
    ans = A % D
    K = K - (A//D)
    if K%2 == 0:
        ans = A - D
print(abs(ans))
import numpy as np
[X, K, D] = list(map(int, input().split()))
X = np.abs(X)
if X != D:
  for k in range(1, K + 1):
    if X > D:
      X = X - D
    else:
      X = X + D
else:
  if K % 2 == 0:
    pass
  else:
    X = 0
print(X)
#C - Walking Takahashi
X,K,D= map(int,input().split())

a = X // D
if a > K :
    print(abs(abs(X) - abs(K*D)))
elif (K - a) % 2 == 0 :
    print(min((abs(abs(X) - abs(a*D))),(abs(abs(X) + abs(a*D)))))
else:
    print(min((abs(abs(X) - abs(a * D)-abs(D))),(abs(abs(X) - abs(a * D)+abs(D)))))
import sys
X, K, D = map(int,input().split())
cnt = 0
a = X
b = 0
tmp = 0
if abs(X) >= K*D:
  if X > 0:
    print(X - K*D)  
  else:
    print(X + K*D)
  sys.exit()
if K % 2 == 0:
  tmp = int(X/D)
  if tmp% 2 == 0:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  b = a - D*2
else:
  tmp = int(X/D)
  if tmp% 2 == 1:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  b = a - D*2
print(min(abs(a),abs(b)))
x, k, d = map(int, input().split())
if k <= x // d:
    print(abs(abs(x) - d * k))
else:
    m = x // d
    k -= m
    x -= d * m
    if k % 2 == 1:
        print(abs(abs(x) - d))
    else:
        print(x)
import math
y, k, d = map(int, input().split())
if y >= 0:
    x = y
else:
    x = -y
i = math.floor(x / d)
if i >= k:
    p = x - k * d
elif i == x / d:
    if i + k == 2 * int(i + k):
        p = 0
    else:
        p = d
else:
    if (2 * i + 1) * d == 2 * x:
        p = x - i * d
    else:
        if i + k == 2 * int((i + k) / 2):
            p = x - i * d
        else:
            p = (i + 1) * d - x
print(int(p))
x,k,d=map(int,input().split())
if abs(x)/d>=k:
  print(abs(x-k*d))
else:
  x,k=x-d*(abs(x)//d),k-abs(x)//d
  if k%2==0:
    print(x)
  else:
    print(abs(x-d))
from math import ceil, floor
X, K, D = map(int, input().split())
ans = abs(X)
fapp = (K*D - X)/(2*D)

if fapp < 0:
    list = [0]
elif fapp > K:
    list = [K]

else:
    list = [ceil(fapp), floor(fapp), int(fapp)]
for f in list:
    abso = abs(X + f*D - (K-f)*D)
    if abso < ans:
        ans = abso

print(ans)
X, K, D = list(map(int,input().rstrip().split()))
X = abs(X)
a = X//D
if D < a:
    print(X-(D*K))
elif a&1 == K&1:
    print(X-(D*a))
else:
    print(D*(a+1)-X)
X,K,D = map(int,input().split())

cand = []
if X//D<=K and (X//D-K)%2==0:
    cand.append(X%D)
if X//D+1<=K and (X//D-K)%2==1:
    cand.append(abs(X%D-D) )
    
if cand:
    print(min(cand))
else:
    print(min(X-K*D, X+K*D))
x,n,d=map(int, input().split())
opt=x//d
if (n-opt)%2==0 and opt<=n:
  print(x-(d*opt))
elif opt>n:
  print(x-(d*n))
else:
  a=x-(d*opt)
  a=abs(a-d)
  print(a)
X,K,D = map(int,input().split())

X = abs(X)
X0 = abs(X)

for i in range(K):
    X -= D
    K -= 1
    if abs(X) < abs(X0):
        X0 = X
    else:
        break

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

q = X // D
mod = X % D

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

print(ans)
l = list(map(int, input().split())) 
X =l[0]
K =l[1]
D =l[2]
abs_X=abs(X)
tmp_int = int(abs_X/D)
# if abs_X%D!=0:
#     increase_tmp_int=tmp_int+1
nearly = abs_X-tmp_int*D

flag =0
if nearly >= abs(abs_X-(tmp_int+1)*D):
    nearly = abs_X-(tmp_int+1)*D
    flag=1
if flag==0 and tmp_int%2==1:
    nearly=0+D
if tmp_int > K:
    nearly = abs_X-(K)*D

print(str(abs(nearly)))
# coding: utf-8
# Your code here!

line = input().split(' ')
X = int(line[0])
D = int(line[1])
K = int(line[2])
x = X
odd_X = 0
eve_X = 0
count = 0
for i in range(D):
    if abs(x - K) < abs(x + K):
        x -= K
    else:
        x += K
    if count > 2:
        if eve_X == X:
            break
        elif odd_X == X:
            break
    if count % 2 == 0:
        eve_X = x
    else:
        odd_X = x
   
    count += 1
print(abs(x))
x,k,d=[int(x) for x in input().split()]


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

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

		k=k-num

		if k%2==0:
			print(abs(x))
		else:
			print(min(abs(x-d),abs(x+d)))