ZhenlongDai/ACPR huggingface dataset:
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = map(int,input().split())
c = int(x/d)
le = int(k-abs(c))
if x==0:
    if le%2==0:
        print(0)
    else:
        print(d)
    exit()
else:
    if le>=0:
        ne = -d*c+x
    else:
        if x>0:
            ne = -d*k+x
        else:
            ne = d*k-x
        exit()
        
if le%2==0:
    print(abs(ne))
elif le<0:
    print(abs(ne))
else:
    print(abs(ne-d))


        


Failing test case input:
7 0 3

Expected output:
7


Actual output:

Fixed submission (verdict: Accepted):
import sys
x,k,d = map(int,input().split())
x=abs(x)
c = int(x/d)
le = int(k-abs(c))
if x==0:
    if k%2==0:
        print(0)
    else:
        print(d)
    sys.exit()
else:
    if le>=0:
        ne = -d*c+x
    else:
        if x>0:
            ne = -d*k+x
        else:
            ne = d*k-x
        print(abs(ne))
        sys.exit()
        
if le%2==0:
    print(abs(ne))
else:
    ans1=abs(ne-d)
    ans2=abs(ne+d)
    print(min(ans1,ans2))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):




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

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

print(ans)

Failing test case input:
1101011100010001 1010100000110001 1110001010000000

Expected output:
8989909989999


Actual output:
0


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

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

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d= map(int, input().split())

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

Failing test case input:
1000011100011110 1001111101110011 1010101000011010

Expected output:
10089899999900


Actual output:
1000011100011110


Fixed submission (verdict: Accepted):
x,k,d= map(int, input().split())

if abs(x) >= k*d:
    print(abs(x)-k*d)
elif abs(x)%d==0:
    if (int(abs(x)/d)+1000000000000000-k)%2==0:
        print(0)
    else:
        print(d)
else:
    if (k-int(abs(x)/d))%2==0:
        print(abs(x)%d)
    else:
        print(d-(abs(x)%d))
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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))

Failing test case input:
1100111000111101 1000110111100101 1010111000001010

Expected output:
90000000110091


Actual output:
920110999890919


Fixed submission (verdict: Accepted):
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))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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+1)%2 == 0 and i!=0:
            an = x
        break
        
print(abs(an))

Failing test case input:
1101010100000001 1010101000100000 1110001000000000

Expected output:
1101010100000001


Actual output:
1118991899999999


Fixed submission (verdict: Accepted):
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
        an = x-d*(x
    else:
        an = x-d*(x
        
print(abs(an))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
a,b,c=map(int, input().split()) 

if abs(a) > 0:
    if abs(a) >= b*c:
        print(abs(a)-b*c)
    else:
        d = abs(a)
        e = b -d
        if e%2== 0:
            print(abs(a)-c*d)
        else:
            print(c*(d+1)-abs(a))
if a == 0:
    if b%2==0:
        print(c)
    else:
        print(0)

Failing test case input:
1100111001010001 1010100001101001 1011001000100010

Expected output:
89110000909991


Actual output:
-1112213322242133022101009190009


Fixed submission (verdict: Accepted):
a,b,c=map(int, input().split()) 
k = b*c
l = abs(a)

if l > 0:
    if l > k:
        print(l-k)
    if l == k:
        print(0)
    if l < k:
        d = int(l
        e = b - d
        if e%2== 0:
            print(l-c*d)
        else:
            f = d + 1
            print(f*c -l)
if l == 0:
    if b%2==0:
        print(0)
    else:
        print(c)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)

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























Failing test case input:
1100110101001000 1010100001000001 1001000000001011

Expected output:
99110100999989


Actual output:
1902889899002033


Fixed submission (verdict: Accepted):
x,k,d = map(int, input().split())
x = abs(x)
if x<k*d:
	ans = abs(k*d-x) % (2*d)
	print(min(ans, 2*d-ans))
else:
	print(x-k*d)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
x, k, d = map(int, input().split())
x = abs(x)


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

    else:
        print(abs(x-math.floor(x/d)*d-k+math.floor(x/d))+1)




else:
    print(x-k*d)

Failing test case input:
1101011100010101 1010111000110011 0110001100110000

Expected output:
109001001199899


Actual output:
1009110901199901


Fixed submission (verdict: Accepted):
import math
x, k, d = map(int, input().split())
x = abs(x)


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


    else:
        print(abs(x-math.floor(x/d+1)*d))




else:
    print(x-k*d)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)


Failing test case input:
1000100100000000 1000101000000000 1000000001000000

Expected output:
999899902000000


Actual output:
1000000000999999.9


Fixed submission (verdict: Accepted):
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))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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))

