CodeEff/ECCO huggingface dataset:
# Original solution
x,k,d=list(map(int,input().split()))
x=abs(x)
sa=x//d
ans=x
pbk,mbk=0,0
bk1,bk2,bk3=1,1,1
mansbk,pansbk=0,0
if sa>=k:
  ans=x-d*k
else:
  ans=x-d*sa
  k=k-sa
  for i in range(k):
    mansbk=abs(ans-d)
    pansbk=abs(ans+d)
    if mansbk!=pansbk:
      ans=min(mansbk,pansbk)
      if bk3!=1:
        bk1=min(mansbk,pansbk)
        bk2=max(mansbk,pansbk)
        ans=1 if (k-i)%2==1 else bk1
        break
      elif ans==1:
        bk3=max(mansbk,pansbk) 
      elif 2*x==d:
        ans=0 if (k-i)%2==1 else x
        break
    else:
      ans=0 if (k-i)%2==0 else d
      break
    pbk=max(mansbk,pansbk)
    mbk=min(mansbk,pansbk)
print(ans)

# Optimized solution
x,k,d=list(map(int,input().split()))
x=abs(x)
sa=x//d
ans=x
pbk,mbk=0,0
bk1,bk2,bk3=1,1,1
mansbk,pansbk=0,0
if sa>=k:
  ans=x-d*k
else:
  ans=x-d*sa
  k=k-sa
  for i in range(k):
    mansbk=abs(ans-d)
    pansbk=abs(ans+d)
    if mansbk!=pansbk:
      ans=min(mansbk,pansbk)
      if bk3!=1:
        bk1=min(mansbk,pansbk)
        bk2=max(mansbk,pansbk)
        ans=mbk if (k-i)%2==0 else bk1
        break
      else:
        bk3=max(mansbk,pansbk) 
    else:
      ans=0 if (k-i)%2==0 else d
      break
    pbk=max(mansbk,pansbk)
    mbk=min(mansbk,pansbk)
print(ans)
# Original solution
x,k,d=list(map(int,input().split()))
x=abs(x)
sa=x//d
ans=x
pbk,mbk=0,0
bk1,bk2,bk3=1,1,1
mansbk,pansbk=0,0
if sa>=k:
  ans=x-d*k
else:
  ans=x-d*sa
  k=k-sa
  for i in range(k):
    mansbk=abs(ans-d)
    pansbk=abs(ans+d)
    if mansbk!=pansbk:
      ans=min(mansbk,pansbk)
      if bk3!=1:
        bk1=min(mansbk,pansbk)
        bk2=max(mansbk,pansbk)
        ans=mbk if (k-i)%2==0 else bk1
        break
      else:
        bk3=max(mansbk,pansbk) 
    else:
      ans=0 if (k-i)%2==0 else d
      break
    pbk=max(mansbk,pansbk)
    mbk=min(mansbk,pansbk)
print(ans)

