Problem:
 Score : 300 points    Problem Statement Takahashi, who lives on the number line, is now at coordinate X . He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D .  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.      Constraints  -10^{15} \leq X \leq 10^{15}  1 \leq K \leq 10^{15}  1 \leq D \leq 10^{15}  All values in input are integers.         Input Input is given from Standard Input in the following format:  X  K  D       Output Print the minimum possible absolute value of the coordinate of the destination.        Sample Input 1 6 2 4      Sample Output 1 2  Takahashi is now at coordinate 6 . It is optimal to make the following moves:   Move from coordinate 6 to ( 6 - 4 = ) 2 .  Move from coordinate 2 to ( 2 - 4 = ) -2 .   Here, the absolute value of the coordinate of the destination is 2 , and we cannot make it smaller.       Sample Input 2 7 4 3      Sample Output 2 1  Takahashi is now at coordinate 7 . It is optimal to make, for example, the following moves:   Move from coordinate 7 to 4 .  Move from coordinate 4 to 7 .  Move from coordinate 7 to 4 .  Move from coordinate 4 to 1 .   Here, the absolute value of the coordinate of the destination is 1 , and we cannot make it smaller.       Sample Input 3 10 1 2      Sample Output 3 8       Sample Input 4 1000000000000000 1000000000000000 1000000000000000      Sample Output 4 1000000000000000  The answer can be enormous.

Solution (Python):

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y


for _ in range(int(input()) if not True else 1):
    
    x, k, d = map(int, input().split())
    
    
    if x > 0:
        req = x // d
        if k <= req:
            print(abs(x - k*d))
        else:
            k -= req
            cur = x % d
            print(abs(cur) if k % 2 == 0 else abs(cur - d))
    else:
        req = (-x) // d
        if k <= req:
            print(abs(x + k*d))
        else:
            k -= req
            cur = - (-x%d)
            print(abs(cur) if k % 2 == 0 else abs(cur + d))

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

if x < 0:
    flag = -1
else:
    flag = 1
x = abs(x)

tmp = x//d

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

Solution (Python):
x,K,D=map(int, input().split())

X=abs(x)
n=X//D

if K<=n:
	print(X-K*D)
elif K%2==n%2:
	print(X-n*D)
else:
	print(abs(X-n*D-D))

Solution (Python):
x,k,d=map(int,input().split())
x=abs(x)
res=10**18
if k*d<=x:
    res=x-k*d
else:
    k-=x//d
    x=x%d
    if k%2==0:
        res=x
    else:
        res=d-x
print(res)

Solution (Python):
X,K,D = [int(hoge) for hoge in input().split()]

X = abs(X)
Risou = X//D
Amari = X%D 
if K<=Risou:
    print(X - D*K)
else:
    Idou = K-Risou
    Idou %= 2
    Amari -= D*Idou
    print(abs(Amari))

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

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

Solution (Python):
x,k,d=map(int,input().split())
x=abs(x)
s=x%d
t=x//d
if k<t:
    print(x-k*d)
else:
    print(abs(s-(k-t)%2*d))

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


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

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

Solution (Python):
x, k, d = [int(z) for z in input().strip().split()]
step = int(abs(x) / d)

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

Solution (Python):
def main():
    X, K, D = map(int, input().split())
    X = abs(X)
    k = X // D
    if k >= K:
        return X - D * K
    K -= k
    X -= D * k
    if K & 1:
        return D - X
    return X

print(main())

Solution (Python):
x, k, d = map(int, input().split())
if x < 0:
    x = abs(x)
    xsign = -1
else:
    xsign = 1

nn, r = divmod(x, d)
kk = k-nn
if kk <= 0:
    print(x-k*d)
elif kk%2 == 0:
    print(r)
else:
    print(abs(r-d))

Solution (Python):
x, k, d = map(int, input().split())
x = abs(x)

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

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

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

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

Solution (Python):
import math

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

if abs(x) - abs(k*d) > 0: 
    if x > 0:
        print(abs(x - k*d))
    else:
        print(abs(x + k*d))
else: 
    r = math.floor(abs(x)/d)
    if x > 0:
        p = x - r*d
        if (k - r) % 2 == 0:
            print(abs(p))
        else:
            print(abs(p-d))
    elif x < 0:
        p = x + r*d
        if (k - r) % 2 == 0:
            print(abs(p))
        else:
            print(abs(p+d))
    else:
        if k % 2 == 0:
            print(0)
        else:
            print(abs(d))

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

