peterverebics/CodeNet_Python_118 huggingface dataset:
X,K,D = map(int,input().split())
if X < 0:
  X = -X
A = X // D
if A > K:
  print(X - (K*D))
else:
  B = X % D
  KK = K - A
  if KK % 2 == 1:
    print(abs(B-D))
  elif KK % 2 == 0:
    print(abs(B))
X, K, D = map(int, input().split())
X = abs(X)
n = X//D
if K < n:
    print(X-K*D)
else:
    if (n-K) % 2 == 0:
        print(X-n*D)
    else:
        print(abs(X-(n+1)*D))
X, K, D = map(int, input().split())
a, b = abs(X)//D, abs(X)%D
if K <= a:
  if X >= 0:
    ans = X - K*D
  else:
    ans = X + K*D
else:
  K = (K - a) % 2
  if X >= 0:
    ans = X - a*D
  else:
    ans = X + a*D
  if K == 1:
    if abs(X+D) < abs(X-D):
      ans += D
    else:
      ans -= D
print(abs(ans))
x, k, d = map(int,input().split())
x = abs(x)
if (x >= k*d):
  print(x - k*d)
else:
  nokori = k - x//d
  if (nokori%2 == 0):
    print(abs(x%d))
  else:
    print(abs(x%d - d))
def solve():
    x, k, d = map(int, input().split())
    l = x - k * d
    r = x + k * d
    if l > 0:
        print(l)
        return
    elif r < 0:
        print(-r)
        return
    a1 = r - r // (2 * d) * (2 * d)
    a2 = a1 - (2 * d)
    ans = min(abs(a1), abs(a2))
    print(ans)


if __name__ == "__main__":
    solve()
X,K,D=map(int,input().split())
if X<0:
  X*=-1
if X-K*D>0:
  print(X-K*D)
