qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
s = int(input())

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

ans = 0
for i in range(x):
    Box = i + 1
    Nokori = s - 3 * Box
    ans_ = cmb(Nokori + Box - 1, Box - 1) 
    ans += ans_
print(ans % (10 ** 9 + 7))

# Fixed code:
s = int(input())

x = s // 3

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

ans = 0
for i in range(x):
    Box = i + 1
    Nokori = s - 3 * Box
    ans_ = cmb(Nokori + Box - 1, Box - 1) 
    ans += ans_
print(ans % (10 ** 9 + 7))
# Buggy code:
#D
s = int(input())

num = [0,0,1]
for i in range(s-3):
    num = [num[1],num[2],num[0]+num[2]]
    #print(num)
    
print(num[2]%(10**9+7))

# Fixed code:
#D
s = int(input())

num = [1,0,0]
for i in range(s-2):
    num = [num[1],num[2],num[0]+num[2]]
    #print(num)
    
print(num[2]%(10**9+7))
# Buggy code:
MOD = 10**9 + 7
S = int(input())
dp = [0]*(S+1)
dp[0] = 1
dp[3] = 1
for i in range(4,S+1):
    for k in range(i-2):
        dp[i] += dp[k]
print(dp[S]%MOD)

# Fixed code:
MOD = 10**9 + 7
S = int(input())
dp = [0]*(S+4)
dp[0] = 1
dp[3] = 1
for i in range(4,S+1):
    for k in range(i-2):
        dp[i] += dp[k]
print(dp[S]%MOD)
# Buggy code:
def main():
    s = int(input())
    mod = 10**9 + 7

    dp = [0] * (s+1)
    dp[0] = 1
#    for i in range(1, s+1):
#        for j in range(0, (i-3)+1):
#            dp[i] += dp[j]
#            dp[i] %= mod
    for i in range(1, s+1):
        if i < 3:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-3]

    print(dp[-1])


if __name__ == "__main__":
    main()

# Fixed code:
def main():
    s = int(input())
    mod = 10**9 + 7

    dp = [0] * (s+1)
    dp[0] = 1
    for i in range(1, s+1):
        for j in range(0, (i-3)+1):
            dp[i] += dp[j]
            dp[i] %= mod
    print(dp[-1])


if __name__ == "__main__":
    main()
# Buggy code:
mod = (10 ** 9 + 7)
tot = 1
l = [1, 0, 0]
for i in range(3, 2000):
  nex = (tot - l[-1] - l[-2])
  tot = (tot + nex) 
  l.append(nex)
print(l[int(input())])

# Fixed code:
mod = (10 ** 9 + 7)
tot = 1
l = [1, 0, 0]
for i in range(2000):
  nex = (tot - l[-1] - l[-2]) % mod
  tot = (tot + nex) % mod
  l.append(nex)
print(l[int(input())])
# Buggy code:
import numpy as np

MOD = 10**9+7

n = int(input())
arr = np.zeros((n+1,n+1), dtype=np.int16)
for i in np.arange(3,n+1):
    arr[0,i] = 1

for i in np.arange(1,n+1):
    sum_ = 0
    for j in np.arange(3*i,n+1):
        sum_ += arr[i-1,j]
        sum_ %= MOD
        if j+3 >= n + 1:
            break
        arr[i,j+3] = sum_

ans = 0
for i in range(n+1):
    ans += arr[i,n]
    ans %= MOD
print(ans)








# Fixed code:
import numpy as np

MOD = 10**9+7

n = int(input())
arr = np.zeros((n+1,n+1), dtype=int)
for i in np.arange(3,n+1):
    arr[0,i] = 1

for i in np.arange(1,n+1):
    sum_ = 0
    for j in np.arange(3*i,n+1):
        sum_ += arr[i-1,j]
        sum_ %= MOD
        if j+3 >= n + 1:
            break
        arr[i,j+3] = sum_

ans = 0
for i in range(n+1):
    ans += arr[i,n]
    ans %= MOD
print(ans)
# Buggy code:
S = int(input())
mod = 10**9+7

ans = 0

x = [0]*(S+1)
x[3] = 1
x[4] = 1
x[5] = 1
for i in range(6, S+1):
    x[i] += 1
    for j in range(3, i-2):
        x[i] += x[j]
        x[i] %= mod

print(x[S])

# Fixed code:
S = int(input())
mod = 10**9+7