Failing test case input:
1101011100010101 1010111000110011 0110101100110000

Expected output:
110101001199899


Actual output:
-110101001199899


Fixed submission (verdict: Accepted):
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)))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())
X = abs(X)
div, mod = divmod(X, D)
if X > D * K:
    ans = X - D * div
elif (K - div) % 2 == 0:
    ans = mod
else:
    ans = D - mod
print(ans)

Failing test case input:
10 1 2

Expected output:
8

Actual output:
0


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())
X = abs(X)
div, mod = divmod(X, D)
if X > D * K:
    ans = X - D * K
elif (K - div) % 2 == 0:
    ans = mod
else:
    ans = D - mod
print(ans)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X,K,D = list(map(int, input().split()))

X = max(X, -X)
if X-(K*D) >0:
  print(X-(K*D))
else:
  step, place, nokori = int(X/K), X-(int(X/K)*K), D-int(X/K)
  if nokori%2 ==0:
    print(place)
  else:
    print(-(place-K))

Failing test case input:
1000100100000000 1000101000000000 1000000001000000

Expected output:
999899902000000


Actual output:
1000100100000000


Fixed submission (verdict: Accepted):
X,K,D = list(map(int, input().split()))

X = max(X, -X)

if X-(K*D)>0:
  print(X-(K*D))
else:
  
  step, place, nokori = int(X/D), X-(int(X/D)*D), K-int(X/D)
  
  if nokori%2 ==0:
    print(place)
  else:
    print(-(place-D))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
IN = list(map(int, input().split()))
X, K, D = IN[0], IN[1], IN[2]

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

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


Failing test case input:
1000100000000000 1000101000000000 1000000001000000

Expected output:
999900002000000


Actual output:
1000100000000000


Fixed submission (verdict: Accepted):
IN = list(map(int, input().split()))
X, K, D = IN[0], IN[1], IN[2]


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

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

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d=map(int,(input().split()))

zx=x
zzx=zx
for i in range(k):
    xm=x+d
    xu=x-d
    x=min(abs(xm),abs(xu))
    k-=1
    if zx<x:
        if k%2==0:
            x=zzx
            break
        else:
            x=zx
            break
    zzx=zx
    zx=x
    
print(x)

Failing test case input:
1100111001010001 1010100001101000 1011001000101011

Expected output:
921890999192021


Actual output:
1100111001010001


Fixed submission (verdict: Accepted):
x,k,d=map(int,(input().split()))

x=abs(x)
zx=x
if x<d*k:
    wk,x=divmod(abs(x),d)
    k-=wk    
else:
    x-=d*k
    k=0

for i in range(k):
    xm=abs(x+d)
    xu=abs(x-d)
    x=min(xm,xu)
    k-=1
    if zx+x==d:
        if k%2!=0:
            x=zx
            break
        else:
            break
    zx=x
    
print(x)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import math
X, K, D = list(map(int, input().split(" ")))

x = abs(X)
k = int(math.floor(x/D))
if X==K==D:
    print(X)
    exit()
elif k>=K:
    print(abs(x - K*D))
    exit()
x -= k*D
if K%2==0:
    print(x)
else:
    print(abs(x - D))

Failing test case input:
1001011101010101 1010111000110011 0110101000010010

Expected output:
10102100920011


Actual output:
99998899089999


Fixed submission (verdict: Accepted):

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

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())
X = abs(X)
div, mod = divmod(X, D)
if X > D * div:
    ans = X - D * div
elif (K - div) % 2 == 0:
    ans = mod
else:
    ans = D - mod
print(ans)

Failing test case input:
1000011000111111 1000111111000001 1010101000001010

