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):
n = int(input())
x = [int(w) for w in input().split()]

d = {}

for i in x:
    d[i] = d.get(i, 0) + 1
    
ans = 0
l = list(d.keys())
l = sorted(l)
#print(l)
for i in range(len(l)-2):
    for j in range(i+1, len(l)-1):
        for k in range(j+1, len(l)):
            if l[k] < l[i] + l[j]:
                #print(l[i], l[j], l[k])
                ans += d[l[i]]*d[l[j]]*d[l[k]]
            
            else:
                break
            
print(ans)

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

t = x/d

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

Verdicts: Runtime Error

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

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

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

Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
import itertools

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

if K % 2 == 0:
  q, mod = divmod(abs(X), D*2)
  if mod <= abs(mod - D*2):
    if q*2 <= K:
      print(mod)
    else:
      print(X-(K*D))
  else:
    if q*2 <= K:
      print(mod-D*2)
    else:
      print(X-(K*D))   
else:
  q, mod = divmod(abs(X), D)
  if mod <= abs(mod - D):
    if q <= K:
      print(mod)
    else:
      print(X-(K*D))
  else:
    if q <= K:
      print(mod-D)
    else:
      print(X-(K*D))  

import itertools

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

if K % 2 == 0:
  q, mod = divmod(abs(X), D*2)
  if mod <= abs(mod - D*2):
    if q*2 <= K:
      print(mod)
    else:
      print(abs(abs(X)-(K*D)))
  else:
    if q*2 <= K:
      print(abs(mod-D*2))
    else:
      print(abs(abs(X)-(K*D)))