ans = 0

x = [0]*(2020)
x[3] = 1
x[4] = 1
x[5] = 1
for i in range(6, S+1):
    x[i] += 1
    for j in range(3, i-2):
        x[i] += x[j]
        x[i] %= mod

print(x[S])
# Buggy code:
def f(n):
  if n <= 1:
    return 1
  return f(n-1)*n
 
def h(n,m):
  return f(n+m-1)//f(n)//f(m-1)
 
s=int(input())
 
res = 0
 
pair = s//3
 
for i in range(1,pair+1):
  res += h(s-3*i,i)
print(res%(10**9+7))

# Fixed code:
def f(n):
  res = 1
  if n <= 1:
    return 1
  while n>1:
    res *= n
    n-=1
  return res
 
def h(n,m):
  return f(n+m-1)//f(n)//f(m-1)
 
s=int(input())
 
res = 0
 
pair = s//3
 
for i in range(1,pair+1):
  res += h(s-3*i,i)
print(res%(10**9+7))
# Buggy code:
S = int(input())
mod = 10**9+7
memo = [-1]*(S+1)
def redis(s):
  if memo[s] != -1:
    return memo[s]
  else:
    if s < 3:
      memo[s] = 0
      return 0
    elif s < 6:
      memo[s] = 1
      return 1
    else:
      tmp = 0
      for num in range(s):
        tmp += (redis(num)*redis(s-num))%mod
      memo[s] = tmp
      return tmp%mod
print(redis(S))
    



# Fixed code:
S = int(input())
mod = 10**9+7
memo = [-1]*(S+1)
memo[0] = 1
def redis(s):
  if memo[s] != -1:
    return memo[s]
  else:
    if s < 3:
      memo[s] = 0
      return 0
    elif s < 6:
      memo[s] = 1
      return 1
    else:
      tmp = 0
      for num in range(s-2):
        tmp += redis(num)%mod
      memo[s] = tmp
      return tmp%mod
print(redis(S))
# Buggy code:
n = int(input())
S = n//3

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * pow(i+1, mod-2, mod) % mod
    return res
 
ans = 0
if S>=1:
  for i in range(1,S+1):
    t = n - 3*i
    ans += combination(t+i-1,i-1)
  print(ans)
    
    
else:
  print(0)

# Fixed code:
n = int(input())
S = n//3
mod=10**9+7
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * pow(i+1, mod-2, mod) % mod
    return res
 
ans = 0
if S>=1:
  for i in range(1,S+1):
    t = n - 3*i
    ans += combination(t+i-1,i-1)
  print(ans%mod)
    
    
else:
  print(0)
# Buggy code:
from sys import stdin
input = stdin.readline

S = int(input())

A = [-1] * (S + 1)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))


# Fixed code:
from sys import stdin
input = stdin.readline

S = int(input())

A = [-1] * (2001)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))
# Buggy code:
import sys
import math,bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,OrderedDict
def I(): return int(sys.stdin.readline())
def neo(): return map(int, sys.stdin.readline().split())
def Neo(): return list(map(int, sys.stdin.readline().split()))
mod = 10**9+7
fact = [1]+[0]*(10**4)
for i in range(1,10**4):
    fact[i] = (i*fact[i-1])%mod
N = I()
if N < 3:
    print(0)
r = 1 
Ans = 0
while N-r*3 >= 0:
    n = N-3*r
    Ans += (fact[n+r-1]*pow(fact[n],mod-2,mod)*pow(fact[r-1],mod-2,mod))%mod
    Ans = Ans%mod
    r += 1
print(Ans)


# Fixed code:
import sys
import math,bisect
sys.setrecursionlimit(10 ** 5)
from collections import defaultdict
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,OrderedDict
def I(): return int(sys.stdin.readline())
def neo(): return map(int, sys.stdin.readline().split())
def Neo(): return list(map(int, sys.stdin.readline().split()))
mod = 10**9+7
fact = [1]+[0]*(10**4)
for i in range(1,10**4):
    fact[i] = (i*fact[i-1])%mod
N = I()
if N < 3:
    print(0)
    exit()
r = 1
Ans = 0
while N-r*3 >= 0:
    n = N-3*r
    Ans += (fact[n+r-1]*pow(fact[n],mod-2,mod)*pow(fact[r-1],mod-2,mod))%mod
    Ans = Ans%mod
    r += 1
