TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import sys
X, K, D = map(int,input().split())
cnt = 0
a = X
b = 999999999
tmp = 0
if X == 0:
  if K % 2 == 0:
    print(0)
  else:
    print(D)
  sys.exit()
if X >= K*D:
  print(X - K*D)
  sys.exit()
if K % 2 == 0:
  tmp = int(X/D)
  if tmp% 2 == 0:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  if X >= 0:
    b = a - D*2
  else:
    b = a + D*2
else:
  tmp = int(X/D)
  if tmp% 2 == 1:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  if X >= 0:
    b = a - D*2
  else:
    b = a + D*2
print(tmp,a,b)
print(min(abs(a),abs(b)))


import sys
X, K, D = map(int,input().split())
cnt = 0
a = X
b = 0
tmp = 0
if abs(X) >= K*D:
  if X > 0:
    print(X - K*D)  
  else:
    print(abs(X + K*D))
  sys.exit()
if K % 2 == 0:
  tmp = int(X/D)
  if tmp% 2 == 0:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  b = a - D*2
else:
  tmp = int(X/D)
  if tmp% 2 == 1:
    a = X - D*tmp
  else:
    a = X - D*tmp + D
  b = a - D*2
print(min(abs(a),abs(b)))



Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X,K,D = map(int,input().split())
ans = 0
if X<0:
  X = (-1)*X
  
if X-K*D >=0:
  ans = X-K*D
else:
  Y = int(X/D)
  z = X%D
  if (K-Y)%2=0:
    ans = Z
  if (K-Y)%2=1:
    ans = D-Z
if ans<0:
  ans = (-1)*ans
print(ans)
  


X,K,D = map(int,input().split())
ans = 0
if X<0:
  X = (-1)*X
  
if X-K*D >=0:
  ans = X-K*D
else:
  Y = int(X/D)
  Z = X%D
  if (K-Y)%2==0:
    ans = Z
  if (K-Y)%2==1:
    ans = D-Z
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X,K,D=map(int,input().split())
ans=0
if abs(X)>=K*D:
    ans=abs(X)-K*D
else:
    M=abs(X)//D
    if abs(X)-M*D>abs(abs(X)-(M+1)*D):
        M=M+1
    if (K-M)%2==0:
        ans=abs(abs(X)-M*D)
    else:
        ans=abs(X)-(M-1)*D
print(ans)


X,K,D=map(int,input().split())
ans=0
if abs(X)>=K*D:
    ans=abs(X)-K*D
else:
    M=abs(X)//D
    if abs(X)-M*D>abs(abs(X)-(M+1)*D):
        M=M+1
    if (K-M)%2==0:
        ans=abs(abs(X)-M*D)
    else:
        ans=min(abs(X)-(M-1)*D,abs(abs(X)-(M+1)*D))
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x,k,d=map(int,input().split())

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


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

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


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X,K,D = map(int,input().split())
A = abs(X)
ans = 0
if A >= D*K:
    print( A - (D * K))
else :
    e = A//D
    K -= e
    x %= D
    if K%2 == 0:
        print(x)
    else:
        print(D-x)

X,K,D = map(int,input().split())
A = abs(X)
ans = 0
if A >= D*K:
    print( A - (D * K))
else :
    e = A//D
    K -= e
    A %= D
    if K%2 == 0:
        print(A)
    else:
        print(D-A)

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X,K,D=map(int, input().split())

X = abs(X)
a = X / D
b = round(a)

c = K - b

if c < 0:
    print(X-(K*D))
elif c % 2 != 0:
    if a > b:
        b = b + 1
    else:
        b = b - 1
    d = abs(X - (D*b))
    print(d)

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

X = abs(X)
a = X / D
b = round(a)

c = K - b
e = 0

if c < 0:
    print(X-(K*D))
    e = 1
elif c % 2 != 0:
    if a > b:
        b = b + 1
    else:
        b = b - 1
if e == 0:
    d = abs(X - (D*b))
    print(d)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x, k, d = map(int, input().split())

