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

X = abs(X)

n = X // D
m = K - n

A1 = abs(X - n*D)
A2 = abs(X - (n+1)*D)

Ans = A2

if m > 1:
    if A1 <= A2:
        if m % 2 == 0:
            Ans = A1
    else:
        if m-1 % 2 != 0:
            Ans = A2
else:
    Ans = X - K*D

print(Ans)

X, K, L = map(int, input().split())
min_dist = inf
for p_num in range(K+1):
    dist = L*p_num + (-1)*L*(K-p_num)
    if dist < min_dist:
        min_dist = dist
print(min_dist)


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

X = abs(X)

n = X // D
m = K - n

A1 = abs(X - n*D)
A2 = abs(X - (n+1)*D)

Ans = A2

if n+1 < K:
    if (A1 < A2 and m % 2 == 0) or (A1 > A2 and m % 2 != 0):
            Ans = A1
else:
    Ans = X - K*D

print(Ans)

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

X = abs(X)

n = X // D
m = K - n

A1 = abs(X - n*D)
A2 = abs(X - (n+1)*D)

Ans = A2

if m > 1:
    if A1 <= A2:
        if m % 2 == 0:
            Ans = A1
    else:
        if m-1 % 2 != 0:
            Ans = A2
else:
    Ans = X - K*D

print(Ans)

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

X = abs(X)

n = X // D
m = K - n

A1 = abs(X - n*D)
A2 = abs(X - (n+1)*D)

Ans = A2

if m > 1:
    if A1 <= A2:
        if m % 2 == 0:
            Ans = A1
    else:
        if m % 2 == 0:
            Ans = A1
else:
    Ans = abs(X - K*D)

print(Ans)
 

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(' '))))
dX = np.arange(-K,K+1,2)
new_X = X + D * dX
print(np.min(np.abs(new_X)))

import numpy as np
X, K, D = (list(map(int, input('').split(' '))))
X = np.abs(X)

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

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

X, K, D = map(int, input().split())
if X < 0:
    X = -X
k = X // D
if k >= K:
    X -= K * D
    print(abs(X))
else:
    X -= k * D
    K -= k
    if K % 2 == 0:
        print(abs(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):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = -float('inf')
for s in range(N):
    ### Step1
    S = []  
    
    i = P[s] - 1
    S.append(C[i])
    
    while i != s:
        i = P[i] - 1
        S.append(S[-1] + C[i])

    
    
    if K <= len(S):
        score = max(S[:K])
    
    elif S[-1] <= 0:
        score = max(S)
    
    else:
        
        score1 = S[-1] * (K // len(S) - 1)
        score1 += max(S)
        
        score2 = S[-1] * (K // len(S))
        r = K % len(S)
        if r != 0:
            score2 += max(0, max(S[:r]))
        
        score = max(score1, score2)

    ans = max(ans, score)

print(ans)

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

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(x) for x in input().split())
x=abs(X)
a=x//D

b=x-a*D
B=abs(x-(a+1)*D)

if b>B:
  a=a+1

if a>=K:
  print(abs(x-K*D))

else:
  c=K-a
  if c%2 == 0:
    print(abs(x-a*D))
  elif:
    d=abs(x-(a-1)*D)
    e=abs(x-(a+1)*D)
    print(min(d,e))

X,K,D=(int(x) for x in input().split())
x=abs(X)
a=x//D

b=x-a*D
B=abs(x-(a+1)*D)

if b>B:
  a=a+1

if a>=K:
  print(abs(x-K*D))

else:
  c=K-a
  if c%2 == 0:
    print(abs(x-a*D))
  else:
    d=abs(x-(a-1)*D)
    e=abs(x-(a+1)*D)
    print(min(d,e))

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 = input().split()
ans = 0
if abs(x) > abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d 
    k_2 = k - kaisuu
    if k_2/2 == 2:
        ans = abs(x) - d*kaisuu 
    else:
        ans = (abs(x) - d*kaisuu) - d
print(ans)


x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) > abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d
    k_2 = k - kaisuu
    if k_2/2 == 2:
        ans = abs(x) - d*kaisuu 
    else:
        ans = (abs(x) - d*kaisuu) - d
print(ans)


x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) >= abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d
    k_2 = k - kaisuu
    if k_2/2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = abs((abs(x) - d*kaisuu) - abs(d))