print(Ans%mod)
# Buggy code:
s=int(input())
mod=10**9+7
dp=[0]*s
dp[0]=1

for i in range(0,s+1):
	dp[i]=dp[i-1]+dp[i-3]
	dp[i]%=mod

print(dp[s])



# Fixed code:
s=int(input())
mod=10**9+7
dp=[0]*(s+1)
dp[0]=1

for i in range(1,s+1):
	for j in range(0,(i-3)+1):
		dp[i]+=dp[j]
		dp[i]%=mod
print(dp[s])
# Buggy code:
s = int(input())
p = [1]*(s+1)
mod = 10**9 + 7

p[1] = 0
p[2] = 0
if s >= 3
	for i in range(3,s+1):
		p[i] = (sum(p[:i-2]))%mod
print(p[s])

# Fixed code:
s = int(input())
p = [0]*(s+1)
mod = 10**9 + 7
p[0] = 1

if s >= 3:
	for i in range(3,s+1):
		p[i] = (sum(p[:i-2]))%mod
print(p[s])
# Buggy code:
S = int(input())

dp = [0] * (S+1)

dp[0] = 1

for i in range(S+1):
  for j in range(0,(i-3)+1):
    dp[i] += dp[j]
    dp[i] %= 10**9+7

print(dp[-1] % 10**9+7)

# Fixed code:
mod = pow(10,9) + 7
S = int(input())

dp = [0] * (S+1)

dp[0] = 1

for i in range(S+1):
  for j in range(0,(i-3)+1):
    dp[i] += dp[j]
    dp[i] %= mod

print(dp[-1] % mod)
# Buggy code:
from operator import mul
from functools import reduce


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