Expected output:
10089999889899


Actual output:
1000011000111111


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())
X = abs(X)
div, mod = divmod(X, D)
if X > D * K:
    ans = X - D * K
elif (K - div) % 2 == 0:
    ans = mod
else:
    ans = D - mod
print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x, k, d = list(map(int, input().split()))

x = abs(x)
p = 0

if(x - k*d >=0):
  p = x - k*d

else:
    p = x%d
    if (k - x/d)%2 == 1:
        p = p-d
print(abs(p))


Failing test case input:
1101011100010001 1010100000110001 1110001010010000

Expected output:
8989909999999


Actual output:
1101011100010001


Fixed submission (verdict: Accepted):
x, k, d = list(map(int, input().split()))

x = abs(x)
p = 0

if x/d >= k:
    p = x-(k*d)

else:
    p = x%d
    if (k - int(x/d))%2 == 1:
        p = p-d
print(abs(p))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = map(int, input().split())
x = abs(x)

t = True
cnt = 0

while t == True:
  cnt += 1
  x -= d
  if cnt == k or x < d/2:
    break

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

print(abs(x))

Failing test case input:
3 2 4

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
x,k,d = map(int, input().split())
x = abs(x)

cnt = int(x/d)

x -= d*min(cnt, k)

if x > d/2 and cnt < k:
  x = abs(x - d)
  cnt += 1

if (k-cnt) % 2 == 1 and cnt < k:
  x -= d

print(abs(x))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

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

print(ans)

Failing test case input:
0101011100010001 1010111000110001 1110001100010000

Expected output:
1008989999999999


Actual output:
101011100010001


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

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

print(ans)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X,D,C = map(int,input().split())
count=abs(X)
a = X
b = X%C
if a>D:
  print(count-D*C)
elif a==D:
  print(0)
elif a<D:
  D = D-a
  if D%2==0:
    print(b)
  else:
    print(min(abs(b-C),abs(b+C)))

Failing test case input:
1000011101011001 1000111000110011 1110101000010010

Expected output:
110089898999009


Actual output:
1000011101011001


Fixed submission (verdict: Accepted):
X,D,C = map(int,input().split())
count=abs(X)
a = abs(X
b = abs(X%C)
if a>D:
  print(count-D*C)
elif a==D:
  print(b)
elif a<D:
  D = D-a
  if D%2==0:
    print(b)
  else:
    print(min(abs(b-C),abs(b+C)))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

X,K,D=nm()
X=abs(X)
if(K*D<=X):
    print(X-K*D)
    sys.exit(0)
else:
    tmp=X%D
    print(min(tmp,D-tmp))

Failing test case input:
1101110100000001 1010101001100000 1110001000000000

Expected output:
1101110100000001


Actual output:
8890899999999


Fixed submission (verdict: Accepted):
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

X,K,D=nm()
X=abs(X)
if(K*D<=X):
    print(X-K*D)
    sys.exit(0)
else:
    tmp=X%D
    tmp2=K-(X
    if(tmp2%2==0):
        print(tmp)
        sys.exit(0)
    else:
        print(D-tmp)
        sys.exit(0)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

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

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

Failing test case input:
1100111001000001 1010100001101001 1011001000000010

Expected output:
89110000999991


Actual output:
921890999000019


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

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

if(X/D >= K):
  print(X-D*K)
else:
  if((K - (X-min_pos)/D)%2 == 0):
    print(min_pos)
  else:
    print(abs(min_neg))
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x, k, d = map(int, input().split())
 
if (x - k*d > 0 and x > 0) or (x + k*d < 0 and x < 0):
    print(abs(x) - k*d )
else:
    if x % d == 0:
        if ((x/d) % 2) == (k % 2):
            print(0)
        else:
            print(d)
    else:
        if (x - (x % d)) % d == k % 2:
            print(x % d)
        else:
            print(d - x % d)

Failing test case input:
1100110001000001 1010100001101001 1011001000000011

Expected output:
89109000999990


Actual output:
921891999000021


Fixed submission (verdict: Accepted):
x, k, d = map(int, input().split())
if (x - k*d > 0 and x > 0) or (x + k*d < 0 and x < 0):
    print(abs(x) - k*d )
else:
    if x % d == 0:
        if ((x/d) % 2) == (k % 2):
            print(0)
        else:
            print(d)
    else:
        y = abs(x)
        if (y % d < d - (y % d) and ((y - (y % d)) / d) % 2 == k % 2) or (y % d > d - (y % d) and ((y - (y % d)) / d) % 2 == k % 2):
            print(y % d)
        else:
            print(d - (y % d))

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x,k,d=map(int, input().split())
x=abs(x)

if x+2*d >=k*d:
    print(abs(x-k*d))
    exit()

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

kaisu=int(x/(2*d))
ans=abs(x-kaisu*d*2)
print(ans)

Failing test case input:
1000100100000000 1000101000000000 1000000001000000

Expected output:
999899902000000


Actual output:
1000100100000000


Fixed submission (verdict: Accepted):
x,k,d=map(int, input().split())
x=abs(x)

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

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

kaisu=int(x/(2*d))
ans=abs(x-kaisu*d*2)
if ans >=d:
    ans=2*d-ans

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong 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(d)

print(answer)

Failing test case input:
1000011100001000 1001111000110011 1010101000110010

Expected output:
10089900109010


Actual output:
1010101000110010


Fixed submission (verdict: Accepted):
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 = abs(x - step * d - d)

print(answer)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int,input().split())
absX = abs(X)
t = X 
remain_K = K - t
l = X % D
if remain_K < 0:
    a = abs(X - (K * D))
    b = abs(X + (K * D))
else:
    if remain_K % 2 == 0:
        a = abs(l - (D * 2))
        b = abs(l + (D * 2))
        if l < a:
            a = l
        if l < b:
            b = l
    else:
        a = abs(l - D)
        b = abs(l + D)
if a < b:
    print(a)
else:
    print(b)

Failing test case input:
1100111000111111 1000110111100101 1010111000001010

Expected output:
90000000110101


Actual output:
1010222224434443132312210990899


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

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)


