CodeEff/ECCO huggingface dataset:
# Original solution
from sys import stdin
readline = stdin.readline


import heapq

def main():
    heap = []
    while True:
        line = readline()
        if line[2] == 't':
            print((heapq.heappop(heap)[1]))
        elif line[2] == 's':
            n = int(line.split()[1])
            heapq.heappush(heap, (-n, n))
        else:
            break

main()

# Optimized solution
from sys import stdin
from heapq import heappop, heappush
readline = stdin.readline


heap = []
while True:
    line = readline()
    if line[1] == 'x':print((-heappop(heap)))
    elif line[0] == 'i':heappush(heap, -int(line.split()[1]))
    else:break
# Original solution
def dw_heap(A,i,length):
    l = i*2
    r = i*2 + 1
    largest = i
    if l < length and A[l] > A[largest]: largest = l
    if r < length and A[r] > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        dw_heap(A, largest, length)


def up_heap(A,i):
    if i==1: return
    p = i//2
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        up_heap(A,p)


def extract(A,last):
    max_item = A[1]
    A[1],A[last] = A[last],A[1]
    dw_heap(A,1,last)
    return max_item


def build_heap(A,length):
    for i in range(length//2,0,-1): dw_heap(A,i,length)


if __name__=='__main__':
    hp = [None]*2*10**6
    i = 1
    while True:
        op = input().split() 
        if   op[0] != 'insert': break
        hp[i] = int(op[1])
        i += 1
    if op[0] != 'end': build_heap(hp,i)
    while True:
        if   op[0] == 'end': break
        if   op[0] == 'insert':
            hp[i] = int(op[1])
            up_heap(hp,i)
            i += 1
        else:
            print((extract(hp,i-1)))
            i -= 1
        op = input().split() 

# Optimized solution
def dw_heap(A,i,length):
    l = i*2
    r = i*2 + 1
    largest = i
    if l < length and A[l] > A[largest]: largest = l
    if r < length and A[r] > A[largest]: largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i] 
        dw_heap(A, largest, length)


def up_heap(A,i):
    if i==1: return
    p = i//2
    if A[i] > A[p]:
        A[i], A[p] = A[p], A[i] 
        up_heap(A,p)


def extract(A,last):
    max_item = A[1]
    A[1],A[last] = A[last],A[1]
    dw_heap(A,1,last)
    return max_item


