peterverebics/CodeNet_Python_118 huggingface dataset:
s = input()
if s == "RRR":
  print(3)
elif s == "RRS" or s == "SRR":
  print(2)
elif s == "RSR" or s == "RSS" or s == "SSR":
  print(1)
else:
  print(0)
s = str(input())
if s == "rrs" or s == "srr":
    print('2')
elif s == "rrr":
    print('3')
elif s == "sss":
    print('0')
else:
    print('1')
w=input()
count=0

for i in range(len(w)):
 if w[i]=="R":
  count+=1
 if w[i]=="S":
  if i==1:
    count=0

print(count)
S = input()
c = 0
ans = 0
for i in range(3):
  if S[i] == 'R':
    c+=1
  else:
    ans = max(c,ans)
print(ans)
s=input()
if s=='RRR':
    print(0)
elif s=='SSS':
    print(3)
elif s in ['RRS','SRR']:
    print(2)
else:
    print(1)
def main():
    s = input()
    cnt = 0
    cnt2 = 0
    for i in s:
        if i == "R":
            cnt2 += 1
        else:
            cnt = max(cnt, cnt2)
            cnt2 = 0
    print(cnt)


main()
def solve(x):
  if x.count("RRR"):
    return 3
  if x.count("RR"):
    return 2
  if x.count("R"):
    return 1

x = input()
print(solve(x))
L = [s for s in input()]
if not 'R' in L:
  print(0)
elif not 'S' in L:
  print(3)
elif L[1] == 'S':
  if 'R' in L :
    print(1)
else:
  print(2)
s = list(input())

if s[0] == 'R':
  if s[1] != 'R':
    print(1)
  else:
    if s[2] == 'R':
      print(3)
    else:
      print(2)
else:
  if 'R' not in s:
    print(0)
  elif s == ['R', 'R']:
    print(2)
  else:
    print(1)
a = str(input())
count = 0
 
for i in a:
  if i == 'R':
    count += 1
  else:
    count = 0
  answer = count
 
print(answer)
s=input()
print(max(s.count('R')-(s[1]=='S'),0))
import sys
read = sys.stdin.readline
import time
from heapq import heappush, heappop
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

x, k, d = inpl()

t = abs(x) // d

if k <= t:
    print(abs(x)-k*d)
    sys.exit()

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

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)
X, K, D = map(int, input().split())

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