else:
  p=X-(X//D)*D
  K-=X//D
  q=abs(p-D)
  if K%2==0:
    print(p)
  else:
    print(q)
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()



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

if X<0:
    X*=-1


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

MIN = x-k*d


if 0 <= MIN:
    print(MIN)
else:
    a, R = divmod(x, d)
    L = d-R
    cnt = k-a
    if cnt % 2 == 0:
        print(R)
    else:
        print(L)
a = list(map(int, input().split()))
x = a[0]
k = a[1]
d = a[2]
x = abs(x)

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

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

t = abs(x)/d
t2 = abs(x)//d
if t>=k:
    print(abs(x)-k*d)
else:
    x = abs(x)-t2*d
    if (k-t2)%2==0:
        print(x)
    else:
        print(d-x)
x, k, d = map(int, input().split())
x = abs(x)
if (x - k*d) >= 0:
    x -= k*d
else:
    k -= int(x/d)
    x -= int(x/d) * d
    if (k%2) != 0:
        x -= d 
print(abs(x))
x, k, d = map(int, input().split())
x = abs(x)
n = x // d
if k <= n:
    print(x - k * d)
    quit()
k -= n
x %= d
print(x if k % 2 == 0 else d - x)
def main():
  x, k, d = map(int, input().split())
  if x < 0:
    x *= -1
  if x - d < 0:
    if k%2==0:
      print(x)
    else:
      print(d - x)
  elif x - k*d > 0:
    print(x - k*d)
  else:
    k -= x//d
    if k%2==0:
      print(x%d)
    else:
      print(-(x%d-d))

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 % 2 == 1:
    X -= D
  print(min(X % (2 * D) , (D * 2) - X % (D * 2)))
x,k,d=map(int,input().split())
X=abs(x)
print(X-k*d if X>k*d else abs(X%d-(k-X//d)%2*d))
def resolve():
    x, k, d = map(int, input().split())
    x = abs(x)
    if x // d > k:  # 最大長が0まで届くか
        print(x - k * d)
    elif (k - x // d) % 2 == 0:  # 0を反復横跳びする     偶数->X側、奇数->-X側
        print(x % d)
    else:
        print(d - x % d)
        
resolve()
X, K, D = map(int, input().split())
if X < 0:
    X = -X

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

zan = X%D


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

def sol(x, k, d):

    x = abs(x)

    temp = x // d

    if temp >= k:
        return x - d * k

    x -= temp * d
    k -= temp

    if k % 2 == 0:
        return x
    
    return abs(x - d)

print (sol(x, k, d))
import math
x, k, d = map(int, input().split())
if k * d <= abs(x):
    print(abs(x) - k * d)
    exit()
if x < 0:
    x = abs(x)
move = math.ceil(x/d)
x = x - d * move
k -= move
if k % 2 == 0:
    print(abs(x))
else:
    x = x + d
    print(abs(x))
from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    # n=int(stdin.readline())
    x,k,d=list(map(int,stdin.readline().split()))
    '''if x==k==d:
        print(0 if k&1 else x)
        continue'''
    x=abs(x)
    des=x%d
    op=x//d
    # print(des,op)
    a=[des,des-d]
    if k<op:#check for eq
        print(x-k*d)
    else:
        print(abs(a[(k-op)%2]))
X,K,D=(int(x) for x in input().split())
x=abs(X)
a=x//D

b=x-a*D
B=abs(x-(a+1)*D)

if b>B:
  a=a+1

if a>=K:
  print(abs(x-K*D))

else:
  c=K-a
  if c%2 == 0:
    print(abs(x-a*D))
  else:
    d=abs(x-(a-1)*D)
    e=abs(x-(a+1)*D)
    print(min(d,e))
X, K, D = map(int, input().split())
X = abs(X)
a = X // D
if K <= a:
    print(X - D * K)
    exit()
X -= D * a
K -= a
if K % 2 == 1:
    print(abs(X - D))
else:
    print(X)
# cook your dish here

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

ans = 0

if(k<=f):
    ans = abs(x) - abs(k*d)
    
else:
    e =  (k - f)%2
    if(e==0):
        ans = x - f*d;
    else:
        ans = x - (f+1)*d;
            
    
print(abs(ans))
X, K, D = map(int, input().split())
X = abs(X)
q, m = divmod(X, D)
if q >= K:
    print(X-K*D)
elif (q+K)%2==0:
    print(m)
else:
    print(-(m-D))
v = input().split(" ")
x = int(v[0])
k = int(v[1])
d = int(v[2])

if (x == 0):
    if (k % 2 == 0):
        ans = 0
    else:
        ans = d
else:
    if ((k * d) > abs(x)):
        y = abs(x) // d
        ans = abs(abs(x) - y * d)
        if ((k - y) % 2 == 1):
            ans = abs(d - ans)
    else:
        ans = abs(x) - k * d


print(ans)
from sys import stdin
input = stdin.readline

def main():
    X, K, D = map(int, input().rstrip().split())
    X = abs(X)
    c = X // D
    if c < K:   
        X = X % D
        K = K - c
        K = K % 2
    ans = X - (D * K)
    print(abs(ans))
if __name__ == "__main__":
    main()
x, k, d = map(int, input().split())
x = abs(x)
straight = min(k, x // d)
k -= straight
x -= straight * d
if k % 2 == 0:
  print(x)
else:
  print(d - x)
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))
x,k,d = mp()
x = abs(x)
if x - k*d >= 0:
    print(x-k*d)
else:
    u = x % d
    l = abs(u - d)
    if (k - x//d) % 2 == 0:
        print(u)
    else:
        print(l)
def main():
    x, k, d = map(int, input().split())

    if k >= abs(x) // d:
        a = abs(x) - d * (abs(x) // d)
        b = abs(a - d)
        left_number = k - (abs(x) // d)
        if left_number % 2 == 0:
            minimum = a
        else:
            minimum = b

    else:
        minimum = abs(x) - k * d

    print(minimum)


if __name__ == '__main__':
    main()
X, K, D = [int(x) for x in input().split()]

X = abs(X)
fl = X // D
cl = fl + 1

if fl > K:
    ans = X - K * D
elif K % 2 == fl % 2:
    ans = X - fl * D
else:
    ans = cl * D - X

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


def input():
    return sys.stdin.readline().rstrip()


def main():
    X,K,D =map(int,input().split())
    ans =10**19
    if X >= K*D:
        print(X-K*D)
    elif -X>= K*D:
        print(-X - K*D)

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








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

passSinaiCount = abs(x)//d

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

passSinaiDistance = abs(x) - passSinaiCount * d
passSuruDistance = d - passSinaiDistance

nokoriCount = k - passSinaiCount
if nokoriCount % 2 == 0:
    print(passSinaiDistance)
else:
    print(passSuruDistance)
def main():
    X, K, D = map(int, input().split())
    if X < 0:
        X *= (-1)
    i = min(X // D, K)
    out = X - i * D
    if (K - i) % 2 == 0 or K < X//D:
        print(out)
    else:
        print(min(abs(out - D), abs(out + D)))


if __name__ == '__main__':
    main()
x,k,d=map(int,raw_input().split())

def solve(x,k,d):
    x=abs(x)
    if (x>0 and x/d>=k):
        x=x-k*d
        return x
    y=x//d
    x-=y*d
    k-=y
    if k%2==0:
        return abs(x)
    return min(abs(x+d),abs(x-d))
print(solve(x,k,d))
import math
x, k, d = map(int,input().split())
x = abs(x)
if x > k * d:
    print(x - k * d)
else:
    time = math.floor(x/d)
    x -= time * d
    k -= time
    if k % 2 == 0:
        print(x)
    else:
        print(d - x)
x,k,d = map(int,input().split())

x = abs(x)
a = x // d
b = k - a

if b < 0:
    s = abs(x - k * d)
else:
    if b % 2 == 0:
        s = abs(x - a * d)
    else:
        s = abs(x - (a+1) * d)

print(s)
x, m, d = map(int, input().split())
x = abs(x)
mn = float('inf')
if x // d > m:
    mn = x-m*d
else:
    m -= x//d
    if m % 2 == 0:
        mn = x %d
    else:
        mn = abs(x%d -d)
print(mn)
#n = int(input())
#L = list(map(int, input().split()))
x, k, d = map(int, input().split())
#p = list(set(L))
a = abs(x)//d
b = abs(x)%d
if k < a:
  print(abs(x) - d*k)
else:
  if (k-a)%2 == 0:
    print(b)
  else:
    print(d-b)
from sys import stdin,stdout
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
X, K, D = map(int, input().split())
X = abs(X)
if X >= K * D:
    print(abs(X - K * D))
    exit()
mov = X // D    
if abs(X-mov*D) > abs(X-(mov+1)*D):
    mov += 1
rem = abs(X-mov*D)
mov = K - mov   
mov = mov % 2
print(abs(rem-mov*D))
import math
x,k,d=map(int,input().split(" "))


if x<0:
  x=(-1)*x
if d<0:
  d=(-1)*d
  
s=math.floor(x/d)

if k<s:
  print(x-d*k)
else:
  w=k-s
  v=x-d*s
  if w%2==0:
    print(v)
  else:
    print(abs(v-d))
import math
x,k,d=map(int,input().split())
count=int(math.sqrt(x*x)/d)
if k<=count:
    count=k
    k=2
else:
    k=k-count
ans=int(math.sqrt(x*x)-d*count)
if k%2==1:
    ans=math.sqrt((d-ans)**2)
print(int(ans))
x, k , d = map(int , input().split())
r = abs(x)//d

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

X = abs(X)

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

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

x = abs(x)

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

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

x_ = abs(x)

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

a = x_ % d
b = - (a - d)
k_ = x_ // d
l = k - k_

if l % 2 == 0:
    print(a)
else:
    print(b)
import sys

X, K, D = [int(x) for x in input().strip().split(" ")]

X = abs(X)
k, x = divmod(X, D)

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

X = x
K -= k

if K % 2 == 0:
    print(abs(X))
    sys.exit(0)

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

if abs(X) > K*D:
    print(abs(X) - K*D)
else:
    X = abs(X)
    K -= X//D
    X = X%D
    if K%2 == 0:
        print(X)
    else:
        print(abs(X-D))
# -*- 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())

dx = abs(x)
y = dx // d

if k >= y:
    dx = dx - y * d
    if (k-y) % 2 == 0:
        print(dx)
    else:
        dx = abs(dx - d)
        print(dx)
elif k < y:
    dx = dx - k * d
    print(dx)
x,k,d = map(int, input().split())
x = abs(x)
a= x//d
b = x%d
if a>=k:
  print(x-k*d)
  exit(0)
c = abs(b-d)
if (k-a)%2==0:
  print(b)
else:
  print(c)
x, k, d = map(int, input().split())

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

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

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

X=abs(X)

q=X//D
r=X%D

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

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

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

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

ans = 9999999
if abs(X) >= K * D:
    ans = abs(X) - K*D
else:
    A = abs(X) % D
    B = K - (abs(X) // D)

    if B % 2 == 0:
        ans = A
    else:
        ans = abs(A - D)

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

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

X=abs(X)

q=X//D
r=X%D

if r < D-r:
    n=q
    ans1=r
    ans2=D-r
else:
    n=q+1
    ans1=D-r
    ans2=r

if K <= n:
    ans=X-K*D
    ans=abs(ans)
else:
    d=K-n
    if d%2==0:
        ans = ans1
    else:
        ans = ans2
print(ans)
X, K, D = map(int, input().split())

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

if x < 0:
    x = -x

if x >= k * d:
    print(x - k * d)
else:
    if (x // d) % 2 == 1:
        if k % 2 == 1:
            print(x % d)
        else:
            print(d - x % d)
    else:
        if k % 2 == 1:
            print(d - x % d)
        else:
            print(x % d)
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
  ans=x-k*d
else:
  n=x//d
  if (k-n)%2==0:
    ans=x-n*d
  else:
    ans=abs(x-(n+1)*d)
print(ans)
X,K,D=map(int,input().split())
c=[]
k=K
if X<0:
  X=-X
if X-K*D>0:
  print(X-K*D)
else:
  a=X//D
  if a%2==K%2:
    print(min((X-D*a),abs(X-D*(a+2))))
  else:
    print(min((X-D*(a-1)),abs(X-D*(a+1))))
X, K, D = map(int, input().split())
X = abs(X)
r = X % D
t = X // D
if t >= K:
    ans = abs(X - K * D)
elif (K - t) % 2 == 0:
    ans = r
else:
    ans = D - r
print(ans)
x,k,d= map(int, input().split())

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

# 0を横切らない場合
if K * D <= abs(X):
    print(abs(X) - K * D)
# 0を横切る場合
else:
    sho = abs(X) // D
    # 偶奇一致
    if sho % 2 == K % 2:
        print(abs(X) % D)
    else:
        print(abs(abs(X) % D - D))

# print('-----output-----')
x,k,d = map(int,input().split())
x = abs(x)
if x - k*d > x%d:
    print(x - k*d)
else:
    if x%d == 0 and x // d <= k:
        if (k - x//d)%2 == 0:
            print(0)
        else:
            print(d)
    else:
        if (k - x // d) % 2 == 1:
            print(abs(x%d-d))
        else:
            print(x%d)
X, K, D = map(int, input().split())
X = abs(X)
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()
import sys
X,K,D = map(int,input().split())
X = abs(X)
if X > K * D:
    print(X - K*D)
    
elif X != 0:
    if (X // D) % 2 == K % 2:
        print(X % D)
    elif (X // D) % 2 != K % 2:
        print(abs(X % D - D))
        
else:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
x, k, d = map(int, input().split())

def sgn(x):
  if x > 0:
    return 1
  if x < 0:
    return -1
  return 0

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

if sgn(x) == sgn(x1):
  print(abs(x1))
  exit()
  
xright = x % d
xleft = x % d - d
#0目前
xr = (abs(x - xright) // d) % 2
if k % 2 == xr:
  print(abs(xright))
elif k % 2 != xr:
  print(abs(xleft))
X,K,D=map(int, input().split())

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

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


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

if K2 % 2 == 1:
    X= abs(X) - D


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

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

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


lap, rem = divmod(x, d)
if lap >= k:
    print(x - k * d)
    exit()

nokori = k - lap
rem0, rem1 = rem, d - rem
if nokori % 2 == 0:
    print(rem0)
else:
    print(rem1)
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
    print(x-k*d)
else:
    k-=x//d
    x-=(d*(x//d))
    ans=[x,abs(d-x)]
    print(ans[k%2])
x, k, d = map(int,input().split())

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

k -= a
x -= a * d

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

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


x=abs(x)
if k*d<=x:
    print(x-k*d)
else:
    tem = int(x/d)
    x-= tem*d
    k-= tem
    if k%2==0:
        print(x)
    else:
        print(abs(x-d))
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))
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

x, K, D = map(int, readline().split())
if x - K * D >= 0:
    print(abs(x - K * D))
elif x + K * D <= 0:
    print(abs(x + K * D))
else:
    low, high = 0, K
    while high - low > 1:
        mid = (high + low) // 2
        if x + (-K + 2 * mid) * D <= 0:
            low = mid
        else:
            high = mid
    print(min(abs(x + (-K + 2 * low) * D), abs(x + (-K + 2 * high) * D)))
x,k,d= map(int,input().split())
x=abs(x)
if x>d*k:
  print(x-d*k)
else:
  m=x//d
  k=(k-m)%2
  print(abs((x%d)-k*d))
import sys

# C - Walking Takahashi
X, K, D = map(int, input().split())

if D * K <= abs(X):
	print(abs(X) - D * K)
else:
	distance = abs(X) % D

	# 残りの移動回数
	count = K - (abs(X) // D)

	if count % 2 == 1:
		print(abs(D - distance))
	else:
		print(distance)
x, k, d = map(int, input().split())

if x > k*d or -x > k*d:
    print(abs(abs(x) -k*d))
else:
    num = abs(x) // d
    rest = k - num
    if rest%2 == 1:
        print(abs(abs(x)%d -d))
    else:
        print(abs(abs(x)%d))
import math

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

X = abs(X)

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

X = abs(X)
reach_or_before = X // D


if K <= reach_or_before:
    print(X - D * K)
else:
    #remaining jump
    remain = K - reach_or_before
    before_dist = X - D * reach_or_before #(>0)
    after_dist = D * (reach_or_before + 1) - X
    if remain % 2 == 0:
        print(before_dist)
    else:
        print(after_dist)
X, K, D = map(int, input().split())
X = abs(X)

if K*D <= X:
    print(abs(X - K*D))
else:
    m = X // D
    re = K - m
    if re % 2 == 0:
        print(abs(X - D*m))
    else:
        print(abs(X - D*(m+1)))
x,k,d=map(int,input().split())
x=abs(x)
ans=0
if x>k*d:
    ans=x-(k*d)
else:
    if k%2==(x//d)%2:
        ans=x%d
    else:
        ans=abs(x%d-d)
print(ans)
def resolve():
    x,k,d = map(int,input().split())
    if x < 0:
        x = -x
    if k*d > x:
        g = x//d * d
        if (k - x//d) % 2 == 0:
            print(x - g)
        else:
            print(abs(x-g-d))
    else:
        print(x-k*d)
resolve()
import math
X,K,D =map(int,input().split())
X=abs(X)
a=X//D
b=X%D
if a >K:
  ans=(a-K)*D+b
else:
  ans=X-a*D-((K-a)%2)*D
print(abs(ans))
a=list(map(int,input().split()))
if a[0]<0:
    a[0]=-a[0]
x=a[0]%a[2]
y=a[0]//a[2]
if y>=a[1]:
    print(a[0]-a[1]*a[2])
elif (a[1]-y)%2==1:
    print(a[2]-x)
else:
    print(x)
x,k,d = list(map(int, input().split()))

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

now = abs(X)
rest = K

step1 = min(now//D, K)
rest -= step1
now -= step1 * D

if rest <= 0:
    print(abs(now))
else:
    if rest % 2 == 1:
        now = abs(now - D)
        print(now)
    else:
        print(now)
X,K,D=map(int,input().split())
Y=X%D
if abs(X)-K*D>0:
    ans=abs(X)-K*D
else:
    Z=(K-abs(Y-X)//D)%2
    if Z==0:
        ans=Y
    else:
        ans=Y-D
print(abs(ans))
#c
x,k,d = map(int,input().split())

num = 0

x = abs(x)

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

    
print(num)
# 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==KOE:
        print(M)
    else :
        print(min(abs(M+D),abs(M-D)))
X, K, D = map(int, input().split())
A= abs(X)%D
B = abs(X)//D
if abs(X) - K*D > 0:
  print(abs(X)-K*D)
elif K%2 != B%2:
  print(min(abs(A+D),abs(A-D)))
else:
  print(A)
X,K,D=map(int,input().split())
zX = abs(X)

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