Failing test case input:
1101011100010001 1010111000110001 1110001100010000

Expected output:
8989999999999


Actual output:
0


Fixed submission (verdict: Accepted):
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)

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q <= K:
    if mod == 0:
        if q % 2 == 1:
            ans = D
        else:
            ans = mod
    else:
        if q % 2 == 0:
            ans = mod
        else:
            ans = D + mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Failing test case input:
1001011100010101 1010111000110011 0110101100110000

Expected output:
10101199020101


Actual output:
120202299130101


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d=list(map(int,input().split()))
print(x,k,d)
result=abs(x)-k*d
swithn=0

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

Failing test case input:
1000111101000000 1010100001000001 1001000000001011

Expected output:
888899001011


Actual output:
1000111101000000 1010100001000001 1001000000001011
888899001011


Fixed submission (verdict: Accepted):
x,k,d=list(map(int,input().split()))

result=abs(x)-k*d
swithn=0

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

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    ddd = q % 2
    l = q % 2
    if l == 0:
        ans = mod
    else:
        ans = D + mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Failing test case input:
1000110101000000 1010100001000001 1001000000001011

Expected output:
889899001011


Actual output:
1000110101000000


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d=map(int,input().split())

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

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


Failing test case input:
1000100100000000 1000101001000000 1000000000001000

Expected output:
999899900002000


Actual output:
-999899900002000


Fixed submission (verdict: Accepted):
x,k,d=map(int,input().split())

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

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

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math
X,K,D = map(int,input().split())

m = abs(X)/D
if K >= m:
  if m%2 == K%2:
    print(abs(X%D))
  else:
    print(min(abs(X%D+D), abs(X%D-D)))
else:
  print( min( abs(X-D*K) , abs(X+D*K) ) )


Failing test case input:
1100111001000001 1010100001101001 1011001000000010

Expected output:
89110000999991


Actual output:
921890999000019


Fixed submission (verdict: Accepted):
X,K,D = map(int,input().split())
X = abs(X)

if X - (D*K) >= 0:
  print(X-D*K)