print(int(ans))


x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) >= abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d
    k_2 = k - kaisuu
    if k_2/2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = abs((abs(x) - d*kaisuu) - abs(d))
print(ans)


x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) > abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d
    k_2 = k - kaisuu
    if k_2/2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = (abs(x) - d*kaisuu) - d
print(ans)


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

Verdicts: Runtime Error

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

param_x_tmp = param_x

if param_x > 0:
  int_times_nega_posi = -1
else:
  int_times_nega_posi =  1

count = 0
while param_x_tmp*param_x > 0:
  
  param_x_tmp = param_x_tmp + param_d*int_times_nega_posi
  
  count = count + 1
  
  if param_k - count == 0:
    print(param_x_tmp*int_times_nega_posi*-1)

if count < param_k:
  int_move = param_k - count 
  int_move_devide_2_no_amari = int_move % 2
  print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi*-1))

param_x, param_k, param_d = map(int, input().split())

param_x_tmp = param_x

if param_x > 0:
  int_times_nega_posi = -1
else:
  int_times_nega_posi =  1
  
if (param_x*int_times_nega_posi*-1) - (param_k*param_d) > 0:
  print((param_x*int_times_nega_posi*-1) - (param_k*param_d))
  
else:
  int_time_before_cross_0 = int((param_x*int_times_nega_posi*-1) / param_d)
  # print(int_time_before_cross_0)
  
  param_x_tmp = param_x + int_time_before_cross_0*param_d*int_times_nega_posi
  # print(param_x_tmp)
  
  int_move = param_k - int_time_before_cross_0 
  int_move_devide_2_no_amari = int_move % 2
  print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi))
  
  #count = 0
  
  #  
  
  #  
  #  count = count + 1
  #  
  #  if param_k - count == 0:
  #    print(abs(param_x_tmp))
  #
  #if count < param_k:
  #  int_move = param_k - count 
  #  int_move_devide_2_no_amari = int_move % 2
  

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_list = []

if X+K*D <= 0:
    ans = abs(X+K*D)
else:
    if D>0:
        a = int((X+K*D)/(2*D))
            ans = abs(X+(K-(a+i))*D - (a+i)*D)
print(ans)

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

ans_list = []

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

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

if X+K*D <= 0:
    ans = abs(X+K*D)
else:
    a = (X+K*D)//(2*D)
    if a >= K:
        a = K
        ans = abs(X-K*D)
    else:
        ans_1 = abs(X+K*D-2*a*D)
        ans_2 = abs(X+K*D-2*(a+1)*D)
        ans = min(ans_1, ans_2)
print(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())


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


ans = 0

if 2 * x < d:
    ans = x
else:
    t = x // d
    if k > t - 2:
        if (k - t) / 2 == 0:
            t0 = abs(x - (t - 2) * d)
            t1 = abs(x - (t) * d)
            t2 = abs(x - (t + 2) * d)
            ans = min(t0, min(t1, t2))
        else:
            t0 = abs(x - (t - 1) * d)
            t2 = abs(x - (t + 1) * d)
            ans = min(t0, min(t1, t2))
    else:
      ans = abs(x- (k) * d)

print(ans)


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

x = abs(x)

ans = 0

t = x // d
s = x % d

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


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)
E=X%D
A=(X-E)/D
A=K-A
if X>=K*D:
  print(X-K*D)
eise:
  E=X%D
  A=(X-E)/D
  A=K-A
  A=A%2
  if A==0:
    print(E)
  eise:
    print(D-E)


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


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)

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


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

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

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

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

Verdicts: 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):
x,k,d=input().split()
x=abs(int(x))
k=int(k)
d=int(d)
a=x//d
b=x-a*d
c=(x-b)/d
i=int(c)
if k<=i:
  print(abs(x)-d*k)
  print('a')
else:
  if (k-(i))%2==0:
    print(abs(x)-d*(i))
    print('b')
  else:
    print(abs(abs(x)-d*(i+1)))
    print('c')

