Buggy python submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 1
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    minx = abs(i*d-x)
    if (k-i) % 2 == 0:
      answer = abs(minx)
    if (k-i) % 2 == 1:
      answer = min(abs(minx-d),abs(minx+d))
    i += 1

print(answer)

Fixed submission:
x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)

Buggy python submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 1
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    minx = min(abs(i*d), (i * d - x))
    if (k-i) % 2 == 0:
      answer = abs(minx)
    if (k-i) % 2 == 1:
      answer = abs(min(abs(minx-d), abs(minx+d)))
    i += 1

print(answer)

Fixed submission:
x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)

Buggy python submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 1
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    if i % 2 == 0:
      answer = abs(x - i * d)
    if i % 2 == 1:
      answer = abs(i*d)
    i += 1



print(answer)

Fixed submission:
x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)

Buggy python submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 0
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    answer = min(abs(i*d-x),i*d+x)
    i += 1


print(answer)

Fixed submission:
x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)

Buggy python submission (verdict: Runtime Error):
x,k,d = map(int, input().split())

def moving(x,k,d):
  if k == 0:
    return x
  
  x = min(abs(x-d), abs(x+d))
  return moving(x,k - 1, d)

answer = moving(x,k,d)
print(answer)

Fixed submission:
x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)

Buggy python submission (verdict: Runtime Error):
x,k,d = map(int, input().split())

def moving(x,k,d):
  if k == 0:
    return x
  
  x = min(abs(x-d), abs(x+d))
  return moving(x,k - 1, d)

answer = moving(x,k,d)
print(answer)

Fixed submission:
x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)