def build_heap(A,length):
    for i in range(length//2,0,-1): dw_heap(A,i,length)


if __name__=='__main__':
    hp = [None]*(2*10**6)
    i = 1
    j = -1 
    while True:
        op = input() 
        if   op[0] != 'i': break
        hp[i] = int(op[7:])
        i += 1
    if op[2] != 'd': build_heap(hp,i)
    while True:
        if   op[2] == 'd': break
        if   op[0] == 'i':
            hp[i] = int(op[7:])
            up_heap(hp,i)
            i += 1
        else:
            hp[j] = extract(hp,i-1)
            i -= 1
            j -= 1
        op = input() 
    print(*hp[:j:-1],sep='\n')
# Original solution
#!/usr/bin/python3
import sys
import queue

# main
q = queue.PriorityQueue()
m = 2 * (10 ** 9)
while True:
    s = sys.stdin.readline().split()
    if s[0].startswith('i'):
        q.put(m - int(s[1]))
    elif s[0].startswith('ex'):
        print((m - q.get()))
    if s[0] == 'end':
        exit()

# Optimized solution
#!/usr/bin/python3
import sys
import queue

# main
q = queue.PriorityQueue()
m = 2 * (10 ** 9)
S = sys.stdin.readlines()
for line in S:
    s = line.split()
    if s[0].startswith('i'):
        q.put(m - int(s[1]))
    elif s[0].startswith('ex'):
        print((m - q.get()))
    if s[0] == 'end':
        exit()
# Original solution
#!/usr/bin/python3
import sys
import queue

# main
q = queue.PriorityQueue()
m = 2 * (10 ** 9)
S = sys.stdin.readlines()
for line in S:
    s = line.split()
    if s[0].startswith('i'):
        q.put(m - int(s[1]))
    elif s[0].startswith('ex'):
        print((m - q.get()))
    if s[0] == 'end':
        exit()

# Optimized solution
#!/usr/bin/python3
import sys
import heapq

# main
q = []
S = sys.stdin.readlines()
for line in S:
    if line[0].startswith('i'):
        heapq.heappush(q, -int(line.split()[1]))
    elif line[1] == 'x':
        print((-heapq.heappop(q)))
    else:
        exit()
# Original solution
import sys
import heapq

heap = []
while True:
	input_line = sys.stdin.readline()
	input_line = input_line.strip().split(' ')
	if input_line[0][0] == 'i' :
		heapq.heappush(heap,-int(input_line[1]))
		heapq.heapify(heap)
	elif input_line[0][1] == 'x' :
		print((-int(heapq.heappop(heap))))
	else :
		break

# Optimized solution
import sys
import heapq

heap = []
while True:
	input_line = sys.stdin.readline()
	input_line = input_line.strip().split(' ')
	if input_line[0][0] == 'i' :
		heapq.heappush(heap,-int(input_line[1]))
	elif input_line[0][1] == 'x' :
		print((-int(heapq.heappop(heap))))
	else :
		break
# Original solution
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

A = []
inp = [None]
while inp[0] != "end":
    inp = [n for n in input().split()]
    if inp[0] == "insert":
        heappush(A, -int(inp[1]))
    elif inp[0] == "extract":
        print((-heappop(A)))

# Optimized solution
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

A = []
inp = [None]
while inp[0] != "end":
    inp = input().split()
    if inp[0] == "insert":
        heappush(A, -int(inp[1]))
    elif inp[0] == "extract":
        print((-heappop(A)))
# Original solution
def insert(a, data):
    a.append(data)
    heapinc(a, len(a)-1)

def heapinc(a, index):
    parent = (index - 1) // 2
    if parent >= 0:
        if a[parent] < a[index]:
            memo = a[parent]
            a[parent] = a[index]
            a[index] = memo
            heapinc(a, parent)

def extract(a):
    root = a[0]
    a[0] = a[-1]
    del a[-1]
    maxheapify(a, 0)
    return root

def maxheapify(a, i):
    l = i*2 + 1
    r = i*2 + 2

    if r < len(a):
        if a[l] > a[i]:
            largest = l
        else:
            largest = i
        if a[r] > a[largest]:
            largest = r

        if largest != i:
            memo = a[i]
            a[i] = a[largest]
            a[largest] = memo
            maxheapify(a, largest)

    elif l < len(a):
        if a[l] > a[i]:
            largest = l
        else:
            largest = i
        if largest != i:
            memo = a[i]
            a[i] = a[largest]
            a[largest] = memo
            maxheapify(a, largest)

a = []
while 1:
    com = input().split()
    if com[0] == 'insert':
        insert(a, int(com[1]))
    elif com[0] == 'extract':
        print((extract(a)))
    else:
        break



# Optimized solution
from heapq import *

a = []
while 1:
    com = input().split()
    if com[0] == 'end':
        break
    elif com[0] == 'insert':
        heappush(a, -int(com[1]))
    else:
        print((-heappop(a)))
# Original solution
n = int(eval(input()))
print((0 if n == 0 else len(str(bin(n))[2:])))

# Optimized solution
n = int(eval(input()))
print((0 * (n == 0) + len(str(bin(n))[2:]) * (n != 0)))
# Original solution
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(eval(input()))
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    if isSame:
        if isSheep:
            return ans[ind-1]
        else:
            return not ans[ind-1]
    else:
        if isSheep:
            return not ans[ind-1]
        else:
            return ans[ind-1]

    return isSame ^ isSheep ^ ans[ind-1]


def check(first: bool, last: bool)->list:
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")


# Optimized solution
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(eval(input()))
s = input()[:-1]
ans = [1]*(N+2)


def print_ans(l: list):
    ret = ""
    for a in l[1:-1]:
        ret += "S" if a else "W"
    print(ret)


def next(ind: int, isSame: bool, isSheep: bool)->bool:
    return isSame ^ isSheep ^ ans[ind-1]


def check(first: bool, last: bool)->list:
    ans[0] = last
    ans[1] = first
    for i in range(1, N+1):
        ans[i+1] = next(i, s[i-1] == "o", ans[i])

    return ans[0] == ans[N] and ans[1] == ans[N+1]


for first in [True, False]:
    for last in [True, False]:
        if check(first, last):
            print_ans(ans)
            exit()
print("-1")
# Original solution
while True:
	a,b,c,d,e = list(map(int,input().split()))
	if a==0:
		break
	na,nb,nc = list(map(int,input().split()))
	v=[0]*(na+nb+nc)
	for i in range(na):
		v[i]=a
	for i in range(nb):
		v[i+na]=b
	for i in range(nc):
		v[i+na+nb]=c
	t=na+nb+nc
	ans=na*a+nb*b+nc*c
	if t < d:
		if ans > d*e:
			ans=d*e
	else:
		tmp = 0
		for i in range(d):
			tmp += v[len(v)-1-i]
		if tmp >= d*e:
			for i in range(len(v)):
				if e < v[i]:
					v[i] = e
			for i in range(d):
				v[len(v)-1-i] = e
		ans=0
		for i in range(len(v)):
			ans += v[i]

	print(ans)

# Optimized solution
while True:
	a,b,c,d,e = list(map(int,input().split()))
	if a==0:
		break
	na,nb,nc = list(map(int,input().split()))
	t=na+nb+nc
	ans=na*a+nb*b+nc*c
	if t < d:
		if ans > d*e:
			ans=d*e
	else:
		tmp = 0
		dd=d
		cnt=0
		if dd>=nc:
			cnt+=nc*c
			dd-=nc
		else:
			cnt+=dd*c
			dd=0

		if dd>=nb:
			cnt+=nb*b
			dd-=nb
		else:
			cnt+=dd*b
			dd=0

		if dd>=na:
			cnt+=na*a
			dd-=na
		else:
			cnt+=dd*a
			dd=0
		
		if cnt >= d*e:
			if e<a:
				a=e
			if e<b:
				b=e
			if e<c:
				c=e
			dd=d
			cnt=0
			# print "cnt"
			if dd>=nc:
				cnt+=nc*e
				dd-=nc
			else:
				cnt+=dd*e
				cnt+=(nc-dd)*min(e,c)
				dd=0
			# print cnt
			if dd>=nb:
				cnt+=nb*e
				dd-=nb
			else:
				cnt+=dd*e
				cnt+=(nb-dd)*min(e,b)
				dd=0
# 70 100 340 4 200
# 1 1 2
			# print cnt
			if dd>=na:
				cnt+=na*e
				dd-=na
			else:
				cnt+=dd*e
				cnt+=(na-dd)*min(e,a)
				dd=0
			ans=cnt

	print(ans)
# Original solution
# -*- using:utf-8 -*-
class main:
  def function(x, k, d):
    for i in range(k):
      if abs(x + d) > abs(x - d):
        x = x - d
      elif abs(x + d) < abs(x - d):
        x = x + d
      else:
        if (k - i) % 2 == 0:
          return abs(x)
          break
        else:
          return abs(x + d)
          break
    return abs(x)

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

# Optimized solution
# -*- using:utf-8 -*-

class main:
  def function(x, k, d):
    if x >= k * d:
      ans = x - k * d
    else:
      r = x // d
      n = k - r
      if n % 2 == 0:
        ans = x % d
      else:
        ans = abs(x % d - d)
    return ans

if __name__ == "__main__":
  x, k, d = list(map(int, input().split()))
  x = abs(x)
  ans = main.function(x, k, d)
  print(ans)
# Original solution
from math import floor

def solve(X, D, lb, ub):
    # min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
    ts = [
        lb,
        ub,
        max(min(floor(-X / D), ub), lb),
        max(min(floor(-X / D) + 1, ub), lb),
    ]   
    return min([abs(X + t * D) for t in ts])

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

y1 = X - K * D
y2 = X + K * D
if (y1 > 0 and y2 > 0) or (y1 < 0 and y2 < 0): # same sign
    print((min(abs(y1), abs(y2))))
else:
    if K % 2 == 0:
        ans = solve(X, D * 2, -(K // 2), +(K // 2))
    else:
        ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
        ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
        ans = min(ans1, ans2)
    print(ans)



# Optimized solution
from math import floor

def solve(X, D, lb, ub):
    # min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
    ts = [
        lb,
        ub,
        max(min(floor(-X / D), ub), lb),
        max(min(floor(-X / D) + 1, ub), lb),
    ]
    return min([abs(X + t * D) for t in ts])

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

if K % 2 == 0:
    ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
    ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
    ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
    ans = min(ans1, ans2)
print(ans)
# Original solution
def main():
    X, K, D = list(map(int, input().split()))
    for i in range(K):
        if abs(X - D) > abs(X + D):
            X = X + D
        else:
            X = X - D
            if X <= 0:
                if (i % 2 == 1 and K % 2 == 0) or (i % 2 == 0 and K % 2 == 1):
                    print((abs(X)))
                    return
                else:
                    if abs(X - D) < X:
                        print((abs(X - D)))
                        return
                    elif abs(X + D) < X:
                        print((abs(X + D)))
                        return
    print((abs(X)))
main()


# Optimized solution
def main():
    X, K, D = list(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)))
        return
    
    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)))
