CodeEff/ECCO huggingface dataset:
# Original solution
X,K,D = list(map(int,input().split()))

if X < 0:
    X = -X

cnt = 0
for i in range(K):
    X -= D
    cnt += 1
    if X <= 0:
        break
    else:
        continue
    
remain = K-cnt
    
if remain == 0:
    print((abs(X)))
else:
    if remain % 2 == 0:
        print((abs(X)))
    else:
        print((abs(X+D)))

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

if X < 0:
    X = -X

cnt = 0
Q = X//D
R = X%D

if K < Q:
    print((X-K*D))
else:
    if (K - Q)%2 == 0:
        print((abs(R)))
    else:
        print((abs(R-D)))
# Original solution
x,k,d=list(map(int,input().split()))
if x==0:
    if d%2==0:
        print((0))
    else:
        print(d)
else:
    cou=0
    ok=True
    if x>0:
        while x>0:
            cou+=1
            x-=d
            if cou==k:
                ans=x
                ok=False
                break
        xx=x+d
        if ok:
            if cou%2==0 and k%2==0:
                ans=x
            elif cou%2==0 and k%2==1:
                ans=xx
            elif cou%2==1 and k%2==0:
                ans=xx
            else:
                ans=x
    
    if x<0:
        while x<0:
            cou+=1
            x+=d
            if cou==k:
                ans=x
                ok=False
                break
        xx=x-d
        if ok:
            if cou%2==0 and k%2==0:
                ans=x
            elif cou%2==0 and k%2==1:
                ans=xx
            elif cou%2==1 and k%2==0:
                ans=xx
            else:
                ans=x
    print((abs(ans)))

# Optimized solution
x,k,d=list(map(int,input().split()))
if x==0:
    if d%2==0:
        print((0))
    else:
        print(d)
else:
    cou=0
    ok=True
    if x>0:
        xx=x
        while x>0:
            if xx-k*d>0:
                ans=x-k*d
                ok=False
                break
            cou+=1
            x-=d
            
        xx=x+d
        if ok:
            if cou%2==0 and k%2==0:
                ans=x
            elif cou%2==0 and k%2==1:
                ans=xx
            elif cou%2==1 and k%2==0:
                ans=xx
            else:
                ans=x
    
    if x<0:
        xx=x
        while x<0:
            if xx+k*d<0:
                ans=xx+k*d
                ok=False
                break
            cou+=1
            x+=d
            
        xx=x-d
        if ok:
            if cou%2==0 and k%2==0:
                ans=x
            elif cou%2==0 and k%2==1:
                ans=xx
            elif cou%2==1 and k%2==0:
                ans=xx
            else:
                ans=x
    print((abs(ans)))
# Original solution
x,k,d = list(map(int,input().split()))
dis = x
cnt = 0
def zet(x):
    if x >= 0:
        return x
    else:
        return -x
while cnt<k:
    if zet(dis)<d:
        recnt = k -cnt
        if recnt%2==0:
            pass
        else:
            dis = d-zet(dis)
        break
    elif dis>=0:
        dis = dis - d
    else:
        dis = dis + d
    cnt += 1
print((zet(dis)))

# Optimized solution
x,k,d = list(map(int,input().split()))
x = abs(x)
point =x % d
num = x//d
if num<k:
    rest = k - num
    if rest%2==0:
        pass
    else:
        point = d -point
else:
    point = x - k*d
