peterverebics/CodeNet_Python_118 huggingface dataset:
x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) > abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d
    k_2 = k - kaisuu
    if k_2/2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = (abs(x) - d*kaisuu) - d
print(ans)
input_line = input()
data = input_line.split(" ")
x =abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
num = k - res
if num % 2 == 1 :
  ans = abs(b - d)
else :
  ans = res
print(ans)
x,k,d = map(int,input().split())

if x > k*d:
    print(x - k*d)
elif x < -k*d:
    print(x + k*d)
elif x == k*d:
    print(0)
elif x == -k*d:
    print(0)
else:
    s = 0
    y = abs(x)
    while y > 0:
        y -= d
        s += 1
    if (k - s) % 2 == 1:
        print((y + d))
    else:
        print(abs(y))
x, k, d = map(int, input().split())
if k%2 == 0 and abs(x)==abs(d):
  print(abs(x))
  exit()
res = []
i = 0
t = abs(x+d*k)
while i != k:
  res.append(t)
  i+=1
  t = t-k
print(min(res))
X,K,D = map(int,input().split())
result = 0
if X < 0:
  X = X * -1
  
if X >= K * D:
  print(X - K * D)
  exit(0)
else:
  if (K - (X // D)) % 2 == 0:
    result = X % D
  elif (X % D - D) == ((X % D) * -1):
    result = X % D
  else:
    result = X % D + D
if result < 0:
  print(result * -1)
else:
  print(result)
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!

X,K,D = map(int, input().split())
#Xが場所、Kが回数、Dが移動距離

A=X//D#0に近いやつ
B=K*D#動ける最大
#print(A,B)

if A>K:
    ANS=X-B
    #print("A")
elif A%2==0:
    #print("B")
    ANS=X-(min(abs(A*D),abs(B)))
else:
    #print("C")
    ANS=(min(abs(A*D),abs(X-B)))

print(ANS)
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-K*D))
    else:
        print(X-X//D*D)
import sys
X,K,D=map(int,input().split())
if abs(X) >= K*D:
    print(abs(X)-K*D)
else:
    y = X//D
    z = K-y
    X = abs(X) - (y*D)
    if z%2 == 0:
        print(abs(X))
    else:
        print(abs(X-D))
xkd = list(map(int,input().split()))
xkd[0] = abs(xkd[0])
x = xkd[0] // xkd[2]
x = abs(x)
xkd[0] -= xkd[2] * x
xkd[1] -= x
if xkd[1] < 1:
  xkd[0] += abs(xkd[1]) * xkd[2]
ans = xkd[0]
if xkd[1] % 2 != 0:
    ans -= xkd[2]
    if ans > xkd[0] + xkd[2]:
        ans += xkd[2] * 2
print(abs(ans))
lst = input().split()

X = int(lst[0])
K = int(lst[1])
D = int(lst[2])

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

if a < 0:
   a = 0

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

lst2 = [abs(f(a))]

if a + 1 <= K:
   lst2.append(abs(f(a+1)))

if 0 < a:
   lst2.append(abs(f(a-1)))

result = min(lst2)

print(result)
#移動の最小値(高速化問題)
x,k,d = map(int,input().split())
x = abs(x)
if (x//d) > k:
    ans = x - d*k
elif k- (x//d)%2 != 0:
    y = x-(x//d)*d
    ans = y
else:
    y = x-(x//d)*d
    ans = y-d
print(abs(ans))
x,k,d= map(int,input().split())
import sys
z = abs(x) // d
if z <= k:
    y = abs(x) - d * z
    if y > abs(y - d):
        y = abs(y-d)
else:
    y = abs(x) - d * k
if x == d:
    if k % 2 == 0:
        y = x
    else:
        y = 0
print(abs(y))
X, K, D = map(int, input().split())
ans = 0

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

print(ans)
import sys
X, K, D = map(int,input().split())
cnt = 0
a = X
b = 0
tmp = 0
if X >= K*D:
  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())
x0 = x
if k%2 == 0 and abs(x)==abs(d):
  print(abs(x))
  exit()

for i in range(k):
  """if abs(x - d) <= abs(x + d):
      x = x - d
  else:
      x = x + d"""
  if abs(x) > abs(x - (d*i) + d*(k-i)):
    x = x - (d*i) + d*(k-i)
    #print(x)
if abs(x) > abs(x0 - d*k):
    x = x0 - (d*k)
print(abs(x))
X,K,D = map(int,input().split()) 
mlist = []
for i in range(K+1):
    t = X + i*D - (K-i)*D
    if t < 0 :
        t = -t
    mlist.append(t)
print(mlist)
print(min(mlist))
X,K,D = map(int,input().split())

m = X//D
if K >= m:
  if m%2 == K%2:
    print(abs(X%D))
  else:
    print(min(abs(X%D+D), abs(X%D-D)))
else:
  print( min( abs(X-D*K) , abs(X+D*K) ) )
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    x,k,d = map(int, input().split())
    n = x//d
    ans = x
    for i in range(n):
        ans -= d
        k -= 1
        if k == 0:
            break
    ans_2 = abs(ans - d)
    if k%2 ==0:
        print(ans)
    else:
        print(ans_2)

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

Xa = abs(X)
Xs = X // D
Xm = X % 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())

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

k = K - k1
x = X % D

while k > 0:
    x = abs(x - D)
    k -= 1
    if k == 0:
        print(x)
        exit()
    if abs(x) < D:
        if k % 2 == 0:
            print(abs(x))
        else:
            print(D-abs(x))
        exit()
x,k,d=map(int, input().split())
x=abs(x)
n=x//d
m=x%d

if m>d-m:
  n+=1
  m=m-d
if k<=n:
  print(x-k*d)
elif m==d-m:
  print(abs(m))
else:
	if k%2==n%2:
  		print(abs(m))
	else:
  		print(abs(m+d))
x,k,d=map(int,input().strip().split())
p=x
hold=x
for i in range(k):
	if p<=0 and x<=0:
		x+=d

	elif p<=0 and x>=0:
		break

	if p>=0 and x>=0:
		x-=d

	elif p>=0 and x<=0:
		break

	if hold>=0:
		hold=hold-d

	if hold<0:
		hold=hold+d



if i+1!=k:
	k=k-(i)

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

	else:
		print(min(abs(x-d),abs(x+d)))
else:
	print(hold)
X, K, D = map(int, input().split())

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

if(X/D >= K):
  print(X-D*K)
else:
  if(((X-min_pos)/D)%2 == 0):
    print("A", min_pos)
  else:
    print(abs(min_neg))
x, k, d = map(int, input().split())
if x / d >= k and x > d:
    print(abs(x - d * k))
elif x <= d:
    print(abs(x - d) if k % 2 == 1 else x)
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())

moves = abs(x//d)

if moves >= k:
	if x <= 0:
		print(abs(x+k*d))
	else:
		print(abs(x-k*d))
else:
	k -= moves
	if x <= 0:
		if k%2 == 0:
			print(abs(x+moves*d))
		else:
			print(abs(x+(moves+1)*d))
	else:
		if k%2 == 0:
			print(abs(x-moves*d))
		else:
			print(abs(x-(moves+1)*d))
# AtCoder Beginner Contest 175
# C - Walking Takahashi

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

KOE=K%2

A=abs(X)//D
M=abs(X)%D

# print(A)

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

else :
    if A%2==0:
        print(min(M,abs(M-D),abs(M+D)))
    else :

        print(min(abs(M+D),abs(M-D)))
X, K, D = map(int,input().split())

i = 0

if(X <= D):
    if(K % 2 == 0):
        X = D
    else:
        X = abs(X - D)
else:
    while(i < K):
        if(abs(X + D) < abs(X - D)):
            X = abs(X + D)
        else:
            X = abs(X - D)
    
        i += 1

print(X)
a,b,c = list(map(int, input().split()))

a = abs(a)
c = abs(c)

if b*c <= a:
  print(a - (b*c))
else:
  c -= a//b
  a = a%b
  #print(a,b,c)
  if c%2==0:
    print(a)
  else:
    print(abs(a-b))
x,k,d = map(int,input().split())
x2 = x

if x2 - k * d > 0:
    print(x2 - k * d)
    exit()

for i in range(k + 1):
    if x < 0:
        ans = min(abs(x),abs(x + d))
        i2 = i
        if i2 % 2 == k % 2:
            #print("a")
            print(abs(x))
            exit()
        else:
            #print("b")
            print(x + d)
            exit()
    x = x - d
x,k,d = map(int,input().split())

n = abs(x)//d
if n <= k :
    x -= d*n
    count = k-n+2
    if count % 2 == 0 :
        now = abs(x)
    else :
        now = d-abs(x)
else :
    now = abs(x) - k*d

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


if k >= x//d:
    k -= x//d
    diff = abs(x-d*(x//d))
    if k % 2 == 0:
        print(diff)
    else:
        print(abs(diff-d))
else:
    if x >= 0:
        print(abs(x-k*d))
    else:
        print(abs(x+k*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!=0:
  ans=abs(x-d)
elif k*d>x:
  ans=x%d
else:
  ans=abs(x)-k*d
print(ans)
x,k,d = map(int,input().split())

n = x//d
#print(k-n,(abs(x-d*k)),(abs(x-(x//d)*d-d)),abs(x-(x//d)*d))
if n >= k:
    print(abs(x-d*k))
elif n < k:
    if (k-n)%2 == 1:
        print((abs(x-(x//d)*d-d)))#,abs(x-(x//d)*d)))
    else:
        print(abs(x-(x//d)*d))
        #print(min(abs(x%d),abs(x%d-d)))
x, k, d = map(int, input().split())
t = abs(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)
b = []

for i in a:
    b.append(-i)
for i in b:
    a.append(i)

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

if(x>0):
	i=-1
else:
	i=1


div = x/d
div = int(div)
if(div < k):
	x=x+(i)*div*d
	k-=div
else:
	x=x+(i)*k*d
	k-=k
ans = abs(x)
if (k>0):
	if(ans==0):
		ans = abs(d)
	else:
		ans = min(abs(x), abs(x+(i)*d))

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

Y = X

if X < 0:
    X = -X

i = 0
posA = X % D
posB = posA - D
i = X // D + 1

if K >= i:
    if K % 2 == i % 2:
        print(abs(posB))
    else:
        print(abs(posA))
else:
    print(abs(Y-D*K))
X,K,D=map(int,input().split(' '))
time=0
while X>0:
    X-=D
    time+=1
    if time==K:
        break
if (K-time)%2==0:
    print(abs(X))
else:
    print(X+D)
X, K, D = map(int, input().split())
flag = True
if abs(X)-K*D>=D:
  ans = abs(abs(X)-K*D)
  flag = False
else:
  ans = X

res = abs(X)%D
r = X//D
if flag:
  if r%2 == K%2:
    ans = min(ans, res)
  else:
    ans = min(ans, abs(res-D))
  
print(ans)
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 = map(int, input().split())
X = abs(X) % D
K -= X // D
if K % 2 == 0:
  print(X)
else:
  print(abs(X - D))
x,k,d=list(map(int,input().split()))

if x==0:
	if k%2==1:
		print(d)
		exit()
	if k%2==0:
		print(0)
		exit()
if x==d:
	if k%2==1:
		print(0)
		exit()
	if k%2==0:
		print(x)
		exit()
if x-(k*d)>0:
	print(x-(k*d))
	exit()
if x-(k*d)<0:
	print(min(x%d,abs((x%d)-d)))
	exit()
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
str= str(input())
if len(str.split())==3:
    s=[int(x)  for x in str.split()]
x=s[0]
k=s[1]
d=s[2]
cnt=int(x/d)
if cnt>=k:
    print(int(abs(x)-k*d))
else:
    num=int(k-cnt)
    num=int(num%2)
    if num>0 :
        ans1=abs(x)-cnt*d-d
        ans2=abs(x)-cnt*d+d;
        print(int(min(abs(ans1),abs(ans2))));
    else:
        print(int(abs(x)-cnt*d));
x, k, d = map(int, input().split())

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

else:
    cent = x % d
    num = x // d

if d / 2 > cent and cent != 0:
    cent = d - cent
    num += 1

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

rem = k - num

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

    if K > 0:
        if K%2 == 1:
            A = A - D

print(abs(A))
X,K,D=map(int, input().split())
min=X+K*D
for k in range(K):
  current=X-k*D+(K-k)*D
  if min>abs(current):
    min=abs(current)
print(min)
x, k, d= map(int, input().split())
x = abs(x)
if x - k * d >= 0:
    print(x - k * d)
else:
    ans1 = x % d
    check = x // d
    ans2 = ans1 - d
    if(ans1 + ans2 > 0 and(k - (check + 1))%2==0):
        print(abs(ans2))
    elif(ans1 + ans2 > 0 and (k - (check + 1))%2==0==1):
        print(ans1)
    elif(ans1 + ans2 < 0 and (k - check)%2==0):
        print(ans1)
    else:
        print(abs(ans2))
x,k,d=list(map(int, input("").split()))
c=x//d
m=x%d
if c<k:
    m=abs(m)
    if (k-c)%2==0:
        x=m
    else:
        if abs(m+d) <= abs(m-d):
            x=m+d
        else:
            x=m-d
else:
    x=m

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

# print((abs(abs(X)-K*D)/D)%2)
if abs(X) >= K*D:
    print(abs(abs(X)-K*D))
elif (abs((abs(X)-K*D)/D))%2 == 0:
    print(0)
elif (abs((abs(X)-K*D)/D))%2 <= 0.5:
    print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D-1))))
elif (abs((abs(X)-K*D)/D))%2 <= 1.5:
    print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D+1))))
start, move, distance = list(map(int, input().split()))
if abs(start) > abs(distance) and abs(start) // abs(distance) <= abs(move):
    n = abs(start) // abs(distance)
    print(abs(start) - (abs(distance) * n))
elif abs(start) > abs(distance) and abs(start) // abs(distance) > abs(move):
    n = abs(start) // abs(distance)
    print(abs(start) - (abs(distance) * abs(move)))
else:
    print(abs(start))
x, k, d = list(map(int, input().split()))

a = True

for i in range(k):
  nx = min(abs(x+d), abs(x-d))
  if x <= nx:
    if (k-i-1)%2 == 0:
      print(nx)
      a = False
      break
    else:
      print(x)
      a = False
      break
  else:
    x = nx

if a == True:
  print(x)
X, K, D = map(int, input().split())

X = abs(X)
a = X/D
ans = 0

if a>=K:
    ans = X-(D*K)
else:
    if K%2==0:
        if a%2==0: ans = X-(D*a)
        else: ans = X-(D*a)-D
    else:
        if a%2==0: ans = X-(D*a)-D
        else: ans = X-(D*a)

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

if abs(x) > k * d:
    if x < 0:
        print(x + k * d)
        exit()
    else:
        print(x - k * d)
        exit()

a = abs(x) % d
s = 1
if x < 0:
    s = -1

nokori = k - abs(x) // d
if nokori % 2 == 0:
    print(abs(a * s))
else:
    print(abs(a + s * -1 * d))
a, b, c = map(int, input().split())

if a - ( b * c ) >= 0:
    print(a - ( b * c ))
else:
    l = 0
    r = b

    while r - l > 1:
        mid = (r + l) // 2

        if a - ( mid * c ) >= 0:
            l = mid
        else:
            r = mid

    A = a - ( l * c )
    B = abs( a - ( ( l + 1 ) * c ) )

    k = b - l

    if k % 2 == 0:
        print(A)
    else:
        print(B)
X,K,D=map(int,input().split())
if X>=0:
    if X-K*D>X%D:
        print(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(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())

if X - K*D >= 0:
    ans = X - K*D
else:
    plus = X % D
    minus = plus - D
    rem = K - X//D
    if rem%2 == 0:
        ans = plus
    else:
        ans = abs(minus)
print(ans)
x,k,d=map(int,input().split())
a=divmod(abs(x),d)  
if a[0]<k:
  if a[1]==0 and a[0]%2==1:
    print(d)
  elif a[1]==0 and a[0]%2==0:
    print(0)
  elif a[1]!=0 and a[0]%2!=0:
    print(abs(d-a[1]))
  else:
    print(a[1])
else:
  print(abs(x)-d*k)
#!/usr/bin/env python3

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

    cnt = X // D
    X -= min(K, cnt) * D
    K -= min(K, cnt)
    if K % 2 == 0:
        ans = X
    else:
        ans = abs(X - D)
    print(ans)


if __name__ == "__main__":
    main()
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(x + k * d)
elif k % 2 == 0:
    a = x % (2 * d)
    print(min(a, abs(a - 2 * d)))
else:
    a = (x - d) % (2 * d)
    print(min(a, abs(a - 2 * d)))
x, k, d = map(int, input().split())
if k%2 == 0 and abs(x)==abs(d):
  print(abs(x))
  exit()

for i in range(k):
  if abs(x - d) <= abs(x + d):
      x = x - d
  else:
      x = x + d
  print(x)
print(abs(x))
x, k, d = input().strip().split()
x = int(x)
k = int(k)
d = int(d)
temp = int(x / d)
temp = min(temp, k)
x -= temp * d
k -= temp
if k % 2 == 1:
	print(abs(x - d))
else:
	print(abs(x))
X,K,D=map(int,input().split())

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

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


if X>0:
    S = int(abs(X) / D)
    aX = X -D * S
    if S>=K:
        print(X-D*K)
    elif (K-S)%2==0:
        print(abs(aX))
    else:
        print(abs(aX-D))
else:
    S = int(abs(X) / D)
    aX = X + D * S
    if S>=K:
        print(abs(X+D*K))
    elif (K-S)%2==0:
        print(abs(aX))
    else:
        print(abs(aX-D))
import math

start, kai, step = map(int, input().split(" "))

if step < start - (kai * step):
    print(abs(start - (kai * step)))
    exit()

ans1 = start % step
ans2 = abs(ans1 - step)
if (kai - abs(start // step)) % 2 == 0:
    print(abs(ans1))
else:
    print(abs(ans2))
x,k,d=map(int,input().split())

a=x//d

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

q = X // D
mod = X % D

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

print(ans)
x,k,d = map(int, input().split())
x,m = abs(x), min(k,x//d)
x -= m*d
k -= m
if k%2:
  x = abs(x-d)
print(x)
a, b, c = map(int, input().split())
result = a
for i in range(b):
    if abs(a + c) < abs(a - c):
        a += c
        if abs(result) < abs(a):
            break
        result = a
    else:
        a -= c
        if abs(result) < abs(a):
            break
        result = a
print(abs(a))
a, b, c = map(int, input().split())
for i in range(b):
  if abs(a-c) < abs(a+c):
    a = a - c
  else:
    a = a + c
print(a)
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(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 = map(int, input().split())
x = abs(x)
# x > 0のとき
left = abs(x - d * (x // d + 1))
right = abs(x - d * (x // d))

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

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

if x == 0:
    print(0 if k % 2 == 0 else d)
elif x > 0:
    p = x // d
    if p >= k:
        print(x - k * d)
    else:
        q = 0 if (k-p)%2 == 0 else 1
        print(abs(x - ((p+q) * d)))
else:
    p = abs(x) // d
    if p >= k:
        print(x + k * d)
    else:
        q = 0 if (k-p) % 2 == 0 else 1
        print(abs(x + ((p+q) * d)))
var = input()
x = int(var.split()[0])
k = int(var.split()[1])
d = int(var.split()[2])
cnt = x // d
if (k <= cnt) :
  print(x - d * k)
else :
  kk = k - cnt
  if (kk % 2 == 0) :
    print(x - d * cnt)
  else :
    print(d - (x - d * cnt))
x,k,d=map(int, input().split())
if x>d*k:
	ans=x-k*d
else:
	k=k-x//d
	x=x%d
	if k%2==0:
		ans=x%d
	else:
		ans=abs(x%d-d)
print(ans)
x,k,d=list(map(int,input().split()))
t=abs(x)//d
if k<=t:
  if x<0:
    print(-(x+d*k))
  else:
    print(x-k*d)
else:
  if x<0:
    print(x%d if (t-k)%2 else d-(x%d))
  else:
    print(x%d if (t-k+1)%2 else d-(x%d))
x,k,d = map(int,input().split())
ans_1 = x%d #プラスの最小
ans_2 = abs(ans_1-d) #マイナスの最小

if x//d > k:
    print(x-(d*k))
    exit()
    
if ans_1 > ans_2:
    if (k-(x//d)-1)%2 == 0:
        print(ans_2)
    else:
        print(ans_1)

elif ans_1 < ans_2:
    if (k-(x//d))%2 == 0:
        print(int(ans_1))
    else:
        print(int(ans_2))

elif ans_1 == ans_2:
    print(ans_1)
import math

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


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

if K > 10000000 and K % 2 == 0:
    K = 10000
if K > 10000000 and K % 2 == 1:
    K = 10001

for i in range(K):
    if place == 0 and (K-i)%2==0:
        break

    if place >= 0 and (place - D) >= 0:
        place -= D

    elif place >= 0 and (place - D) <= 0:
        place -= D
  
    else: 
        place += D 
      
if place < 0:
    place = abs(place)
print(place)
x, k, d = map(int, input().split())

isReturn = False
i = 0
while i < k:
    if(x >= 0):
        x -= d
    else:
        x += d
        isReturn = True

    if i+1 < k:
        if isReturn:
            if((k-i) % 2 == 0):
                i = k-2
            else:
                i = k-1

    i += 1

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

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

k -= abs(x) // d
a = x % d
b = min(abs(a + d), abs(a - d))

if k % 2 == 0:
    print(a)
else:
    print(b)
X, K, D = map(int, input().split())
s = 0
g = K

def d(h):
    return X + (h - (K-h))*D

if d(s) >= 0:
    ans = d(s)
elif d(g) <= 0:
    ans = d(g)
else:
    half = (s + g)//2
    while s < half:
        if d(half) < 0:
            s = half
        else:
            g = half
        half = (s + g)//2

    ans = min(abs(d(s)) , abs(d(g)) )
print(ans)
x,k,d=map(int,input().split())
if abs(x)>=k*d:
  ans=min(x-k*d,x+k*d)
  print(ans)
else:
  s=1
  while True:
    if abs(x)>=s*d:
      s+=1
    else:
      break
  if (k-s)%2==0:
    print(abs(abs(x)-s*d))
  else:
    print(abs(abs(x)-(s-1)*d))
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:
    print(abs(X-D*(tm+1)))
  else:
    print(abs(X-D*tm))
x,k,d=input().split()
x=int(x)
k=int(k)
d=int(d)
a=x//d
b=x-a*d
c=(x-b)/d
print(int(c))
i=int(c)
if k<=i:
  print(abs(x)-d*k)
else:
  if (k-(i))%2==0:
    print(abs(x)-d*(i))
  else:
    print(abs(abs(x)-d*(i+1)))
x , k , d = list( map( int , input().split() ))


if x // d <= k:
  k -= x // d
  x -= (x // d) * d 
  if k & 1: 
  	print( d - x %d )
  else:
  	print( x %d)
else:
  print( x - k *d )
x,k,d=map(int,input().split())
s=[x]
if x>k*d:
    ans=x-k*d
else:  
    for i in range(k):
        if x>0:
            x=x-d
            ans=x
        else:
            x=x+d
            ans=x
        s.append(x)
        if abs(s[i-2])==abs(s[i]) and i>=2:
            ans=s[i]
            break
        
print(abs(ans))
x, k, d = map(int,input().split(' '))
flg = True
hituyou_kaisuu = x//d
saisyou = x%d


if saisyou > d // 2:
    saisyou -= d
    hituyou_kaisuu += 1
    flg = False

amari = k - hituyou_kaisuu

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

ans = X
for i in range(K):
    if ans >= 0:
        ans -= D
    else:
        ans += D
print(ans)
X, K, D = map(int, input().split())

minimum_try = min(abs(X) // D, K)
tmp_goal = abs(X - minimum_try*D)

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

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

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