main()
# Original solution
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(eval(input()))
    P = 10**9+7
    INF = 10**18+10


    x,k,d = LMIIS()
    sign = -1 if x < 0 else 1
    absX = abs(x)
    if k*d <= abs(x):
        print((absX-k*d))
        return
    num = absX // d
    k -= num
    if k & 1:
        num += 1
    print((abs(absX-num*d)))

     
    



    
main()

# Optimized solution
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(eval(input()))
    P = 10**9+7
    INF = 10**18+10


    x,k,d = LMIIS()

    absX = abs(x)
    # 0にできるだけ近づいて終わり
    if k*d <= abs(x):
        print((absX-k*d))
        return
    # マイナスにならない範囲でできるだけ0に近づく
    num = absX // d
    k -= num
    # 残りの移動回数が奇数なら、あと1回だけ移動する
    if k & 1:
        num += 1
    print((abs(absX-num*d)))

     
    



    
main()
# Original solution
import sys
input = sys.stdin.readline
from collections import *

def f(x):
    return 2*D*x+X-K*D

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

if f(0)==0 or f(K)==0:
    print((0))
    exit()

if f(0)>0:
    print((f(0)))
elif f(K)<0:
    print((abs(f(K))))
else:
    m = (K*D-X)//(2*D)
    ans = 10**18
    
    for i in range(m-100, m+100):
        if 0<=i<=K:
            ans = min(ans, abs(f(i)))
    
    print(ans)

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