x = abs(x)

if d*k > x:
    m = x//d
    pos = x - m*d
    neg = d*(m+1)-x
    if abs(k - m) % 2 == 0:
        print(pos)
    else:
        print(neg)
else:
    print(x - d*k)

Solution (Python):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18


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






X = abs(X)
n = X // D + 1

if n >= K:
    answer = abs(abs(X) - D * K)
else:
    answer = abs(abs(X) - D * n)
    K -= n
    
    if K % 2:
        answer = abs(answer - D)
        
print(answer)

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

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

Solution (Python):
import math
X, K, D = map(int, input().split())

if X < 0:
    X = -1*X

M = math.ceil(X/D)
right = abs(X-(M-1)*D)
left = abs(X-M*D)

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

if right <= left:
    if (M-1)%2 == K%2:
        print(right)
    else:
        print(left)
else:
    if M%2 == K%2:
        print(left)
    else:
        print(right)

Solution (Python):
xkd=input().split()
x=int(xkd[0])
k=int(xkd[1])
d=int(xkd[2])

ans = abs(x + k*d)
ans = min(ans, abs(x - k*d))

pos = x%d

if (abs(x-pos) // d) % 2 == k % 2 and k >= abs(x-pos)//d: ans=min(ans, pos)

negpos = pos - d

if(abs(x-negpos) // d) % 2 == k % 2 and k >= abs(x-negpos)//d: ans=min(ans,abs(negpos))

print(ans)

Solution (Python):


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

if X+K*D<=0:
  answer = -X-K*D
elif X-K*D>=0:
  answer = X-K*D
else:
  r = (X+K*D)%(2*D)
  if r>=2*D-r:
    answer = 2*D-r
  else:
    answer = r

print(answer)

Solution (Python):
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    x, k, d = mi()
    x = abs(x)
    if k % 2 == 1:
        x -= d
        x = abs(x)
        k -= 1
    d2 = 2 * d
    kaisuu = x // d2
    k //= 2
    if kaisuu <= k:
        k -= kaisuu
        x -= kaisuu * d2
    else:
        x -= d2 * k
        print(x)
        exit()
    if abs(x - d2) < x and k > 0:
        print(abs(x - d2))
    else:
        print(x)


main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
input = sys.stdin.readline
X,K,D = map(int,input().split())

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

Solution (Python):
import sys
input = sys.stdin.readline

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

if X<0:
    X=-X

A=X//D

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

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

Solution (Python):


from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))


def main():
	X, K, D = getlist()
	if X - K * D >= 0:
		print(X - K * D)
	elif X + K * D <= 0:
		print(abs(X + K * D))

	else:
		X = abs(X)
		K -= X // D
		X = X % D

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



if __name__ == '__main__':
	main()

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

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

Solution (Python):
x, k, d = map(int, input().split())
if x < 0:
    x = -x

if k * d <= x:
    print(x - k * d)
else:
    steps, x = divmod(x, d)
    k -= steps
    k %= 2
    if k == 0:
        print(x)
    else:
        print(abs(x - d))

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

if abs(X) >= K * D:  print(abs(X) - K * D)
else:
    if X >= 0:
        ans1 = X % D
        ans2 = abs(ans1 - D)
        m = X // D
    else:
        ans1 = (-X % D)
        ans2 = -ans1 + D
        m = -X // D

    if (K - m) % 2 == 0:  print(ans1)
    else:  print(ans2)

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def solve(x, k, d):
    if x - k * d >= 0:
        return x - k * d
    else:
        j = x // d
        xj = abs(x - d * j)
        xj1 = abs(x - d * (j + 1))
        rem = k - j
        if rem % 2 == 0:
            return xj
        else:
            return xj1
        
    

def main():
    from builtins import int, map
    X, K, D = map(int, input().split())
    if X < 0:
        X *= -1
    print(solve(X, K, D))


if __name__ == '__main__':
    main()

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

if abs(X) >= K * D:
  if X > 0:
    ans = X - K * D
  else:
    ans = X + K * D
  print(abs(ans))
