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):
x,k,d=list(map(int,input().split()))
print(x,k,d)
result=abs(x)-k*d
swithn=0

if result<0:
    if k%2==1:
        x-=d
    result=min(x%(2*d),-x%(2*d))
print(result)

x,k,d=list(map(int,input().split()))
print(x,k,d)
result=abs(x)-k*d

if result<0:
    result%=2
print(result)

x,k,d=list(map(int,input().split()))
#print(x,k,d)
result=abs(x)-k*d
swithn=0

if result<0:
    if k%2==1:
        x-=d
    result=min(x%(2*d),-x%(2*d))
print(result)

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

Y = X // D
if K > Y:
  A = Y
  if A % 2 != 0:
    if X > 0:
      X += D
    else:
      X -= D
else:
  A = K

print( abs( X ) - abs( A * D ) )


X, K, D = map( int, input().split())
 
Y = abs( X ) // D
if K <= Y:
  print( min( abs( X - K * D ) , abs( X + K * D ) ))
else:
  if ( K - Y ) % 2 == 0:
    print( min( abs( X - Y * D ) , abs( X + Y * D ),
                abs( X - ( Y - 2 ) * D ), abs( X - ( Y + 2 ) * D ),
                abs( X + ( Y - 2 ) * D ), abs( X + ( Y + 2 ) * D )))
  else:
    print( min( abs( X - ( Y - 1 ) * D ), abs( X - ( Y + 1 ) * D ),
                abs( X + ( Y - 1 ) * D ), abs( X + ( Y + 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):
X,K,D = map(int, input().split())
tm = X/D
if K <= tm:
  print(X-D*K)
else:
  if (K - tm)%2==1:
    print(abs(X-D*(tm+1)))
  else:
    print(abs(X-D*(tm)))

import math
 
X,K,D = map(int, input().split())
tm = round(X/D)
if K <= tm:
  print(abs(X+D*K)if absabs(X+D*K) < abs(X-D*K)else abs(X-D*K))
else:
  if (K-tm)%2==1:
    print(abs(X-D*(tm+1)) if abs(X-D*(tm+1)) < abs(X-D*(tm-1))else abs(X-D*(tm-1)))
  else:
    print(abs(X+D*K)if absabs(X+D*K) < abs(X-D*K)else abs(X-D*K))

X,K,D = map(int, input().split())
tm = round(X/D)
if K <= tm:
  print(X-D*K)
else:
  if (K-tm)%2==1:
    print(abs(X-D*(tm+1)))
  else:
    print(X-D*tm)

import math

X,K,D = map(int, input().split())
for i in range(K):
  if abs(X-D) < abs(X+D):
    X-=D
  else:
    X+=D
print(X)

X, K, D = map(int, input().split())
 
Xa = abs(X)
Xs = Xa // D
Xm = Xa % D
 
if (K <= Xs):
    print(abs(Xa-D*K))
elif (K-Xs) % 2 == 0:
    print(abs(Xm))
else:
    print(abs(D-Xm))

Verdicts: Wrong Answer

Runtime Error

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()))
L = X + D * K
 
if X >= 0:
   if K == 1 or D == 1:
      print(abs(X - D*K))
      exit()

elif X < 0:
   if K == 1 or D == 1:
      print(abs(X + D*K))
      exit()

elif L >= 0:
   if L / (2 * D) - int(L / (2 * D)) > 0.5:
      a = L // (2 * D) + 1
   else:
      a = L // (2 * D)
 
elif L < 0:
   if L / (2 * D) - int(L / (2 * D)) < -0.5:
      a = int(L / (2 * D)) - 1
   else:
      a = int(L / (2 * D)) 
print(abs(X-2*D*a+D*K))

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

a = (k * d - x) / (2 * d)

if abs(x) < k * d:
   if abs(int(a) + 1 - a) >= abs(int(a) - a):
      print(abs(x + 2 * int(a) * d - k * d))
   else:
      print(abs(x + 2 * (int(a) + 1) * d - k * d))

elif x < 0:
   print(abs(x + k * d))
else:
   print(x - k * 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=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)


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)


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
if a >= k:
  print(x - d * k)