else:
  q, mod = divmod(abs(X)-D, D*2)
  if mod <= abs(mod - D*2):
    if q*2 <= K:
      print(mod)
    else:
      print(abs(abs(X)-(K*D)))
  else:
    if q*2 <= K:
      print(abs(mod-D*2))
    else:
      print(abs(abs(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 bisect

N = int(input())
L = list(map(int, input().split()))

cnt = 0
L = list(set(L))
L = sorted(L)


if N >= 3:
    for i in range(len(L)-2):
        for j in range(i+1, len(L)-1):
            ind = bisect.bisect_left(L, L[i]+L[j])
            cnt += max(0, ind-j)
    print(cnt)

else:
    print(0)


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

if abs(K*D) > abs(X):
    A = X//D
    A %= 2
    if K % 2 == A:
        print(X%D)
    else:
        print(D-X%D)
else:
    print(abs(X)-abs(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 = map(int, input().split())
lists = []
 
step = int(x/d) 

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

print(answer)

x,k,d = map(int, input().split())
lists = []
i = 1
 

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



print(answer)

x,k,d = map(int, input().split())
lists = []
 
step = int(x/d) 

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

print(answer)

x,k,d = map(int, input().split())
lists = []
x = abs(x)
 
step = int(x/d) 
 
if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = min(abs(x % d - d), abs(x % d + d))
 
print(answer)

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

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

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

if X >= 0:
  a= 1
else:
  a = -1

h = min(K, int(a*X/D))
K = K-h
X = X - a*D*h

print(X, K, D)
      


flg = 0
minx = abs(X)
Xnow = X
Xprepre = 0
for i in range(K):
  if i != 0:
    Xprepre = Xpre
  Xpre = Xnow 
  X1 = Xnow -D
  X2 = Xnow +D
  if abs(X1) < abs(X2):
    Xnow = X1
  else:
    Xnow = X2
  
  if Xprepre == Xnow:
    flg = 1
    if (K-i+1)%2 == 0:
      print(abs(Xnow))
    else:
      print(abs(Xpre))
    break
if flg == 0:
  print(abs(Xnow))



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

if X >= 0:
  a= 1
else:
  a = -1

h = min(K, int(a*X/D))
K = K-h
X = X - a*D*h

#print(X, K, D)
      


flg = 0
minx = abs(X)
Xnow = X
Xprepre = 0
for i in range(K):
  if i != 0:
    Xprepre = Xpre
  Xpre = Xnow 
  X1 = Xnow -D
  X2 = Xnow +D
  if abs(X1) < abs(X2):
    Xnow = X1
  else:
    Xnow = X2
  
  if Xprepre == Xnow:
    flg = 1
    if (K-i+1)%2 == 0:
      print(abs(Xnow))
    else:
      print(abs(Xpre))
    break
if flg == 0:
  print(abs(Xnow))


Verdicts: Wrong Answer

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

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

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

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

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

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

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

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

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

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

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

Verdicts: Runtime Error

Wrong Answer

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(' '))
b = x + k * d;
if b > 0:
    a = int(b / (2 * d))
    if a <= k:
        print(max(b-a*2*d, -(b-(a+1)*2*d)))
    else:
        print(b-k*2*d)
else:
    print(-b)

# x, k, d = map(int, input().split(' '))
x, k, d = map(int, input().split(' '))
b = x + k * d;
if b > 0:
    a = int(b / (2 * d))
    if a <= k:
        print(max(b-a*2*d, b-(a+1)*2*d))
    else:
        print(b-k*2*d)
else:
    print(-b)

x, k, d = map(int, input().split(' '))
b = x + k * d;
if b > 0:
    a = int(b / (2 * d))
    if a <= k:
        print(min(b-a*2*d, -(b-(a+1)*2*d)))
    else:
        print(b-k*2*d)
else:
    print(-b)

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(x) for x in input().split()]

print(x)

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

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

		k=k-num

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


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

if x==d:
	print(x)
else:
	
	while(k>0):
		if abs(x+d) < abs(x-d):
			x=x+d
		else:
			x=x-d
		k-=1

	print(x)

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


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

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

		k=k-num

		if k%2==0:
			print(abs(x))
		else:
			print(min(abs(x-d),abs(x+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):
from sys import stdin
input = stdin.readline
X, K, D = map(int, input().split())

A=min(int((X/D+K)/2),K)
print(A)
j=0
k=X
for i in range(A-1,A+1):
    j=abs(-K*D+2*i*D+X)
    if abs(j)<=abs(k) :k=abs(j)

print(k)


from sys import stdin
input = stdin.readline
X, K, D = map(int, input().split())
A=int((K-X/D)/2)
if 0<=A and A<=K:print(min(abs(-K*D+2*A*D+X),abs(-K*D+2*(A+1)*D+X)))
else:print(min(abs(X+K*D),abs(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):
X,K,D=map(int, input().split())

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


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

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

else:
  ans=abs(X)-K*D
    
print(abs(ans))

Verdicts: Wrong Answer

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

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

k = X // D
if abs(X - k * D) <= abs(X - (k + 1) * D):
    best_k = k
else:
    best_k = k + 1

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


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

k = X // D
if abs(X - D * k) <= abs(X - D * (k + 1)):
    best_k = k
else:
    best_k = k + 1

if K < best_k:
    print(abs(X - K * D))
elif (K - best_k) % 2 == 0:
    print(abs(X - best_k * D))
else:
    print(abs(X - (best_k - 1) * D))


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

k = X // D
if abs(X - k * D) <= abs(X - (k + 1) * D):
    best_k = k
else:
    best_k = k + 1

if K < best_k:
    print(abs(X - K * D))
elif (K - best_k) % 2 == 0:
    print(abs(X - best_k * D))
else:
    print(min(abs(X - best_k * D + D), abs(X - best_k * 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):
X,K,D = [int(x) for x in input().split()]

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

X,K,D = [int(x) for x in input().split()]

if abs(X) >= K * D:
    print(abs(X) - K * D)
else:
    K = K - int(abs(X) / D)
    print(K)
    X = int(abs(X) % D)
    print(X)
    if X >= int(D / 2):
        if K % 2 == 0:
            print(X)
            print("no")
        else:
            print(D - X)
    else:
        if K % 2 != 0:
            print(D - X)
        else:
            print(X)

X,K,D = [int(x) for x in input().split()]

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

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):

def input2():
	return map(int,input().split())


x,k,d=input2()

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


def input2():
	return map(int,input().split())

x,k,d=input2()
abs_x=abs(x)
count=min(abs_x//d,k) 
abs_x-=d*count 
rem=k-count


if rem>0:
	if rem%2==1:
		abs_x-=d 

ans=abs(abs_x)
print(ans)

Verdicts: Wrong Answer

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

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

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

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

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

X = abs(X)
a = X/D
ans = 0

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

ans = int(abs(ans))
print(ans)


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

X = abs(X)
a = int(X/D)
ans = 0

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

ans = int(abs(ans))
print(ans)


Verdicts: Wrong Answer

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

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

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

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

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

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

print(abs(x))


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

print(x)


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

print(abs(x))


Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
a = input().split()
x = int(a[0])
k = int(a[1])
d = int(a[2])

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

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

R = X // D
Q = X - D * K

if K <= R:
  result = Q
else:
  O = R - K
  O %= 2
  P = X - D * R
  if O == 0:
    result = P
  else:
    result = abs(P - K)

print(result)

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

minus = X < 0
if minus:
  X = -X

R = X // D

if K <= R:
  result = X - D * K
else:
  n = K - R
  n %= 2
  P = X - D * R
  if n == 0:
    result = P
  else:
    result = abs(P - D)
    

print(result)

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]=[int(_) for _ in input().split()]
X=abs(X)
Y=X//D
if K>Y:
  K-=Y
  X-=Y*D
print(X,K,D)
X/=D
for _ in range(K//2):
  X = min([abs(X-2), abs(X), abs(X+2)])
  print(X)
if K%2 == 1:
  X = min([abs(X-1), abs(X+1)])
  print(X)
print(abs(int(X*D)))

[X,K,D]=[int(_) for _ in input().split()]
X=abs(X)
Y=X//D
if Y <= K:
  X-=Y*D
  if (K-Y)%2 != 0:
    X = abs(X-D) if abs(X-D) < abs(X+D) else abs(X+D)
else:
  X-=K*D
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 = map(int,input().split())
jud = x//d
if(k<=jud):
  print(abs(abs(x)-d*k))
else:
  if((k-jud%2) == 1):
    print(abs(abs(x)-(jud+1*d)))
  else:
    print(abs(abs(x)-jud*d))

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


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


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

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

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


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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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 = input().split()
X = abs(X)
Q, mod = divmod(X, D)
if K < Q:
    ans = X - K*D
else:
    Rest = (K - Q)%2
    if Rest == 0:
         ans = mod
    else:
         ans = D - mod
print(ans)

X, K ,D = input().split()
X = abs(int(X))
K = int(K)
D = int(D)
Q, mod = divmod(X, D)
if K < Q:
    ans = X - K*D
else:
    Rest = (K - Q)%2
    if Rest == 0:
         ans = mod
    else:
         ans = D - mod
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 = [int(x) for x in input().split()]
t = abs(int(x/d))
if x < 0:
    d = -d
if t >= k:
    print(x-d*k)
elif t == 0:
    if k % 2 == 0:
        print(abs(x))
    else:
        print(min(abs(x-d),abs(x+d)))
elif t < k:
    if abs(x-d*t) < abs(x-d*t-d):
        if (t-k)%2==0:
            print(abs(x-d*t))
        else:
            print(min(abs(x-d*t+d),abs(x-d*t-d)))
    elif abs(x-d*t) = abs(x-d*t-d):
        print(abs(x-d*t))
    else:
        if (t-k-1)%2==0:
            print(abs(x-d*t-d))
        else:
            print(min(abs(x-d*t),abs(x-d*t-2*d)))


x,k,d = [int(x) for x in input().split()]
t = abs(int(x/d))
if x < 0:
    d = -d
if t >= k:
    print(x-d*k)
elif t == 0:
    if k % 2 == 0:
        print(abs(x))
    else:
        print(min(abs(x-d),abs(x+d)))
elif t < k:
    if abs(x-d*t) < abs(x-d*t-d):
        if (t-k)%2==0:
            print(abs(x-d*t))
        else:
            print(min(abs(x-d*t+d),abs(x-d*t-d)))
    elif  abs(x-d*t) = abs(x-d*t-d):
        print(abs(x-d*t))
    else:
        if (t-k-1)%2==0:
            print(abs(x-d*t-d))
        else:
            print(min(abs(x-d*t),abs(x-d*t-2*d)))


x,k,d = [int(x) for x in input().split()]
t = abs(int(x/d))
if x < 0:
    d = -d
if t >= k:
    print(abs(x-d*k))
elif t == 0:
    if k % 2 == 0:
        print(abs(x))
    else:
        print(min(abs(x-d),abs(x+d)))
elif t < k:
    if abs(x-d*t) < abs(x-d*t-d):
        if (k-t)%2==0:
            print(abs(x-d*t))
        else:
            print(min(abs(x-d*t+d),abs(x-d*t-d)))
    elif abs(x-d*t) == abs(x-d*t-d):
        print(abs(x-d*t))
    else:
        if (k-t-1)%2==0:
            print(abs(x-d*t-d))
        else:
            print(min(abs(x-d*t),abs(x-d*t-2*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):
LI = lambda: list(map(int, input().split()))

X, K, D = LI()


def main():
    x = abs(X)
    a = x // D
    if K <= a:
        ans = x - K * D
        print(ans)
        return
    
    x -= a * D
    k = K - a
    print(a, k)
    if k % 2 == 0:
        ans = x - a * D
    else:
        ans = abs(x - D)
    print(ans)
    
    
if __name__ == "__main__":
    main()


LI = lambda: list(map(int, input().split()))

X, K, D = LI()


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

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

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


x,k,d = map(int,input().split())
#print(x,k,d)
x=abs(x)
a = x//d
b = x%d

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

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

if( x == 0 ):
    if( k % 2 == 0 ):
        printf("{}".format(0))
else:
    print("{}".format(abs(d)))

if( x > 0 ) :
    if( x - k * d >= 0 ) :
        ret = x - k * d
        print("{}".format(ret))
    rem = x % d
    cost = x // d
    rem2 = abs(rem - d)
    remc = k - cost
    if( remc % 2 == 0 ) : 
        ret = rem
        print("{}".format(ret))
    else:
        ret = rem2
        print("{}".format(ret))
elif( x < 0 ) :
    if( x + k * d <= 0 ) :
        ret = abs( x + k * d )
        print("{}".format(ret))
    rem = (-x) % d
    cost = (-x) / d
    rem *= -1
    rem2 = rem + d
    remc = k - cost
    if( remc % 2 == 0 ):
        ret = abs(rem)
        print("{}".format(ret))
    else :
        ret = rem2
        print("{}".format(ret))




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

if( x == 0 ):
    if( k % 2 == 0 ):
        print("{}".format(0))
        exit()
    else:
        print("{}".format(abs(d)))
        exit()

if( x > 0 ) :
    if( x - k * d >= 0 ) :
        ret = x - k * d
        print("{}".format(ret))
        exit()
    rem = x % d
    cost = x // d
    rem2 = abs(rem - d)
    remc = k - cost
    if( remc % 2 == 0 ) : 
        ret = rem
        print("{}".format(ret))
        exit()
    else:
        ret = rem2
        print("{}".format(ret))
        exit()
elif( x < 0 ) :
    if( x + k * d <= 0 ) :
        ret = abs( x + k * d )
        print("{}".format(ret))
        exit()
    rem = (-x) % d
    cost = (-x) // d
    rem *= -1
    rem2 = rem + d
    remc = k - cost
    if( remc % 2 == 0 ):
        ret = abs(rem)
        print("{}".format(ret))
        exit()
    else :
        ret = rem2
        print("{}".format(ret))
        exit()




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


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

if a >= k:
    for i in range(k):
        if x > 0:
            x = x - d;

        elif x <= 0:
            x = x + d;

elif a < k:
    
    if x > 0:
        for i in range(a):
            x = x - d;

        if (k-a) % 2 != 0:
            x = x + d;

    elif x <= 0:    
        for i in range(a):
            x = x + d;

        if (k-a) % 2 != 0:
            x = x - d;


if x < 0:
    x = x * (-1);

print(x);

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

if x>k*d:
    print(x-k*d)
else:
    k-=x//d
    x-=(d*(x//d))
    and=[x,abs(d-x)]
    print(ans[k%2])

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

Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
from collections import defaultdict,deque
import math
import copy
def main():
    x,k,d=map(int, input().split())
    res = float('inf')
    l = 0
    r = k+1
    tmp_res = 0
    while(l+1!=r):
        mid = (l+r)//2
        tmp_res = copy.deepcopy(res)
        if((k-mid)%2==1):
         	res = min(res, abs(abs(x)-(mid+1)*d))
            res = min(res, abs(abs(x)-(mid-1)*d))
            mid+=1
        if((k-mid)%2==0):
            res = min(res, abs(abs(x)-mid*d))
            res = abs(res)
        if(abs(abs(x)-mid*d) > x):
            r = mid
        else:
            l = mid
        if tmp_res == res:
            break

    print(res)




if __name__ == '__main__':
    main()



from collections import defaultdict,deque
import math
import copy
def main():
    x,k,d=map(int, input().split())
    res = float('inf')
    l = 0
    r = k+1
    tmp_res = 0
    while(l+1!=r):
        mid = (l+r)//2
        tmp_res = copy.deepcopy(res)
        if((k-mid)%2==1):
         	res = min(res, abs(abs(x)-(mid+1)*d))
            res = min(res, abs(abs(x)-(mid-1)*d))
            mid+=1
        if((k-mid)%2==0):
            res = min(res, abs(abs(x)-mid*d))
            res = abs(res)
        if(abs(abs(x)-mid*d) > x):
            r = mid
        else:
            l = mid
        if tmp_res == res:
            break

    print(res)




if __name__ == '__main__':
    main()


from collections import defaultdict,deque
import math
import copy
def main():
    x,k,d=map(int, input().split())
    res = float('inf')
    x = abs(x)

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




if __name__ == '__main__':
    main()


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

if abs(X) >= K * D:
  if X >= 0:
    Ans = X - (K * D)
  else:
    Ans = abs(X + (K * D))
    
else:
  abX = abs(X)
#  if X >= 0:
  if (K - abX // D) % 2 == 0:
      Ans = abX - ((abX // D) * D)
    else:
      Ans = abs(abX - ((abX // D) * D) - D)
      
#  else:
#    print(abs(X // D))

#      Ans = abs(X + (abs((X // D)) * D))
#    else:
#      Ans = abs(X + (abs((X // D)) * D) - D)
    
print(Ans)


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

if abs(X) >= K * D:
  if X >= 0:
    Ans = X - (K * D)
  else:
    Ans = abs(X + (K * D))
    
else:
  abX = abs(X)
#  if X >= 0:
  if (K - abX // D) % 2 == 0:
    Ans = abX - ((abX // D) * D)
  else:
    Ans = abs(abX - ((abX // D) * D) - D)
      
#  else:
#    print(abs(X // D))

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


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


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):
# coding: utf-8
import math
X, K, D = list(map(int, input().split(" ")))

if X==K==D:
    print(X)
    exit()
x = X
vmin = abs(X)
cnt = 0
# for k in range(K):
#     if X>0:
#         x -= D
#     else:
#         x += D
#     if vmin>abs(x):
#         vmin = abs(x)
#         cnt += 1
#     else:
#         break
cnt = min(math.floor(X / D), K)
print(cnt)
if X>0:
    print(abs(X - (cnt * D)))
else:
    print(abs(X + (cnt * D)))

# coding: utf-8
import math
X, K, D = list(map(int, input().split(" ")))

x = abs(X)
k = int(math.floor(x/D))
if k>=K:
    print(abs(x - K*D))
    exit()
x -= k*D
if (K-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):
X,K,D=map(int,input().split())
if D*K<abs(X):
  print(abs(X)-D*K)
else:
  K2=abs(X)//D
  if K2>K:
    K2=K
  if (K-K2)%2==0:
    print(abs(X)-K2*D)
  else:
    K2=K2-1
    print(abs(X)-K2*D)

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

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

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

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

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

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

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

Verdicts: Wrong Answer

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

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

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

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

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

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

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

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


Verdicts: Wrong Answer

Wrong Answer

Accepted