print(point)
# Original solution
x,k,d=list(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=min(abs(x%d-d),abs(x%d+d))
print(ans)

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

i = 0
nokori = 0

if X > 0 :
    while X > 0 and i < K:
        X -= D
        i += 1
    
    nokori = K - i
    if nokori % 2 == 1 :
        X += D

else :
    while X <= 0 and i < K:
        X += D
        i += 1
    nokori = K - i
    if nokori % 2 == 1 :
        X -= D

print((abs(X)))

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

X = abs(X)
aa = X // D

if K < aa :
    X -= K * D
else :
    if (K - aa) % 2 == 1 :
        X -= (aa+1) * D
    else :
        X -= aa * D

print((abs(X)))
# Original solution
X,K,D=list(map(int,input().split()))
kai = 0
xy = abs(X)
ds = D
if xy >= K*D:
    kotae = abs(xy-(K*D))
if xy < K*D:
    while xy >ds:
        ds=ds+D
        kai = kai+1
    ds = ds-D
    if (K-kai)%2==0:
        kotae = abs(xy-ds)
    if (K-kai)%2!=0:
        kouho1 = abs(xy-ds-D)
        kouho2 = abs(xy-ds+D)
        if kouho1>=kouho2:
            kotae = kouho2
        if kouho1<kouho2:
            kotae = kouho1
print(kotae)

# Optimized solution
X,K,D=list(map(int,input().split()))
kai = 0
xy = abs(X)
if xy >= K*D:
    kotae = abs(xy-(K*D))
if xy < K*D:
    kai, mod = divmod(xy, D)
    ds = kai*D
    if (K-kai)%2==0:
        kotae = abs(xy-ds)
    if (K-kai)%2!=0:
        kouho1 = abs(xy-ds-D)
        kouho2 = abs(xy-ds+D)
        if kouho1>=kouho2:
            kotae = kouho2
        if kouho1<kouho2:
            kotae = kouho1
print(kotae)
# Original solution
X,K,D=list(map(int,input().split()))

X=abs(X)
a=min(K,X//D)
X-=a*D
K-=a
#print(X,K)
if K%2:
    X=abs(X-D)
ans=X
print(ans)


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

X=abs(X)
a=min(K,X//D)
ans=X-a*D
if (K-a)%2:
    ans=D-ans

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

cnt = abs(x) // d
x = abs(x)
if k % 2 == cnt % 2:
    ans = min(abs(x - d * min(k,cnt)), abs(x + d * min(k,cnt)))
elif k % 2 != cnt % 2:
    ans = min(abs(x - d * min(k,(cnt + 1))), abs(x - d * min(k,(cnt + 1))))
print(ans)


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

x, cnt = abs(x), abs(x) // d
if k % 2 == cnt % 2:
    ans = abs(x - d * min(k,cnt))
elif k % 2 != cnt % 2:
    ans = abs(x - d * min(k,(cnt + 1)))
print(ans)
# Original solution
x, k, d = list(map(int, input().split()))

x, cnt = abs(x), abs(x) // d
if k % 2 == cnt % 2:
    ans = abs(x - d * min(k,cnt))
elif k % 2 != cnt % 2:
    ans = abs(x - d * min(k,(cnt + 1)))
print(ans)


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

x, cnt = abs(x), abs(x) // d
ans = abs(x - d * min(k, cnt + (k % 2 != cnt % 2)))
print(ans)
# Original solution
def main():
    x, k, d = list(map(int, input().split()))
    x = abs(x)
    count = x // d
    if count > k:
        ans = x - (k*d)
    else:
        if k % 2 == count % 2:
            ans = x - (count*d)
        else:
            ans = x - (count+1) * d
    print((abs(ans)))
    
if __name__ == '__main__':
    main()

# Optimized solution
def main():
    x, k, d = list(map(int, input().split()))
    x = abs(x)
    count = x // d
    if count > k:
        ans = x - (k*d)
    else:
        # if k % 2 == count % 2:
        if (k - count) % 2 == 0:
            ans = x - (count*d)
        else:
            ans = x - (count+1) * d
    print((abs(ans)))
    
if __name__ == '__main__':
    main()
# Original solution
import math
y, k, d = list(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) / 2):
        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)))

# Optimized solution
y, k, d = list(map(int, input().split()))
x = abs(y)
i = int(x / d)
if i >= k:
    p = x - k * d
elif i == x / d:
    if (i + k) % 2 == 0:
        p = 0
    else:
        p = d
else:
    if ((2 * i + 1) * d == 2 * x) or ((i + k) % 2 == 0):
        p = x - i * d
    else:
        p = (i + 1) * d - x
print((int(p)))
# Original solution
X, K, D = list(map(int, input().split(" ")))

X = abs(X)
now = X
over_zero_step = 0
over_zero = 0
not_over_zero = now
flg = 0
for i in range(1, K+1):
    if X < abs(K * D):
        nxt = now - D
    #    print(nxt, i)
        if nxt < 0:
            over_zero = nxt
            not_over_zero = now
            over_zero_step = i
            break
        now = nxt
    else:
        remaining_step = 0
        nearest_point = X - K * D
        flg = 1