else:
  count = int(abs(X) / D)
  if X > 0:
    one = X - D * count
    two = one - D
    if (K - count) % 2 == 0:
      print(abs(one))
    else:
      print(abs(two))
  else:
    one = X + D * count
    two = one + D
    if (K - count) % 2 == 0:
      print(abs(one))
    else:
      print(abs(two))

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

l = X - K * D
r = X + K * D


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

Solution (Python):
def main():
    X, K, D = map(int, input().split())
    X = abs(X)
    cnt = X // D
    if cnt >= K:
        print(X - (K * D))
        exit()
    
    if cnt % 2 == K % 2:
        print(X - (cnt * D))
    else:
        print(abs(X - ((cnt + 1) * D)))




if __name__ == "__main__":
    main()

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

k = abs(X // D)
r = X % D

if k <= K:
    K -= k
    X = r
    if K % 2 == 0:
        print(r)
    else:
        print(abs(r - D))
else:
    print(abs(X) - K * D)

Solution (Python):
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy


MOD = 10 ** 9 + 7



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

Solution (Python):
x, k, d = map(int, input().split())
x = abs(x)

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

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

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

mod = x % d
mod_d = d - mod

if x >= 0:
    if x - d * k >= 0:
        print(x - d * k)
    else:
        k -= (x - mod) // d
        if k % 2 == 0:
            print(mod)
        else:
            print(mod_d)
    
else:
    if x + d * k <= 0:
        print(abs(x + d * k))
    else:
        k -= (-x + mod) // d
        if k % 2 == 0:
            print(mod)
        else:
            print(mod_d)

Solution (Python):
import copy
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    x,k,d=INTM()
    if abs(x)-k*d>0:
        flg=1
        ans=abs(x)-k*d
    else:
        flg=2
        a=x%d
        b=a-d
        
        if (k-((x-a)//d))%2==0:
            flg=3
            ans=abs(a)
        else:
            flg=4
            ans=abs(b)
            
    print(ans)
    
    
    
    
if __name__ == '__main__':
    do()

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

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

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

x,k,d=mp()
x=abs(x)
if k*d<=x:
    print(x-k*d)
    exit()
y=x//d
if (k-y)%2==1:
    print(abs(x-d*(y+1)))
else:
    print(abs(x-d*y))

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

Solution (Python):
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)

Solution (Python):
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    X, K, D = mi()

    if X < 0:
        n = -X // D
        if n >= K:
            print(abs(X+K*D))
            return
        print(abs(X+(n+(K-n)%2)*D))
    else:
        n = X // D
        if n >= K:
            print(abs(X-K*D))
            return
        print(abs(X-(n+(K-n)%2)*D))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline

def solve():
    X, K, D = map(int, readline().split())

    X = abs(X)

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

solve()

Solution (Python):
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])

Solution (Python):
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)))

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