if X-D*K>=0:
    print((X-D*K))
else:
    p = X%D
    c = (X-p)//D
    
    if (K-c)%2==0:
        print(p)
    else:
        print((-(p-D)))
# Original solution
x,k,d = list(map(int,input().split()))
#偶数回前後に移動したら0
#偶数回一方向に移動したら2D

for i in range(k):
  x = abs(x) - d

  if x < 0:
    break



if (k-i+1) % 2 == 0:
  #そのまま
  ans = abs(x)
else:
  ans = min(abs(x-d),abs(x+d))

print(ans)

# Optimized solution

x,k,d = list(map(int,input().split()))
#偶数回前後に移動したら0
#偶数回一方向に移動したら2D

if x >= 0:
  capa_iter = x // d
  if capa_iter < k:
    if (k - capa_iter) % 2 == 0:
      print((x - capa_iter*d))
    else:
      print((min([abs(x - capa_iter*d-d),x - capa_iter*d+d])))
    exit()

  ans =x-d*k
  print(ans)

if x < 0:
  capa_iter = abs(-x // d)
  if capa_iter < k:
    if (k - capa_iter) % 2 == 0:
      print((abs(x + capa_iter*d)))
    else:
      print((min([abs(x + capa_iter*d+d),abs(x + capa_iter*d -  d)])))
    exit()

  ans =abs(x+d*k)
  print(ans)
# Original solution
X, K, D = list(map(int, input().split()))
if X < 0:
    X = -X
step = 0
while X > D and not K == 0:
    step += 1
    X -= D
    K -= 1
if K == 0:
    print(X)
    exit()
if K % 2 == 0:
    print(X)
else:
    print((abs(X-D)))


# Optimized solution
X, K, D = list(map(int, input().split()))
if X < 0:
    X = -X
step = X//D
X -= D*step
K -= step

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

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

x = abs(x)
if k <= x//d:
  y = x-k*d
else:
  if (k-x//d)%2 == 0:
    y = x%d
  else:
    y = min(abs(x%d-d),abs(x%d+d))
print(y)
# Original solution
def WalkingTakahashi():
    
    data = list(map(int,input().split()))
    
    position = data[0]
    
    if data[0] == data[2] and data[1]%2 == 0:
        print((data[2]))
    
    elif data[0] == data[2] and data[1]%2 == 1:
        print((0))
        
    else:
        for i in range(data[1]):
            
            if abs(position + data[2]) < abs(position - data[2]):
                position = position + data[2]
                
            else:
                position = position - data[2]
                
        print((abs(position)))
        
if __name__ == '__main__':
    WalkingTakahashi()




# Optimized solution
def WalkingTakahashi():
    
    data = list(map(int,input().split()))
    
    position = abs(data[0])
    
    m = min(data[1], position//data[2])
    
    position = position - data[2]*m
    
    data[1] = data[1] - m
    
    data[1] %= 2
    
    position = position - data[2]*data[1]
    
    print((abs(position)))
    
if __name__ == '__main__':
    WalkingTakahashi()
# Original solution
X, K, D = list(map(int, input().split()))

ogpos = True

if X > 0:
    ogpos = True
else:
    ogpos = False

old = X
newpos = ogpos


while newpos == ogpos and K>0:
    K -= 1
    if X > 0:
        X -= D
    elif X < 0:
        X += D
    else:
        if ogpos == True:
            X -= D
        else:
            X += D

    if X>0:
        newpos = True
    elif X<0:
        newpos = False
        


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


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

X = abs(X)

cuts = X//D

if cuts>=K:
    print((X-(K*D)))
else:
    remainingcuts = K-cuts
    r = X-cuts*D

    if remainingcuts%2 == 1:
        print((abs(r-D)))
    else:
        print(r)
# Original solution
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))

x,k,d=nii()

dist=abs(x)

num=dist//d

if num>k:
  print((abs(dist-d*k)))
  exit()
else:
  k-=num
  dist1=dist-d*num

  if k>=1:
    dist2=abs(dist1-d)
    if dist2<=dist1:
      k-=1
      dist1=dist2

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

# Optimized solution
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))