# Optimized solution
x,k,d=list(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)))
# Original solution
X, K, D = list(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=min(X,K*D-X)
    for i in range(0,K):
        ans=ans-D
        if ans<0 and (K-i)%2==0:
            ans=ans+D
            break
        elif ans<0 and (K-i)%2==1:
            ans=-ans
            break
print(ans)

# Optimized solution
X, K, D = list(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)
# Original solution
X,K,D = list(map(int, input().split()))
co = 0
ans = abs(X)
while abs(ans) > D/2 and (K - co) > 0:
    ans = abs(ans) - D
    co += 1
if (K - co) % 2 == 0:
    print((abs(ans)))
else:
    ans = abs(ans) - D
    print((abs(ans)))

# Optimized solution
X,K,D = list(map(int, input().split()))
co,ans = divmod(abs(X),D)
if (K - co) > 0:
    if (K - co) % 2 == 0:
        pass
    else:
        ans = abs(ans) - D
else:
    ans = abs(X) - K*D

print((abs(ans)))
# Original solution
import sys
input = sys.stdin.readline


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

    if x < 0:
        step = abs(x) // d
        if step >= k:
            ans = abs(x + k*d)
        else:
            residue = k - step
            residue %= 2
            ans = abs(x + (step+residue)*d)

    elif x == 0:
        k %= 2
        ans = k * d
    else:
        step = abs(x) // d
        if step >= k:
            ans = abs(x - k*d)
        else:
            residue = k - step
            residue %= 2
            ans = abs(x - (step+residue)*d)

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
input = sys.stdin.readline


def main():
    x, k, d = list(map(int, input().split()))
    x = abs(x)
    step = x // d
    if step >= k:
        ans = x - d * k
        print(ans)
        return

    k -= step
    x = x - step * d
    k %= 2
    ans = abs(x - d*k)
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
[_x, _k, _d] = list(map(int, input().split(" ")))
_x = abs(_x)

while _k > 0:
  if _x >= _d:
    _x = abs(_x - _d)
    _k -= 1
  else:
    if _k % 2 == 1:
      _x = abs(_x - _d)
    _k = 0

print(_x)

# Optimized solution
[_x, _k, _d] = list(map(int, input().split(" ")))
_x = abs(_x)

if _x >= _d:
  _y = _x//_d
  if _k < _y:
    _y = _k
  _x = abs(_x - _d * _y)
  _k -= _y
if _k % 2 == 1:
  _x = abs(_x - _d)

print(_x)
# Original solution
x, k, d = list(map(int, input().split()))
x_pre = x
while k > 0:
    if x >= 0:
        x -= d
    else:
        x += d

    if abs(x) >= abs(x_pre):
        if k % 2 == 0:
            print((abs(x_pre)))
            exit()
        else:
            print((abs(abs(x_pre) - d)))
            exit()
    else:
        x_pre = x
        k -= 1

print((abs(x_pre)))

# Optimized solution
x, k, d = list(map(int, input().split()))
x_pre = x
y = abs(x) - k*d

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

while k > 0:
    if x >= 0:
        x -= d
    else:
        x += d

    if abs(x) >= abs(x_pre):
        if k % 2 == 0:
            print((abs(x_pre)))
            exit()
        else:
            print((abs(abs(x_pre) - d)))
            exit()
    else:
        x_pre = x
        k -= 1

print((abs(x_pre)))
# Original solution
import sys


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


def main():
    X,K,D =list(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()


# Optimized solution
import sys


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


def main():
    X,K,D =list(map(int,input().split()))
    X= abs(X)
    if X >= K*D:
        print((X-K*D))

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








if __name__ == "__main__":
    main()
# Original solution
x,k,d=list(map(int,input().split()))
if x<=0:
  x=x*(-1)
if d>=x:
  if k%2==0:
    print(x)
    exit()
  else:
    print((d-x))
    exit()
else:
  if x//d>=k and x>d:
    print((x-k*d))
    exit()
  elif x<=d:
    if k%2==0:
      print(x)
      exit()
    else:
      print((d-x))
    exit()
  else:
    if (x//d)%2==k%2:
      print((x%d))
      exit()
    else:
      print((d-x%d))
      exit()


# Optimized solution
x,k,d=list(map(int,input().split()))
if x<=0:
  x*=-1
mi=x//d
if mi>=k:
  print((x-k*d))
  exit()
else:
  if (mi-k)%2==0:
    print((x-mi*d))
  else:
    print((abs(x-mi*d-d)))
# Original solution
X,K,D=list(map(int,input().split()))
a=round(abs(X/D))
if K<a:
  print((abs(abs(X)-K*abs(D))))
elif (K-a)%2==0:
  l=[]
  l.append(abs(abs(X)-a*abs(D)))
  l.append(abs(abs(X)-(a+2)*abs(D)))
  l.append(abs(abs(X)-(a-2)*abs(D)))
  print((min(l)))
elif (K-a)%2!=0:
  l=[]
  l.append(abs(abs(X)-(a+1)*abs(D)))
  l.append(abs(abs(X)-(a-1)*abs(D)))  
  print((min(l)))

# Optimized solution
x,k,d=list(map(int,input().split()))
if abs(x) >= k*d:
    print((abs(x)-k*d))
else:
    just=abs(x)//d
    if (k-just)%2==0:
        print((min(abs(abs(x)-just*d),abs(abs(x)-(just+2)*d))))
    else:
        print((min(abs(abs(x)-(just+1)*d),abs(abs(x)-(just-1)*d))))
# Original solution
x, k, d = list(map(int, input().split()))
mind = 1000000000000000
c = 0
while k > 0:
    k -= 1
    if abs(x - d - 0) <= abs(x + d - 0):
        x -= d
    else:
        x += d
    if abs(x) == mind:
        break
    mind = min(mind, abs(x))

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

# Optimized solution
x, k, d = list(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)))
# Original solution
X, K, D = list(map(int, input().split()))

ans = 1000000000000007
prev = 1000000000000007
if K % 2 == 0:
  i = K // 2
  for k in range(0, i+1):
    mn = abs(X + k * D * 2)
    if prev < mn:
      break
    prev = mn
    ans = abs(min(mn, ans))

  prev = 1000000000000007
  for k in range(0, i+1):
    mn = abs(X - k * D * 2)
    if prev < mn:
      break
    prev = mn
    ans = abs(min(mn, ans))

else:
  for k in range(1, K+1, 2):
    mn = abs(X + k * D)
    if prev < mn:
      break
    prev = mn
    ans = abs(min(mn, ans))

  prev = 1000000000000007
  for k in range(1, K+1, 2):
    mn = abs(X - k * D)
    if prev < mn:
      break
    prev = mn
    ans = abs(min(mn, ans))

print(ans)


# Optimized solution
X,K,D = list(map(int,input().split()))
 
if X<0:
    X *= -1
n = X//D
m = min(K,n)
 
X -= m*D
K -= m
if K%2:
    print((abs(X-D)))
else:
    print(X)
# Original solution
x, k, d = list(map(int, input().split()))
  
x = abs(x)

if x > k * d:
  print((x - k * d))
else:
  g = k - int(x / d)
  if g > 0:
    if g % 2 == 1:
      g -= 1
    k = k - g

  for i in range(k):
    if x < 0:
      x += d
    else:
      x -= d

  print((abs(x)))

# Optimized solution
x, k, d = list(map(int, input().split()))
  
x = abs(x)

if x > k * d:
  print((x - k * d))
else:
  f = int(x / d)
  x = x - f * d
  g = (k - f) % 2
  if g == 1:
    x = x - d
  print((abs(x)))
# Original solution
x,k,d = list(map(int,input().split()))
an = x

if x < 0:
    x = -x

if x-d*k >= 0:
    an = x-d*k
else:
    for i in range(k):
        if x > 0:
            x -= d
        else:
            x += d
            
        if an > abs(x) or i==0:
            an = x
        else:
            if (k-i-1)%2 == 0:
                an = x
            break
        
print((abs(an)))

# Optimized solution
x,k,d = list(map(int,input().split()))
an = x

if x < 0:
    x = -x

if k <= x/d:
    an = x-d*k
else:
    if (k-x//d)%2==0:
        an = x-d*(x//d)
    else:
        an = x-d*(x//d)-d
        
print((abs(an)))
# Original solution
X, K, D = list(map(int, input().split()))
X_a = abs(X)
if X_a - K * D > D:
    print((X_a - K * D))
else:
    while X_a >= D:
        X_a -= D
        K -= 1
    if  K % 2 == 0:
        print(X_a)
    else:
        print((abs(X_a-D)))

# Optimized solution
X, K, D = list(map(int, input().split()))
X_a = abs(X)
if X_a - K * D > D:
    print((X_a - K * D))
else:
    K -= X_a // D
    X_a = X_a % D
    while X_a >= D:
        X_a -= D
        K -= 1
    if  K % 2 == 0:
        print(X_a)
    else:
        print((abs(X_a-D)))
# Original solution
import sys
si = sys.stdin.readline


def main():
    [x, k, d] = [int(e) for e in si().split()]
    if x == 0:
        if k % 2 == 0:
            print((0))
        else:
            print((abs(d)))
    elif x < 0:
        while x < 0 and k:
            x += d
            k -= 1
        if k > 0:
            if k % 2:
                print((abs(x-d)))
            else:
                print(x)
        else:
            print((abs(x)))
    else:
        while x > 0 and k:
            x -= d
            k -= 1
        if k > 0:
            if k % 2:
                print((x+d))
            else:
                print((abs(x)))
        else:
            print((abs(x)))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
si = sys.stdin.readline


def main():
    [x, k, d] = [int(e) for e in si().split()]
    if x == 0:
        if k % 2 == 0:
            print((0))
        else:
            print((abs(d)))
    elif x < 0:
        mul = (0-x)//d
        if k <= mul:
            x += d*k
            print((abs(x)))
            return
        else:
            x += d*mul
            k -= mul
        while x < 0 and k:
            x += d
            k -= 1
        if k > 0:
            if k % 2:
                print((abs(x-d)))
            else:
                print(x)
        else:
            print((abs(x)))
    else:
        mul = (x-0)//d
        if k <= mul:
            x -= d*k
            print(x)
            return
        else:
            x -= d*mul
            k -= mul
        while x > 0 and k:
            x -= d
            k -= 1
        if k > 0:
            if k % 2:
                print((x+d))
            else:
                print((abs(x)))
        else:
            print((abs(x)))


if __name__ == '__main__':
    main()
# Original solution
l=list(map(int,input().split()))
x=l[0]
k=l[1]
d=l[2]
x1=abs(x)
cou=0
while x1>0:
  x1-=d
  cou+=1
if k<cou:
  x2=abs(x)-k*d
  print(x2)
  # if x<=0:
  #   x3=x2*(-1)
  #   print(x3)
  # else:
  #   print(x2)

else:
  a=cou%2
  b=k%2
  x4=x1*(-1)
  if a==b:
    print((abs(x1)))
  if a!=b:
    print((x1+d))


# Optimized solution
l=list(map(int,input().split()))
x=l[0]
k=l[1]
d=l[2]
x1=abs(x)

cou=x1//d
cou+=1
x1=x1-d*cou
# while x1>0:
#   x1-=d
#   cou+=1
if k<cou:
  x2=abs(x)-k*d
  print(x2)


else:
  a=cou%2
  b=k%2
  x4=x1*(-1)
  if a==b:
    print((abs(x1)))
  if a!=b:
    print((x1+d))
# Original solution
X,K,D = list(map(int,input().split()))

X = abs(X) 
cnt = 0

if X == 0:
    if K%2==0:
        ans = 0
    elif K%2==1:
        ans = D
elif X >= K*D:
    ans = X-K*D
else:
    while K > cnt:
        X = X - D
        cnt += 1
        if X<=0:
            if (K-cnt)%2 == 0:
                ans = abs(X)
                break
            elif (K-cnt)%2 == 1:
                ans = abs(X+D)
                break
        ans = X

print((abs(ans)))


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

X = abs(X) 

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

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

# print(x,k,d)

x = abs(x)
if x <= d:
    if k%2:
        print((d-x))
    else:
        print(x)
    exit()

c = min(x//d, k)
x -= d*c
k -= c
if k%2:
    print((abs(d-x)))
else:
    print(x)



# Optimized solution
x, k, d = list(map(int, input().split()))
x = abs(x)
if x > d:
    c = min(x//d, k)
    x -= d*c
    k -= c
if k%2: x = d - x
print(x)
# Original solution
x, k, d = list(map(int, input().split()))
if x == 0:
    if k % 2 == 0:
        print((0))
    else:
        print(d)
else:
    a = abs(x) // d
    b = abs(x) % d
    if a >= k:
        print((abs(x) - (d * k)))
    else:
        if (k - a) % 2 == 0:
            print((abs(b)))              
        else:
            print((abs(b - d)))

# Optimized solution
x, k, d = list(map(int, input().split()))
a = abs(x) // d
b = abs(x) % d
if a >= k:
    print((abs(x) - (d * k)))
else:
    if (k - a) % 2 == 0:
        print((abs(b)))              
    else:
        print((abs(b - d)))
# Original solution
x,k,d = list(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 = abs(x - step * d - d)

print(answer)

# Optimized solution
x,k,d = list(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)
# Original solution
Xa, K, D = list(map(int, input().split()))

X = abs(Xa)
Xs = X // D
Xm = X % D

if K < Xs:
#     print("A")
    print((abs(X-K*D)))
# elif Xa == 0:
#     if K % 2 == 0:
#         print(0)
#     else:
#         print(D)
# elif Xm == 0:
#     if K % 2 == 0:
#         print(D)
#     else:
#         print(0)
elif ((K-Xs) % 2 == 0):
    print((abs(Xm)))
else:
    print((abs(D-Xm)))
# else:
# #     print(abs(D-K))
#     if ((K-Xs) % 2 == 0):
#         print(abs(D-K))
#     else:
#         print(abs(D-Xm))


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

Xa = abs(X)
Xs = Xa // D
Xm = Xa % D

if (K <= Xs):
    print((abs(Xa-D*K)))
elif (K-Xs) % 2 == 0:
    print((abs(Xm)))
else:
    print((abs(D-Xm)))
# Original solution
X,K,D=list(map(int,input().split()))
 
x=min(K,abs(X)//D)
 
if X>0:
    X_=X-(D*x)
else:
    X_=X+(D*x)
 
k=K-x
if k%2!=0:
    ans=min(abs(X_-D),abs(X_+D))
else:
    ans=abs(X_)
print(ans)

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

X=abs(X)
k=min(K,X//D)
X_=X-(k*D)
K_=K-k

if K_%2!=0:
    ans=min(abs(X_-D),abs(X_+D))
else:
    ans=abs(X_)

print(ans)
# Original solution
x,k,d = list(map(int, input().split()))
line = [x]
if abs(x) >= k*d:
  print((abs(x) - k*d))
else:
  for i in range(k):
    if x > 0:
      x -= d
    else:
      x += d
    line.append(x)
    if i != 0:
      if line[i-1] == line[i+1]:
        if (k - i + 1) % 2 == 0:
          x = line[i+1]
          break
        else:
          x = line[i]
          break
  print((abs(x)))

# Optimized solution
x,k,d = list(map(int, input().split()))
count = abs(x) // d
if count >= k:
  print((abs(x)-k*d))
else:
  if (k - count) % 2 == 0:
    print((abs(x)-count*d))
  else:
    print((abs(abs(x)-(count+1)*d)))
# Original solution
X, K, D = list(map(int, input().split()))
if X == D:
    if K % 2 != 0:
        print('0')
    else:
        print(D)
else:
    if K * D < X:
        print((X - K * D))
    else:
        for i in range(K):
            if X >= 0:
                X = X - D
            else:
                X = X + D
        print((abs(X)))

# Optimized solution
X, K, D = list(map(int, input().split()))
X = abs(X)
if X == D:
    if K % 2 != 0:
        print('0')
    else:
        print(D)
else:
    span = X // D
    if span < K:
        if (K - span) % 2 == 0:
            print((X % D))
        else:
            print((abs(X % D - D)))
    else:
        print((X - K * D))
# Original solution
def resolve():
    X, K, D = list(map(int, input().split()))
    count = min(abs(X//D), K)
    for i in range(count):
        if X > 0:
            X -= D
        else:
            X += D
        K -= 1
    if K > 0:
        if K%2 == 0:
            print((abs(X)))
        else:
            print((D-abs(X)))
    else:
        print((abs(X)))
resolve()

# Optimized solution
def resolve():
    X, K, D = list(map(int, input().split()))
    count = min(abs(X//D), K)
    if X > 0:
        X -= D*count
    else:
        X += D*count
    K -= count
    if K > 0:
        if K%2 == 0:
            print((abs(X)))
        else:
            print((D-abs(X)))
    else:
        print((abs(X)))
resolve()
# Original solution
X , K ,D = list(map(int, input().split()))


if X>0:
    for k in range(K):
        bx = X
        X-=D
        if X<=0:
            break
else:
    for k in range(K):
        bx = X
        X+=D
        if X>=0:
            break

if K == k + 1 or (K-k-1)%2==0:
    print((abs(X)))
else:
    print((abs(bx)))

# Optimized solution
X , K ,D = list(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)))
# Original solution
X, K, D = list(map(int, input().split()))
if X == 0 and K%2 == 0:
  print((0))
elif X == 0 and K%2 == 1:
  print((abs(D)))
elif X > 0 and X - D*K >= 0:
  print((X - D*K))
elif X < 0 and X + D*K <= 0:
  print((abs(X + D*K)))
else:
  i = abs(X)//D
  if (K - i) % 2 == 0:
    print((abs(X)%D))
  else:
    print((abs(abs(X)%D-D)))

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

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

if(X > 0):
    if(X-K*D >= 0):
        print((X-K*D))
    else:
        while(X >= 0):
            X = X-D
            K -= 1
        if(K % 2 == 0):
            print((abs(X)))
        else:
            print((abs(X+D)))
elif(X < 0):
    if((X+K*D) <= 0):
        print((abs(X+K*D)))
    else:
        while(X <= 0):
            X = X+D
            K -= 1
        if(K % 2 == 0):
            print((abs(X)))
        else:
            print((abs(X-D)))
else:
    if(K % 2 == 0):
        print((0))
    else:
        print((abs(D)))


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

if(X > 0):
    if(X-K*D >= 0):
        print((X-K*D))
    else:
        l = X//D
        X = X-D*(l+1)
        K = K-l-1
        if(K % 2 == 0):
            print((abs(X)))
        else:
            print((abs(X+D)))
elif(X < 0):
    if((X+K*D) <= 0):
        print((abs(X+K*D)))
    else:
        l = -X//D
        X = X + D*(l+1)
        K = K-l-1
        if(K % 2 == 0):
            print((abs(X)))
        else:
            print((abs(X-D)))
else:
    if(K % 2 == 0):
        print((0))
    else:
        print((abs(D)))
# Original solution
[X, K, D] = list(map(int, input().split()))
X = abs(X)
Y = K%2
for i in range(K):
    X -= D
    if X<0:
        if (i+1)%2 != Y:
            X += D
        else:
            X = abs(X)
        break
print(X)

# Optimized solution
[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)
# Original solution
X, K, D = list(map(int, input().split()))
X = abs(X)
for i in range(K):
    X_ = min(X, abs(X-D))
    if X == X_:
        X = abs(X_ - (K - i)%2*D)
        break
    X = X_
print(X)


# Optimized solution
X, K, D = list(map(int, input().split()))
X = abs(X)
if X // D <= K:
    print((min(abs(X % D - (K - (X // D))%2*D), abs(X % D + (K - (X // D))%2*D))))
else:
    print((min(abs(X - K*D), abs(X + K*D))))
# Original solution
s = input().split()
X=int(s[0])
K=int(s[1])
D=int(s[2])
q, mod = divmod(X, D)
if q < 0:
  q = -q
if 2*mod < D:
   if K < q:
      if X > 0:
         m = X - D*K
      else:
         m = X + D*K
   else:
       restmovement = (K-q)%2
       if restmovement==0:
          m = mod
       else:
          m = D - mod
else:
   if X > 0:
      if K < q+1:
         m = X - D*K
      else:
         restmovement = (K - q - 1)%2
         if restmovement==0:
                    m = D - mod
         else:
                    m = mod
   else:
       if K < q-1:
          m=X - D*K
       else:
          restmovement = (K+1-q)%2
          if restmovement==0:
                m = D-mod
          else:
                m = mod
if m < 0:
   print((-m))
else:
   print(m)

# Optimized solution
X, K ,D = input().split()
X = abs(int(X))
K = int(K)
D = int(D)
Q, mod = divmod(X, D)
if K < Q:
    ans = X - K*D
else:
    Rest = (K - Q)%2
    if Rest == 0:
         ans = mod
    else:
         ans = D - mod
print(ans)
# Original solution
# AtCoder Beginner Contest 175
# C - Walking Takahashi

X,K,D =list(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))))

# Optimized solution
# AtCoder Beginner Contest 175
# C - Walking Takahashi

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

X=abs(X)

A=X//D
M=X%D

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

else :
    if A%2==K%2:
        print(M)
    else :
        print((min(abs(M+D),abs(M-D))))
# Original solution
dates = [int(i) for i in input().split(" ")]
X = dates[0]
K = dates[1]
D = dates[2]

if X >= 0:
    while X > 0 and K > 0:
        X -= D
        K -= 1
else:
    while X <= 0 and K > 0:
        X += D
        K -= 1

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


# Optimized solution
import math

dates = [int(i) for i in input().split(" ")]
X = dates[0]
K = dates[1]
D = dates[2]
numDiv = math.ceil(abs(X) / D)

if numDiv < K:
    if X >= 0:
        X -= numDiv * D
        K -= numDiv
    else:
        X += numDiv * D
        K -= numDiv
else:
    if X >= 0:
        X -= K * D
        K = 0
    else:
        X += K * D
        K = 0

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