if X >= 0:
    num = min(K, X//D)
    X -= num*D
    K -= num
    if K%2:
        X -= D
else:
    num = min(K, abs(X)//D)
    X += num*D
    K -= num
    if K%2:
        X += D

print(abs(X))

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

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

kaisu = abs(x) // d

if kaisu >= k:
    print(abs(x) - k * d)
else:
    left = k - kaisu
    if left % 2 == 0:
        print(abs(x) % d)
    else:
        print(abs((abs(x) % d) - d))

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

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

if(x<0):
    x *= -1

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

Solution (Python):

import sys
input = sys.stdin.readline

x, k, d = map(int, input().split())
x = abs(x)
init = x // d
x -= min(init, k) * d
k -= min(init, k)

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

Solution (Python):
LI = lambda: list(map(int, input().split()))

X, K, D = LI()


def main():
    x = abs(X)
    a = x // D
    if K <= a:
        ans = x - K * D
        print(ans)
        return
    
    x -= a * D
    k = K - a
    if k % 2 == 0:
        ans = x
    else:
        ans = abs(x - D)
    print(ans)
    
    
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    x,k,d = map(int,input().split())
    if x>0:
        mv = x//d
        if mv<k:
            x = x - mv*d
            k = k - mv
        else:
            print(x - k*d)
            return
        if k%2==0:
            print(abs(x))
        else:
            print(abs(x-d))
    else:
        mv = -1*x // d
        if mv < k:
            x = x + mv * d
            k = k-mv
        else:
            print(abs(x + k*d))
            return
        if k % 2 == 0:
            print(abs(x))
        else:
            print(abs(x+d))

if __name__ == "__main__":
    main()

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


x,k,d = m()

if abs(x) >= abs(d) * k:
    print(abs(x) - (abs(d) * k))
else:
    po = abs(x) // abs(d)
    if (k - po) % 2 == 0:
        print(abs(abs(x) - po*abs(d)))
    else: 
        popo = po + 1
        print(abs(abs(x) - popo*abs(d)))

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

x,k,d = lr()
dis = abs(x)
if k*d < dis:
    print(dis-k*d)
else:
    tmp = dis//d
    ret = k-tmp
    if ret%2 == 0:
        print(dis-tmp*d)
    else:
        print(abs(dis-(tmp+1)*d))

Solution (Python):
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:
    x_greedy = x - k * d
else:
    x_greedy = x + k * d

if sgn(x) == sgn(x_greedy):
    print(abs(x_greedy))
    exit()
x_r = x % d
x_l = x_r - d

r_parity = (abs(x - x_r) // d) % 2

if k%2 == r_parity:
    print(abs(x_r))
else:
    print(abs(x_l))

Solution (Python):

import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(X, K, D):
    X = abs(X)
    n = X // D
    if n > K:
        return  abs(X-D*K)

    return abs(X-(n + (K-n) % 2) * D)


def main():
    X, K, D = read_int_n()
    print(slv(X, K, D))


if __name__ == '__main__':
    main()

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

X = abs(X)

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

K -= X//D
X %= D
if K % 2 == 1:
    X = D-X
print(X)

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

k = (D*K-X)//(2*D)
ans = min(abs(X+D*K), abs(X-D*K))
for i in range(k-10, k+10):
  if 0<=i<=K:
    ans = min(ans, abs(X+i*D-(K-i)*D))
print(ans)

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

l_ast = (K*D-X) / (2*D)

def dist(l):
    return abs(X+2*l*D-K*D)

if l_ast > K:
    d = dist(K)
elif l_ast < 0:
    d = dist(0)
else:
    l_ = int(l_ast)
    if l_ast - l_ < 0.5:
        d = dist(l_)
    else:
        d = dist(l_+1)
print(d)

Solution (Python):
x,k,d=map(int,input().split())
if abs(k*d)<=abs(x):
    print(abs(x)-abs(k*d))
else:
    moves = abs(x//d)
    ans=abs(x%d)
    left=k-moves
    if left%2:
        print(abs(d-ans))
    else:
        print(ans)

Solution (Python):
def examA():
    S = SI()
    ans = 0
    if "R" in S:
        ans = 1
    if "RR" in S:
        ans = 2
    if "RRR" in S:
        ans = 3
    print(ans)
    return

def examB():
    N = I()
    L = LI()
    L.sort()
    cnt = 0
    for i in range(N):
        for j in range(i+1,N):
            for k in range(j+1,N):
                if L[i]==L[j]:
                    continue
                if L[j]==L[k]:
                    continue
                if L[i]+L[j]>L[k]:
                    cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    X, K, D = LI()
    if X<0:
        X = -X
    ans = inf
    if X>K*D:
        ans = X-K*D
        print(ans)
        return

    K -= X//D
    X -= D * (X//D)

    ans = X
    if K>0:
        if K%2==1:
            ans = abs(X-D)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
x, k, d = map(int, input().split())
flip = x < 0
if flip:
    x = -x
if x >= k * d:
    ans = x - k * d
else:
    if k % 2:
        x -= d
        k -= 1
    ans = min(x % (2 * d), 2*d - x % (2*d))
    
print(ans)

Solution (Python):
X, K, D = [int(_) for _ in input().split()]
X = abs(X)
if X - K * D >= 0:
    ans = X - K * D
else:
    c1, ans = divmod(X, D)
    c2 = (K - c1) % 2
    if c2:
        ans = abs(ans - D)
print(ans)

Solution (Python):
from math import ceil
X,K,D=map(int,input().split())


if abs(X)-K*D>=0:
    print(abs(abs(X)-D*K))
else:
    cnt=ceil(abs(X)/D)

    dist_1= -(abs(X)-cnt*D)
    dist_2= abs(X)-(cnt-1)*D


    remain_hop=K-cnt

    if remain_hop%2==0:
        print(dist_1)
    else:
        print(dist_2)

Solution (Python):
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()