x,k,d=input().split()
x=int(x)
k=int(k)
d=int(d)
a=x//d
b=x-a*d
c=(x-b)/d
print(int(c))
i=int(c)
if k<=i:
  print(abs(x)-d*k)
else:
  if (k-(i))%2==0:
    print(abs(x)-d*(i))
  else:
    print(abs(abs(x)-d*(i+1)))

x,k,d=input().split()
x=abs(int(x))
k=int(k)
d=int(d)
a=x//d
b=x-a*d
c=(x-b)/d
i=int(c)
if k<=i:
  print(abs(x)-d*k)
else:
  if (k-(i))%2==0:
    print(abs(x)-d*(i))
  else:
    print(abs(abs(x)-d*(i+1)))

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(input()) for i in range(3)]
print(2)

X,K,D = list(map(int, input().split()))
co,ans = divmod(abs(X),D)
if (K - co) > 0:
    if (K - co) % 2 == 0:
        pass
    else:
        ans = abs(ans) - D
else:
    ans = abs(X) - K*D

print(abs(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 = int(input())
k = int(input())
d = int(input())

if ((k * d) > abs(x)):
    y = x // d
    if ((k - y) % 2 == 0):
        ans = abs(x) - y * d
    else:
        ans = abs(x - (x // abs(x)) * (y + 1) * d)
else:
    ans = abs(x) - k * d


print(ans)

v = input().split(" ")
x = int(v[0])
k = int(v[1])
d = int(v[2])

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


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


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


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


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())
i = 1

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


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

if k*d <= x:
    print(x-k*d)
else:
    i = x//d + 1
    #print(i)
    if (k-i)%2 == 0:
        print(abs(x-d*i))
    else:
        print(x-d*i + 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())
x1=abs(x)%d
x2=abs(abs(x1)-d)
num=abs(x)//d
if((k-num>=0):
	if((k-num)%2==0):
    	print(x1)
	else:
    	print(x2)
else:
   print(abs(x)-k*d)

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

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

strL = line.split()
X = abs(int(strL[0]))
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    ans = X - K * D
elif (K - div) % 2 != 0:
    ans = mod - D
else:
    ans = mod

print(int(ans))

line = input()

strL = line.split()
X = abs(int(strL[0]))
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    ans = X - K * D
elif (K - div) % 2 != 0:
    ans = mod - D
else:
    ans = mod

print(abs(int(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):
import sys

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

X,K,D = LI()

sho = X // D
amari = X % D

if (sho>=K):
    saigo = X - (K*D)
    print(abs(saigo))
else:
    nokori = K - ans(sho)
    if nokori % 2 == 0:
        print(abs(amari))
    else:
        ans = min(amari+D,amari-D)
        print(abs(ans))
        

import sys

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

X,K,D = LI()
X = abs(X)
sho = X // D
amari = X % D

if (sho>=K):
    saigo = X - (K*D)
    print(abs(saigo))
else:
    nokori = K - abs(sho)
    if nokori % 2 == 0:
        print(abs(amari))
    else:
        ans = min(amari+D,amari-D)
        print(abs(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 = (int(x) for x in 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)

X, K, D = (int(x) for x in 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(" "))
X = abs(X)
 
a = X // D
b = X % D
 
remain_count = K - a
 
if remain_count < 0:
    ans = X - K * D
else:
    if remain_count % 2 == 0:
        ans = b
    else:
        ans = abs(b - D)

X, K, D = map(int, input().split(" "))
X = abs(X)
 
a = X // D
b = X % D
 
remain_count = K - a
 
if remain_count < 0:
    ans = X - K * D
else:
    if remain_count % 2 == 0:
        ans = b
    else:
        ans = abs(b - 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):
import math
X, K, D = map(int,input().split())
X = math.fabs(X)
ans = 0
E = X//D
if E > K:
    ans = X - K * D
elif K%2 == E%2:
    ans = X-E*D
else:
    ans = -X+(E+1)*D
print(ans)

import math
X, K, D = map(int,input().split())
X = math.fabs(X)
ans = 0
if X - K*D > math.fabs(X- (K+1)*D):
    ans = X - K * D
elif K%2 == X//D%2:
    ans = int(X-(X//D)*D) 
else:
    ans = math.fabs(int(X-(X//D+1)*D))
print(ans)

import math
X, K, D = map(int,input().split())
X = math.fabs(X)
ans = 0
E = X//D
if X - K*D > math.fabs(X- (K+1)*D):
    ans = X - K * D
elif K%2 == X//D%2:
    ans = X-E*D
else:
    ans = -X+(E+1)*D
print(ans)


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

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=round(abs(X/D))
if K<a:
  print(abs(abs(X)-K*abs(D)))
elif (K-a)%2==0:
  l=[]
  l.append(abs(abs(X)-a*abs(D)))
  l.append(abs(abs(X)-(a+2)*abs(D)))
  l.append(abs(abs(X)-(a-2)*abs(D)))
  print(min(l))
elif (K-a)%2!=0:
  l=[]
    l.append(abs(abs(X)-(a+1)*abs(D)))
    l.append(abs(abs(X)-(a-1)*abs(D)))  
  print(min(l))

x,k,d=map(int,input().split())
if abs(x) >= k*d:
    print(abs(x)-k*d)
else:
    just=abs(x)//d
    if (k-just)%2==0:
        print(min(abs(abs(x)-just*d),abs(abs(x)-(just+2)*d)))
    else:
        print(min(abs(abs(x)-(just+1)*d),abs(abs(x)-(just-1)*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):
nums = [int(e) for e in input().split()]
current = nums[0]
num = nums[1]
move = nums[2]


current = abs(current)
if num%2 == 1:
    current -= move

res = current / move
if res < num:
    tmp = current - res*move
    if abs(tmp) > abs(tmp-move):
        print(abs(tmp-move))
    else:
        print(tmp)
else:
    print(current - num*move)


nums = [int(e) for e in input().split()]
current = nums[0]
num = nums[1]
move = nums[2]


current = abs(current)

res = current // move

if res >= num:
    print(current - move*num)
else:
    current = current - move * res
    num -= res
    if num%2 == 0:
        print(current)
    else:
        print(abs(current-move))


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


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

if q <= K:
    if (K-q)%2==0:
        ans=mod
        print("A")
    else:
        ans=D-mod
        print("B")
else:
    ans=X-K*D
print(ans)


X,K,D = map(int,input().split())
X=abs(X)
q=X//D
mod=X%D

if q <= K:
    if (K-q)%2==0:
        ans=mod
    else:
        ans=D-mod
else:
    ans=X-K*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())
an = x

if x < 0:
    x = -x
    
for i in range(k):
    x -= d
    if an > abs(x):
        an = x
    else:
        if (k-i)%2 != 0 and i!=0:
            print((k-i)%2)
            an = x
        break
        
print(abs(an))

x,k,d = map(int,input().split())
an = x
for i in range(k):
    a = x+d
    b = x-d
    if abs(a) < abs(b):
        x = a
    else:
        x = b
    
    if an > x:
        an = x
        
    if an == x:
        if (k-i)%2 == 0:
            an += d
        break
        
print(an)

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

if x < 0:
    x = -x

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

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 itertools
N=int(input())
A=list(map(int, input().split()))
ans=0
for any_pair in itertools.combinations(A, 3):
    pair=sorted(any_pair)
    print(type(pair))
    if pair[0]+pair[1]>pair[2] and pair[0]!=pair[1] and pair[1]!=pair[2]:
        ans+=1
        print(pair)
print(ans)

import itertools
N=int(input())
A=list(map(int, input().split()))
ans=0
for any_pair in itertools.combinations(A, 3):
    pair=sorted(any_pair)
    
    if pair[0]+pair[1]>pair[2] and pair[0]!=pair[1] and pair[1]!=pair[2]:
        ans+=1
        
print(ans)

X,K,D=map(int, input().split())
n=(K*D-X)//(2*D)
#print(n)
if n<0:
    ans=abs(X-K*D)
elif n>=K:
    ans=abs(X+K*D)
else:
    ans1=abs(X+(2*n-K)*D)
    ans2=abs(X+(2*(n+1)-K)*D)
    ans=min(ans1,ans2)
    #print(n,ans1,ans2)
print(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())
x=abs(x) 

if x%d==0:
    minNear  = x%d + d
    minFar = x%d
    minTransitionToNear = (x-minNear)/d
else:
    minNear  = x%d
    minFar = x%d - d
    minTransitionToNear = (x-minPlus)/d
    
if k<minTransitionToNear:
    print(x-k*d)
else:
    if (k-minTransitionToNear)%2==0:
        print(minNear)
    else:
        print(minFar)

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

if x%d==0:
    minNear  = x%d + d
    minFar = x%d
    minTransitionToNear = (x-minNear)/d
    #print(minNear)
    #print(minFar)
    #print(minTransitionToNear)
    
else:
    minNear  = x%d
    minFar = x%d - d
    minTransitionToNear = (x-minNear)/d
    #print(minNear)
    #print(minFar)
    #print(minTransitionToNear)
    
if k<minTransitionToNear:
    print(x-k*d)
else:
    if (k-minTransitionToNear)%2==0:
        print(abs(minNear))
    else:
        print(abs(minFar))

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):
input_line = input()
data = input_line.split(" ")
x = abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
if res >= k :
  ans = x - k * d
else :
  num = k - res
  if num % 2 == 1 :
    ans = abs(res - d)
  else :
    ans = res
  print(ans)


input_line = input()
data = input_line.split(" ")
x = abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
if res >= k :
  ans = x - k * d
else :
  num = k - res
  if num % 2 == 1 :
    ans = abs(res - d)
  else :
    ans = res
print(ans)


input_line = input()
data = input_line.split(" ")
x = abs(int(data[0]))
k = int(data[1])
d = int(data[2])
a = x // d
b = x % d
res = abs(a)
if res >= k :
  ans = x - k * d
else :
  num = k - res
  if num % 2 == 1 :
    ans = abs(b - d)
  else :
    ans = b
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 X > 0:
  v = 1
else:
  v = 0

for i in range(K):
  if X > 0:
    if v==0 and (K-i)%2==1:
      print(abs(X-D))
      v=2
      break
    elif v==0 and (K-i)%2==1:
      print(abs(X))
      v=2
      break
    X -= D
  else:
    if v==1 and (K-i)%2==1:
      print(abs(X+D))
      v=2
      break
    elif v==1 and (K-i)%2==0:
      print(abs(X))
      v=2
      break
    X += D
if v!=2:
  print(X)
    

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

if X==0:
  if K%2==0:
    print(X)
  else:
    print(D)
elif abs(X)-K*D>=0:
  print(abs(X)-K*D)
else:
  a = int(abs(X) / D)
  b = abs(X) % D
  if (K-a)%2==0:
    print(b)
  else:
    print(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:
    flag = -1
else:
    flag = 1

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


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

if x < 0:
    flag = -1
else:
    flag = 1

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

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

print((abs(abs(X)-K*D)/D)%2)
if abs(X) >= K*D:
    print(abs(X-K*D))
elif (abs((abs(X)-K*D)/D))%2 == 0:
    print(0)
elif (abs((abs(X)-K*D)/D))%2 <= 0.5:
    print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D-1))))
elif (abs((abs(X)-K*D)/D))%2 <= 1.5:
    print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D+1))))

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


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

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

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

if x > 0:
    d *= -1
    for i in range(k):
        x += d
        if x < 0:
            d *= -1
    print(x)
    exit()

if x < 0:
    for i in range(k):
        x += d
        if x > 0:
            d *= -1
    print(x)
    exit()

import math

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

if x < 0:
    x *= -1

if x-k*d < 0:
    if (k-(math.floor(x/d)))%2 == 0:
        print(x%d)
    else:
        print(abs(x%d-d))
else:
    print(x-k*d)

Verdicts: 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):
X, K, D = map(int, input().split())
abs_x = abs(X)
hikukazu = abs(X) // D
count = K - (hikukazu)
if K > hikukazu:
    if count % 2 == 0:
        hikukazu = hikukazu
    else:
        hikukazu = hikukazu + 1
else:
    hikukazu = K


for i in range(hikukazu):
    
    abs_x = abs_x - D

    # print(X)

print(abs_x)

X, K, D = map(int, input().split())
abs_x = abs(X)
hikukazu = abs(X) // D
count = K - (hikukazu)
if K > hikukazu:
    if count % 2 == 0:
        hikukazu = hikukazu
    else:
        hikukazu = hikukazu + 1
else:
    hikukazu = K

for i in range(hikukazu):
    
    abs_x = abs_x - D

    # print(X)

print(abs(X))

X, K, D = map(int, input().split())
abs_x = abs(X)
hikukazu = abs(X) // D
count = K - (hikukazu)
if K > hikukazu:
    if count % 2 == 0:
        hikukazu = hikukazu
    else:
        hikukazu = hikukazu + 1
else:
    hikukazu = D*K-1

for i in range(hikukazu):
    
    abs_x = abs_x - D

    # print(X)

print(abs(X))

X, K, D = map(int, input().split())
abs_x = abs(X)
hikukazu = abs(X) // D
count = K - (hikukazu)
if K > hikukazu:
    if count % 2 == 0:
        hikukazu = hikukazu
    else:
        hikukazu = hikukazu + 1
else:
    hikukazu = K



    
#     abs_x = abs_x - D
abs_x = abs_x - (D*hikukazu)
    # print(X)

print(abs(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):
k = int(input())
x = 7 % k
for i in range(1, k+1):
    if x == 0:
        print(i)
        exit()
    x = (x*10+7)%k
print(-1)


k = int(input())
x = 7 % k
for i in range(1, k+1):
    if x == 0:
        print(i)
    x = (x*10+7)%k
print(-1)


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

if kd<=x:
    print(x-kd)
else:
    count = x // d
    k_dash = k - count
    x -= count * d
    if k_dash % 2 == 0:
        print(x)
    else:
        print(d-x)


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

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

x,k,d=map(int, input().split())
if abs(k*d)>abs(x):
    if k%2==0:
        a=x%(2*d)
        print(min(abs(a),abs(a-2*d)))
    else:
        a=x%(2*d)
        print(min(abs(a-d),abs(a+d)))
else:
    print(abs(x)-abs(k*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):
n,k,m = map(int,input().split())
#print(k*m,n)
if k*m >= n:
    #print(min(n%m, n-(n%m)))
    x = n//m;
    left = n - x*m;
    right = left + m;
    k = k - x;
    if k&1:
        print(right)
    else:
        print(left)
    
else:
    print(n - k*m)


n,k,m = map(int,input().split())
#print(k*m,n)
if n>=0:
    if k*m > n:
        #print(min(n%m, n-(n%m)))
        x = n//m;
        left = n - x*m;
        right = abs(left - m);
        k = k - x;
        if k&1:
            print(right)
        else:
            print(left)
        
    else:
        print(n - k*m)
else:
    n = abs(n)
    k = abs(k)
    m = abs(m)
    if k*m > n:
        #print(min(n%m, n-(n%m)))
        x = n//m;
        left = n - x*m;
        right = abs(left - m);
        k = k - x;
        if k&1:
            print(right)
        else:
            print(left)
        
    else:
        print(n - k*m)


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

#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]

#[0]*n

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

num = k*d

x = abs(x)

if x >= num:
    print(x - num)
else:
    if x > d:
        j = int(x / d)
    else:
        if x*2 > d:
            j = 1
        else:
            j = 0

    if j != 0 and j != 1:
        b = x % (d*j)
    elif j == 1:
        b = d - x
    else:
        b = x
    min = min(b, d - b)
    max = max(b, d - b)
    if min == d - b:
        j += 1

    if (k - j) % 2 == 0:
        print(min)
    else:
        print(max)



#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]

#[0]*n

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

num = k*d

x = abs(x)
flag = 0

if x >= num:
    print(x - num)
else:
    if x > d:
        j = int(x / d)
    else:
        if x*2 > d:
            j = 1
            flag = 1
        else:
            j = 0

    if j == 0:
        b = x
    elif j == 1 and flag == 1:
        b = d - x
    else:
        b = x % (d*j)
    min = min(b, d - b)
    max = max(b, d - b)
    if min == d - b:
        j += 1

    if (k - j) % 2 == 0:
        print(min)
    else:
        print(max)


Verdicts: Wrong Answer

Accepted