N = int(input())
ans = 0
amari = int(N % 3)
shou = int(N // 3)

for i in range(shou):
    amari += 3
    shou -= 1
    ans = (ans + combinations_count((amari + shou - 1), amari)) % (10**9 + 7)
print(ans)


# Fixed code:
from operator import mul
from functools import reduce


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


N = int(input())
ans = 0
amari = int(N % 3)
shou = int(N // 3)

for i in range(shou):

    ans = (ans + combinations_count((amari + shou - 1), amari)) % (10**9 + 7)
    amari += 3
    shou -= 1
print(ans)
# Buggy code:
n=int(input())
mod=10**9+7

def kaijou(n):
  ans=1
  for i in range(1,n+1):
    ans*=i
    ans%=mod
  return ans%mod

k,t=divmod(n,3)
if t==0:
  ans=1
elif t==1:
  ans=k
else:
  ans=(kaijou(2+k-1)*pow(kaijou(k-1),mod-2,mod)*pow(kaijou(2),mod-2,mod))
bunpai=t
for i in range(k-1,0,-1):
  bunpai+=3
  ans+=(kaijou(bunpai+i-1)*pow(kaijou(i-1),mod-2,mod)*pow(kaijou(bunpai),mod-2,mod))
  ans%=mod
print(ans)

    

# Fixed code:
n=int(input())
mod=10**9+7

def kaijou(n):
  ans=1
  for i in range(1,n+1):
    ans*=i
    ans%=mod
  return ans%mod

k,t=divmod(n,3)
if n>=3:
  ans=(kaijou(t+k-1)*pow(kaijou(k-1),mod-2,mod)*pow(kaijou(t),mod-2,mod))
  bunpai=t
  for i in range(k-1,0,-1):
    bunpai+=3
    ans+=(kaijou(bunpai+i-1)*pow(kaijou(i-1),mod-2,mod)*pow(kaijou(bunpai),mod-2,mod))
    ans%=mod
  print(ans%mod)
else:
  print(0)
# Buggy code:
s = int(input())
import sys
p = 10**9+7
dp = [0]*100#2003
dp[2]=1
if s<=3:
    print(dp[s-1])
    sys.exit()
for i in range(3,s):
    dp[i] = (dp[i-1]%p+dp[i-3]%p)%p


print(dp[s-1])

# Fixed code:
s = int(input())
import sys
p = 10**9+7
dp = [0]*2003
dp[2]=1
if s<=3:
    print(dp[s-1])
    sys.exit()
for i in range(3,s):
    dp[i] = (dp[i-1]%p+dp[i-3]%p)%p


print(dp[s-1])
# Buggy code:
from decimal import *
x, k, d = map(Decimal, input().split())

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

# Fixed code:
from decimal import *
x, k, d = map(Decimal, input().split())

if x >= 0:
  if x-k*d >= 0:
    print(abs(x-k*d))
  else:
    if x//d%2 == k%2:
      print(abs(x%d))
    else:
      print(abs(d-x%d))
else:
  if x+k*d <= 0:
    print(abs(x+k*d))
  else:
    if -x//d%2 == k%2:
      print(abs(-x%d))
    else:
      print(abs(d+x%d))
# Buggy code:
x,k,d=[int(x) for x in input().split()]

print(x)

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

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

		k=k-num

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


# Fixed code:
x,k,d=[int(x) for x in input().split()]


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

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

		k=k-num

		if k%2==0:
			print(abs(x))
		else:
			print(min(abs(x-d),abs(x+d)))
# Buggy code:
x,k,d=map(int,input().split())

x=abs(x)
i=x//d

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

# Fixed code:
x,k,d=map(int,input().split())

x=abs(x)
i=x//d

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

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

print(ans)

# Fixed code:
x,k,d=map(int,input().split())

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

print(ans)
# Buggy code:
def resolve():
    X, K, D = list(map(int, input().split()))
    X = -X if X < 0 else X
    m = X//D
    if m < K and X%D > D-X%D:
        nmove = m+1
        print(D-X%D if (K-nmove)%2==0 else X%D)
    else:
        nmove = m
        print(X%D if (K-nmove)%2==0 else D-X%D)


if '__main__' == __name__:
    resolve()

# Fixed code:

def resolve():
    X, K, D = list(map(int, input().split()))
    X = -X if X < 0 else X
    m = X//D
    if m < K:
        if X%D > D-X%D:
            nmove = m+1
            print(D-X%D if (K-nmove)%2==0 else X%D)
        else:
            nmove = m
            print(X%D if (K-nmove)%2==0 else D-X%D)
    else:
        nmove = m
        print(X-K*+D)


if '__main__' == __name__:
    resolve()
# Buggy code:
X,K,D = map(int,input().split())
X = abs(X)
 
if X <= K * D :
  if K % 2 == 1 :
    answer = abs(X % D - D)
  else :
    answer = X % D
else :
  answer = X - K * D
  
print(answer)

# Fixed code:
X,K,D = map(int,input().split())
X = abs(X)
 
if X <= K * D :
  if (K - X // D) % 2 == 1 :
    answer = abs(X % D - D)
  else :
    answer = X % D
else :
  answer = X - K * D
  
print(answer)
# Buggy code:
line = input()

strL = line.split()
X = int(strL[0])
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    ans = abs(X - K * D)
elif (K - div) % 2 != 0:
    if mod > 0:
        ans = mod - D
    else:
        ans = mod + D

print(int(abs(ans)))

# Fixed code:
line = input()

strL = line.split()
X = abs(int(strL[0]))
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    ans = X - K * D
elif (K - div) % 2 != 0:
    ans = mod - D
else:
    ans = mod

print(abs(int(ans)))
# Buggy code:
X, K, D = map(int, input().split())
count1 = X // D
count2 = (X // D)-1
if count1 < K:
    if (K - count1) %2 ==0:
        print(abs(abs(X)-abs(D*count1)))
    else:
        print(abs(abs(X)-abs(D*count2)))
else:
    print(abs(abs(X)-abs(D*K)))

# Fixed code:
X, K, D = map(int, input().split())
count1 = abs(X) // D
count2 = (abs(X) // D)+1
if count1 < K:
    if (K - count1) %2 ==0:
        print(abs(abs(X)-abs(D*count1)))
        
    else:
        print(abs(abs(X)-abs(D*count2)))
else:
    print(abs(abs(X)-abs(D*K)))
# Buggy code:
from sys import stdin


def f(x, k, d):
    if k == 0:
        return x

    if x == 0:
        if k % 2 == 0:
            return 0
        elif k % 2 == 1:
            return d
    elif x > 0:
        tmp = abs(x) / d
        if d * tmp > d * k:
            return x - d * k
        else:
            return f((x-d*tmp), (k-tmp), d)
    elif x < 0:
        tmp = abs(x) / d
        if d * tmp > d * k:
            return x + d * k
        else:
            return f((x+d*tmp), (k-tmp), d)


if __name__ == '__main__':
    X, K, D = [int(x) for x in stdin.readline().rstrip().split()]
    print(abs(f(X, K, D)))


# Fixed code:
from sys import stdin


def f(x, k, d):
    if k == 0:
        return x

    absX = abs(x)
    tmp = absX // d

    if tmp > k:
        return absX - d * k
    else:
        absX = absX - d * tmp
        k = k - tmp
        if k % 2 == 0:
            return absX
        else:
            return abs(absX - d)


if __name__ == '__main__':
    X, K, D = [int(x) for x in stdin.readline().rstrip().split()]
    print(f(X, K, D))
# Buggy code:
x,k,d=list(map(int,input().split()))
syou, amari = divmod(x,d)
if x>0:
    if x-k*d==0:
        print(0)
    elif x-k*d<0:
        if amari==0:
            newk=k-syou
            if newk%2==0:
                print(0)
            else:
                print(d)
        elif amari!=0:
            newk=k-syou+1
            if newk%2==0:
                print(abs(x-d*(syou+1)))
            else:
                print(abs(x-d*syou))
    elif x-k*d>0:
        print(abs(x-k+d))
if x==0:
    if k%2==0:
        print(0)
    else:
        print(d)

# Fixed code:
x,k,d=list(map(int,input().split()))
x=abs(x)
syou, amari = divmod(abs(x),d)
if x>0:
    if x-k*d==0:
        print(0)
    elif x-k*d<0:
        if amari==0:
            newk=k-syou
            if newk%2==0:
                print(0)
            else:
                print(d)
        elif amari!=0:
            newk=k-syou+1
            if newk%2==0:
                print(abs(x-d*(syou+1)))
            else:
                print(abs(x-d*syou))
    elif x-k*d>0:
        print(abs(x-k*d))
if x==0:
    if k%2==0:
        print(0)
    else:
        print(d)
# Buggy code:
x, k, d = map(int, input().split())

# if x == 0:
#     if k % 2 == 0:
#         print(0)
#     else:
#         print(d)
elif 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))


# Fixed code:
x, k, d = map(int, input().split())

if x == 0:
    if k % 2 == 0:
        print(0)
    else:
        print(d)
elif 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))
# Buggy code:
x,k,d = [int(i) for i in input().split()]
x=x-k*d*x//abs(x) if abs(x)>=k*d else x-(abs(x)//d)*d*x//abs(x)-(d if abs(x)//d%2==1 else 0)*x//abs(x)
print(x)

# Fixed code:
x,k,d = [int(i) for i in input().split()]
x=abs(x)
x=x-k*d if x>=k*d else abs(x%d-(k-x//d)%2*d)
print(x)
# Buggy code:
x,k,d=map(int,input().split())
kai=x//d
k-=kai
if k%2 ==0:
    y=x-(kai*d)
else:
    y=x-(kai*d+1)
print(abs(y))

# Fixed code:
x,k,d=map(int,input().split())
x=abs(x)
kai=x//d
if k < kai:
    print(x-d*k)
else:
    k-=kai
    if k%2 ==0:
        y=x-(d*kai)
    else:
        y=x-(d*(kai+1))
    print(abs(y))
# Buggy code:
input_line = input()
data = input_line.split(" ")
x =abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
num = k - res
if num % 2 == 1 :
  ans = abs(b - d)
else :
  ans = res
print(ans)

# Fixed code:
input_line = input()
data = input_line.split(" ")
x = abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
if res >= k :
  ans = x - k * d
else :
  num = k - res
  if num % 2 == 1 :
    ans = abs(b - d)
  else :
    ans = b
print(ans)
# Buggy code:
x, k, d = map(int, input().split())
x = abs(x)

p = x // d
if p > k:
  print(x - k * d)
else:
  min = [x, x]
  min[0] = x - p * d
  min[1] = abs(min[0] - d)
  print(min[k%2])

# Fixed code:
x, k, d = map(int, input().split())
x = abs(x)

p = x // d
if p > k:
  print(x - k * d)
else:
  min = [x, x]
  min[p%2] = x - p * d
  min[(p+1)%2] = abs(min[p%2] - d)
  print(min[k%2])
# Buggy code:
x, k, d = map(int, input().split())
if x - k / d >= 0:
    print(x-k*d)
else:
    k -= x // d
    x %= d
    if k % 2 == 0:
        print(x)
    else:
        print(abs(x-d))


# Fixed code:
x, k, d = map(int, input().split())
x = abs(x)

t = x/d

 
if t >= k:
    print(abs(x - (k*d)))
    
elif (k-int(t))%2==0:
    print(abs(x-abs(int(t)*d)))
    
else:
    print(abs(x-abs(int(t)*d)-d))
# Buggy code:
x,k,d=map(int,input().split())
q = abs(x) // d
if (k - q) % 2 == 0:
  print(abs(x)-q*d)
else:
  print(q*d+d-abs(x))


# Fixed code:
x,k,d=map(int,input().split())
q = abs(x) // d
if q >= k:
  print(abs(x)-k*d)
elif (k - q) % 2 == 0:
  print(abs(x)-q*d)
else:
  print(q*d+d-abs(x))
# Buggy code:
X, K, D = map(int, input().split())
def resolve_best_i(X, K, D):
    if abs(X - int(X / D) * D) < abs(X - (int(X / D)+1)*D):
        return abs(X - int(X / D) * D), int(X /D)
    else:
        return abs(X - (int(X / D)+1)*D), int(X /D) + 1
def make_most_min(X, K, D):
    mokuhyou = X
    best = 0
    if X >= 0:
        mokuhyou, best = resolve_best_i(X, K, D)
        if best > K:
            best_posi = abs(X - best * D)
            return best_posi
        if best % 2 == K % 2:
            return abs(X - best * D)
        else:
            return min(abs(X - (best+1) * (D)), abs(X - (best-1) * (D)))
if X >= 0:
    a = make_most_min(abs(X), K, abs(D))
else:
    a = make_most_min(-X, K, abs(D))
print(a)

# Fixed code:
X, K, D = map(int, input().split())
def resolve_best_i(X, K, D):
    if abs(X - int(X / D) * D) < abs(X - (int(X / D)+1)*D):
        return abs(X - int(X / D) * D), int(X /D)
    else:
        return abs(X - (int(X / D)+1)*D), int(X /D) + 1
def make_most_min(X, K, D):
    mokuhyou = X
    best = 0
    if X >= 0:
        mokuhyou, best = resolve_best_i(X, K, D)
        if best > K:
            best_posi = abs(X - K * D)
            return best_posi
        if best % 2 == K % 2:
            return abs(X - best * D)
        else:
            return min(abs(X - (best+1) * (D)), abs(X - (best-1) * (D)))
if X >= 0:
    a = make_most_min(abs(X), K, abs(D))
else:
    a = make_most_min(-X, K, abs(D))
print(a)
# Buggy code:
X,K,D = map(int,input().split()) 
if X >= K*D:
    print(X-K*D)
else:
    if (K-X//D) % 2 ==1:
        print(D-(X-K*D))
    else:
        print(X-X//D*D)

# Fixed code:
X,K,D = map(int,input().split()) 
X = abs(X)
if X >= K*D:
    print(X-K*D)
else:
    if (K-X//D) % 2 == 1:
        print(D-(X-X//D*D))
    else:
        print(X-X//D*D)
# Buggy code:
X, K, D = [int(n) for n in input()]

#X = 10
#K = 1
#D = 2


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

N1 = startN + 1
N2 = startN
N3 = startN - 1

if N1 < 0:
    N1 = 0
if N2 < 0:
    N2 = 0
if N3 < 0:
    N3 = 0

def getScore(n):
    score = X + n * D - D * (K - n)
    if score < 0:
        score = score * -1
    return score

score1 = getScore(N1)
score2 = getScore(N2)
score3 = getScore(N3)

minScore = score1
if minScore > score2:
    minScore = score2
if minScore > score3:
    minScore = score3

print(minScore)

# Fixed code:
X, K, D = [int(n) for n in input().split(" ")]

#X = 10
#K = 1
#D = 2


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

N1 = startN + 1
N2 = startN
N3 = startN - 1

if N1 < 0:
    N1 = 0
if N2 < 0:
    N2 = 0
if N3 < 0:
    N3 = 0
if N1 > K:
    N1 = K
if N2 > K:
    N2 = K
if N3 > K:
    N3 = K

def getScore(n):
    score = X + n * D - D * (K - n)
    if score < 0:
        score = score * -1
    return score

score1 = getScore(N1)
score2 = getScore(N2)
score3 = getScore(N3)

minScore = score1
if minScore > score2:
    minScore = score2
if minScore > score3:
    minScore = score3

print(minScore)