x,k,d=nii()

dist=abs(x)
num=dist//d

if num>k:
  print((abs(dist-d*k)))
  exit()
else:
  k-=num
  dist-=d*num

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

zx=x
#zzx=zx
for i in range(k):
    xm=abs(x+d)
    xu=abs(x-d)
    x=min(xm,xu)
    k-=1
    if zx+x==d:
        if k%2!=0:
            x=zx
            break
        else:
#            x=zx
            break
#    zzx=zx
    zx=x
    
print(x)      

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

x=abs(x)
zx=x
if x<d*k:
    wk,x=divmod(abs(x),d)
    k-=wk    
else:
    x-=d*k
    k=0

for i in range(k):
    xm=abs(x+d)
    xu=abs(x-d)
    x=min(xm,xu)
    k-=1
    if zx+x==d:
        if k%2!=0:
            x=zx
            break
        else:
            break
    zx=x
    
print(x)
# Original solution
#!/usr/bin/env python3
import math
# スペース区切りの整数の入力
X, K, D = list(map(int, input().split()))

cross = abs(-(-X//D))

if cross >= K:
    for i in range(K):
        if X >= 0:
            X -= D
        else:
            X += D
    print((abs(X)))
else:
    for i in range(cross):
        if X >= 0:
            X -= D
        else:
            X += D
    
    if (K-cross)%2 == 0:
        print((abs(X)))
    else:
        if X >= 0:
            print((abs(X-D)))
        else:
            print((abs(X+D)))





# Optimized solution
#!/usr/bin/env python3
import math
# スペース区切りの整数の入力
X, K, D = list(map(int, input().split()))

cross = abs(-(-X//D))

if cross >= K:
    if X >= 0:
        X -= D*K
    else:
        X += D*K
    print((abs(X)))
else:
    if X >= 0:
        X -= D*cross
    else:
        X += D*cross
    
    if (K-cross)%2 == 0:
        print((abs(X)))
    else:
        if X >= 0:
            print((abs(X-D)))
        else:
            print((abs(X+D)))
# Original solution
x,k,d=list(map(int,input().split()))
if k%2==0:
    ans=min(abs(x),abs(x+2*d),abs(x-2*d),abs(x+4*d),abs(x-4*d),abs(x+k*d),abs(x-k*d),abs(x+(k-2)*d),abs(x-(k-2)*d),abs(x+(k-4)*d),abs(x-(k-4)*d))
else:
    if k==1:
        ans=min(abs(x+d),abs(x-d))
    else:
        ans=min(abs(x+d),abs(x-d),abs(x+3*d),abs(x-3*d),abs(x+k*d),abs(x-k*d),abs(x+(k-2)*d),abs(x-(k-2)*d),abs(x+(k-4)*d),abs(x-(k-4)*d))
if k>=abs(x)//d:
    if (k-(abs(x)//d))%2==0:
        ans=min(ans,abs(x+(abs(x)//d)*d),abs(x-(abs(x)//d)*d))
    else:
        ans=min(ans,abs(x+(abs(x)//d)*d+d),abs(x-(abs(x)//d)*d+d),abs(x+(abs(x)//d)*d-d),abs(x-(abs(x)//d)*d-d))
print(ans)


# Optimized solution
x,k,d=list(map(int,input().split()))
x=abs(x)
ans=0
if x-d*k>=0:
    ans=x-d*k
else:
    e=x//d
    k-=e
    x-=e*d
    if k%2==1:
        ans=abs(x-d)
    else:
        ans=x
print(ans)
# Original solution
X, K, D = list(map(int, input().rstrip().split()))
before = X

if abs(X)//D>=K:
  print((abs(X)-D*K))
else:
  for i in range(K):
    buf = X
    if X<0:
      X += D
    else:
      X -= D
    if X == before:
      if (K-i)%2 == 0:
        if X<0:
          X += D
        else:
          X -= D
      else:
        X = before
      break
    before=buf
  print((abs(X)))

# Optimized solution
x,k,d = list(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))
# Original solution
x,k,d=list(map(int,input().split()))
def counta(x,k,d):
    #xcnt=0
    x=abs(x)
    if d<2*x:
        while x>=d:
            x-=d
            k-=1
            if k==0:
                print((abs(x)))
                return
        if k%2==0:
            print(x)
            return
        else:
            print((abs(x-d)))
            return
    else:
        if k%2==0:
            print(x)
            return
        else:
            print((abs(x-d)))
            return
counta(x,k,d)

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

def counta(x,k,d):
    #xcnt=0
    x=abs(x)
    if d<2*x:
        ans=x//d
        #amari=x%d
        if ans>k:
            print((abs(x-k*d)))
            return
        k=k-ans
        x=x-ans*d
        if k%2==0:
            print(x)
            return
        else:
            print((abs(x-d)))
            return
    else:
        if k%2==0:
            print(x)
            return
        else:
            print((abs(x-d)))
            return
counta(x,k,d)