if flg == 0:
        
    if abs(over_zero) <= not_over_zero:
        nearest_point = over_zero
        nearest_point_step = over_zero_step
        next_nearest_point = not_over_zero
        remaining_step = K - nearest_point_step
    else:
        nearest_point = not_over_zero
        nearest_point_step = over_zero_step - 1
        next_nearest_point = over_zero
        remaining_step = K - nearest_point_step

#print("rem", remaining_step)
if remaining_step % 2 == 0:
    print((abs(nearest_point)))
else:
    print((abs(next_nearest_point)))

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

X = abs(X)
now = X
over_zero_step = 0
over_zero = 0
not_over_zero = now
flg = 0

if X < abs(K * D):
    q = X // D
    now = X - q * D
    now = abs(now)
#    print(now, q)    
    for i in range(q+1, K+1):
        nxt = now - D
        if nxt < 0:
            over_zero = nxt
            not_over_zero = now
            over_zero_step = i
            break
        now = nxt
else:
    remaining_step = 0
    nearest_point = X - K * D
    flg = 1

if flg == 0:
        
    if abs(over_zero) <= not_over_zero:
        nearest_point = over_zero
        nearest_point_step = over_zero_step
        next_nearest_point = not_over_zero
        remaining_step = K - nearest_point_step
    else:
        nearest_point = not_over_zero
        nearest_point_step = over_zero_step - 1
        next_nearest_point = over_zero
        remaining_step = K - nearest_point_step

#print("rem", remaining_step)
if remaining_step % 2 == 0:
    print((abs(nearest_point)))
else:
    print((abs(next_nearest_point)))
# Original solution
X, K, D = list(map(int, input().split()))

if int(abs(X) / D) < K:
    if abs(X) < abs(X) % D:
        if K % 2 == 0:
            print((abs(X)))
        else:
            print((min(abs(X - D), abs(X + D))))
    else:
        if int(K - int(abs(X) / D)) % 2 == 0:
            print((abs(X) % D))
        else:
            print((min(abs(abs(X) % D - D), abs(abs(X) % D + D))))
else:
    print((abs(X) - D * K))

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

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

for i in range(k):
    if abs(x+d) < abs(x-d):
        if abs(x)<abs(x+d):
            if (k-i)%2 == 0:
                break;
            else:
                x = x+d
                break
        x = x+d
    else:
        if abs(x)<abs(x-d):
            if (k-i)%2 == 0:
                break;
            else:
                x = x-d
                break
        x = x-d
print((abs(x)))

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

if k < s:
    print((x-d*k))
else:
    if ans < -ans+d:
        if (k-s)%2 == 0:
            print(ans)
        else:
            print((-ans+d))
    else:
        if (k-s)%2 == 0:
            print(ans)
        else:
            print((-ans+d))
# Original solution
x, k, d = list(map(int, input().split()))

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 残り回数が0回の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = abs(cur - d)

print(cur)

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

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = cur - d

ans = abs(cur)
print(ans)
# Original solution
# -*- coding: utf-8 -*-
X,K,D=list(map(int,input().split()))

for ii in range(K):
    if abs(X)<=D:
        if (K-ii)%2==1:
            if X>=0:
                X-=D
            else:
                X+=D
        break
    elif X>=0:
        X-=D
    else:
        X+=D
print((abs(X)))
        


# Optimized solution
# -*- coding: utf-8 -*-
X,K,D=list(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)))
# Original solution
x,k,d=input().split()
x=int(x)
k=int(k)
d=int(d)
if(abs(x)>k*d):
    print((abs(x)-k*d))
else:
    for i in range(k):
        x=abs(x)-d
        if(x<1):
            break
    k=k-i-1
    if(k==0):
        print((abs(x)))
    elif(k%2==0):
        print((abs(x)))
    else:
        print((abs(x+d)))
        

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

