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

if x>= 0:
  if x > d*k:
    m = x - d*k
  else:
    for i in range(k):
      x -= d
      if x <=0:
        if (i+k) % 2 != 0:
          m = (-1)*x
        else:
          m = x+d
        break

else:
  if x > (-1)*d*k:
    m = x + d*k
  else:
    for i in range(k):
      x += d
      if x >=0:
        if (i+k) % 2 != 0:
          m = x
        else:
          m = (-1)*(x-d)
        break
print(m)

Fixed submission:
from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)

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

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  for i in range(k):
    if xi - d*i <= 0:
      if (i+k) % 2 != 0:
        m = abs(xi)
      else:
        m = min(abs(xi+d),abs(xi-d))
      break
    break
print(m)

Fixed submission:
from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)

Buggy python submission (verdict: Time Limit Exceeded):
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  for i in range(k):
    xi -= d
    if xi <= 0:
      if (i+k) % 2 != 0:
        m = abs(xi)
      else:
        m = min(abs(xi+d),abs(xi-d))
      break
print(m)

Fixed submission:
from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)

Buggy python submission (verdict: Time Limit Exceeded):
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  for i in range(k):
    xi -= d
    if xi <= 0:
      if (i+k) % 2 != 0:
        m = min(abs(xi),abs(xi+2*d),abs(xi-2*d))
      else:
        m = min(abs(xi+d),abs(xi-d))
      break
print(m)

Fixed submission:
from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)

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

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  for _ in range(k):
    xi -= d
    if xi < 0:
      m = min(abs(xi),abs(xi+d),abs(xi-d))
      break
print(m)

Fixed submission:
from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)

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

xi = abs(x)
if abs(x) > d*k:
  m = abs(min(x+d*k, x-d*k))
else:
  for _ in range(k):
    xi -= d
    if xi < 0:
      m = abs(min(xi,xi+d,xi-d))
      break
print(m)

Fixed submission:
from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)

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

xi = abs(x)
if abs(x) > d*k:
  m = abs(min(x+d*k, x-d*k))
else:
  for i in range(k):
    xi -= d*i
    if xi < 0:
      m = abs(min(x+d*i,x-d*i,x+d*(i-1),x-d*(i-1)))
      break
print(m)

Fixed submission:
from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)