else:
  k = K - (X
  if k % 2 == 0:
    print(X%D)
  else:
    print(min(abs(X%D+D), abs(X%D-D)))
Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    if mod == 0:
        if q % 2 == 1:
            ans = D + mod
        else:
            ans = mod
    else:
        ans = mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Failing test case input:
1000011101011000 1000111000110011 1110101000110010

Expected output:
110089899099010


Actual output:
1000011101011000


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
  X, K, D = map(int, input().split())
  if abs(X) > K * D:
    print(X-K*D)
  else:
    Y = X 
    if (K-Y) % 2 == 0:
      print(D*Y-abs(X))
    else:
      Z = min(abs(D*(Y+1)-abs(X)), abs(D*(Y-1)-abs(X)))
      print(Z)
main()

Failing test case input:
1000011100011000 1001111000110011 1010101000011010

Expected output:
10089900000010


Actual output:
1010112212143219223099021087990


Fixed submission (verdict: Accepted):
import math
def main():
  X, K, D = map(int, input().split())
  if abs(X) >= K * D:
    print(abs(X)-K*D)
  else:
    Y = math.ceil(abs(X) / D)
    if (K-Y) % 2 == 0:
      print(D*Y-abs(X))
    else:
      Z = abs(X)-D*(Y-1)
      print(Z)
main()

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    X, K, D = map(int, input().split())

    d, m = divmod(X, D)
    if abs(d) >= K:
        print(abs(abs(X) - (K * D)))
    else:
        if d % 2:
            print(D - m)
        else:
            print(m)


main()


Failing test case input:
1001011101010001 1010111000110011 0110101000010010

Expected output:
10102100919911


Actual output:
99998899090099


Fixed submission (verdict: Accepted):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    X, K, D = map(int, input().split())

    d, m = divmod(X, D)
    if abs(d) >= K:
        print(abs(abs(X) - (K * D)))
    else:
        if (K - d) % 2:
            print(D - m)
        else:
            print(m)


main()

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X,K,D = map(int,input().split( ))

X = abs(X)

q, mod = divmod(X, D)

if q >= K:
  print(X-D*q)

else:
  cnt = K-q
  if cnt%2 == 0:
    print(mod)
  if cnt%2 == 1:
    print(D-mod)

Failing test case input:
7 0 3

Expected output:
7


Actual output:
1


Fixed submission (verdict: Accepted):
X,K,D = map(int,input().split( ))
 
X = abs(X)
 
q, mod = divmod(X, D)

if q >= K:
  print(X-D*K)

else:
  cnt = K-q
  if cnt%2 == 0:
    print(mod)
  if cnt%2 == 1:
    print(D-mod)
Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x,k,d=map(int,input().split())

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

print(ans)

Failing test case input:
3 2 4

Expected output:
3


Actual output:
0.0


Fixed submission (verdict: Accepted):
x,k,d=map(int,input().split())

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

print(ans)

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x,k,d = map(int, input().split())
if x < 0:
    x = -x
if int(x/d) > k:
    x -= k * d
else:
    x -= int(x/d) * d
    k -= int(x/d)
    if k % 2 == 1:
        x = abs(x - d)
print(x)

Failing test case input:
1100111001010001 1010100001101001 1011001000101011

Expected output:
89110000908990


Actual output:
921890999192021


Fixed submission (verdict: Accepted):
x,k,d = map(int, input().split())
if x < 0:
    x = -x
x_min = x
if x
    x_min -= k * d
else:
    x_min -= x
    k -= x
    if k % 2 == 1:
        x_min = abs(x_min - d)
print(x_min)

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
xx, kk, dd= list(map(int,input().split()))

xx = abs(xx)

if dd * kk <= xx:
    ans = xx - dd*kk
else:
    aa_int = int(xx/dd)
    remaining_move = kk - aa_int
    if (aa_int % 2) == 0:
        ans = xx - dd*aa_int
    else:
        ans = xx - dd*(aa_int+1)

print(abs(ans))

Failing test case input:
1100100100000000 1010100001010001 1000000000001000

Expected output:
100100099999000


Actual output:
899899900002000


Fixed submission (verdict: Accepted):
xx, kk, dd= list(map(int,input().split()))

xx = abs(xx)

if dd * kk <= xx:
    ans = xx - dd*kk
else:
    aa_int = int(xx/dd)
    remaining_move = kk - aa_int
    if (remaining_move % 2) == 0:
        ans = xx - dd*aa_int
    else:
        ans = xx - dd*(aa_int+1)

print(abs(ans))

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x, k, d = map(int, input().split())
ans = 0
if abs(x) <= k * d:
  ans = abs(x) % k
  ans = min([ans, k-ans])
else:
  ans = abs(x) - k * d
print(ans)

Failing test case input:
1101110100000001 1010101001100001 1110001000000000

Expected output:
8890899999999


Actual output:
91009098900000


Fixed submission (verdict: Accepted):
x, k, d = map(int, input().split())
ans = 0
if abs(x) <= k * d:
  if (abs(x) 
    ans = abs(x) % d
  else:
    ans = d - abs(x) % d
else:
  ans = abs(x) - k * d
print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = map(int, input().split())
while(x > 0):
  x -= d
  k -= 1
if k%2 == 0:
  print(x)
else:
  print(x-d)

Failing test case input:
1100111001010001 1010100001101001 1011001000101011

Expected output:
89110000908990


Actual output:
-1932891999293032


Fixed submission (verdict: Accepted):
x,k,d = map(int,input().split())
x = abs(x)
div = min(x
cnt = 0
k-=div
x -= div*d
if k%2 == 0:
  print(x)
else:
  print(abs(x-d))
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
x, k, d = map(int, input().split())
x = abs(x)


if k > x/d:
    if x-math.floor(x/d)*d < abs(x-(math.floor(x/d)+1)*d):
        print(x-math.floor(x/d)*d)
    else:
        print(abs(x-(math.floor(x/d)+1)*d))
else:
    print(x-k*d)


Failing test case input:
0101011100010001 1010111000110001 1110001100110000

Expected output:
1008990000099999


Actual output:
101011100010001


Fixed submission (verdict: Accepted):
import math
x, k, d = map(int, input().split())
x = abs(x)


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


    else:
        print(abs(x-math.floor(x/d+1)*d))




else:
    print(x-k*d)

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X,K,D = map(int,input().split())

Xmin = X - D*K
Xmax = X + D*K

if Xmin * Xmax <= 0:
    ans = min(X%D, D - X%D)
elif Xmin > 0:
    ans = Xmin
else:
    ans = -Xmax

print(ans)


Failing test case input:
0101011100010001 1010111000110001 1110001100010000

Expected output:
1008989999999999


Actual output:
101011100010001


Fixed submission (verdict: Accepted):
X,K,D = map(int,input().split())

Xmin = X - D*K
Xmax = X + D*K

if Xmin * Xmax <= 0:
    ans = min(Xmax%(2*D), 2*D - (Xmax%(2*D)))
elif Xmin > 0:
    ans = Xmin
else:
    ans = -Xmax

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
k,x,d=input().split()
k=int(k)
x=int(x)
d=int(d)
x=abs(x)
if(k*d<=x):
    print(x-k*d)
else:
    k-=x/d
    x%=d
    if(k%2):
        print(d-x)
    else:
        print(x)

Failing test case input:
1101011100010001 1010100000100000 1110001000000000

Expected output:
1101011100010001


Actual output:
99900999900000


Fixed submission (verdict: Accepted):
x,k,d=input().split()
k=int(k)
x=int(x)
d=int(d)
x=int(abs(x))
if((k*d)<=x):
    print(x-(k*d))
else:
    k-=int(x/d)
    x%=d
    if(k%2):
        print(d-x)
    else:
        print(x)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d=map(int,input().split())
div=x
if div<=k:
    print(abs(x-k*d))
else:
    k-=div
    t=abs(x-div*d)
    if k%2==0:
        print(t)
    else:
        print(abs(t-d))

Failing test case input:
0101011100010001 1010111000110001 1110001100010000

Expected output:
1008989999999999


Actual output:
1121224321254302239991099999999


Fixed submission (verdict: Accepted):
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
    print(x-k*d)
else:
    if (k-x
        print(x-d*(x
    else:
 
        print(abs(d-(x-d*(x
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x, k, d = map(int, input().split())

mod1 = x % d
mod2 = mod1 - d
mod = min(mod1, abs(mod2))
modx = max(mod1, abs(mod2))
x1 = abs(x)

a = (x-mod)/d

if mod1+k*d <= x1:
    print(x-k*d)
elif (k-a) % 2 == 0:
    print(mod)
else:
    print(modx)


Failing test case input:
1000011101011001 1000111000110011 1110101000010010

Expected output:
110089898999009


Actual output:
1000011101011001


Fixed submission (verdict: Accepted):
x, k, d = map(int, input().split())

x1 = abs(x)
mod1 = x1 % d
mod2 = mod1 - d
if mod1 > abs(mod2):
    mod = mod2
    modx = mod1
else:
    mod = mod1
    modx = mod2

a = abs(x1-mod) / d 

if k*d < x1-mod:
   print(x1-k*d)
elif (k-a) % 2 == 0:
    print(abs(mod))
else:
    print(abs(modx))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
1100110000000001 1010100001100001 1111001000000011

Expected output:
10891000000010


Actual output:
1010100001100001
1100110000000001
10891000000010


Fixed submission (verdict: Accepted):
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)

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x,k,d=map(int,input().split())

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

print(ans)

Failing test case input:
1000011101011000 1000111000110011 1110101000110010

Expected output:
110089899099010


Actual output:
0.0


Fixed submission (verdict: Accepted):
x,k,d=map(int,input().split())

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

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

n = X 

if K <= n:
  ans = abs(X - K * D)

else:
  if (K - n) % 2:
    ans = abs((n+1) * D - X)
  else:
    ans = abs(X - n * D)

print(ans)

Failing test case input:
1000110101000000 1010100001000001 1001000000001011

Expected output:
889899001011


Actual output:
1001110211102011112202010001011


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

X = abs(X)
if X >= K * D:
  ans = X - K * D

else:
  n, d = divmod(X, D)
  ans = d
  if (K - n) % 2:
    ans = D - d


print(ans)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

n = X 

if K <= n:
  ans = X - K * D

else:
  if (K - n) % 2:
    ans = (n+1) * D - X
  else:
    ans = X - n * D

print(ans)

Failing test case input:
1000011100011000 1001111000110011 1110101000010010

Expected output:
110089899999010


Actual output:
1110113322143321332201010109010


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

X = abs(X)
if X >= K * D:
  ans = X - K * D

else:
  n, d = divmod(X, D)
  ans = d
  if (K - n) % 2:
    ans = D - d


print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

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

X = abs(X)
k, x = divmod(X, D)

if K <= k:
    print(abs(X - D * K))
    sys.exit(0)

X = x
K -= k

if k % 2 == 0:
    print(abs(X))
    sys.exit(0)

print(abs(X - D))

Failing test case input:
1101011100010001 1010111000110001 1110001100110000

Expected output:
8990000099999


Actual output:
1101011100010001


Fixed submission (verdict: Accepted):
import sys

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

X = abs(X)
k, x = divmod(X, D)

if K <= k:
    print(X - D * K)
    sys.exit(0)

X = x
K -= k

if K % 2 == 0:
    print(abs(X))
    sys.exit(0)

print(abs(X - D))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import math
X, K, D = list(map(int, input().split(" ")))

if X==K==D:
    print(X)
    exit()
x = X
vmin = abs(X)
cnt = 0










cnt = min(math.floor(X / D), K)
print(cnt)
if X>0:
    print(abs(X - (cnt * D)))
else:
    print(abs(X + (cnt * D)))

Failing test case input:
1100111001010001 1010100001101000 1011001000001011

Expected output:
921890998992021


Actual output:
1
89110001008990


Fixed submission (verdict: Accepted):

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

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)
    
    print(min(s,t))


Failing test case input:
1100110000000001 1010100001100001 1111001000000011

Expected output:
10891000000010


Actual output:
-10891000000010


Fixed submission (verdict: Accepted):
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))
Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    if mod == 0:
        if q % 2 == 1:
            ans = D
        else:
            ans = mod
    else:
        ans = mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Failing test case input:
1100110000000001 1010101001100001 1110001000000011

Expected output:
9891000000010


Actual output:
1100110000000001


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = list(map(int, input().split()))

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

Failing test case input:
1101011100010101 1010111000110011 0110101100110000

Expected output:
110101001199899


Actual output:
98910101


Fixed submission (verdict: Accepted):
X, K, D = list(map(int, input().split()))

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

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

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

Failing test case input:
1000011100001000 1001111000110011 1010101000110010

Expected output:
10089900109010


Actual output:
1000011100001000


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

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

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X,K,D = map(int,input().split())

m = X
if K >= m:
  if m%2 == K%2:
    print(abs(X%D))
  else:
    print(min(abs(X%D+D), abs(X%D-D)))
else:
  print( min( abs(X-D*K) , abs(X+D*K) ) )

Failing test case input:
1101011100010101 1010111000110011 0110001100110000

Expected output:
109001001199899


Actual output:
111113321245312440013101199899


Fixed submission (verdict: Accepted):
X,K,D = map(int,input().split())
X = abs(X)

if X - (D*K) >= 0:
  print(X-D*K)
else:
  k = K - (X
  if k % 2 == 0:
    print(X%D)
  else:
    print(min(abs(X%D+D), abs(X%D-D)))
Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x,k,d=map(int, input().split())
x=abs(x)

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

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

kaisu=int(x/(2*d))
ans=abs(x-kaisu*d*2)
print(ans)

Failing test case input:
1000100100000000 1000101001000000 1000000000001000

Expected output:
999899900002000


Actual output:
1000100100000000


Fixed submission (verdict: Accepted):
x,k,d=map(int, input().split())
x=abs(x)

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

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

kaisu=int(x/(2*d))
ans=abs(x-kaisu*d*2)
if ans >=d:
    ans=2*d-ans

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)
    if s<t:
      print(s)
    else:
      print(t)


Failing test case input:
1100111001010001 1010100001101001 1011001000001011

Expected output:
89110001008990


Actual output:
-89110001008990


Fixed submission (verdict: Accepted):
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))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

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

X = abs(X)
k, x = divmod(X, D)

if K <= k:
    print(x)
    sys.exit(0)

X = x
K -= k

if K % 2 == 0:
    print(abs(X))
    sys.exit(0)

print(abs(X - D))

Failing test case input:
7 0 3

Expected output:
7


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

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

X = abs(X)
k, x = divmod(X, D)

if K <= k:
    print(X - D * K)
    sys.exit(0)

X = x
K -= k

if K % 2 == 0:
    print(abs(X))
    sys.exit(0)

print(abs(X - D))

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D + mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Failing test case input:
1000011000011111 1100110110000001 1000111000001000

Expected output:
99999989889


Actual output:
2000122000012111


Fixed submission (verdict: Accepted):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = map(int,input().split())

if x < 0:
    x *= -1

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

Failing test case input:
1000011000111101 1100110111000101 1000111000001000

Expected output:
99999889899


Actual output:
1000011000111101


Fixed submission (verdict: Accepted):
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)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
1000100100000000 1000101001000001 1000000000001000

Expected output:
100099999000


Actual output:
1000101001000000
100099999000
100099999000


Fixed submission (verdict: Accepted):
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)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x, k, d = list(map(int, input().split()))

x = abs(x)
p = 0
if x != 0:
    
    if x/d > k:
        p = x-(k*d)

    
    else:
        p = x%d
        if (k - x/d)%2 == 1:
            p = p-d
print(abs(p))


Failing test case input:
1101110100000001 1010101001100001 1110001000000000

Expected output:
8890899999999


Actual output:
1101110100000001


Fixed submission (verdict: Accepted):
x, k, d = list(map(int, input().split()))

x = abs(x)
p = 0

if x/d >= k:
    p = x-(k*d)

else:
    p = x%d
    if (k - int(x/d))%2 == 1:
        p = p-d
print(abs(p))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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:
            an = x
        break
        
print(abs(an))

Failing test case input:
1101011100010001 1010100000100000 1110001000000000

Expected output:
1101011100010001


Actual output:
1118990899989999


Fixed submission (verdict: Accepted):
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
        an = x-d*(x
    else:
        an = x-d*(x
        
print(abs(an))