# if x == 0:
#     if k % 2 == 0:
#         print(0)
#     else:
#         print(d)
if x >= 0:
    if x >= k * d:
        print((x - k * d))
    else:
        q, mod = divmod(x, d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print((abs(mod - d)))
elif x < 0:
    if abs(x) >= k * d:
        print((abs(x + k * d)))
    else:
        q, mod = divmod(abs(x), d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print((abs(mod - d)))


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

if x >= 0:
    if x >= k * d:
        print((x - k * d))
    else:
        q, mod = divmod(x, d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print((abs(mod - d)))
else:
    if abs(x) >= k * d:
        print((abs(x) - k * d))
    else:
        q, mod = divmod(abs(x), d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print((abs(mod - d)))
# Original solution
x, k, d = list(map(int, input().split()))

if x >= 0:
    if x >= k * d:
        print((x - k * d))
    else:
        q, mod = divmod(x, d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print((abs(mod - d)))
else:
    if abs(x) >= k * d:
        print((abs(x) - k * d))
    else:
        q, mod = divmod(abs(x), d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print((abs(mod - d)))


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

# if x >= 0:
if abs(x) >= k * d:
    print((abs(x) - k * d))
else:
    q, mod = divmod(x, d)
    k -= q
    if k % 2 == 0:
        print(mod)
    else:
        print((abs(mod - d)))
# else:
#     if abs(x) >= k * d:
#         print(abs(x) - k * d)
#     else:
#         q, mod = divmod(abs(x), d)
#         k -= q
#         if k % 2 == 0:
#             print(mod)
#         else:
#             print(abs(mod - d))
# Original solution
X,K,D = list(map(int, input().split()))
x = 0
if X == 0:
  if K%2 == 0:
    print((0))
  else:
    print((abs(D)))
  x =1
elif X < 0:
  if abs(X) >= K*D:
    print((abs(X+K*D)))
    x = 1
  if x == 0:
    for i in range (K):
      X += D
      if X >= 0:
        if (K-i-1)%2 == 0:
          print((abs(X)))
        else:
          print((abs(X-D)))
        x = 1
        break
else:
  if X >= K*D:
    print((X-K*D))
    x = 1
  if x == 0:
    for i in range (K):
      X -= D
      if X < 0:
        if (K-i)%2 == 0:
          print((abs(X+D)))
        else:
          print((abs(X)))
        x = 1
        break

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

    def solve(x, k, d):
        # Xを絶対値でプラスの値にし、0に近づける問題に置き換える
        x = abs(x)

        # (x // d)は0の手前まで移動するのに必要な回数。kの方が小さい場合はk回移動してしまえばよい
        if k < (x // d):
            return x - (k * d)
        # kのほうが大きい場合はそこから数回移動が必要
        else:
            # xからとりあえずx//d回は移動してOK
            current_x = x - d * (x // d)
            k = k - (x // d)

            # 結局ここをfor文で探索すると時間がかかるので終わらない。(10**30回とか探索しちゃう。)
            if (k % 2) == 0:
                # 残りの移動回数が偶数回なら移動を繰り返してその場所に戻ってくる
                return current_x
            else:
                # 奇数回の場合、偶数回移動を繰り返した後、もう一回だけ移動する。
                # この時、current_xは0以上なので、マイナス方向に動けばOK
                return abs(current_x - d)

    ans = solve(x, k, d)
    print(ans)

if __name__ == '__main__':
    abc175_c_2()

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

    def solve(x, k, d):
        """
        https://atcoder.jp/contests/abc175/editorial/52
        """

        x = abs(x)

        straight = int(min(k, x / d))
        k -= straight
        x -= straight * d

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

    ans = solve(x, k, d)
    print(ans)

if __name__ == '__main__':
    abc175_c_3()
# Original solution
[x,k,d] = [int(i) for i in input().split()]
tmp_diff = abs(x)

while tmp_diff > d and k > 0:
    tmp_diff -= d
    k -= 1

if k <= 0:
    print(tmp_diff)
else:
    if k % 2 == 0:
        print(tmp_diff)
    else:
        print((d - tmp_diff))


# Optimized solution
[x,k,d] = [int(i) for i in input().split()]
x = abs(x)

if k < x//d:
    print((x - k * d))
else:
    k -= x // d
    x -= (x // d) * d
    if k % 2:
        print((abs(x-d)))
    else:
        print(x)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def li():
    return [int(x) for x in input().split()]


X, K, D = li()

if X < 0:
    X *= -1

ans = 0
if K * D < X:
    #print("A")
    ans = X - K * D
else:
    over_K = X // D + 1
    #print(over_K)
    if (K - over_K) % 2 == 1:
        #print("B")
        ans = X % D
    else:
        #print("C")
        ans = D - (X % D)

print(ans)

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

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

if abs(X) > K*D:
    print((abs(X) - K*D))
elif K == 1:
    print((min(abs(X-D),abs(X+D))))
elif K == 2:
    print((min(abs(X+D+D),abs(X-D-D),abs(X))))
elif K == 3:
    print((min(abs(X+D+D+D),abs(X+D),abs(X-D),abs(X-D-D-D))))
else:
    for i in range(3):
        if abs(X - D) >= abs(X+D):
            List.append(abs(X+D))
            X = X+D
        else:
            List.append(abs(X-D))
            X = X-D

    for i in range(K-3):
        if List[i] == List[i+2]:
            if K%2 == i%2:
                print((List[i+1]))
            else:
                print((List[i]))
            break
        else:
            if abs(X - D) >= abs(X+D):
                List.append(abs(X+D))
                X = X+D
            else:
                List.append(abs(X-D))
                X = X-D

    if len(List) == K:
        print((List[K-1]))
    else:
        pass

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

t = abs(X) // D
s = abs(X) % D

if abs(X) > K*D:
    print((abs(X) - K*D))
elif t%2 == K%2:
    print(s)
else:
    print((D-s))
# Original solution
def main():
	X, K, D = list(map(int, input().split()))

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

 
if __name__ == "__main__":
  	main()

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

	ans = 0

	if abs(X) >= K * D: # 0にたどり着かない or ちょうど0にたどり着く
		ans = abs(X) - K * D
	else: # 0を通り過ぎて往復する
		s = abs(X) // D
		if (K - s) % 2 == 0:
			ans = abs(X) - s * D # abs(X) - s * D - 0
		else:
			ans = -abs(X) + (s + 1) * D # 0 - (abs(X) - (s + 1) * D)

	print(ans)

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

def judge():
    if x > 0:
        for r in range(d):
            if (x - r)/d == (x - r)//d:
                i = (x - r)//d
                if (k - i)%2 == 0:
                    print(r)
                else:
                    print((d-r))
                exit()
    else:
        l = -x
        for r in range(d):
            if (l - r)/d == (l - r)//d:
                i = (l - r)//d
                if (k - i)%2 == 0:
                    print(r)
                else:
                    print((d-r))
                exit()


if x == 0:
    if k%2 == 0:
        print((0))
    else:
        print(d)
elif x < 0:
    if k*d + x > 0:
        judge()
    else:
        print((abs(k*d + x)))
else:
    if x - k*d < 0:
        judge()
    else:
        print((abs(x - k*d)))


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

def judge():
    l = x if x > 0 else -x
    i = l//d
    r = l%d

    if (k - i)%2 == 0:
        print(r)
    else:
        print((d - r))
    '''
    if x > 0:
        for r in range(d):
            if (x - r)/d == (x - r)//d:
                i = (x - r)//d
                if (k - i)%2 == 0:
                    print(r)
                else:
                    print(d-r)
                exit()
    else:
        l = -x
        for r in range(d):
            if (l - r)/d == (l - r)//d:
                i = (l - r)//d
                if (k - i)%2 == 0:
                    print(r)
                else:
                    print(d-r)
                exit()
    '''

if x == 0:
    if k%2 == 0:
        print((0))
    else:
        print(d)
elif x < 0:
    if k*d + x > 0:
        judge()
    else:
        print((abs(k*d + x)))
else:
    if x - k*d < 0:
        judge()
    else:
        print((abs(x - k*d)))
# Original solution
x,k,d=input().split()
x=int(x)
k=int(k)
d=int(d)
i=1
while i*d<=abs(x):
  i+=1
if k<=i-1:
  print((abs(x)-d*k))
else:
  if (k-(i-1))%2==0:
    print((abs(x)-d*(i-1)))
  else:
    print((abs(abs(x)-d*(i))))

# Optimized solution
x,k,d=input().split()
x=abs(int(x))
k=int(k)
d=int(d)
a=x//d
b=x-a*d
c=(x-b)/d
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))))