a = [abs(x // d), x % d]

if a[0] > k:
   ans = min(abs(x+k*d) ,abs(x-k*d))
else:
    b = (k- a[0]) % 2
    ans = min(abs(a[1]+b*d) ,abs(a[1]-b*d))

print(ans))

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

a = [abs(x // d), x % d]

if a[0] > k:
   ans = min(abs(x+k*d) ,abs(x-k*d))
else:
    b = (k- a[0]) % 2
    ans = min(abs(a[1]+b*d) ,abs(a[1]-b*d))

print(ans)

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X,K,D=map(int,input().split())
if K%2==0:
  if abs(2*D)>=abs(X):
    print(X)
  else:
    p=K*D
    q=abs(X-p)
    r=min(q%D,abs(q%D-D))
    print(r)   
else:
  if K==1:
    print(min(X,min(X+D,X-D)))
  else:
    if abs(D)>=abs(X):
      print(X)
    else:
      p=K*D
      q=abs(X-p)
      r=min(q%D,abs(q%D-D))
      print(r)  

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

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X,K,D=map(int,input().split())
if X<0:
  X*=-1
if X-K*D>0:
  print(X-K*D)
elif 2*X>D:
  print(X)
else:
  p=X-(X//D)*D
  p=min(abs(p-D),p)
  print(p)


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


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import math
x,k,d=map(int,input().split(" "))


if x<0:
  x=(-1)*x
if d<0:
  d=(-1)*d
  
s=math.floor(x/d)

if k<s:
  print(x-d*k)
else:
  w=k-s
  v=x-d*s
  if w%2==0:
    print(v)
  else:
    print(v-d)
  

import math
x,k,d=map(int,input().split(" "))


if x<0:
  x=(-1)*x
if d<0:
  d=(-1)*d
  
s=math.floor(x/d)

if k<s:
  print(x-d*k)
else:
  w=k-s
  v=x-d*s
  if w%2==0:
    print(v)
  else:
    print(abs(v-d))
  

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x, k, d = input().split()
x = int(x)
k = int(k)
d = int(d)
x = abs(x)
if x > d:
  if  x // d > k:
    x = x - k*d
    print(x)
    exit()
  else:
  	k -= x // d
    x = x % d
    
    
if k % 2 == 1:
  x = abs(x-d)

print(x)
    

x, k, d = input().split()
x = int(x)
k = int(k)
d = int(d)
x = abs(x)
if x > d:
  if  x // d > k:
    x = x - k*d
    print(x)
    exit()
  else:
  	k -= x // d
  	x = x % d
    
    
if k % 2 == 1:
  x = abs(x-d)

print(x)
    

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X, K, D = map(int,input().split())
print(X)
time = X // D
X = X - (D * time)
K = K - time
print(X)
print(K)

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

X, K, D = map(int,input().split())
X = abs(X)
time = X // D
time = min(K, time)
X = X - (D * time)
K = K - time

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

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x, k, d = map(int,input().split())
x = abs(x)
if x>k*d:
    ans = x-k*d
else:
    cnt = x//d
    if (k-cnt)%2==0:
        ans = x-cnt*d
    else:
        if x > 0:
            ans = x-cnt*d-d
        else:
            ans = x-cnt*d+d
print(ans)

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X, K, D = map(int, input().split())
if (abs(X) - K * D) >= 0:
  print(abs(X) - K * D)
else:
  print(min(X%D, abs(X%D - D))


X, K, D = map(int, input.split())
if (abs(X) - K * D) > = 0:
  print(abs(X) - K * D)
else:
  print(min(X%D, D-X%D))

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x,k,d = ,ap(int,input().split())
x = abs(x)
if x-k*d>0:
    print(x-k*d)
elif (k-x//d)%2 ==1:
    print(abs(x%d-d))
else:
    print(x%d)

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

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    x = kwargs["x"]
    k = kwargs["k"]
    d = kwargs["d"]
    if k * d < abs(x):
        res = abs(x) - k * d
    else:
        res_1 = abs(x) % d
        res_2 = res_1 - k * (abs(x) // d % 2)
        res = abs(res_2)

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["x"], kwargs["k"], kwargs["d"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    x = kwargs["x"]
    k = kwargs["k"]
    d = kwargs["d"]
    if k * d <= abs(x):
        res = abs(x) - k * d
    else:
        res = abs(abs(x) % d - (k - abs(x) // d) % 2 * d)

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["x"], kwargs["k"], kwargs["d"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
a,k,d = map(int, input().split())

if a < 0:
    x = -a
else:
    x = a

y = x % d
l = x // d
m = k - l

if m < 0:
    ans = x - (k * d)
elif m % 2 ==0:
    ans = y
else :
    ans = y - d

a,k,d = map(int, input().split())

if a < 0:
    x = -a
else:
    x = a

y = x % d
l = x // d
m = k - l

if m < 0:
    ans = x - (k * d)
elif m % 2 ==0:
    ans = y
else :
    ans = y - d

print(abs(ans))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x,k,d= list(map(int, input().split()))
a=x//d
if k>=a:
    if (k-a)%2==0:
        x=abs(x)
        print(x%d)
    else:
        x=abs(x)
        if x%d>d-(x%d):
            print(d-(x%d))
        else:
            print(d+(x%d))
else:
    x=abs(x)
    print(x-(k*d))

    

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


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


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X, K, D = map(int,input().split())
absX = abs(X)
t = K % 2
if t == 0:
    a = abs(X - (D * 2))
    b = abs(X + (D * 2))
    if absX < a:
        a = absX
    if absX < b:
        a = absX
else:
    a = abs(X - D)
    b = abs(X + D)

if a < b:
    print(a)
else:
    print(b)

X, K, D = map(int,input().split())
absX = abs(X)
t = abs(X // D)
remain_K = K - t
l = X % D
if remain_K < 0:
    a = abs(X - (K * D))
    b = abs(X + (K * D))
    if a < b:
        ans = a
    else:
        ans = b
else:
    if remain_K % 2 == 0:
        a = abs(l - (D * 2))
        b = abs(l + (D * 2))
        if a < b and a < l:
            ans = a
        elif a > b and b < l:
            ans = b
        else:
            ans = l
    else:
        a = abs(l - D)
        b = abs(l + D)
        if a < b:
            ans = a
        else:
            ans = b
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X,K,D=map(int,input().split(' '))
time=0
if X>=0:
    while X>0:
        X-=D
        time+=1
        if time==K:
            break
    if (K-time)%2==0:
    print(abs(X))
else:
    print(X+D)
else:
    while X<0:
        X+=D
        time+=1
        if time==K:
            break
    if (K-time)%2==0:
    print(abs(X))
else:
    print(X-D)

X,K,D=map(int,input().split(' '))
if X>=0:
    time=X//D
    if time>K:
        print(X-K*D)
    elif (K-time)%2==0:
        print(X%D)
    else:
        print(abs((X%D)-D))
else:
    time=-(X//D)
    if time>K:
        print(abs(X+K*D))
    elif (K-time)%2==0:
        print(X%D)
    else:
        print(abs((X%D)-D))

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x,k,d=[int(i) for i in input().split()]

x=abs(x)

t=x

if k%2==1:
    t-=d
    k-=1

min=abs(t)

if t-k*d>0:
    print(t-k*d)
    exit(0)

if t-k*d<0:
    s=int(t/(d*2))
    print(s)
    k-=s*2
    t-=d*s*2
    min=abs(t)

while(-x<t and k>0):
    t-=d*2
    k-=2
    if min < abs(t):
        break
    else:
        min=abs(t)

print(min)


x,k,d=[int(i) for i in input().split()]

x=abs(x)

t=x

if k%2==1:
    t-=d
    k-=1

min=abs(t)

if abs(x-k*d)<min:
    print(x-k*d)
    exit(0)

if x-k*d<0:
    k-=(x/(d*2))*2


while(-x<t and k>0):
    t-=d*2
    k-=2
    if min < abs(t):
        break
    else:
        min=abs(t)

print(min)


x,k,d=[int(i) for i in input().split()]

x=abs(x)

t=x

if k%2==1:
    t-=d
    k-=1

min=abs(t)

if t-k*d>0:
    print(t-k*d)
    exit(0)

if t-k*d<0:
    s=(x/(d*2))*2
    k-=s
    t-=d*s

while(-x<t and k>0):
    t-=d*2
    k-=2
    if min < abs(t):
        break
    else:
        min=abs(t)

print(min)


x,k,d=[int(i) for i in input().split()]

x=abs(x)

a=int(x/d)


if a>k:
    a=k

k-=a

x-=a*d

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

print(x)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
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(abs(x)%d+d)
else:
    print(abs(x)-d*k)

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)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
xkd = list(map(int,input().split()))
xkd[0] = abs(xkd[0])
x = xkd[0] // xkd[2]
x = abs(x)
xkd[0] -= xkd[2] * x
xkd[1] -= x
if xkd[1] < 1:
  xkd[0] += abs(xkd[1]) * xkd[2]
  print(xkd[0])
else:
    ans = xkd[0]
    if xkd[1] % 2 != 0:
        ans -= xkd[2]
        if ans > xkd[0] + xkd[2]:
            ans += xkd[2] * 2
            print(abs(ans))

X,K,D=map(int,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)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x, k, d = map(int, input().split())


n = int(x / d + 0.5)
if n > k:
    ans = x - k*d
else:
    a = x - n*d
    if (k - n) % 2:
        if a > 0:
            ans = a - d
        else:
            ans = a + d
    else:
        ans = a
        
print(ans)

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

ax = abs(x)
n = ax // d
if n >= k:
    ans = ax - k*d
else:
    a = ax - n*d
    if (k - n) % 2:
        ans = abs(a - d)
    else:
        ans = abs(a)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
    print(x-k*d)
else:
    p=x//k
    if p%2==k%2:
        print(x-k*p)
    else:
        print(abs(x-(k+1)*p))

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))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import sys

x = abs(int(input()))
k = int(input())
d = int(input())

move_cnt = int(x / d)
if (move_cnt <= k):
    k -= move_cnt
    amari = x - move_cnt * d

else:
    amari = x - k * d
    k = 0

if (k > 0):
    if (k % 2 == 1):
        if (amari > 0):
            amari -= d
        else:
            amari += d

print(abs(amari))

import sys

x = abs(int(input()))
k = int(input())
d = int(input())

move_cnt = float(x / d)
if (move_cnt <= k):
    k -= move_cnt
    amari = x - move_cnt * d

else:
    k = 0
    amari = x - move_cnt * d

if (k > 0):
    if (k % 2 == 1):
        if (amari > 0):
            amari -= d
        else:
            amari += d

print(int(abs(amari)))

import sys

# x = abs(int(input()))

# d = int(input())

array = list(map(int, input().strip().split()))
x = abs(array[0])
k = array[1]
d = array[2]
if (d == 0):
    amari = abs(x)

else:
    move_cnt = int(x / d)
    if (move_cnt <= k):
        k -= move_cnt
        amari = x - move_cnt * d

    else:
        amari = x - k * d
        k = 0

    if (k > 0):
        if (k % 2 == 1):
            if (amari > 0):
                amari -= d
            else:
                amari += d

print(abs(amari))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
IN = list(map(int, input().split()))
X, K, D = IN[0], IN[1], IN[2]

mv = int(-X / D + 0.5)
if (abs(mv)>K): mv = mv * K / abs(mv)
residual_moves = K - abs(mv)

if residual_moves % 2 == 0:
    print (int(abs(X + D * mv)))
else:
    posa = X+D*(mv+1)
    posb = X+D*(mv-1)
    posc = X+D*(mv+2)
    posd = X+D*(mv-2)
    print(int(abs(min(posa, posb, posc, posd))))

    


IN = list(map(int, input().split()))
X, K, D = IN[0], IN[1], IN[2]

#mv = int(-X / D + 0.5)
mv = round(-X / D, 0)
if (abs(mv)>K): mv = mv * K / abs(mv)
residual_moves = K - abs(mv)

if residual_moves % 2 == 0:
    print (int(abs(X + D * mv)))
else:
    posa = abs(X+D*(mv+1))
    posb = abs(X+D*(mv-1))
    posc = abs(X+D*(mv+2))
    posd = abs(X+D*(mv-2))
    print(int(min(posa, posb, posc, posd)))


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import sys
input = sys.stdin.readline

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

a = abs(x) // d
b = abs(x) // d + 1

if a > k:
    print(abs(x) - k * d)
else:
    if b < a:
        a = b

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


import sys
input = sys.stdin.readline

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

a = abs(x) // d
b = abs(x) // d + 1

if a > k:
    print(abs(x) - k * d)
else:
    if b < a:
        a = b

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


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X, K, D = map(int, input().split())

if int(abs(X) / D) > K:
    if abs(X) < abs(X) % D:
        if K % 2 == 0:
            print(abs(X))
        else:
            print(min(abs(X - D), abs(X + D)))
    else:
        if int(K - int(abs(X) / D)) % 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)

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

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

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
def abc175c_walking_takahashi():
    x, k, d = map(int, input().split())
    x = -x if x < 0 else x
    num = math.ceil(x / d)
    if num > k:
        print(x-k*d)
        return
    else:
        k -= num
        x -= num*d
        if k % 2 == 0:
            print(abs(x))
        else:
            print(x+d)
abc175c_walking_takahashi()

import math

def abc175c_walking_takahashi():
    x, k, d = map(int, input().split())
    x = -x if x < 0 else x
    num = math.ceil(x / d)
    if num > k:
        print(x-k*d)
        return
    else:
        k -= num
        x -= num*d
        if k % 2 == 0:
            print(abs(x))
        else:
            print(x+d)
abc175c_walking_takahashi()


Verdicts: Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X, K, D = map(int,input().split())
ans = abs(X)
k = min(X//D,K)
ans -= k*D
K -= k
if k % 2 == 0:
    print(ans)
else:
    ans += D
    print(ans)




X, K, D = map(int,input().split())
ans = abs(X)
k = min(X//D,K)
ans -= k*D
K -= k
if K % 2 == 0:
    print(ans)
else:
    ans += D
    print(ans)




X, K, D = map(int,input().split())
ans = abs(X)
rem = K
k = min(X//D,K)
ans -= k*D
rem -= k
if rem > 0:
    if rem % 2 == 1:
        ans = ans - D
        print(abs(ans))
print(abs(ans))



X, K, D = map(int,input().split())
ans = abs(X)
rem = K
k = min(ans//D,K)
ans -= k*D
rem -= k
if rem > 0:
    if rem % 2 == 1:
        ans = ans - D
        print(abs(ans))
print(abs(ans))



X, K, D = map(int,input().split())
ans = abs(X)
rem = K
k = min(ans//D,K)
ans -= k*D
rem -= k
if rem > 0:
    if rem % 2 == 1:
        ans = ans - D
        # print(abs(ans))
print(abs(ans))



Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x,k,d = list(map(int,input().split()))

x = abs(x)

mod = x % d

if mod >= k:
    ans = x - (d*k)

elif (k-mod) % 2 == 0:
    ans = x - (d*mod)

else:
    ans = x - (d*mod) - d

print(ans)

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

x = abs(x)

m = x // d

if m >= k:
    ans = x - (d*k)

elif (k-m) % 2 == 0:
    ans = x - (d*m)

else:
    ans = x - (d*m) - d

print(abs(ans))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
X, K, D = map(int, input().split())

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

if(X/D > K):
  print(X-D*K)
else:
  if(int(X/D)%2 == 0):
    print(int(X/D))
    print("A", min_pos)
  else:
    print(int(X/D))
    print("B", abs(min_neg))

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

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

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

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

X, K, D = MAP()

if X == 0:
	if K%2 == 0:
		print(0)
	else:
		print(D)
	exit()

if K - abs(X)//D*D <= 0:
	if X < 0:
		print(X+D*K)
	else:
		print(X-D*K)
	exit()


K -= abs(X)//D
if X < 0:
	X += D*(abs(X)//D)
else:
	X -= D*(abs(X)//D)


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



import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

X, K, D = MAP()

if X == 0:
	if K%2 == 0:
		print(0)
	else:
		print(D)
	exit()

flg = X//abs(X)
n = abs(X)//D

if abs(X-n*D*flg) > abs(X-(n+1)*D*flg):
	n += 1

if K <= n:
	print(abs(X-K*D*flg))
	exit()

X -= flg*n*D
if X == 0:
	flg = 1
else:
	flg = X//abs(X)
K -= n

if K%2 == 0:
	print(abs(X))
else:
	print(abs(X-flg*D))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x, k, d = map(int, input().split())

if x >= 0:
    if x >= k * d:
        print(x - k * d)
    else:
        func(x, k, d)
        
        
        
        #     print(mod)
        # else:
        #     print(abs(mod - d))
else:
    if abs(x) >= k * d:
        print(abs(x) - k * d)
    else:
        func(x, k, d)
        
        
        
        #     print(mod)
        # else:
        #     print(abs(mod - d))


def func(x, k, d):
    q, mod = divmod(abs(x), d)
    k -= q
    if k % 2 == 0:
        print(mod)
    else:
        print(abs(mod - d))


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

if x >= 0:
    if x >= k * d:
        print(x - k * d)
    else:
        func(x, k, d)
        
        
        
        #     print(mod)
        # else:
        #     print(abs(mod - d))
else:
    if abs(x) >= k * d:
        print(abs(x) - k * d)
    else:
        func(x, k, d)
        
        
        
        #     print(mod)
        # else:
        #     print(abs(mod - d))


def func(x, k, d):
    q, mod = divmod(abs(x), d)
    k -= q
    if k % 2 == 0:
        print(mod)
    else:
        print(abs(mod - d))
    return 0


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

# if x == 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))


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

if abs(x) >= k * d:
    print(abs(x) - k * d)
else:
    q, mod = divmod(x, d)
    if (k - q) % 2 == 0:
        print(mod)
    else:
        print(abs(mod - d))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import math

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

ans = 0
if x == 0:
    if k%2 == 0:
        ans = 0
    elif k%2 == 0:
        ans = abs(d)
else :
    if abs(x) - k*d >= 0:
        ans = x - k*d
        #if abs(x) - k*d == 0:
            
                
            #else:
                
    elif abs(x) - k*d < 0:
        if  abs(x) - d*(abs(x) // d) != 0:
            if (k - (math.ceil(abs(x) / d) )) % 2 == 1:
                ans = abs(abs(x) - d*(abs(x) // d))
            else:
                ans = (abs(x) - d*(abs(x) // d + 1))
        else:
            if (k - (math.ceil(abs(x) // d) ) ) % 2 == 1:
                ans = d
            else:
                ans = 0
print(ans)


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

x = abs(x)
y = k * d
ans = x + d
if(x > y):
    ans = min(ans , x - y)
else:
    mar = x % d
    if (x // d) % 2 == (k % 2):
        ans = min(ans , mar)
    else:
        ans = min(ans , abs(d - mar))
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
x = abs(x)
t = x // d
if t >= k:
    answer = x - (t * d)
else:
    if (k - t) % 2 == 0:
        answer = x - (t * d)
    else:
        answer = x - (t - 1) * d
        
print(answer)

# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
x = abs(x)
t = x // d
if t >= k:
    answer = x - (k * d)
else:
    if (k - t) % 2 == 0:
        answer = x - (t * d)
    else:
        answer = x - (t - 1) * d
        
print(answer)

# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
x = abs(x)
t = x // d
if t >= k:
    answer = x - (k * d)
else:
    if (k - t) % 2 == 0:
        answer = x - (t * d)
    else:
        answer = x - (t + 1) * d
        
print(abs(answer))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
x, k, d = map(int, input().split())
x = abs(x)
s = x//d
elif s>k:
    print(x-d*k)
elif s<k:
    if (k-s)%2==0:
        print(x-d*s)
    elif (k-s)%2==1:
        print(abs(x-d*(s+1)))

x, k, d = map(int, input().split())
end = False
plus =True
if x >= 0:
    for i in range(k):
        if x >= 0 and plus == False:
            if (k-(i+1))%2 == 1:
                print(abs(x))
                end = True
                break
            elif (k-(i+1))%2 == 0:
                print(abs(x-d))
                end = True
                break
        elif x >= 0:
            x=x-d
        elif x < 0:
            x=x+d
            plus = False
if x < 0:
    for i in range(k):
        if x < 0 and plus == False:
            if (k-(i+1))%2 == 1:
                print(abs(x))
                end = True
                break
            elif (k-(i+1))%2 == 0:
                print(abs(x-d))
                end = True
                break
        elif x >= 0:
            x=x-d
            plus = False
        elif x < 0:
            x=x+d
if end == False:
    print(x)

x, k, d = map(int, input().split())
minus=False
if x<0:
    minus = True
x = abs(x)
s = x//d
if s==0:
    k%2==0:
        if minus==True
            print(-x)
        else: print(x)
    k%2==1:
        if minus==True
            print(-x+d)
        else: print(x-d)
elif s>k:
    if minus==True
        print(x-d*k)
    else: print(-x+d*k)
elif s<k:
    (k-s)%2==0:
        if minus==True
            print(-x+d*s)
        else: print(x-d*s)
    (k-s)%2==1:
        if minus==True
            print(-x+d*(s+1))
        else: print(x-d*(s+1))

x, k, d = map(int, input().split())
x = abs(x)
s = x//d
if s>k:
    print(x-d*k)
elif s<=k:
    if (k-s)%2==0:
        print(x-d*s)
    elif (k-s)%2==1:
        print(abs(x-d*(s+1)))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
import math
N=input().split()
X=int(math.fabs(int(N[0])))
K=int(N[1])
D=int(N[2])
if X-K*D>=0:
    print(X-K*D)
else:
    x=X%D
    y=X-X%D
    ans_pre=min(x,y)
    i=int((X-ans_pre)/D)
    if i%2==K%2:
        print(ans_pre)
    else:
        print(max(x,y))

import math
N=input().split()
X=int(math.fabs(int(N[0])))
K=int(N[1])
D=int(N[2])
if X-K*D>=0:
    print(X-K*D)
else:
    x=X%D
    y=X-X%D
    a=int((X-x)/D)
    b=int((X-y)/D)
    if K%2==0:
        if a%2==0:
            print(x)
        else:
            print(y)
    else:
        if a%2==1:
            print(x)
        else:
            print(y)

import math
N=input().split()
X=int(math.fabs(int(N[0])))
K=int(N[1])
D=int(N[2])
if X-K*D>=0:
    print(X-K*D)
else:
    syou=X//D
    x=X-syou*D
    y=X-(syou+1)*D
    if K%2==0:
        if syou%2==0:
            print(x)
        else:
            print(int(math.fabs(y)))
    else:
        if syou%2==0:
            print(int(math.fabs(y)))
        else:
            print(x)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.  More specifically, in one move, he can go from coordinate x to x + D or x - D.  He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.  Find the minimum possible absolute value of the coordinate of the destination.

Submission attempts (in order):
def abc175_c_1():
    x, k, d = map(int, input().split())

    def solve(x, k, d):
        to_l_max = x - (k * d)
        to_r_max = x + (k * d)

        if to_l_max > 0:
            return to_l_max
        if to_r_max < 0:
            return to_r_max

        current_x = x

        for i in range(k):
            current_x = min(abs(current_x + d), abs(current_x - d))
        print(current_x)

    ans = solve(x, k, d)
    print(ans)

if __name__ == '__main__':
    abc175_c_1()

def abc175_c_3():
    x, k, d = map(int, input().split())

    def solve(x, k, d):
        

        x = abs(x)

        straight = int(min(k, x / d))
        k -= straight
        x -= straight * d

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

    ans = solve(x, k, d)
    print(ans)

if __name__ == '__main__':
    abc175_c_3()

Verdicts: Wrong Answer

Accepted