mod = abs(X) % D
if (K - (abs(X) // D)) % 2 == 0:
    print(mod)
else:
    print(abs(mod - D))
X,K,D = map(int,input().split())
if X > 0:
  if X // D >= K:
    ans = X - D*K
  else:
    K -= X//D
    X = X%D
    if K%2 == 0:
      ans = X
    else:
      ans = abs(X -D)
if X < 0:
  if -1*X // D >= K:
    ans = abs(X + D*K)
  else:
    K -= (-1*X)//D
    X = (-1*X)%D
    if K%2 == 0:
      ans = X
    else:
      ans = abs(X -D)
if X == 0:
  if K%2==0:
    ans = 0
  else:
    ans = D
print(ans)
# cook your dish here
x,k,d=map(int,input().split())
l=0
r=k
while (l<r-1):
    m=l+(r-l)//2
    if(x-k*d+2*m*d>0): r=m
    else: l=m
ans1=x-k*d+2*l*d;
ans2=x-k*d+2*r*d;
print(min(abs(ans1),abs(ans2)))
x, k, d = map(int, input().split())
x = abs(x)
if x >= k * d:
    print(x - k * d)
else:
    cnt = x // d
    if cnt % 2 == k % 2:
        point = x - x // d * d
    else:
        point = x - (x // d + 1) * d
    print(abs(point))
def main():
    X,K,D=map(int,input().split())

    zero_flag=0
    if abs(X)>=K*D:
        zero_flag=1

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

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

x=x if x>0 else -x
print(x-k*d if k<=x//d else (d-x%d if (k-x//d)%2 else x%d))
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    X, K, D = iim()

    r = 1
    if X < 0:
        r = -1
        X = -X
    a, b = divmod(X, D)

    diff = K - a
    if diff <= 0:
        print(abs(r*(X - K*D)))
        return

    if diff & 1:
        b -= D

    print(abs(r*b))



if __name__ == "__main__":
    resolve()
#!/usr/bin/env python3
def main():
    X, K, D = map(int, input().split())

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


if __name__ == '__main__':
    main()
xkd = input().split()
X = int(xkd[0])
K = int(xkd[1])
D = int(xkd[2])

X = abs(X)
ans = 0
times = int(X/D)
oneMore = False
if X%D > abs(D-X%D):
    times+=1

if times > K:
    ans = X - (D*K)
else:
    if (times%2) == (K%2):
        ans = min(X%D, (D-X%D))
    else:
        ans = max(X%D, (D-X%D))

print(ans)
x, k, d = map(int, input().split())
x = abs(x)
# x > 0のとき
left = abs(x - d * (x // d + 1))
right = abs(x - d * (x // d))

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

if (k - (x // d)) % 2 == 0:
    print(right)
else:
    print(left)
import math
x, k, d = map(int, input().split())
p = math.floor(abs(x/d))
if x > 0:
    if p >= k: print(abs(x-k*d))
    elif (k-p)%2==1: print(abs(x-(p+1)*d))
    else: print(abs(x-p*d))
else:
    if p >= k: print(abs(x+k*d))
    elif (k-p)%2==1: print(abs(x+(p+1)*d))
    else: print(abs(x+p*d))
x,k,d = map(int,input().split())
x = abs(x)
i = int(x / d)
if k < i:
  print(x - k * d)
  exit()
if (k - i) % 2 == 0:
  print(x - i * d)
  exit()
print(abs(x - (i + 1) * d))
x, k, d = map(int, input().split())
x = abs(x)

if x >= k*d:
    ans = x - k*d
elif k&1:
    ans = min((x-d)%(2*d), 2*d - (x-d)%(2*d) )
else:
    ans = min(x%(2*d), 2*d - x%(2*d))

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

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

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

if k * d <= x:
    print(x - k * d)
else:
    k -= x//d
    x %= d
    if k % 2 == 0:
        print(x)
    else:
        print(abs(x-d))
X, K, D = map(int,input().split())
XX = abs(X)
if K > XX // D:
    if (K - (XX // D)) % 2 == 0:
        ans = XX - (XX // D) * D
        print(abs(ans))
    else:
        ans = (XX - (XX // D) * D) - D
        print(abs(ans))
else:
    ans = XX - D * K
    print(abs(ans))
X,K,D=map(int,input().split())
if abs(X)>=K*D:
    print(abs(X)-K*D)
else:
    if K%2==abs(X)//D%2:
        print(abs(X)%D)
    else:
        print(D-abs(X)%D)
X, K, D = map(int,input().split())
res = 0
X = abs(X)
if X >= K * D:
    res = X - K * D
else:
    i = X // D
    j = K - i
    if j % 2 == 0:
        res = X - D * i
    else:
        res = X - D * (i + 1)
print(abs(res))
from sys import exit, stdin

# import copy
# from collections import deque,Counter
# import numpy as np
input = stdin.readline

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

if abs(X) >= K * D:
    print((abs(X) - K * D))
else:
    A1 = abs(X) % D
    A2 = abs(A1 - D)
    n = int((abs(X) - A1)/D)
    if (K - n) % 2 == 0:
        print(A1)
    else:
        print(A2)
x, k, d = 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)
x,k,d = map(int, input().split())

x = abs(x)
div,mod = divmod(x,d)

cnt = min(k,div)
k -= cnt
ans = x - cnt * d

if k > 0:
    ans -= (k%2) * d

print(abs(ans))
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    X, K, D = map(int, input().split())

    d, m = divmod(X, D)
    if abs(d) >= K:
        print(abs(abs(X) - (K * D)))
    else:
        if (K - d) % 2:
            print(D - m)
        else:
            print(m)


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

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

new_X = abs(X) % D
new_K = K - abs(X) // D

if new_K % 2 == 0:
    print(new_X)
else:
    print(abs(new_X-D))
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
    print(x-k*d)
else:
    p=x//d
    if p%2==k%2:
        print(x-p*d)
    else:
        print(abs(x-(p+1)*d))
import math
x,k,d=map(int,input().split())
x1=abs(x)
if k*d<x1:
    print(x1-k*d)
else:
    a=math.ceil(x1/d)
    if (k-a)%2==0:
        print(abs(x1-d*a))
    else:
        print(abs(x1-d*(a-1)))
X, K, D = map(int, input().split())

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

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

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

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

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

x=abs(x)

cnt=abs(x)//d


if cnt>=k:
    print(x-d*k)
else:
    k-=cnt

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

ans = 0
if k * d < abs(x):
    if x >= 0:
        ans = x - k*d
    else:
        ans = x + k*d
    print(abs(ans))
    exit()
    
xd = x // (2*d)
if k % 2:
    tmp = x - 2*d*xd
    l = [abs(tmp-d), abs(tmp+d), abs(tmp+3*d)]
    ans = min(l)
else:
    tmp = x - 2*d*xd
    l = [abs(tmp-2*d), abs(tmp), abs(tmp+2*d)]
    ans = min(l)
print(ans)
it = lambda: list(map(int, input().strip().split()))

def solve():
    X, K, D = it()
    X = abs(X)
    if X - K * D >= 0:
        return X - K * D
    K = K - X // D
    X = X - X // D * D
    assert K >= 0
    assert X >= 0
    return abs(X) if K % 2 == 0 else abs(X - D)


if __name__ == '__main__':
    ans = solve()
    print(ans)
x,k,d = map(int,input().split())
c = abs(x)//d
if c < k:
    if (k-c) % 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)
input_line = input().split()
x = int(input_line[0])
k = int(input_line[1])
d = int(input_line[2])

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

if y < k:
  x -= y * d
  if (k-y) % 2 == 1:
    x -= d

else:
  x -= k*d
    
print(abs(x))
x, k, d = map(int, input().split())

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

ans = None

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

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

if ref >= K:
    ans = abs(X) - K * D
else:
    ans = abs(X) - ref * D
    K = K - ref
    if K % 2 == 1:
        ans = abs(ans - D)
    else:
        pass

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

minimum = x - d * k
maximum = x + d * k

if minimum >= 0:
    print(minimum)
elif maximum <= 0:
    print(-maximum)
else:
    c1 = maximum % (2*d)
    c2 = c1 - 2*d
    print(min(abs(c1), abs(c2)))
x,k,d = map(int,input().split())
x = abs(x)
q,mod = divmod(x,d)
if k <= q:
    ans = x - k*d
else:
    ans = mod
    ans -= (k-q)%2*d
print(abs(ans))
x,k,d=map(int,input().split())
x=abs(x)
c=x//d
if k<=c:
  print(abs(x-k*d))
else:
  f=x-c*d
  k-=c
  if f>0:
    if k%2==1:
      print(abs(f-d))
    else:
      print(abs(f))
  if f<0:
    if k%2==1:
      print(abs(f+d))
    else:
      print(abs(f))
  if  f==0:
    if k%2==1:
      print(abs(f+d))
    else:
      print(0)
x,k,d=map(int, input().split())
x=abs(x)
if x/k >= d:
  print(x-d*k)
elif (k-int(x/d))%2==0:
  print(abs(x-int(x/d)*d))
else:
  print(abs(x-int(x/d)*d-d))
x,k,d = map(int,input().split())
x = abs(x)
if x//d > k:
  print(x-k*d)
elif (k-x//d)%2 == 0:
  print(x%d)
else:
  print(d-x%d)
X, K, D = map(int, input().split())
X = abs(X)

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

print(ans)
startX, countK, distanceD = map(int, input().split())
n = int(abs(startX) / distanceD)
ans = abs(startX) % distanceD
if n > countK:
    ans += distanceD * (n - countK)
else:
    if (countK - n) % 2 == 1:
        ans= abs(ans - distanceD)
print(ans)
X, K, D = map(int, input().split())

X = abs(X)

K_main = X // D
K_sub = K - K_main

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

k = X // D
if abs(X - k * D) <= abs(X - (k + 1) * D):
    best_k = k
else:
    best_k = k + 1

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

if q <= K:
    if (K-q)%2==0:
        ans=mod
    else:
        ans=D-mod
else:
    ans=X-K*D
print(ans)
X,K,D=map(int,input().split())
X=max(X,-X)

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

x = abs(x)

if x >= k * d:
    print(x - k * d)
else:
    div, mod = divmod(x, d)
    if (k - div) % 2 == 0:
        print(mod)
    else:
        print(abs(mod - d))
x, k, d = map(int, input().split())
if x >= 0:
    if x//d >= k:
        print(abs(x - k*d))
    else:
        if (k - x//d)%2 == 0:
            print(abs(x%d))
        else:
            print(abs(x%d - d))
else:
    if abs(x)//d >= k:
        print(abs(x + k*d))
    else:
        if (k - abs(x)//d)%2 == 0:
            print(abs(x)%d)
        else:
            print(d - abs(x)%d)
def main():
    x, k, d = map(int, input().split())
    y = abs(x) // d
    if y == k:
        print(abs(x) % d)
    elif y < k:
        if (k-y) % 2 == 0:
            print(abs(x) % d)
        else:
            print(min(abs(abs(x) % d - d), abs(abs(x) % d + d)))
    else:
        print(min(abs(abs(x)-d*k), abs(abs(x)+d*k)))




if __name__ == '__main__':
    main()
X,K,D=map(int,input().split())
X=abs(X)
if X-K*D>=0:
    print(X-K*D)
else:
    d,m=divmod(X,D)
    if (K-d)%2==0:
        print(m)
    else:
        print(abs(m-D))
x,k,d=map(int,input().split())
x=abs(x)
if x>=k*d:
    print(x-k*d)
else:
    cnt=x//d
    if (k-cnt)%2==0:
        print(x-cnt*d)
    else:
        print(abs(x-(cnt+1)*d))
L=list(map(int,input().split()))
X,K,D = abs(L[0]),L[1],L[2]
Y = X-K*D
W = (K-X//D)%2
if Y >= 0:
    Z = Y
elif Y < 0:
    if W == 1:
        Z = D - X % D
    else:
        Z = X % D
print(Z)
X, K, D = map(int, input().split())
X = abs(X)
if K * D <= X:
    ans = X - K * D
else:
    k = K - X // D
    if k % 2 == 0:
        ans = X % D
    else:
        ans = abs(X % D - D)
print(ans)
x, k, d = map(int, input().split())

if abs(x) - k * d > 0:
    print(abs(x) - k * d)
else:
    kk = abs(x) // d
    l = (k - kk) % 2
    print(abs(abs(x) - (kk + l) * d))
x,k,d = map(int,input().split())
n = abs(x)//d
if n>k:
  ans = min(abs(x-k*d),abs(x+k*d))
else:
  ans = min(abs(x+min(k,n)*d),abs(x-min(k,n)*d))
  if (k-n)%2:
    ans = min(abs(ans-d),abs(ans+d))
print(ans)
x,k,d=map(int,input().split())
x=abs(x)
ans=10**15
r=x//d
if x>=d*k:
  ans=x-d*k
else:
  k-=r
  if k%2==0:
    ans=abs(x-d*r)
  else:
    ans=abs(x-d*(r+1))
print(ans)
x,k,d = map(int,input().split())

min_p = abs(x)//d
min_n = min_p + 1
rest_p = abs(x)- d*min_p
rest_n = rest_p - d

if k < min_p:
  print(abs(x) - k*d)
elif (k-min_p) % 2 == 0:
  print(rest_p)
else:
  print(abs(rest_n))
x, k, d = map(int, input().split())

if x < 0:
    flag = -1
else:
    flag = 1

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

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

X = abs(X)
ans = 0
if X - K*D >= 0:
  ans = X - K*D
else:
  count = X // D
  K = K - (X // D)
  if K % 2 == 0: 
    ans = X - count*D
  else: 
    ans = D - (X - count*D)
    
print(ans)
import math

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

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

ans1 = start % step
ans2 = abs(ans1 - step)
if (kai - abs(start // step)) % 2 == 0:
    print(abs(ans1))
else:
    print(abs(ans2))
import sys
input = sys.stdin.readline

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

if k < tmp:
  result = abs(abs(x) - d*k)
elif tmp%2 == k%2:
  result = abs(abs(x) - d*tmp)
else:
  a = result = abs(abs(x) - d*tmp)
  result = abs(abs(a) - d)

print(result)
x,k,d = map(int,input().split())
x = abs(x)
if x <= k * d:
    k -= x//d
    x %= d
    if k % 2 == 1:
        print(d-x)
    else:
        print(x)
else:
    print(x-k*d)
X,K,D=map(int,input().split())
if D*K<abs(X):
  print(abs(X)-D*K)
else:
  K2=abs(X)//D
  if K2>K:
    K2=K
  if (K-K2)%2==0:
    print(abs(X)-K2*D)
  else:
    ans=min(abs(X)-(K2-1)*D, (K2+1)*D-abs(X))
    print(ans)
X, K, D = [int(x) for x in 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)
X, K, D = map(int, input().split())
X = abs(X)

a, b = divmod(X, D)
# print(f'{a=}, {b=}')

if a >= K:
    ans = X - K * D
    ans = abs(ans)
    print(ans)
    exit()

_K = K - a
# print(f'{_K=}')
if _K % 2 == 0:
    ans = b
else:
    ans = abs(b - D)
print(ans)
X, K, D = map(int, input().split())

num = abs(X)//D
if num >= K:
    X = abs(X) - K*D

else:
    if num%2 == K%2:
        X = abs(X) - D*num
    else:
        X = abs(X) - D*(num+1)
        
print(abs(X))
x, k, d = map(int,input().split())
if x < 0: x = -x
mv = x // d
if mv >= k:
    # なるべく0に近づけば良い
    print(abs(x)-d*k)
else:
    nearest = x % d
    if (k - mv) % 2 == 1:
        print(abs(nearest - d))
    else:
        print(nearest)
x,k,d = map(int,input().split())

ab = abs(x)//d
ab_1 = ab +1

koho1 = abs(x) - abs(d*ab)
koho2 = abs(abs(x) -abs(d*ab_1))

tmp = k-ab

koho_s = []

if(tmp > 0):
    if(tmp%2 == 0):
        ans = koho1
    else:
        ans = koho2
elif(tmp == 0):
    ans = koho1
else:
    ans = abs(x) - abs(d*k)

print(ans)
import math
import sys

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

a = X - K * D
if a > 0:
    print(a)
    sys.exit()
if a + 2 * K * D < 0:
    print(abs(a + 2 * K * D))
    sys.exit()
else:
    b = a / (-2 * D)
    p = math.floor(b)
    q = math.ceil(b)
    r = -(a + 2 * D * p)
    s = a + 2 * D * q
    print(min(r,s))
    sys.exit()
X, K, D = map(int, input().split())
s = (abs(X) // D)
t = abs(abs(X) - D*s)
u = abs(abs(X) - D*(s+1))
if abs(X) > (K*D):
    print(abs(X) - K*D)
else:
    if (K-s) % 2 == 0:
        print(t)
    else:
        print(u)
x,k,d=map(int,input().split())
x=abs(x-0)
if (x-(k*d))>0:
    print((x-(k*d)))
else:
    k1=0
    k1=x//d
    k-=k1
    a=(x-(k1*d))
    if k%2==0:
        print(a)
    else:
        print(abs(a-d))
X, K, D = map(int, input().split())

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

def f(a):
  return abs(x + d * (k - 2 * a))

if p > k or p < 0:
  print(min(f(0), f(k)))
else:
  print(min(f(p), f(p + 1)))
x,k,d=map(int,input().split())
if x<0:
    x=-x

if x>=k*d:
    print(x-k*d)
else:
    c=x//d
    x_r=x-d*c
    x_l=x-d*(c+1)
    k=k-c
    if k%2==1:
        print(abs(x_l))
    else:
        print(x_r)
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)
#!/usr/bin/env python3
x, k, d = map(int, input().split())
x = abs(x)
if (n := k - x // d) < 0:
    print(x - k * d)
else:
    print(abs(d - x % d) if n % 2 else x % d)
X, K, D = map(int, input().split())
X = abs(X)

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

K -= X//D

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

if k2%2 == 0:
    print(x%d)
else:
    print(abs(x%d-d))
import math
X, K, D = map(int, input().split())
X = abs(X) 

mini = math.ceil(X/D)

if mini >= K:
    print(abs(X-D*K))
else:
    if (K-mini)%2 == 0:
        print(abs(X-D*mini))
    else:
        print(X-D*(mini-1))
import sys
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


from itertools import combinations
from collections import Counter as cc
def main():
    x, k , d = mi()
    x = abs(x)
    ans = max(x%d, x-k*d)
    k -= x//d
    if k > 0 and k%2 == 1:
        ans = abs(ans-d)
    print(ans)
    





if __name__ == '__main__':
    main()
X, K, D = map(int, input().split())
X = abs(X)
D = abs(D)
if X > K * D:
    X = X - K*D
else:
    quo = X//D
    X = X - D*quo
    res = K - quo
    if res % 2 == 1:
        X = X - D
    else:
        pass

print(abs(X))
x,k,d=map(int,input().split())
x =abs(x)
o =x//d
if (x-d*k) >=0:
    print(x-d*k)
    exit()
else:
    if (k-o)%2==0:
        print(abs(x%d))
        exit()
    else:
        print(abs(x%d-d))
        exit()
x, k, d = map(int,input().split())
max_length = k * d
xx = abs(x)
answer = 0
if xx >= max_length:
    answer = xx - max_length
else:
    if (k - xx // d) % 2 == 0:
        answer = xx - xx // d * d
    else:
        answer = xx - (xx // d + 1) * d
print(abs(answer))
start, num_move, distance = map(int, input().split())

# move toward
desired_move = abs(start) // distance

another_move = num_move - desired_move
if another_move <= 0:
    ans_abs = abs(start) - num_move * distance
    print(ans_abs)

else:
    if another_move % 2 == 0:
        ans_abs = abs(start) - desired_move * distance
        print(ans_abs)
    else:
        ans_abs = abs(abs(start) - (desired_move+1) * distance)
        print(ans_abs)
X, K, D = map(int, input().split())

sho = abs(X)//D
amari = abs(X) % D

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

if sho % 2 == K % 2:
    print(amari)
else:
    print(D - amari)
X, K, D = list(map(int, input().split()))

X = abs(X)
count = X // D

if count >= K:
    answer = X - K*D
else:
    if (K - count) % 2 == 0:
        answer = X - count*D
    else:
        answer = abs(X - (count+1)*D)

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

print(ans)
def main():
    x, k, d = map(int, input().split())
    if x < 0: x = -x

    if k * d <= x:
        print(x - k*d)
        return

    x %= d + d
    if k % 2 == 1:
        x -= d
    else:
        x = min(abs(x-d-d), x)

    print(abs(x))

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

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