elif (k - a) % 2:
  print(d * (a + 1) - a)
else:
  print(a - d * a)


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

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


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

q=X//D
if q>K:
    print(abs(X)-K*D)
else:
    if (K-q)%2==0:
        print(abs(X)-q*D)
    else:
        print(abs(X)-(q+1)*D)


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

X=abs(X)
q=X//D
if q>K:
    print(X-K*D)
else:
    if (K-q)%2==0:
        print(X-q*D)
    else:
        print(X-(q+1)*D)


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

X=abs(X)
q=X//D
if q>K:
    print(X-K*D)
else:
    if (K-q)%2==0:
        print(X-q*D)
    else:
        print(-X+(q+1)*D)

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())
ans=0

if abs(x)<d :
    if k%2==0 :
        ans=x
    else :
        x1,x2=x-d,x+d
        ans=x2
        if abs(x1)<abs(x2) :
            ans=x1

else :
    if x>0 :
        X=x%d
        K=k-(x//d)
        if K%2==0 and K>0 :
            ans=X
        elif K%2==1 and K>0 :
            x3,x4=X-d,X+d
            ans=x4
            if abs(x3)<x4 :
                ans=x3
        else :
            ans=x-k*d

    else :
        Y=abs(x)%d
        K=k-(abs(x)//d)
        if K%2==0 and K>0 :
            ans=-Y
        elif K%2==1 and K>0 :
            y1,y2=-Y+d,-Y-d
            ans=y1
            if abs(y2)<y1 :
                ans=y2
        else :
            ans=x+k*d

print(ans)
    
    

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

if abs(x)<d :
    if k%2==0 :
        ans=x
    else :
        x1,x2=x-d,x+d

else :
    if x>0 :
        X=x%d
        K=k-(x//d)
        if K%2==0 and K>0 :
            ans=X
        elif K%2==1 and K>0 :
            x3,x4=X-d,X+d
            ans=x4
            if abs(x3)<x4 :
                ans=x3
        else :
            ans=x-k*d

    else :
        Y=abs(x)%d
        K=k-(abs(x)//d)
        if K%2==0 and K>0 :
            ans=-Y
        elif K%2==1 and K>0 :
            y1,y2=-Y+d,-Y-d
            ans=y1
            if abs(y2)<y1 :
                ans=y2
        else :
            ans=x+k*d

print(ans)
    

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

if abs(x)<d :
    if k%2==0 :
        ans=abs(x)
    else :
        x1,x2=x-d,x+d
        ans=abs(x2)
        if abs(x1)<abs(x2) :
            ans=abs(x1)

else :
    if x>0 :
        X=x%d
        K=k-(x//d)
        if K%2==0 and K>0 :
            ans=abs(X)
        elif K%2==1 and K>0 :
            x3,x4=X-d,X+d
            ans=abs(x4)
            if abs(x3)<x4 :
                ans=abs(x3)
        else :
            ans=abs(x-k*d)

    else :
        Y=abs(x)%d
        K=k-(abs(x)//d)
        if K%2==0 and K>0 :
            ans=abs(-Y)
        elif K%2==1 and K>0 :
            y1,y2=-Y+d,-Y-d
            ans=abs(y1)
            if abs(y2)<y1 :
                ans=abs(y2)
        else :
            ans=abs(x+k*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):
import math

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

a = X - K * D
if a > 0:
    print(a)
    return
if a + 2 * K * D < 0:
    print(abs(a + 2 * K * D))
    return
else:
    b = a / (-2 * D)
    p = math.floor(b)
    q = math.ceil(b)
    r = -(a + 2 * D * p)
    s = a + 2 * D * q
    print(min(r,s))
    return


import math
import sys

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

a = X - K * D
if a > 0:
    print(a)
    sys.exit()
if a + 2 * K * D < 0:
    print(abs(a + 2 * K * D))
    sys.exit()
else:
    b = a / (-2 * D)
    p = math.floor(b)
    q = math.ceil(b)
    r = -(a + 2 * D * p)
    s = a + 2 * D * q
    print(min(r,s))
    sys.exit()

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

minx=x-k*d
maxx=x+k*d
targetx=minx%(2*d)
if targetx>d:
    targetx-=2*d
if targetx==-d:
    if x<0:
        targetx-=2*d

if minx>targetx:
    print(minx)
    exit()
if maxx<targetx:
    print(maxx)
    exit()
print(targetx)


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

minx=x-k*d
maxx=x+k*d
targetx=minx%(2*d)
if targetx>d:
    targetx-=2*d
if targetx==d:
    if x<0:
        targetx-=2*d

if minx>targetx:
    print(minx)
    exit()
if maxx<targetx:
    print(maxx)
    exit()
print(targetx)


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

minx=x-k*d
maxx=x+k*d
targetx=minx%(2*d)
if targetx>d:
    targetx-=2*d
if targetx==d:
    if x<0:
        targetx-=2*d

if minx>targetx:
    print(abs(minx))
    exit()
if maxx<targetx:
    print(abs(maxx))
    exit()
print(abs(targetx))


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

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)

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)
print(x)
ans = 0
if x//d>k:
    ans = abs(x-d*k)
else:
    tmp = x//d
    k -= tmp
    x -= tmp*d
    if k%2 == 1:
        ans = abs(x-d)
    else:
        ans = abs(x)
print(ans)

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

x, k,d = map(int, input().split())
x = abs(x)
ans = 0
if x//d>k:
    ans = abs(x-d*k)
else:
    tmp = x//d
    k -= tmp
    x -= tmp*d
    if k%2 == 1:
        ans = abs(x-d)
    else:
        ans = abs(x)
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):
#C
x,k,d=map(int, input().split())


s = abs(x)//d


if s >= k:
    print(abs(x) - k*d)


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

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


s = x//d


if s >= k:
    print(abs(x) - abs(k*d))


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

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

s = abs(x)//d
 

if s >= k:
    print(abs(x) - k*d)
 

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

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:
    if X >= 0:
        ans = X - K*D
    else:
        ans = X + K*D
else:
    if X >= 0:
        if (K - X//D)%2 == 0:
            ans = X%D
        else:
            ans = X%D - D
    else:
        if (K - X//D)%2 == 0:
            ans = X%D - D
        else:
            ans = X%D

print(ans)

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



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

print(ans)

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



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

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):
,K,D = map(int,input().split())

y = abs(X)//D

if K<=y:
    print(abs(abs(X)-K*D))

else  :
    a = (X-y*D)
    b = (X-(y+1)*D)
    
    C = abs(a)
    D = abs(b)
    
    if (K-y)%2==0:
        print(C)
    else:
        print(D)


#print(y+1)
#print(1000000000000000)

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

y = abs(X)//D

if K<=y:
    print(abs(abs(X)-K*D))

else  :
    a = (abs(X)-y*D)
    b = (abs(X)-(y+1)*D)
    
    C = abs(a)
    D = abs(b)
    
    if (K-y)%2==0:
        print(C)
    else:
        print(D)


#print(y+1)
#print(1000000000000000)

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_1 = x%d 
ans_2 = abs(ans_1-d) 

if x//d > k:
    print(x-(d*k))
    exit()
if ans_1 > ans_2:
    if (k-(x//d)-1)%2 == 0:
        print(min(ans_1,ans_2))
    else:
        print(max(ans_1,ans_2))
        
        
elif ans_1 < ans_2:
    if (k-(x//d))%2 == 0:
        print(int(ans_1))
    else:
        print(int(ans_2))

        

x,k,d = map(int,input().split())
x = abs(x)
num = x//d
a = x-d*num
b = abs(a-d)
if x >= (d*k):
  print(x-(d*k))
  exit()
else:
  if min(a,b) == b:
    num += 1
  if (k-num) % 2 == 0:
    print(min(a,b))
  else:
    print(max(a,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):
def Qc():
    x, k, d = map(int, input().split())
    x = abs(x)
    print(x,k,d)
    for v in range(k):
        x -= d
        ans = x
        if x <= 0:
            ans = min(abs(x-d), abs(x+d))
            break
    print(ans)


if __name__ == '__main__':
    Qc()


def Qc():
    x, k, d = map(int, input().split())
    x = abs(x)
    all_minus = abs(x) - (k * d)
    if 0 <= all_minus:
        ans = all_minus
    else:
        point = abs(all_minus) // d
        all_minus += d * point
        ans = abs(all_minus)
        if point % 2 != 0:
            ans = min(abs(all_minus - d), abs(all_minus + d))
    print(ans)


if __name__ == '__main__':
    Qc()


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 <= 0:
    d = X//D
    K -= d
    x -= D*d
    if K%2 == 0:
        print(a)
    else:
        print(abs(a-d))
else:
    print(X-K*D)

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

X = abs(X)

if X-K*D <= 0:
    d = X//D
    K -= d
    X -= D*d
    if K%2 == 0:
        print(X)
    else:
        print(abs(X-D))
else:
    print(X-K*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):
##C - Walking Takahash


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

if X < 0:
    X = -X
if X > 0 and X-K*D >= 0:
    print(X-K*D)
elif X == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
else:
    if R % 2 == 0:
        print(X - D*(X//D))
    else:
        print(X - D*((X//D)+1))

##C - Walking Takahash


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

if X < 0:
    X = -X
if X > 0 and X-K*D >= 0:
    print(X-K*D)
else:
    if R % 2 == 0:
        print(X - D*(X//D))
    else:
        print(X - D*((X//D)+1))

##C - Walking Takahash


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

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

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):
import sys
x,k,d=map(int,input().split())

x=abs(x)

a=x//d

if a>=k:
    ans=x-k*d

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

else:
    ans=x-d*m-d

print(abs(ans)

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

x=abs(x)

if k*d<=x:
    print(x-k*d)
    sys.exit()

if k>=x:

    
else:
    print(x%d)

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

x=abs(x)

a=x//d

if a>=k:
    ans=x-k*d

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

else:
    ans=x-d*a-d

print(abs(ans))

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 = map(int, input().split())

if abs(X) <= D * K:
    for i in range(K):
        a = abs(X) - (D * (i + 1))
        b = abs(X) - (D * i)
        if a < 0:
            break
    if abs(a) < abs(b):
        c = K - (i + 1)
        if c % 2 == 0:
            if 0 <= X:
                goal = a
            else:
                goal = -a
        else:
            if 0 <= X:
                goal = b
            else:
                goal = -b

    if abs(b) <= abs(a):
        c = K - i
        if c % 2 == 0:
            if 0 <= X:
                goal = b
            else:
                goal = -b
        else:
            if 0 <= X:
                goal = a
            else:
                goal = -a
else:
    if 0 <= X:
        goal = X - D * K
    else:
        goal = X + D * K

print(goal)

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

if abs(X) <= D * K:
    for i in range(K):
        a = abs(X) - (D * (i + 1))
        b = abs(X) - (D * i)
        print(a,b)
        if a < 0:
            break
    if abs(a) < abs(b):
        c = K - (i + 1)
        if c % 2 == 0:
            if 0 <= X:
                goal = a
            else:
                goal = -a
        else:
            if 0 <= X:
                goal = b
            else:
                goal = -b

    if abs(b) <= abs(a):
        c = K - i
        if c % 2 == 0:
            if 0 <= X:
                goal = b
            else:
                goal = -b
        else:
            if 0 <= X:
                goal = a
            else:
                goal = -a
else:
    if 0 <= X:
        goal = X - D * K
    else:
        goal = X + D * K

print(goal)

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

if abs(X) < (K * D):
    a = abs(X) % D
    b = abs(D - a)
    c = abs(X) // D + 1
    if (K - c) % 2 == 0:
        goal = b
    else:
        goal = a
else:
    goal = abs(X) - ( D * K )

print(goal)

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 = [int(i) for i in input().split()]
for i in range(k):
  x+=d if x<0 else -d
  if abs(x)<d:
    x=(abs(x)-d)*x/abs(x) if (k-1-i)&1==1 else x
    break
print(x)

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)

x,k,d = [int(i) for i in input().split()]
for _ in range(k):
  x+=d if x<0 else -d
print(x)

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)

Verdicts: Runtime Error

Runtime Error

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

def solve(x, k, d):
    x = math.fabs(x)
    if x - k * d >= 0:
        return x - k * d
    else:
        cur = x - x // d * d
        k = k - x // d
        if k % 2 == 0:
            return cur
        else:
            return abs(cur - d)

if __name__ == "__main__":
    x, k, d = map(int, input().split(' '))
    print(solve(x, k, d))


import math

def solve(x, k, d):
    x = math.fabs(x)
    if x - k * d >= 0:
        return int(x - k * d)
    else:
        cur = x - x // d * d
        k = k - x // d
        if k % 2 == 0:
            return int(cur)
        else:
            return int(abs(cur - d))

if __name__ == "__main__":
    x, k, d = map(int, input().split(' '))
    print(solve(x, k, 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,K,D = map(int, input().split())
if X < 0: X = abs(X) 

if X // D > K:
    X = X - (K * D)
    print(X)
    sys.exit() 

if (X // D) + 1 < K:
    if X % D >= abs((X % D)-D):
        if (K - (X // D)) % 2 == 1:
            print(abs((X % D)-D))
            sys.exit()
        else:
            print(X % D)
            sys.exit()
    else:
        print(X % D)
        sys.exit()





import sys
X,K,D = map(int, input().split())
if X < 0: X = abs(X) 

if X // D > K:
    X = X - (K * D)
    print(X)
    sys.exit() 

if (X // D) + 1 < K:
    if X % D >= abs((X % D)-D):
        print(abs((X % D)-D))
        sys.exit()
    else:
        print(X%D)
        sys.exit()





import sys
X,K,D = map(int, input().split())
if X < 0: X = abs(X) 

if X // D > K:
    X = X - (K * D)
    print(X)
    sys.exit() 

if (X // D) <= K:
    if X % D >= abs((X % D)-D):
        if (K - (X // D)) % 2 == 1:
            print(abs((X % D)-D))
            sys.exit()
        else:
            print(X % D)
            sys.exit()
    else:
        if (K - (X // D)) % 2 == 1:
            print(abs((X % D)-D))
            sys.exit()
        else:
            print(X % D)
            sys.exit()





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())
mini=0
if abs(x)>=k*d:
 mini=abs(x)-k*d
 print(mini)
else:
 q=abs(x)//d
 s=abs(x)%d
 if (k-q)%2==0:
  print(s)
 else:
  print(s-d)

x,k,d=map(int,input().split())
mini=0
if abs(x)>=k*d:
 mini=abs(x)-k*d
 print(mini)
else:
 q=abs(x)//d
 s=abs(x)%d
 if (k-q)%2==0:
  print(s)
 else:
  print(abs(s-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())
cur=abs(x)
count=min(cur//d,k)
cur-=d*count
s=k-count
if s%2==1:
  cur-=-d
print(abs(cur))


x,k,d=map(int,input().split())
cur=abs(x)
count=min(cur//d,k)
cur-=d*count
k-=count
if k%2==1:
  cur-=-d
print(abs(cur))

x,k,d=map(int,input().split())
cur=abs(x)
count=min(cur//d,k)
cur-=d*count
k-=count
if k%2==1:
  cur-=d
print(abs(cur))


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 = list(map(int, input().split()))

i = min(X//D, K) 
k = X%D

if k == 0:
    #print("1")
    print(X - i*D)
else:
    n = K - i
    if n%2==0:
        #print("2")
        print(X - i*D)
    else:
        #print("3")
        print(X - i*D - D)


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

i = min(X//D, K) 
X = X - i*D
K = K - i

if K > 0:
    if K % 2 == 1:
        X = X - D
print(abs(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):
#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    long long X,K,D;
    long long ans = 0;
    cin >> X >> K >> D;

    if(K * D <  abs(X)){
        ans = abs(X) - K * D;
    }else{
        if( (abs(X) / D) % 2 == 0 ){
            if( K % 2 == 0){
                ans = abs(X) % D;
            }else{
                ans = abs(abs(X) % D  - D);
            }
            
        }else{
            if( K % 2 == 0){
                ans = abs(abs(X) % D  - D);
            }else{
                ans = abs(X) % D;
            }
        }
    }

    cout << ans << endl;

}


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

X = abs(X)
if X / D > K:
    ans = X - K * D
else:
    if X // D % 2 == K % 2:
        ans = X % D
    else:
        ans = abs(X % D - 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())

K -= int(X/D)
X -= int(X/D)*D

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

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

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

X,K,D = map(int,input().split())
a = int(X/D)
if a < K:
    K -= a
    X -= a*D

K %= 2

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

X,K,D = map(int,input().split())
X = abs(X)
a = int(X/D)
if a < K:
        K -= a
        X -= a*D

if K*D <= X:
    X -= K*D
else:
    K %= 2
    for i in range(K):
        if X > 0:
            X -= D
        else:
            X += D
print(abs(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):
# coding: utf-8
# Your code here!

import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    X, K, D = LI()
    X = abs(X)

    a = math.ceil(X/D)

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


if __name__ == '__main__':
    main()


# coding: utf-8
# Your code here!

import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    X, K, D = LI()
    X = abs(X)

    a = math.ceil(X/D)

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


if __name__ == '__main__':
    main()


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())
s=[]
if x//d>k:
  print(x-d*k)
else:
  for i in range(k):
    s.append(abs(x-d*i))
    print(min(s))

x,k,d= map(int,input().split())
x=abs(x)
if x>d*k:
  print(x-d*k)
else:
  m=x//d
  k=(k-m)%2
  print(abs((x%d)-k*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())

low = 0
high = K

while low <= high:
    mid = (low + high) //2
    i = mid
    j = K-mid
    ans_pre = (X + D*i - D*j)
    if ans_pre > 0:
        high = mid-1
    else:
        low = mid+1
        

if low > K :
    low = high
    
ans_l = min(abs((X + D*low - D*(K-low))), abs(X + D*(K-low)-D*low))
    
print(ans_l)

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

low = 0
high = K

while low <= high:
    mid = (low + high) //2
    i = mid
    j = K-mid
    ans_pre = (X + D*i - D*j)
    if ans_pre > 0:
        high = mid-1
    else:
        low = mid+1
        

if high < 0:
    high = 0


ans_l = min(abs((X + D*low - D*(K-low))), abs(X + D*(K-low)-D*low))
    
print(ans_l)

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

low = 0
high = K

while low <= high:
    mid = (low + high) //2
    i = mid
    j = K-mid
    ans_pre = (X + D*i - D*j)
    if ans_pre > 0:
        high = mid-1
    else:
        low = mid+1
        

if low > K :
    low = high
if high < 0:
    high = low
    
ans_h = min(abs((X + D*high - D*(K-high))), abs(X + D*(K-high)-D*high))
ans_l = min(abs((X + D*low - D*(K-low))), abs(X + D*(K-low)-D*low))
    
print(min(ans_l, ans_h))

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):
# # Make IO faster
# import sys
# input = sys.stdin.readline


# X = input()


# N = int(input())

# X, Y = map(int, input().split())
 for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
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 ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, K, D = MAP()
N = X // D

if K <= N:
    print(abs(X - K * D))
else:
    K -= N
    if K % 2 == 1:
        print(min(abs(X - (N + 1) * D), abs(X - (N - 1) * D)))
    else:
        print(min(abs(X - (N + 2) * D), abs(X - N * D), abs(X - (N - 2) * D)))


x, k, d = map(int, input().split())
x = abs(x)
if x > d:
    c = min(x//d, k)
    x -= d*c
    k -= c
if k%2: x = d - x
print(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 = list(map(int,input().rstrip().split()))
X = abs(X)
a = X//D
if K <= a:
    print(abs(X-(D*K)))
elif (K-a)a%2 == 0:
    print(abs(X-(D*a)))
else:
    print(abs(D*(a+1)-X))

X, K, D = list(map(int,input().rstrip().split()))
X = abs(X)
a = X//D
if K <= a:
    print(abs(X-(D*K)))
elif (K-a)%2 == 0:
    print(abs(X-(D*a)))
else:
    print(abs(D*(a+1)-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):
def isEven(num):
  if num%2 == 0:
  	return True
  return False

def isOdd(num):
  if num%2 == 1:
    return True
  return False

if __name__ == "__main__":
  x,k,d = map(int, input().split())
  div = x//d
  cmp = x
  defo = x
  if isOdd(k):
    if x > d:
      if k%div != 0:
        div = min(div,k%div)
      for i in [d,-d]:
        cmp = min(cmp,abs(defo+div*i))
      print(cmp)
    else:
      for i in [d,-d]:
        cmp = min(cmp,abs(defo+i))
      print(cmp)
  if isEven(k):
    div = x//(2*d)
    if x > d:
      div = min(div,k)
      for j in range(1,div):
        for i in [d,-d]:
          cmp = min(cmp,abs(defo+(2*j)*i))
      print(cmp)
    else:
      print(cmp)

def isEven(num):
  if num%2 == 0:
  	return True
  return False

def isOdd(num):
  if num%2 == 1:
    return True
  return False

if __name__ == "__main__":
  x,k,d = map(int, input().split())
  div = x//d
  cmp = x
  defo = x
  if isOdd(k):
    if x > d:
      if k%div != 0:
        div = min(div,k%div)
      for i in [d,-d]:
        cmp = min(cmp,abs(defo+div*i))
      print(cmp)
    else:
      for i in [d,-d]:
        cmp = min(cmp,abs(defo+i))
      print(cmp)
  if isEven(k):
    div = x//(2*d)
    if x > d:
      div = min(div,k)
      for j in range(1,div)
        for i in [d,-d]:
          cmp = min(cmp,abs(defo+(2*j)*i))
      print(cmp)
    else:
      print(cmp)

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

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

Verdicts: Wrong Answer

Runtime Error

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):
for i in range(5,0,-1):


x, k, d = map(int, input().split())
if x < k*d:
    L = []
    s = x
    for i in range(k):
        L.append(s)
        L = sorted(L)
        s = abs(x) - d
        if s >= L[0] or s == 0:
            break
        x = s
    if k%2 == 0:
        if len(L)>1:
            res = L[1]
        else:
            res = L[0]
    else:
        res = L[0]
elif abs(x) >= k*d:
    res = abs(abs(x)-k*d)
print(res)

x, k, d = map(int, input().split())
x = abs(x)
if x > k*d:
    print(x-k*d)
else:
    p = x//d
    if p == 0 or p==1:
          for i in range(1,k+1):
            p2 = x-i*d
            c = k-i
            if p2 <= 0:
                if c%2 != 0:
                    print(abs(d+p2))
                    break
                elif c%2 == 0:
                    print(abs(p2))
                    break
    c = k-p
    elif c%2 == 0:
        print(abs(x-p*d))
    else:
        print(abs(d-abs(x-p*d)))

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


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):
c = x // d

k_r = k - c

ans_2 = x - d * c


if c >= k:
    print(x - k * d )
    exit()

x_l = x - d * c


if k_r % 2 == 0:
    print(ans_2)
    exit()
else :
    x_l -= d
    x_l =abs(x_l)
    print(x_l)

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

x = abs(x)
c = x // d

k_r = k - c

ans_2 = x - d * c


if c >= k:
    print(x - k * d )
    exit()

x_l = x - d * c


if k_r % 2 == 0:
    print(ans_2)
    exit()
else :
    x_l -= d
    x_l =abs(x_l)
    print(x_l)

Verdicts: Runtime Error

Accepted