problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p02584
u494149778
2,000
1,048,576
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.
['input_line = input()\ndata = input_line.split(" ")\nx = abs(int(data[0]))\nk = int(data[1])\nd = int(data[2])\na = x // d\nb = x % d\nres = abs(a)\nif res >= k :\n ans = x - k * d\nelse :\n num = k - res\n if num % 2 == 1 :\n ans = abs(res - d)\n else :\n ans = res\n print(ans)\n', 'input_line = input()\ndata = input_line.split(" ")\nx = abs(int(data[0]))\nk = int(data[1])\nd = int(data[2])\na = x // d\nb = x % d\nres = abs(a)\nif res >= k :\n ans = x - k * d\nelse :\n num = k - res\n if num % 2 == 1 :\n ans = abs(res - d)\n else :\n ans = res\nprint(ans)\n', 'input_line = input()\ndata = input_line.split(" ")\nx = abs(int(data[0]))\nk = int(data[1])\nd = int(data[2])\na = x // d\nb = x % d\nres = abs(a)\nif res >= k :\n ans = x - k * d\nelse :\n num = k - res\n if num % 2 == 1 :\n ans = abs(b - d)\n else :\n ans = b\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s183188851', 's854659915', 's214349222']
[9176.0, 9132.0, 9228.0]
[30.0, 29.0, 32.0]
[274, 272, 267]
p02584
u501364195
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\nif X > 0:\n v = 1\nelse:\n v = 0\n\nfor i in range(K):\n if X > 0:\n if v==0 and (K-i)%2==1:\n print(abs(X-D))\n v=2\n break\n elif v==0 and (K-i)%2==1:\n print(abs(X))\n v=2\n break\n X -= D\n else:\n if v==1 and (K-i)%2==1:\n print(abs(X+D))\n v=2\n break\n elif v==1 and (K-i)%2==0:\n print(abs(X))\n v=2\n break\n X += D\nif v!=2:\n print(X)\n ', 'X, K, D = map(int, input().split())\n\nif X==0:\n if K%2==0:\n print(X)\n else:\n print(D)\nelif abs(X)-K*D>=0:\n print(abs(X)-K*D)\nelse:\n a = int(abs(X) / D)\n b = abs(X) % D\n if (K-a)%2==0:\n print(b)\n else:\n print(abs(b-D))\n ']
['Wrong Answer', 'Accepted']
['s446024719', 's615999010']
[9216.0, 9180.0]
[2206.0, 33.0]
[443, 240]
p02584
u502731482
2,000
1,048,576
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.
['x, k, d = map(int, input().split())\n\nif x < 0:\n flag = -1\nelse:\n flag = 1\n\nif abs(x) >= k * d:\n print(x - k * d * flag)\nelse:\n k -= x // d\n x = x % d\n print(x if k % 2 == 0 else x - d * flag)\n', 'x, k, d = map(int, input().split())\n\nif x < 0:\n flag = -1\nelse:\n flag = 1\n\nif abs(x) >= k * d:\n ans = x - k * d * flag\nelse:\n k -= abs(x) // d\n x = abs(x) % d * flag\n ans = x if k % 2 == 0 else x - d * flag\n\nprint(abs(ans))\n']
['Wrong Answer', 'Accepted']
['s255384790', 's766469653']
[9132.0, 8948.0]
[29.0, 30.0]
[210, 242]
p02584
u504272868
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\nprint((abs(abs(X)-K*D)/D)%2)\nif abs(X) >= K*D:\n print(abs(X-K*D))\nelif (abs((abs(X)-K*D)/D))%2 == 0:\n print(0)\nelif (abs((abs(X)-K*D)/D))%2 <= 0.5:\n print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D-1))))\nelif (abs((abs(X)-K*D)/D))%2 <= 1.5:\n print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D+1))))', 'X, K, D = map(int, input().split())\n\n\nif abs(X) >= K*D:\n print(abs(abs(X)-K*D))\nelif ((abs(X)-K*D)/D)%2 == 0:\n print(0)\nelif ((abs(X)-K*D)/D)%2 <= -1:\n print(abs((abs(X)-K*D)+D*((abs(abs(X)-K*D))//D+1)))\nelif ((abs(X)-K*D)/D)%2 < 0:\n print(abs((abs(X)-K*D)+D*((abs(abs(X)-K*D))//D)))\n \nelif (abs((abs(X)-K*D)/D))%2 < 1:\n print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D))))\nelif (abs((abs(X)-K*D)/D))%2 >=1 :\n print(abs((abs(X)-K*D)+D*abs(((abs(abs(X)-K*D))//D+1))))']
['Wrong Answer', 'Accepted']
['s730653718', 's559517747']
[9216.0, 9312.0]
[34.0, 28.0]
[349, 519]
p02584
u513858037
2,000
1,048,576
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.
['x,k,d = map(int,input().split())\n\nif x < 0:\n x *= -1\n\nif x-k*d < 0:\n if (k-(math.floor(x/d)))%2 == 0:\n print(x%d)\n else:\n print(abs(x%d-d))\nelse:\n print(x-k*d)', 'x,k,d = map(int,input().split())\n\nif x > 0:\n d *= -1\n for i in range(k):\n x += d\n if x < 0:\n d *= -1\n print(x)\n exit()\n\nif x < 0:\n for i in range(k):\n x += d\n if x > 0:\n d *= -1\n print(x)\n exit()', 'import math\n\nx,k,d = map(int,input().split())\n\nif x < 0:\n x *= -1\n\nif x-k*d < 0:\n if (k-(math.floor(x/d)))%2 == 0:\n print(x%d)\n else:\n print(abs(x%d-d))\nelse:\n print(x-k*d)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s238243127', 's450612713', 's312278929']
[9172.0, 9124.0, 9172.0]
[30.0, 2206.0, 31.0]
[185, 266, 198]
p02584
u515128734
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\nabs_x = abs(X)\nhikukazu = abs(X) // D\ncount = K - (hikukazu)\nif K > hikukazu:\n if count % 2 == 0:\n hikukazu = hikukazu\n else:\n hikukazu = hikukazu + 1\nelse:\n hikukazu = K\n\n\nfor i in range(hikukazu):\n \n abs_x = abs_x - D\n\n # print(X)\n\nprint(abs_x)', 'X, K, D = map(int, input().split())\nabs_x = abs(X)\nhikukazu = abs(X) // D\ncount = K - (hikukazu)\nif K > hikukazu:\n if count % 2 == 0:\n hikukazu = hikukazu\n else:\n hikukazu = hikukazu + 1\nelse:\n hikukazu = K\n\nfor i in range(hikukazu):\n \n abs_x = abs_x - D\n\n # print(X)\n\nprint(abs(X))', 'X, K, D = map(int, input().split())\nabs_x = abs(X)\nhikukazu = abs(X) // D\ncount = K - (hikukazu)\nif K > hikukazu:\n if count % 2 == 0:\n hikukazu = hikukazu\n else:\n hikukazu = hikukazu + 1\nelse:\n hikukazu = D*K-1\n\nfor i in range(hikukazu):\n \n abs_x = abs_x - D\n\n # print(X)\n\nprint(abs(X))', 'X, K, D = map(int, input().split())\nabs_x = abs(X)\nhikukazu = abs(X) // D\ncount = K - (hikukazu)\nif K > hikukazu:\n if count % 2 == 0:\n hikukazu = hikukazu\n else:\n hikukazu = hikukazu + 1\nelse:\n hikukazu = K\n\n\n\n \n# abs_x = abs_x - D\nabs_x = abs_x - (D*hikukazu)\n # print(X)\n\nprint(abs(abs_x))']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s249168620', 's518162513', 's669713442', 's998939283']
[9092.0, 9176.0, 9188.0, 9128.0]
[2206.0, 2206.0, 2205.0, 31.0]
[314, 314, 318, 351]
p02584
u517674755
2,000
1,048,576
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.
['k = int(input())\nx = 7 % k\nfor i in range(1, k+1):\n if x == 0:\n print(i)\n exit()\n x = (x*10+7)%k\nprint(-1)\n', 'k = int(input())\nx = 7 % k\nfor i in range(1, k+1):\n if x == 0:\n print(i)\n x = (x*10+7)%k\nprint(-1)\n', 'x,k,d = map(int, input().split())\nx = abs(x)\nkd = k*d\n\nif kd<=x:\n print(x-kd)\nelse:\n count = x // d\n k_dash = k - count\n x -= count * d\n if k_dash % 2 == 0:\n print(x)\n else:\n print(d-x)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s117324104', 's213557275', 's537859280']
[9044.0, 9096.0, 9092.0]
[24.0, 30.0, 29.0]
[127, 112, 218]
p02584
u519922200
2,000
1,048,576
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.
['x,k,d=map(int, input().split())\nif abs(k*d)>abs(x):\n if k%2==0:\n a=x%(2*d)\n print(a)\n else:\n a=x%(2*d)\n print(a-2*d)\nelse:\n print(abs(x)-abs(k*d))', 'x,k,d=map(int, input().split())\nif abs(k*d)>abs(x):\n if k%2==0:\n a=x%(2*d)\n print(min(abs(a),abs(a-2+d)))\n else:\n a=x%(2*d)\n print(min(abs(a-d),abs(a+d)))\nelse:\n print(abs(x)-abs(k*d))', 'x,k,d=map(int, input().split())\nif abs(k*d)>abs(x):\n if k%2==0:\n a=x%(2*d)\n print(min(abs(a),abs(a-2*d)))\n else:\n a=x%(2*d)\n print(min(abs(a-d),abs(a+d)))\nelse:\n print(abs(x)-abs(k*d))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s235413368', 's788665158', 's789835957']
[9184.0, 9188.0, 9200.0]
[29.0, 27.0, 33.0]
[183, 221, 221]
p02584
u526278960
2,000
1,048,576
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.
['n,k,m = map(int,input().split())\n#print(k*m,n)\nif k*m >= n:\n #print(min(n%m, n-(n%m)))\n x = n//m;\n left = n - x*m;\n right = left + m;\n k = k - x;\n if k&1:\n print(right)\n else:\n print(left)\n \nelse:\n print(n - k*m)\n', 'n,k,m = map(int,input().split())\n#print(k*m,n)\nif n>=0:\n if k*m > n:\n #print(min(n%m, n-(n%m)))\n x = n//m;\n left = n - x*m;\n right = abs(left - m);\n k = k - x;\n if k&1:\n print(right)\n else:\n print(left)\n \n else:\n print(n - k*m)\nelse:\n n = abs(n)\n k = abs(k)\n m = abs(m)\n if k*m > n:\n #print(min(n%m, n-(n%m)))\n x = n//m;\n left = n - x*m;\n right = abs(left - m);\n k = k - x;\n if k&1:\n print(right)\n else:\n print(left)\n \n else:\n print(n - k*m)\n']
['Wrong Answer', 'Accepted']
['s590013229', 's082078793']
[9160.0, 9048.0]
[38.0, 30.0]
[254, 633]
p02584
u532549251
2,000
1,048,576
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.
['\n#List = list(map(int, input().split()))\n#req = [list(map(int, input().split())) for _ in range(q)]\n#t = t[:-1]\n\n#[0]*n\n\nimport math\nx, k, d = map(int, input().split())\n\nnum = k*d\n\nx = abs(x)\n\nif x >= num:\n print(x - num)\nelse:\n if x > d:\n j = int(x / d)\n else:\n if x*2 > d:\n j = 1\n else:\n j = 0\n\n if j != 0 and j != 1:\n b = x % (d*j)\n elif j == 1:\n b = d - x\n else:\n b = x\n min = min(b, d - b)\n max = max(b, d - b)\n if min == d - b:\n j += 1\n\n if (k - j) % 2 == 0:\n print(min)\n else:\n print(max)\n', '\n#List = list(map(int, input().split()))\n#req = [list(map(int, input().split())) for _ in range(q)]\n#t = t[:-1]\n\n#[0]*n\n\nimport math\nx, k, d = map(int, input().split())\n\nnum = k*d\n\nx = abs(x)\nflag = 0\n\nif x >= num:\n print(x - num)\nelse:\n if x > d:\n j = int(x / d)\n else:\n if x*2 > d:\n j = 1\n flag = 1\n else:\n j = 0\n\n if j == 0:\n b = x\n elif j == 1 and flag == 1:\n b = d - x\n else:\n b = x % (d*j)\n min = min(b, d - b)\n max = max(b, d - b)\n if min == d - b:\n j += 1\n\n if (k - j) % 2 == 0:\n print(min)\n else:\n print(max)\n']
['Wrong Answer', 'Accepted']
['s979354252', 's687897405']
[9240.0, 9212.0]
[34.0, 32.0]
[726, 759]
p02584
u533350485
2,000
1,048,576
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.
['n = int(input())\nx = [int(w) for w in input().split()]\n\nd = {}\n\nfor i in x:\n d[i] = d.get(i, 0) + 1\n \nans = 0\nl = list(d.keys())\nl = sorted(l)\n#print(l)\nfor i in range(len(l)-2):\n for j in range(i+1, len(l)-1):\n for k in range(j+1, len(l)):\n if l[k] < l[i] + l[j]:\n #print(l[i], l[j], l[k])\n ans += d[l[i]]*d[l[j]]*d[l[k]]\n \n else:\n break\n \nprint(ans)', 'x, k, d = map(int, input().split())\nx = abs(x)\n\nt = x/d\n\n \nif t >= k:\n print(abs(x - (k*d)))\n \nelif (k-int(t))%2==0:\n print(abs(x-abs(int(t)*d)))\n \nelse:\n print(abs(x-abs(int(t)*d)-d))']
['Runtime Error', 'Accepted']
['s290472868', 's159194999']
[9188.0, 9192.0]
[26.0, 30.0]
[456, 199]
p02584
u536034761
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\nX = abs(X)\nif K * D <= X:\n print(X - K * D)\nelse:\n A = K - X // D\n if A % 2 == 0:\n print(X - K * D)\n else:\n print(abs(X - K * D - D)) ', 'X, K, D = map(int, input().split())\nX = abs(X)\nif K * D <= X:\n print(X - K * D)\nelse:\n A = K - X // D\n if A % 2 == 0:\n print(X % D)\n else:\n print(abs((X % D) - D))']
['Wrong Answer', 'Accepted']
['s772203338', 's754453052']
[9172.0, 9176.0]
[31.0, 31.0]
[196, 189]
p02584
u539517139
2,000
1,048,576
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.
['x,k,d=map(int,input().split())\nx=abs(x)\nt=x/d\nif t>k:\n print(x-k*d)\nelse:\n k=k-t\n print(d*(k%2))', 'x,k,d=map(int,input().split())\nx=abs(x)\nt=x//d\nif t>k:\n print(x-k*d)\nelse:\n k=k-t\n if k%2==0:\n print(x%d)\n else:\n print(abs(x%d-d))']
['Wrong Answer', 'Accepted']
['s392993402', 's679607371']
[9172.0, 9168.0]
[34.0, 33.0]
[99, 141]
p02584
u542541293
2,000
1,048,576
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.
['import itertools\n\nX, K, D = map(int, input().split())\n\nif K % 2 == 0:\n q, mod = divmod(abs(X), D*2)\n if mod <= abs(mod - D*2):\n if q*2 <= K:\n print(mod)\n else:\n print(X-(K*D))\n else:\n if q*2 <= K:\n print(mod-D*2)\n else:\n print(X-(K*D)) \nelse:\n q, mod = divmod(abs(X), D)\n if mod <= abs(mod - D):\n if q <= K:\n print(mod)\n else:\n print(X-(K*D))\n else:\n if q <= K:\n print(mod-D)\n else:\n print(X-(K*D)) ', 'import itertools\n\nX, K, D = map(int, input().split())\n\nif K % 2 == 0:\n q, mod = divmod(abs(X), D*2)\n if mod <= abs(mod - D*2):\n if q*2 <= K:\n print(mod)\n else:\n print(abs(abs(X)-(K*D)))\n else:\n if q*2 <= K:\n print(abs(mod-D*2))\n else:\n print(abs(abs(X)-(K*D)))\nelse:\n q, mod = divmod(abs(X)-D, D*2)\n if mod <= abs(mod - D*2):\n if q*2 <= K:\n print(mod)\n else:\n print(abs(abs(X)-(K*D)))\n else:\n if q*2 <= K:\n print(abs(mod-D*2))\n else:\n print(abs(abs(X)-(K*D)))']
['Wrong Answer', 'Accepted']
['s241713164', 's397827971']
[9220.0, 9156.0]
[28.0, 34.0]
[472, 529]
p02584
u547608423
2,000
1,048,576
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.
['import bisect\n\nN = int(input())\nL = list(map(int, input().split()))\n\ncnt = 0\nL = list(set(L))\nL = sorted(L)\n\n\nif N >= 3:\n for i in range(len(L)-2):\n for j in range(i+1, len(L)-1):\n ind = bisect.bisect_left(L, L[i]+L[j])\n cnt += max(0, ind-j)\n print(cnt)\n\nelse:\n print(0)\n', 'X, K, D = map(int, input().split())\n\nif abs(K*D) > abs(X):\n A = X//D\n A %= 2\n if K % 2 == A:\n print(X%D)\n else:\n print(D-X%D)\nelse:\n print(abs(X)-abs(K*D))']
['Runtime Error', 'Accepted']
['s733842260', 's414958067']
[9200.0, 9172.0]
[30.0, 29.0]
[309, 184]
p02584
u548272916
2,000
1,048,576
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.
['x,k,d = map(int, input().split())\nlists = []\n \nstep = int(x/d) \n\nif step >= k:\n answer = x - k * d\nelif step < k:\n k_left = k - int(step)\n if k_left % 2 == 0:\n answer = x % d\n if k_left % 2 == 1:\n answer = abs(d)\n\nprint(answer)', 'x,k,d = map(int, input().split())\nlists = []\ni = 1\n \n\nif k*d <= x:\n answer = x - k*d\nelse:\n while i * d <= x and i <= d:\n if i % 2 == 0:\n answer = abs(x - i * d)\n if i % 2 == 1:\n answer = abs(i*d)\n i += 1\n\n\n\nprint(answer)', 'x,k,d = map(int, input().split())\nlists = []\n \nstep = int(x/d) \n\nif step >= k:\n answer = x - k * d\nelif step < k:\n k_left = k - int(step)\n if k_left % 2 == 0:\n answer = x % d\n if k_left % 2 == 1:\n answer = abs(x - step * x - d)\n\nprint(answer)', 'x,k,d = map(int, input().split())\nlists = []\nx = abs(x)\n \nstep = int(x/d) \n \nif step >= k:\n answer = x - k * d\nelif step < k:\n k_left = k - int(step)\n if k_left % 2 == 0:\n answer = x % d\n if k_left % 2 == 1:\n answer = min(abs(x % d - d), abs(x % d + d))\n \nprint(answer)']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s182629880', 's303146841', 's519964047', 's055650335']
[9000.0, 9032.0, 9112.0, 9196.0]
[31.0, 26.0, 29.0, 28.0]
[237, 242, 252, 279]
p02584
u556594202
2,000
1,048,576
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.
['1', 'X,K,D = map(int,input().split())\n\nX=abs(X)\nif X>=K*D:\n print(abs(X-K*D))\nelse:\n print(abs(X-(abs(X)//D+(K-abs(X)//D)%2)*D))']
['Wrong Answer', 'Accepted']
['s429665533', 's728536099']
[9128.0, 9156.0]
[29.0, 33.0]
[1, 129]
p02584
u557997496
2,000
1,048,576
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.
['\nX, K, D = map(int, input().split())\nK2 = K\n\nif X >= 0:\n a= 1\nelse:\n a = -1\n\nh = min(K, int(a*X/D))\nK = K-h\nX = X - a*D*h\n\nprint(X, K, D)\n \n\n\nflg = 0\nminx = abs(X)\nXnow = X\nXprepre = 0\nfor i in range(K):\n if i != 0:\n Xprepre = Xpre\n Xpre = Xnow \n X1 = Xnow -D\n X2 = Xnow +D\n if abs(X1) < abs(X2):\n Xnow = X1\n else:\n Xnow = X2\n \n if Xprepre == Xnow:\n flg = 1\n if (K-i+1)%2 == 0:\n print(abs(Xnow))\n else:\n print(abs(Xpre))\n break\nif flg == 0:\n print(abs(Xnow))\n', '\nX, K, D = map(int, input().split())\nK2 = K\n\nif X >= 0:\n a= 1\nelse:\n a = -1\n\nh = min(K, int(a*X/D))\nK = K-h\nX = X - a*D*h\n\n#print(X, K, D)\n \n\n\nflg = 0\nminx = abs(X)\nXnow = X\nXprepre = 0\nfor i in range(K):\n if i != 0:\n Xprepre = Xpre\n Xpre = Xnow \n X1 = Xnow -D\n X2 = Xnow +D\n if abs(X1) < abs(X2):\n Xnow = X1\n else:\n Xnow = X2\n \n if Xprepre == Xnow:\n flg = 1\n if (K-i+1)%2 == 0:\n print(abs(Xnow))\n else:\n print(abs(Xpre))\n break\nif flg == 0:\n print(abs(Xnow))\n']
['Wrong Answer', 'Accepted']
['s460682498', 's330491055']
[9148.0, 9040.0]
[30.0, 31.0]
[599, 600]
p02584
u570155187
2,000
1,048,576
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.
['x,k,d = list(map(int,input().split()))\n\nxi = abs(x)\nif abs(x) > d*k:\n m = abs(min(x+d*k, x-d*k))\nelse:\n for i in range(k):\n xi -= d*i\n if xi < 0:\n m = abs(min(x+d*i,x-d*i,x+d*(i-1),x-d*(i-1)))\n break\nprint(m)', 'from math import ceil \nx,k,d = list(map(int,input().split()))\n\nxi = abs(x)\nif abs(x) > d*k:\n m = min(abs(x+d*k),abs(x-d*k))\nelse:\n n = ceil(xi // d)\n if (n+k) % 2 == 0:\n m = abs(xi-d*n)\n else:\n m = abs(xi-d*(n-1))\nprint(m)', 'x,k,d = list(map(int,input().split()))\n\nxi = abs(x)\nif abs(x) > d*k:\n m = abs(min(x+d*k, x-d*k))\nelse:\n for _ in range(k):\n xi -= d\n if xi < 0:\n m = abs(min(xi,xi+d,xi-d))\n break\nprint(m)', 'x,k,d = list(map(int,input().split()))\n\nxi = abs(x)\nif abs(x) > d*k:\n m = min(abs(x+d*k),abs(x-d*k))\nelse:\n for i in range(k):\n if xi - d*i <= 0:\n if (i+k) % 2 != 0:\n m = abs(xi)\n else:\n m = min(abs(xi+d),abs(xi-d))\n break\n break\nprint(m)', 'from math import ceil \nx,k,d = list(map(int,input().split()))\n\nxi = abs(x)\nif abs(x) > d*k:\n m = min(abs(x+d*k),abs(x-d*k))\nelse:\n n = ceil(xi / d)\n if (n+k) % 2 == 0:\n m = abs(xi-d*n)\n else:\n m = abs(xi-d*(n-1))\nprint(m)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s261224427', 's584259358', 's749401456', 's858948167', 's601668097']
[9192.0, 9164.0, 9176.0, 9136.0, 9184.0]
[36.0, 34.0, 2206.0, 26.0, 37.0]
[226, 232, 205, 275, 231]
p02584
u571718615
2,000
1,048,576
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.
["from sys import stdin\n\n\ndef f(x, k, d):\n if k == 0:\n return x\n\n if x == 0:\n if k % 2 == 0:\n return 0\n elif k % 2 == 1:\n return d\n elif x > 0:\n tmp = abs(x) / d\n if d * tmp > d * k:\n return x - d * k\n else:\n return f((x-d*tmp), (k-tmp), d)\n elif x < 0:\n tmp = abs(x) / d\n if d * tmp > d * k:\n return x + d * k\n else:\n return f((x+d*tmp), (k-tmp), d)\n\n\nif __name__ == '__main__':\n X, K, D = [int(x) for x in stdin.readline().rstrip().split()]\n print(abs(f(X, K, D)))\n", "from sys import stdin\n\n\ndef f(x, k, d):\n if k == 0:\n return x\n\n absX = abs(x)\n tmp = absX / d\n\n if tmp > k:\n return absX - d * k\n else:\n absX = absX - d * tmp\n k = k - tmp\n if k % 2 == 0:\n return absX\n else:\n return absX - d\n\n\nif __name__ == '__main__':\n X, K, D = [int(x) for x in stdin.readline().rstrip().split()]\n print(f(X, K, D))", "from sys import stdin\n\n\ndef f(x, k, d):\n if k == 0:\n return x\n\n tmp = abs(x) / d\n if x == 0:\n if k % 2 == 0:\n return 0\n elif k % 2 == 1:\n return d\n\n elif x > 0:\n if tmp > k:\n return x - d * k\n else:\n x = x - d * tmp\n k = k - tmp\n if k % 2 == 0:\n return x\n else:\n return x - d\n elif x < 0:\n if tmp > k:\n return x + d * k\n else:\n x = x + d * tmp\n k = k - tmp\n if k % 2 == 0:\n return x\n else:\n return x + d\n\n\nif __name__ == '__main__':\n X, K, D = [int(x) for x in stdin.readline().rstrip().split()]\n print(abs(f(X, K, D)))\n", "from sys import stdin\n\n\ndef f(x, k, d):\n if k == 0:\n return x\n\n tmp = abs(x) / d\n if x == 0:\n if k % 2 == 0:\n return 0\n elif k % 2 == 1:\n return d\n\n elif x > 0:\n if tmp > k:\n return x - d * k\n else:\n x = x - d * tmp\n k = k - tmp\n if k % 2 == 0:\n return x\n else:\n return x - d\n elif x < 0:\n if tmp > k:\n return x + d * k\n else:\n x = x + d * tmp\n k = k - tmp\n if k % 2 == 0:\n return x\n else:\n return x + d\n\n\nif __name__ == '__main__':\n X, K, D = [int(x) for x in stdin.readline().rstrip().split()]\n print(abs(f(X, K, D)))\n", "from sys import stdin\n\n\ndef f(x, k, d):\n x = abs(x)\n if k == 0:\n return abs(x)\n\n tmp = x // d\n\n if tmp > k:\n return abs(x - d * k)\n else:\n x = x - d * tmp\n k = k - tmp\n if k % 2 == 0:\n return abs(x)\n else:\n return abs(x - d)\n\n\nif __name__ == '__main__':\n X, K, D = [int(x) for x in stdin.readline().rstrip().split()]\n print(f(X, K, D))\n"]
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s000344185', 's188431396', 's277199010', 's432995360', 's040233495']
[9276.0, 9184.0, 9068.0, 9148.0, 9196.0]
[31.0, 34.0, 34.0, 32.0, 31.0]
[612, 420, 782, 782, 421]
p02584
u571832991
2,000
1,048,576
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.
["x, k, d = map(int, input().split(' '))\nb = x + k * d;\nif b > 0:\n a = int(b / (2 * d))\n if a <= k:\n print(max(b-a*2*d, -(b-(a+1)*2*d)))\n else:\n print(b-k*2*d)\nelse:\n print(-b)", "# x, k, d = map(int, input().split(' '))\nx, k, d = map(int, input().split(' '))\nb = x + k * d;\nif b > 0:\n a = int(b / (2 * d))\n if a <= k:\n print(max(b-a*2*d, b-(a+1)*2*d))\n else:\n print(b-k*2*d)\nelse:\n print(-b)", "x, k, d = map(int, input().split(' '))\nb = x + k * d;\nif b > 0:\n a = int(b / (2 * d))\n if a <= k:\n print(min(b-a*2*d, -(b-(a+1)*2*d)))\n else:\n print(b-k*2*d)\nelse:\n print(-b)"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s156658449', 's249709908', 's596259298']
[9192.0, 9044.0, 9192.0]
[31.0, 27.0, 31.0]
[200, 238, 200]
p02584
u579610094
2,000
1,048,576
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.
['x,k,d=[int(x) for x in input().split()]\n\nprint(x)\n\nif abs(x)==d:\n\tif k%2==0:\n\t\tprint(abs(x))\n\telse:\n\t\tprint(0)\nelse:\n\n\tnum= abs(x)//d\n\tif k<num:\n\t\tif x<0:\n\t\t\tx=x+k*d\n\t\telse:\n\t\t\tx=x-k*d\n\t\tprint(abs(x))\n\telse:\n\t\tif x<0:\n\t\t\tx=x+num*d\n\t\telse:\n\t\t\tx=x-num*d\n\n\t\tk=k-num\n\n\t\tif k%2==0:\n\t\t\tprint(abs(x))\n\t\telse:\n\t\t\tprint(min(abs(x-d),abs(x+d)))\n', 'x,k,d=[int(x) for x in input().split()]\n\nif x==d:\n\tprint(x)\nelse:\n\t\n\twhile(k>0):\n\t\tif abs(x+d) < abs(x-d):\n\t\t\tx=x+d\n\t\telse:\n\t\t\tx=x-d\n\t\tk-=1\n\n\tprint(x)', 'x,k,d=[int(x) for x in input().split()]\n\n\nif abs(x)==d:\n\tif k%2==0:\n\t\tprint(abs(x))\n\telse:\n\t\tprint(0)\nelse:\n\n\tnum= abs(x)//d\n\tif k<=num:\n\t\tif x<0:\n\t\t\tx=x+k*d\n\t\telse:\n\t\t\tx=x-k*d\n\t\tprint(abs(x))\n\telse:\n\t\tif x<0:\n\t\t\tx=x+num*d\n\t\telse:\n\t\t\tx=x-num*d\n\n\t\tk=k-num\n\n\t\tif k%2==0:\n\t\t\tprint(abs(x))\n\t\telse:\n\t\t\tprint(min(abs(x-d),abs(x+d)))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s310595848', 's460452182', 's676449698']
[9208.0, 9080.0, 9008.0]
[33.0, 2205.0, 26.0]
[335, 150, 327]
p02584
u580273604
2,000
1,048,576
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.
['from sys import stdin\ninput = stdin.readline\nX, K, D = map(int, input().split())\n\nA=min(int((X/D+K)/2),K)\nprint(A)\nj=0\nk=X\nfor i in range(A-1,A+1):\n j=abs(-K*D+2*i*D+X)\n if abs(j)<=abs(k) :k=abs(j)\n\nprint(k)\n', 'from sys import stdin\ninput = stdin.readline\nX, K, D = map(int, input().split())\nA=int((K-X/D)/2)\nif 0<=A and A<=K:print(min(abs(-K*D+2*A*D+X),abs(-K*D+2*(A+1)*D+X)))\nelse:print(min(abs(X+K*D),abs(X-K*D)))']
['Wrong Answer', 'Accepted']
['s791457259', 's955047981']
[9172.0, 9168.0]
[28.0, 28.0]
[214, 205]
p02584
u585963734
2,000
1,048,576
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.
['X,K,D=map(int, input().split())\n\nif X>=K*D:\n print(X-K*D)\nelif X<=-K*D:\n print(K*D-X)\nelif 0<X<K*D:\n a=X//D\n K-=a\n if K%2==0:\n print(X-D*a)\n else:\n print(X-D*a-D)\nelse:\n a=X//D\n K-=a\n if K%2==0:\n print(X+D*a)\n else:\n print(X+D*a+D)\n', 'X,K,D=map(int, input().split())\n\nif 0<abs(X)<K*D:\n a=X//D\n K-=a\n if K%2==0:\n ans=X-D*a\n else:\n ans=X-D*(a+1)\n\nelse:\n ans=abs(X)-K*D\n \nprint(abs(ans))']
['Wrong Answer', 'Accepted']
['s955814306', 's174295908']
[9136.0, 9184.0]
[26.0, 29.0]
[254, 163]
p02584
u592944963
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\nX = abs(X)\n\nk = X // D\nif abs(X - k * D) <= abs(X - (k + 1) * D):\n best_k = k\nelse:\n best_k = k + 1\n\nif K < best_k:\n print(abs(X - K * D))\nelif (K - best_k) % 2 == 0:\n print(abs(X - best_k * D))\nelse:\n print(abs(X - best_k * D) + D)\n', 'X, K, D = map(int, input().split())\nX = abs(X)\n\nk = X // D\nif abs(X - D * k) <= abs(X - D * (k + 1)):\n best_k = k\nelse:\n best_k = k + 1\n\nif K < best_k:\n print(abs(X - K * D))\nelif (K - best_k) % 2 == 0:\n print(abs(X - best_k * D))\nelse:\n print(abs(X - (best_k - 1) * D))\n', 'X, K, D = map(int, input().split())\nX = abs(X)\n\nk = X // D\nif abs(X - k * D) <= abs(X - (k + 1) * D):\n best_k = k\nelse:\n best_k = k + 1\n\nif K < best_k:\n print(abs(X - K * D))\nelif (K - best_k) % 2 == 0:\n print(abs(X - best_k * D))\nelse:\n print(min(abs(X - best_k * D + D), abs(X - best_k * D - D)))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s366558872', 's849305269', 's490026734']
[9176.0, 9184.0, 9188.0]
[34.0, 33.0, 31.0]
[284, 286, 314]
p02584
u595833382
2,000
1,048,576
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.
['X,K,D = [int(x) for x in input().split()]\n\nif abs(X) >= K * D:\n print(abs(X) - K * D)\nelse:\n K = K - int(abs(X) / D)\n print(K)\n X = int(abs(X) % D)\n print(X)\n if X >= int(D / 2):\n if K % 2 == 0:\n print(X)\n else:\n print(D - X)\n else:\n if K % 2 != 0:\n print(D - X)\n else:\n print(X)', 'X,K,D = [int(x) for x in input().split()]\n\nif abs(X) >= K * D:\n print(abs(X) - K * D)\nelse:\n K = K - int(abs(X) / D)\n print(K)\n X = int(abs(X) % D)\n print(X)\n if X >= int(D / 2):\n if K % 2 == 0:\n print(X)\n print("no")\n else:\n print(D - X)\n else:\n if K % 2 != 0:\n print(D - X)\n else:\n print(X)', 'X,K,D = [int(x) for x in input().split()]\n\nif abs(X) >= K * D:\n print(abs(X) - K * D)\nelse:\n K = K - int(abs(X) / D)\n X = int(abs(X) % D)\n if X >= int(D / 2):\n if K % 2 == 0:\n print(X)\n else:\n print(D - X)\n else:\n if K % 2 != 0:\n print(D - X)\n else:\n print(X)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s022759271', 's597022359', 's985889087']
[9132.0, 9176.0, 9136.0]
[30.0, 33.0, 38.0]
[372, 396, 346]
p02584
u602773379
2,000
1,048,576
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.
['\ndef input2():\n\treturn map(int,input().split())\n\n\nx,k,d=input2()\n\ncount=abs(x//d)\nif k>=count:\n\tif x<0:\n\t\tans=x+d*count\n\telse:\n\t\tans=x-d*count\n\tif count%2==1:\n\t\tans+=d\nelse:\n\tif x<0:\n\t\tans=x+d*k\n\telse:\n\t\tans=x-d*k\n\tif count%2==1:\n\t\tans+=d\nprint(ans)', '\ndef input2():\n\treturn map(int,input().split())\n\nx,k,d=input2()\nabs_x=abs(x)\ncount=min(abs_x//d,k) \nabs_x-=d*count \nrem=k-count\n\n\nif rem>0:\n\tif rem%2==1:\n\t\tabs_x-=d \n\nans=abs(abs_x)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s432219477', 's961622313']
[9124.0, 9196.0]
[31.0, 27.0]
[272, 274]
p02584
u606146341
2,000
1,048,576
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.
['x, k, d = map(int, input().split())\n\nx = abs(x)\nans = x - min(x // d, k) * d\nif (k - x // d) % 2 == 0:\n print(abs(ans))\nelse:\n print(abs(ans+d))', 'x, k, d = map(int, input().split())\n\nx = abs(x)\ndiv = min(x//d, k)\nif (k - div) % 2 == 0:\n ans = abs(x - d * div)\nelse:\n ans = abs(x - d * div - d)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s077008611', 's691328443']
[9060.0, 8964.0]
[27.0, 30.0]
[151, 164]
p02584
u607709109
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\nX = abs(X)\na = X/D\nans = 0\n\nif a>=K:\n ans = X-(D*K)\nelse:\n if K%2==0:\n if a%2==0: ans = X-(D*a)\n else: ans = X-(D*a)-D\n else:\n if a%2==0: ans = X-(D*a)-D\n else: ans = X-(D*a)\n\nans = int(abs(ans))\nprint(ans)\n', 'X, K, D = map(int, input().split())\n\nX = abs(X)\na = int(X/D)\nans = 0\n\nif a>=K:\n ans = X-(D*K)\nelse:\n if K%2==0:\n if a%2==0: ans = X-(D*a)\n else: ans = X-(D*a)-D\n else:\n if a%2==0: ans = X-(D*a)-D\n else: ans = X-(D*a)\n\nans = int(abs(ans))\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s335978781', 's511805000']
[9120.0, 9084.0]
[31.0, 35.0]
[281, 286]
p02584
u623349537
2,000
1,048,576
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.
['X, K,D = map(int, input().split())\n\nif X >= K * D:\n print(X - K * D)\nelif X <= K * (- D):\n print(abs(X + K * D))\nelse:\n if X >= 0:\n pos = X % D\n neg = X % D - D\n if K % 2 == (X // D) % 2:\n print(pos)\n else:\n print(abs(neg))\n if X <= 0:\n pos = D - (abs(X) % D)\n neg = - (abs(X) % D)\n if K % 2 == (X // D) % 2:\n print(abs(neg)\n else:\n print(pos))', 'X, K,D = map(int, input().split())\n\nif X >= K * D:\n print(X - K * D)\nelif X <= K * (- D):\n print(abs(X + K * D))\nelse:\n if X >= 0:\n pos = X % D\n neg = X % D - D\n if K % 2 == (X // D) % 2:\n print(pos)\n else:\n print(abs(neg))\n elif X <= 0:\n pos = D - (abs(X) % D)\n neg = - (abs(X) % D)\n if K % 2 == (abs(X) // D) % 2:\n print(abs(neg))\n else:\n print(pos)']
['Runtime Error', 'Accepted']
['s944728330', 's327430781']
[9060.0, 9076.0]
[31.0, 29.0]
[456, 463]
p02584
u643679148
2,000
1,048,576
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.
['x, k, d = map(int, input().split()) \na = x // d \nb = x % d \nif k <= a: \n x = x - (k*d)\nelse:\n k = k - a \n if k % 2 == 0:\n x = abs(x) - abs(a * d)\n else:\n x = abs(x) - abs(a * d)\n if x > 0:\n x = x + abs(d)\n else:\n x = x + abs(d)\n\nprint(abs(x))\n', 'x, k, d = map(int, input().split()) \na = x // d \nb = x % d \nif k <= a: \n x = abs(x) - k*d\nelse:\n k = k - a \n if k % 2 == 0:\n x = abs(x) - a * d\n else:\n x = abs(x) - a * d\n x = abs(x) - d\n\nprint(x)\n', 'x, k, d = map(int, input().split()) \nx = abs(x)\na = x // d \nb = x % d \nif k <= a: \n x = x - (k*d)\nelse:\n k = k - a \n if k % 2 == 0:\n x = x - (a * d)\n else:\n x = x - (a * d)\n if x > 0:\n x = x - abs(d)\n else:\n x = x + abs(d)\n\nprint(abs(x))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s307460889', 's697913563', 's318365461']
[9188.0, 9148.0, 9092.0]
[34.0, 31.0, 31.0]
[474, 399, 469]
p02584
u644497121
2,000
1,048,576
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.
['a = input().split()\nx = int(a[0])\nk = int(a[1])\nd = int(a[2])\n\nif (x == 0):\n if (k % 2 == 0):\n res = 0\n else:\n res = d\nelse:\n if ((k * d) > abs(x)):\n y = abs(x)\n res = abs(abs(x) - y * d)\n if ((k - y) % 2 == 1):\n res = abs(d - res)\n else:\n res = abs(x) - k * d\nprint(res)', 'v = input().split(" ")\nx = int(v[0])\nk = int(v[1])\nd = int(v[2])\n\nif (x == 0):\n if (k % 2 == 0):\n ans = 0\n else:\n ans = d\nelse:\n if ((k * d) > abs(x)):\n y = abs(x) // d\n ans = abs(abs(x) - y * d)\n if ((k - y) % 2 == 1):\n ans = abs(d - ans)\n else:\n ans = abs(x) - k * d\nprint(ans)']
['Wrong Answer', 'Accepted']
['s029388975', 's113669156']
[9108.0, 9208.0]
[32.0, 29.0]
[336, 344]
p02584
u646130340
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\nR = X // D\nQ = X - D * K\n\nif K <= R:\n result = Q\nelse:\n O = R - K\n O %= 2\n P = X - D * R\n if O == 0:\n result = P\n else:\n result = abs(P - K)\n\nprint(result)', 'X, K, D = map(int, input().split())\n\nminus = X < 0\nif minus:\n X = -X\n\nR = X // D\n\nif K <= R:\n result = X - D * K\nelse:\n n = K - R\n n %= 2\n P = X - D * R\n if n == 0:\n result = P\n else:\n result = abs(P - D)\n \n\nprint(result)']
['Wrong Answer', 'Accepted']
['s044040900', 's079332413']
[9180.0, 9188.0]
[32.0, 33.0]
[204, 237]
p02584
u648452607
2,000
1,048,576
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.
['[X,K,D]=[int(_) for _ in input().split()]\nX=abs(X)\nY=X//D\nif K>Y:\n K-=Y\n X-=Y*D\nprint(X,K,D)\nX/=D\nfor _ in range(K//2):\n X = min([abs(X-2), abs(X), abs(X+2)])\n print(X)\nif K%2 == 1:\n X = min([abs(X-1), abs(X+1)])\n print(X)\nprint(abs(int(X*D)))', '[X,K,D]=[int(_) for _ in input().split()]\nX=abs(X)\nY=X//D\nif Y <= K:\n X-=Y*D\n if (K-Y)%2 != 0:\n X = abs(X-D) if abs(X-D) < abs(X+D) else abs(X+D)\nelse:\n X-=K*D\nprint(X)']
['Wrong Answer', 'Accepted']
['s502542029', 's076496778']
[42828.0, 9076.0]
[2275.0, 30.0]
[249, 174]
p02584
u655048024
2,000
1,048,576
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.
['x,k,d = map(int,input().split())\njud = x//d\nif(k<=jud):\n print(abs(abs(x)-d*k))\nelse:\n if((k-jud%2) == 1):\n print(abs(abs(x)-(jud+1*d)))\n else:\n print(abs(abs(x)-jud*d))', 'x,k,d = map(int,input().split())\nx = abs(x)\nif (x<=k*d):\n print(x-k*d)\nelse:\n if((k-x//d)%2==1):\n print(abs(x-(x//d+1)*d))\n else:\n print(abs(x-(x//d)*d))\n', 'x,k,d = map(int,input().split())\nx = abs(x)\nif (x<=k*d):\n print(x-k*d)\nelse:\n if((k-x//d)%2==1):\n print(abs(x-(x//d)*d))\n else:\n print(abs(x-(x//d+1)*d))\n', 'x,k,d = map(int,input().split())\njud = (x//d)-1\nif(k<=jud):\n print(abs(abs(x)-d*k))\nelse:\n if((k-jud)%2 == 1):\n print(abs(abs(x)-(jud+1)*d))\n else:\n print(abs(abs(x)-(jud)*d))', 'x,k,d = map(int,input().split())\nx = abs(x)\nif (x<=k*d):\n print(x-k*d)\nelse:\n if((k-x//d)%2==1):\n print(abs(x-(x//d;1)*d))\n else:\n print(abs(x-(x//d)*d))', 'x,k,d = map(int,input().split())\njud = x//d\nif(k==1):\n print(abs(abs(x)-d))\nelif(jud == 0):\n if((k%2 == 1):\n print(abs(abs(x)-d))\n else:\n print(abs(x))\nelif(k<=jud+1):\n print(abs(abs(x)-d*k))\nelse:\n if((k-jud)%2 == 1):\n print(abs(abs(x)-(jud+1)*d))\n else:\n print(abs(abs(x)-(jud)*d))\n', 'x,k,d = map(int,input().split())\nx = abs(x)\njud = x//d\nif(k<=jud):\n print(abs(abs(x)-d*k))\nelse:\n if((k-jud)%2 == 1):\n print(abs(abs(x)-(jud+1)*d))\n else:\n print(abs(abs(x)-(jud)*d))\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s007901284', 's087970919', 's255707362', 's373090161', 's545213104', 's580993185', 's378110388']
[9184.0, 9188.0, 9184.0, 9192.0, 8996.0, 9024.0, 9020.0]
[35.0, 30.0, 29.0, 30.0, 28.0, 27.0, 29.0]
[178, 163, 163, 184, 162, 302, 192]
p02584
u663404111
2,000
1,048,576
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.
['X, K, D = input().split()\nX = abs(X)\nQ, mod = divmod(X, D)\nif K < Q:\n ans = X - K*D\nelse:\n Rest = (K - Q)%2\n if Rest == 0:\n ans = mod\n else:\n ans = D - mod\nprint(ans)', 'X, K ,D = input().split()\nX = abs(int(X))\nK = int(K)\nD = int(D)\nQ, mod = divmod(X, D)\nif K < Q:\n ans = X - K*D\nelse:\n Rest = (K - Q)%2\n if Rest == 0:\n ans = mod\n else:\n ans = D - mod\nprint(ans)']
['Runtime Error', 'Accepted']
['s993847332', 's871261394']
[8980.0, 9160.0]
[31.0, 29.0]
[194, 221]
p02584
u664884522
2,000
1,048,576
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.
['x,k,d = [int(x) for x in input().split()]\nt = abs(int(x/d))\nif x < 0:\n d = -d\nif t >= k:\n print(x-d*k)\nelif t == 0:\n if k % 2 == 0:\n print(abs(x))\n else:\n print(min(abs(x-d),abs(x+d)))\nelif t < k:\n if abs(x-d*t) < abs(x-d*t-d):\n if (t-k)%2==0:\n print(abs(x-d*t))\n else:\n print(min(abs(x-d*t+d),abs(x-d*t-d)))\n elif abs(x-d*t) = abs(x-d*t-d):\n print(abs(x-d*t))\n else:\n if (t-k-1)%2==0:\n print(abs(x-d*t-d))\n else:\n print(min(abs(x-d*t),abs(x-d*t-2*d)))\n', 'x,k,d = [int(x) for x in input().split()]\nt = abs(int(x/d))\nif x < 0:\n d = -d\nif t >= k:\n print(x-d*k)\nelif t == 0:\n if k % 2 == 0:\n print(abs(x))\n else:\n print(min(abs(x-d),abs(x+d)))\nelif t < k:\n if abs(x-d*t) < abs(x-d*t-d):\n if (t-k)%2==0:\n print(abs(x-d*t))\n else:\n print(min(abs(x-d*t+d),abs(x-d*t-d)))\n elif abs(x-d*t) = abs(x-d*t-d):\n print(abs(x-d*t))\n else:\n if (t-k-1)%2==0:\n print(abs(x-d*t-d))\n else:\n print(min(abs(x-d*t),abs(x-d*t-2*d)))\n', 'x,k,d = [int(x) for x in input().split()]\nt = abs(int(x/d))\nif x < 0:\n d = -d\nif t >= k:\n print(abs(x-d*k))\nelif t == 0:\n if k % 2 == 0:\n print(abs(x))\n else:\n print(min(abs(x-d),abs(x+d)))\nelif t < k:\n if abs(x-d*t) < abs(x-d*t-d):\n if (k-t)%2==0:\n print(abs(x-d*t))\n else:\n print(min(abs(x-d*t+d),abs(x-d*t-d)))\n elif abs(x-d*t) == abs(x-d*t-d):\n print(abs(x-d*t))\n else:\n if (k-t-1)%2==0:\n print(abs(x-d*t-d))\n else:\n print(min(abs(x-d*t),abs(x-d*t-2*d)))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s841541340', 's896637107', 's797628704']
[9016.0, 8996.0, 9268.0]
[25.0, 30.0, 31.0]
[567, 568, 573]
p02584
u671861352
2,000
1,048,576
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.
['LI = lambda: list(map(int, input().split()))\n\nX, K, D = LI()\n\n\ndef main():\n x = abs(X)\n a = x // D\n if K <= a:\n ans = x - K * D\n print(ans)\n return\n \n x -= a * D\n k = K - a\n print(a, k)\n if k % 2 == 0:\n ans = x - a * D\n else:\n ans = abs(x - D)\n print(ans)\n \n \nif __name__ == "__main__":\n main()\n', 'LI = lambda: list(map(int, input().split()))\n\nX, K, D = LI()\n\n\ndef main():\n x = abs(X)\n a = x // D\n if K <= a:\n ans = x - K * D\n print(ans)\n return\n \n x -= a * D\n k = K - a\n if k % 2 == 0:\n ans = x\n else:\n ans = abs(x - D)\n print(ans)\n \n \nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Accepted']
['s510981327', 's812666058']
[9180.0, 9180.0]
[30.0, 27.0]
[369, 345]
p02584
u680851063
2,000
1,048,576
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.
['a = abs(x//d)\nb = x%d\n\nif k <= a:\n print(abs(abs(x)-k*d))\n\nelse:\n tmp = k-abs(a)\n if tmp%2 == 0:\n print(abs(x)-a*d)\n else:\n print(abs(abs(x)-(a+1)*d))\n', 'x,k,d = map(int,input().split())\n#print(x,k,d)\nx=abs(x)\na = x//d\nb = x%d\n\nif k <= a:\n print(abs(x-k*d))\n\nelse:\n tmp = k-a\n if tmp%2 == 0:\n print(x-a*d)\n else:\n print(abs(x-(a+1)*d))']
['Runtime Error', 'Accepted']
['s601931425', 's105860840']
[9032.0, 9192.0]
[30.0, 32.0]
[177, 207]
p02584
u682965461
2,000
1,048,576
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.
['x,k,d = map( int, input().split())\n\nif( x == 0 ):\n if( k % 2 == 0 ):\n printf("{}".format(0))\nelse:\n print("{}".format(abs(d)))\n\nif( x > 0 ) :\n if( x - k * d >= 0 ) :\n ret = x - k * d\n print("{}".format(ret))\n rem = x % d\n cost = x // d\n rem2 = abs(rem - d)\n remc = k - cost\n if( remc % 2 == 0 ) : \n ret = rem\n print("{}".format(ret))\n else:\n ret = rem2\n print("{}".format(ret))\nelif( x < 0 ) :\n if( x + k * d <= 0 ) :\n ret = abs( x + k * d )\n print("{}".format(ret))\n rem = (-x) % d\n cost = (-x) / d\n rem *= -1\n rem2 = rem + d\n remc = k - cost\n if( remc % 2 == 0 ):\n ret = abs(rem)\n print("{}".format(ret))\n else :\n ret = rem2\n print("{}".format(ret))\n\n\n', 'x,k,d = map( int, input().split())\n\nif( x == 0 ):\n if( k % 2 == 0 ):\n print("{}".format(0))\n exit()\n else:\n print("{}".format(abs(d)))\n exit()\n\nif( x > 0 ) :\n if( x - k * d >= 0 ) :\n ret = x - k * d\n print("{}".format(ret))\n exit()\n rem = x % d\n cost = x // d\n rem2 = abs(rem - d)\n remc = k - cost\n if( remc % 2 == 0 ) : \n ret = rem\n print("{}".format(ret))\n exit()\n else:\n ret = rem2\n print("{}".format(ret))\n exit()\nelif( x < 0 ) :\n if( x + k * d <= 0 ) :\n ret = abs( x + k * d )\n print("{}".format(ret))\n exit()\n rem = (-x) % d\n cost = (-x) // d\n rem *= -1\n rem2 = rem + d\n remc = k - cost\n if( remc % 2 == 0 ):\n ret = abs(rem)\n print("{}".format(ret))\n exit()\n else :\n ret = rem2\n print("{}".format(ret))\n exit()\n\n\n']
['Wrong Answer', 'Accepted']
['s763649209', 's484803565']
[9308.0, 9256.0]
[31.0, 33.0]
[796, 924]
p02584
u683530136
2,000
1,048,576
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.
['import math;\n\n\nx, k, d = map(int, input().split())\n\n\na = math.floor(x / d);\nif x < 0:\n a = a * (-1);\n\nif a >= k:\n for i in range(k):\n if x > 0:\n x = x - d;\n\n elif x <= 0:\n x = x + d;\n\nelif a < k:\n \n if x > 0:\n for i in range(a):\n x = x - d;\n\n if (k-a) % 2 != 0:\n x = x + d;\n\n elif x <= 0: \n for i in range(a):\n x = x + d;\n\n if (k-a) % 2 != 0:\n x = x - d;\n\n\nif x < 0:\n x = x * (-1);\n\nprint(x);', 'x, k, d = ma-(int, input().split())\nx = abs(x)\n\nif x>k*d:\n print(x-k*d)\nelse:\n k-=x//d\n x-=(d*(x//d))\n and=[x,abs(d-x)]\n print(ans[k%2])', 'x,k,d=map(int,input().split())\nx=abs(x)\nif x>k*d:\n print(x-k*d)\nelse:\n k-=x//d\n x-=(d*(x//d))\n ans=[x,abs(d-x)]\n print(ans[k%2])']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s444100705', 's995713086', 's679056113']
[9164.0, 8968.0, 9020.0]
[2206.0, 30.0, 29.0]
[622, 151, 143]
p02584
u685983477
2,000
1,048,576
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.
["from collections import defaultdict,deque\nimport math\nimport copy\ndef main():\n x,k,d=map(int, input().split())\n res = float('inf')\n l = 0\n r = k+1\n tmp_res = 0\n while(l+1!=r):\n mid = (l+r)//2\n tmp_res = copy.deepcopy(res)\n if((k-mid)%2==1):\n \tres = min(res, abs(abs(x)-(mid+1)*d))\n res = min(res, abs(abs(x)-(mid-1)*d))\n mid+=1\n if((k-mid)%2==0):\n res = min(res, abs(abs(x)-mid*d))\n res = abs(res)\n if(abs(abs(x)-mid*d) > x):\n r = mid\n else:\n l = mid\n if tmp_res == res:\n break\n\n print(res)\n\n\n\n\nif __name__ == '__main__':\n main()\n\n", "from collections import defaultdict,deque\nimport math\nimport copy\ndef main():\n x,k,d=map(int, input().split())\n res = float('inf')\n l = 0\n r = k+1\n tmp_res = 0\n while(l+1!=r):\n mid = (l+r)//2\n tmp_res = copy.deepcopy(res)\n if((k-mid)%2==1):\n \tres = min(res, abs(abs(x)-(mid+1)*d))\n res = min(res, abs(abs(x)-(mid-1)*d))\n mid+=1\n if((k-mid)%2==0):\n res = min(res, abs(abs(x)-mid*d))\n res = abs(res)\n if(abs(abs(x)-mid*d) > x):\n r = mid\n else:\n l = mid\n if tmp_res == res:\n break\n\n print(res)\n\n\n\n\nif __name__ == '__main__':\n main()\n", "from collections import defaultdict,deque\nimport math\nimport copy\ndef main():\n x,k,d=map(int, input().split())\n res = float('inf')\n x = abs(x)\n\n if(k*d <= x):\n print(x-k*d)\n else:\n if(k%2 == x//d%2):\n print(x%d)\n else:\n print(d-x%d)\n\n\n\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s312415716', 's484625385', 's198299671']
[9004.0, 9060.0, 9544.0]
[31.0, 29.0, 33.0]
[689, 688, 333]
p02584
u687416863
2,000
1,048,576
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.
['X,K,D = map(int, input().split())\nAns = 0\n\nif abs(X) >= K * D:\n if X >= 0:\n Ans = X - (K * D)\n else:\n Ans = abs(X + (K * D))\n \nelse:\n abX = abs(X)\n# if X >= 0:\n if (K - abX // D) % 2 == 0:\n Ans = abX - ((abX // D) * D)\n else:\n Ans = abs(abX - ((abX // D) * D) - D)\n \n# else:\n# print(abs(X // D))\n\n# Ans = abs(X + (abs((X // D)) * D))\n# else:\n# Ans = abs(X + (abs((X // D)) * D) - D)\n \nprint(Ans)\n', 'X,K,D = map(int, input().split())\nAns = 0\n\nif abs(X) >= K * D:\n if X >= 0:\n Ans = X - (K * D)\n else:\n Ans = abs(X + (K * D))\n \nelse:\n abX = abs(X)\n# if X >= 0:\n if (K - abX // D) % 2 == 0:\n Ans = abX - ((abX // D) * D)\n else:\n Ans = abs(abX - ((abX // D) * D) - D)\n \n# else:\n# print(abs(X // D))\n\n# Ans = abs(X + (abs((X // D)) * D))\n# else:\n# Ans = abs(X + (abs((X // D)) * D) - D)\n \nprint(Ans)\n']
['Runtime Error', 'Accepted']
['s467214456', 's647221396']
[9028.0, 9220.0]
[30.0, 32.0]
[483, 477]
p02584
u689723321
2,000
1,048,576
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.
['X,K,D=map(int, input().split())\nX=abs(X)\nif X-K*D>0:\n print(X-K*D)\nelse:\n if K%2==0:\n s=X-2*D*int(X/(2*D))\n t=-(s-2*D)\n if s<t:\n print(s)\n else:\n print(t)\n else:\n s=X-2*D*int((X-D)/(2*D))+D\n t=-(s-2*D)\n r=s-2D\n print(min(s,t,r))\n', 'X,K,D=map(int, input().split())\nX=abs(X)\nif X-K*D>0:\n print(X-K*D)\nelse:\n if K%2==0:\n s=X-2*D*int(X/(2*D))\n t=-(s-2*D)\n print(min(abs(s),t))\n \n else:\n s=X-2*D*int((X-D)/(2*D))-D\n t=-(s-2*D)\n \n print(min(abs(s),t))\n']
['Runtime Error', 'Accepted']
['s503603012', 's889042440']
[9068.0, 9184.0]
[23.0, 31.0]
[266, 241]
p02584
u690397868
2,000
1,048,576
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.
['# coding: utf-8\nimport math\nX, K, D = list(map(int, input().split(" ")))\n\nif X==K==D:\n print(X)\n exit()\nx = X\nvmin = abs(X)\ncnt = 0\n# for k in range(K):\n# if X>0:\n# x -= D\n# else:\n# x += D\n# if vmin>abs(x):\n# vmin = abs(x)\n# cnt += 1\n# else:\n# break\ncnt = min(math.floor(X / D), K)\nprint(cnt)\nif X>0:\n print(abs(X - (cnt * D)))\nelse:\n print(abs(X + (cnt * D)))', '# coding: utf-8\nimport math\nX, K, D = list(map(int, input().split(" ")))\n\nx = abs(X)\nk = int(math.floor(x/D))\nif k>=K:\n print(abs(x - K*D))\n exit()\nx -= k*D\nif (K-k)%2==0:\n print(abs(x))\nelse:\n print(abs(x - D))']
['Wrong Answer', 'Accepted']
['s472320932', 's892875348']
[9184.0, 9080.0]
[30.0, 34.0]
[428, 223]
p02584
u692311686
2,000
1,048,576
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.
['X,K,D=map(int,input().split())\nif D*K<abs(X):\n print(abs(X)-D*K)\nelse:\n K2=abs(X)//D\n if K2>K:\n K2=K\n if (K-K2)%2==0:\n print(abs(X)-K2*D)\n else:\n K2=K2-1\n print(abs(X)-K2*D)', 'X,K,D=map(int,input().split())\nif D*K<abs(X):\n print(abs(X)-D*K)\nelse:\n K2=abs(X)//D\n if (K-K2)%2==0:\n print(abs(X)-K2*D)\n else:\n K2=K2-1\n print(abs(X)-K2*D)', 'X,K,D=map(int,input().split())\nif D*K<:abs(X):\n print(abs(X)-D*K)\nelse:\n K2=abs(X)//D\n if (K-K2)%2==0:\n print(abs(X)-K2*D)\n else:\n K2=K2-1\n print(abs(X)-K2*D)\n ', 'X,K,D=map(int,input().split())\nif D*K<abs(X):\n print(abs(X)-D*K)\nelse:\n K2=abs(X)//D\n if K2>K:\n K2=K\n if (K-K2)%2==0:\n print(abs(X)-K2*D)\n else:\n ans=min(abs(X)-(K2-1)*D, (K2+1)*D-abs(X))\n print(ans)']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s091397272', 's773677211', 's981523795', 's477029645']
[9168.0, 9104.0, 8868.0, 9088.0]
[30.0, 29.0, 29.0, 30.0]
[190, 170, 176, 216]
p02584
u694665829
2,000
1,048,576
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.
['x, k, d = map(int,input().split())\nx = x if x>=0 else -x\nif k >= x//d:\n if (x//d)%2 == k%2:\n print(x%d)\n else:\n print(min(abs(x%d-k),abs(x%d+k)))\nelse:\n print(abs(x-d*k))\n ', 'x, k, d = map(int,input().split())\nx = x if x>=0 else -x\nif k >= x//d:\n if (x//d)%2 == k%2:\n print(x%d)\n else:\n print(min(abs(x%d-d),abs(x%d+d)))\nelse:\n print(abs(x-d*k))\n ']
['Wrong Answer', 'Accepted']
['s916264204', 's336833890']
[9184.0, 9172.0]
[29.0, 31.0]
[198, 198]
p02584
u695329583
2,000
1,048,576
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.
['x,k,d = map(int,input().split())\n\nif x >= 0 :\n a = abs(x//d)\n if a <= k :\n if (k - a) % 2 == 0 :\n print(abs(x-a*d))\n else :\n print(abs(x-(a+1)*d))\n else :\n print(abs(x-k*d))\nelse :\n if x%d == 0 :\n a = abs(x//d)\n else :\n a = abs(x//d+1)\n if a <= k :\n if (k - a) % 2 == 0 :\n print(abs(x+a*d))\n else :\n print(abs(x+(a+1)*d))\n else :\n print(abs(x+k*d))', 'x,k,d = map(int,input().split())\n\nif x >= 0 :\n a = abs(x//d)\n if a <= k :\n if (k - a) % 2 == 0 :\n print(abs(x-a*d))\n else :\n print(abs(x-(a+1)*d))\n else :\n print(abs(x-k*d))\nelse :\n if x%d == 0 :\n a = abs(x//d)\n else :\n a = abs(x//d+1)\n\n if a <= k :\n if (k - a) % 2 == 0 :\n print(abs(x+a*d))\n else :\n print(abs(x+(a+1)*d))\n else :\n print(abs(x+k*d))']
['Runtime Error', 'Accepted']
['s756642830', 's728356505']
[8824.0, 9096.0]
[26.0, 30.0]
[525, 474]
p02584
u696684809
2,000
1,048,576
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.
['X,K,D = map(int, input().split())\nL = 0\nM = 0\nN = 0\nS = 0\nif(K %2 ==1):\n K =K-1\n if(X >0):\n X = X-D\n else:\n X = X+D\nL = D*2\nN = int(K/2)\nM = int(abs(X)/L)\nS = min(abs(abs(X)-K*N),abs(abs(X)-M*(K+2)))\nif(M < N):\n print(S)\nelse:\n print(abs(abs(X)-K*D))', 'X,K,D = map(int, input().split())\nL = 0\nM = 0\nN = 0\nS = 0\nif(K %2 ==1):\n K =K-1\n if(X >0):\n X = X-D\n else:\n X = X+D\nL = D*2\nN = int(K/2)\nM = int(abs(X)/L)\nS = min(abs(abs(X)-M*N*2),abs(abs(X)-M*2*(N+1)))\nif(M+1 <= N):\n print(S)\nelse:\n print(abs(abs(X)-K*D))', 'x,k,d=map(int,input().split())\nx=abs(x)\nm=min(k,x//d)\nk=k-m\nif k%2==0:\n print(abs(x-m*d))\nelse:\n print(abs(x-(m+1)*d))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s125109412', 's547586794', 's231051191']
[9152.0, 9088.0, 9172.0]
[26.0, 28.0, 30.0]
[261, 268, 125]
p02584
u698568503
2,000
1,048,576
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.
['x,k,d=list(map(int,input().split()))\nprint(x,k,d)\nresult=abs(x)-k*d\nswithn=0\n\nif result<0:\n if k%2==1:\n x-=d\n result=min(x%(2*d),-x%(2*d))\nprint(result)', 'x,k,d=list(map(int,input().split()))\nprint(x,k,d)\nresult=abs(x)-k*d\n\nif result<0:\n result%=2\nprint(result)', 'x,k,d=list(map(int,input().split()))\n#print(x,k,d)\nresult=abs(x)-k*d\nswithn=0\n\nif result<0:\n if k%2==1:\n x-=d\n result=min(x%(2*d),-x%(2*d))\nprint(result)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s595152289', 's807050909', 's247267916']
[8880.0, 9164.0, 9184.0]
[29.0, 28.0, 29.0]
[165, 109, 166]
p02584
u699008198
2,000
1,048,576
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.
['X, K, D = map( int, input().split())\n\nY = X // D\nif K > Y:\n A = Y\n if A % 2 != 0:\n if X > 0:\n X += D\n else:\n X -= D\nelse:\n A = K\n\nprint( abs( X ) - abs( A * D ) )\n', 'X, K, D = map( int, input().split())\n \nY = abs( X ) // D\nif K <= Y:\n print( min( abs( X - K * D ) , abs( X + K * D ) ))\nelse:\n if ( K - Y ) % 2 == 0:\n print( min( abs( X - Y * D ) , abs( X + Y * D ),\n abs( X - ( Y - 2 ) * D ), abs( X - ( Y + 2 ) * D ),\n abs( X + ( Y - 2 ) * D ), abs( X + ( Y + 2 ) * D )))\n else:\n print( min( abs( X - ( Y - 1 ) * D ), abs( X - ( Y + 1 ) * D ),\n abs( X + ( Y - 1 ) * D ), abs( X + ( Y + 1 ) * D )) )\n']
['Wrong Answer', 'Accepted']
['s147636280', 's588404650']
[9160.0, 9180.0]
[29.0, 30.0]
[182, 488]
p02584
u699522269
2,000
1,048,576
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.
['X,K,D = map(int, input().split())\ntm = X/D\nif K <= tm:\n print(X-D*K)\nelse:\n if (K - tm)%2==1:\n print(abs(X-D*(tm+1)))\n else:\n print(abs(X-D*(tm)))', 'import math\n \nX,K,D = map(int, input().split())\ntm = round(X/D)\nif K <= tm:\n print(abs(X+D*K)if absabs(X+D*K) < abs(X-D*K)else abs(X-D*K))\nelse:\n if (K-tm)%2==1:\n print(abs(X-D*(tm+1)) if abs(X-D*(tm+1)) < abs(X-D*(tm-1))else abs(X-D*(tm-1)))\n else:\n print(abs(X+D*K)if absabs(X+D*K) < abs(X-D*K)else abs(X-D*K))', 'X,K,D = map(int, input().split())\ntm = round(X/D)\nif K <= tm:\n print(X-D*K)\nelse:\n if (K-tm)%2==1:\n print(abs(X-D*(tm+1)))\n else:\n print(X-D*tm)', 'import math\n\nX,K,D = map(int, input().split())\nfor i in range(K):\n if abs(X-D) < abs(X+D):\n X-=D\n else:\n X+=D\nprint(X)', 'X, K, D = map(int, input().split())\n \nXa = abs(X)\nXs = Xa // D\nXm = Xa % D\n \nif (K <= Xs):\n print(abs(Xa-D*K))\nelif (K-Xs) % 2 == 0:\n print(abs(Xm))\nelse:\n print(abs(D-Xm))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s484196516', 's572201126', 's704723634', 's738137859', 's376269840']
[9172.0, 9220.0, 9176.0, 9156.0, 9184.0]
[28.0, 30.0, 33.0, 2206.0, 29.0]
[155, 321, 153, 126, 181]
p02584
u699944218
2,000
1,048,576
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.
['X, K, D = list(map(int, input().split()))\nL = X + D * K\n \nif X >= 0:\n if K == 1 or D == 1:\n print(abs(X - D*K))\n exit()\n\nelif X < 0:\n if K == 1 or D == 1:\n print(abs(X + D*K))\n exit()\n\nelif L >= 0:\n if L / (2 * D) - int(L / (2 * D)) > 0.5:\n a = L // (2 * D) + 1\n else:\n a = L // (2 * D)\n \nelif L < 0:\n if L / (2 * D) - int(L / (2 * D)) < -0.5:\n a = int(L / (2 * D)) - 1\n else:\n a = int(L / (2 * D)) \nprint(abs(X-2*D*a+D*K))', 'x, k, d = list(map(int,input().split()))\n\na = (k * d - x) / (2 * d)\n\nif abs(x) < k * d:\n if abs(int(a) + 1 - a) >= abs(int(a) - a):\n print(abs(x + 2 * int(a) * d - k * d))\n else:\n print(abs(x + 2 * (int(a) + 1) * d - k * d))\n\nelif x < 0:\n print(abs(x + k * d))\nelse:\n print(x - k * d)']
['Runtime Error', 'Accepted']
['s261768642', 's026977429']
[9152.0, 9104.0]
[32.0, 32.0]
[477, 302]
p02584
u702399883
2,000
1,048,576
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.
['x,k,d=list(map(int,input.split()))\nsyou, amari = divmod(x,d)\nif x>0:\n if x-k*d==0:\n print(0)\n elif x-k*d<0:\n if amari==0:\n newk=k-syou\n if newk%2==0:\n print(0)\n else:\n print(d)\n elif amari!=0:\n newk=k-syou+1\n if newk%2==0:\n print(abs(x-d*(syou+1)))\n else:\n print(abs(x-d*syou))\n elif x-k*d>0:\n print(abs(x-k*d))\nif x==0:\n if k%2==0:\n print(0)\n else:\n print(d)\n', 'x,k,d=list(map(int,input().split()))\nx=abs(x)\nsyou, amari = divmod(abs(x),d)\nif x>0:\n if x-k*d==0:\n print(0)\n elif x-k*d<0:\n if amari==0:\n newk=k-syou\n if newk%2==0:\n print(0)\n else:\n print(d)\n elif amari!=0:\n newk=k-syou+1\n if newk%2==0:\n print(abs(x-d*(syou+1)))\n else:\n print(abs(x-d*syou))\n elif x-k*d>0:\n print(abs(x-k*d))\nif x==0:\n if k%2==0:\n print(0)\n else:\n print(d)\n']
['Runtime Error', 'Accepted']
['s054999690', 's814648850']
[9044.0, 9188.0]
[27.0, 33.0]
[543, 559]
p02584
u711539583
2,000
1,048,576
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.
['x, k, d = map(int, input().split())\nx = abs(x)\na = x // d\nif a >= k:\n print(x - d * k)\nelif (k - a) % 2:\n print(d * (a + 1) - a)\nelse:\n print(a - d * a)\n', 'x, k, d = map(int, input().split())\nx = abs(x)\na = x // d\nif a >= k:\n print(x - d * k)\nelif (k - d) % 2:\n print(d * (a + 1) - a)\nelse:\n print(a - d * a)', 'x, k, d = map(int, input().split())\nx = abs(x)\na = x // d\nif a >= k:\n print(x - d * k)\nelif (k - a) % 2:\n print(d * (a + 1) - x)\nelse:\n print(x - d * a)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s173828822', 's589539546', 's956167998']
[9064.0, 9056.0, 9112.0]
[30.0, 32.0, 28.0]
[156, 155, 156]
p02584
u731436822
2,000
1,048,576
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.
['\nX,K,D=map(int,input().split())\n\nq=X//D\nif q>K:\n print(abs(X)-K*D)\nelse:\n if (K-q)%2==0:\n print(abs(X)-q*D)\n else:\n print(abs(X)-(q+1)*D)', '\nX,K,D=map(int,input().split())\n\nX=abs(X)\nq=X//D\nif q>K:\n print(X-K*D)\nelse:\n if (K-q)%2==0:\n print(X-q*D)\n else:\n print(X-(q+1)*D)', '\nX,K,D=map(int,input().split())\n\nX=abs(X)\nq=X//D\nif q>K:\n print(X-K*D)\nelse:\n if (K-q)%2==0:\n print(X-q*D)\n else:\n print(-X+(q+1)*D)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s025249330', 's643817473', 's710016880']
[9160.0, 9172.0, 9088.0]
[28.0, 30.0, 27.0]
[192, 186, 187]
p02584
u733866054
2,000
1,048,576
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.
['x,k,d=map(int,input().split())\nans=0\n\nif abs(x)<d :\n if k%2==0 :\n ans=x\n else :\n x1,x2=x-d,x+d\n ans=x2\n if abs(x1)<abs(x2) :\n ans=x1\n\nelse :\n if x>0 :\n X=x%d\n K=k-(x//d)\n if K%2==0 and K>0 :\n ans=X\n elif K%2==1 and K>0 :\n x3,x4=X-d,X+d\n ans=x4\n if abs(x3)<x4 :\n ans=x3\n else :\n ans=x-k*d\n\n else :\n Y=abs(x)%d\n K=k-(abs(x)//d)\n if K%2==0 and K>0 :\n ans=-Y\n elif K%2==1 and K>0 :\n y1,y2=-Y+d,-Y-d\n ans=y1\n if abs(y2)<y1 :\n ans=y2\n else :\n ans=x+k*d\n\nprint(ans)\n \n ', 'x,k,d=map(int,input().split())\nans=0\n\nif abs(x)<d :\n if k%2==0 :\n ans=x\n else :\n x1,x2=x-d,x+d\n\nelse :\n if x>0 :\n X=x%d\n K=k-(x//d)\n if K%2==0 and K>0 :\n ans=X\n elif K%2==1 and K>0 :\n x3,x4=X-d,X+d\n ans=x4\n if abs(x3)<x4 :\n ans=x3\n else :\n ans=x-k*d\n\n else :\n Y=abs(x)%d\n K=k-(abs(x)//d)\n if K%2==0 and K>0 :\n ans=-Y\n elif K%2==1 and K>0 :\n y1,y2=-Y+d,-Y-d\n ans=y1\n if abs(y2)<y1 :\n ans=y2\n else :\n ans=x+k*d\n\nprint(ans)\n ', 'x,k,d=map(int,input().split())\nans=0\n\nif abs(x)<d :\n if k%2==0 :\n ans=abs(x)\n else :\n x1,x2=x-d,x+d\n ans=abs(x2)\n if abs(x1)<abs(x2) :\n ans=abs(x1)\n\nelse :\n if x>0 :\n X=x%d\n K=k-(x//d)\n if K%2==0 and K>0 :\n ans=abs(X)\n elif K%2==1 and K>0 :\n x3,x4=X-d,X+d\n ans=abs(x4)\n if abs(x3)<x4 :\n ans=abs(x3)\n else :\n ans=abs(x-k*d)\n\n else :\n Y=abs(x)%d\n K=k-(abs(x)//d)\n if K%2==0 and K>0 :\n ans=abs(-Y)\n elif K%2==1 and K>0 :\n y1,y2=-Y+d,-Y-d\n ans=abs(y1)\n if abs(y2)<y1 :\n ans=abs(y2)\n else :\n ans=abs(x+k*d)\n\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s302911495', 's980219875', 's190947146']
[9212.0, 9196.0, 9136.0]
[35.0, 31.0, 28.0]
[729, 661, 774]
p02584
u734423776
2,000
1,048,576
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.
['import math\n\nX, K, D = map(int, input().split())\n\na = X - K * D\nif a > 0:\n print(a)\n return\nif a + 2 * K * D < 0:\n print(abs(a + 2 * K * D))\n return\nelse:\n b = a / (-2 * D)\n p = math.floor(b)\n q = math.ceil(b)\n r = -(a + 2 * D * p)\n s = a + 2 * D * q\n print(min(r,s))\n return\n', 'import math\nimport sys\n\nX, K, D = map(int, input().split())\n\na = X - K * D\nif a > 0:\n print(a)\n sys.exit()\nif a + 2 * K * D < 0:\n print(abs(a + 2 * K * D))\n sys.exit()\nelse:\n b = a / (-2 * D)\n p = math.floor(b)\n q = math.ceil(b)\n r = -(a + 2 * D * p)\n s = a + 2 * D * q\n print(min(r,s))\n sys.exit()']
['Runtime Error', 'Accepted']
['s354858916', 's479403813']
[9116.0, 9180.0]
[27.0, 31.0]
[309, 331]
p02584
u737252485
2,000
1,048,576
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.
['x,k,d=map(int,input().split())\n\nminx=x-k*d\nmaxx=x+k*d\ntargetx=minx%(2*d)\nif targetx>d:\n targetx-=2*d\nif targetx==-d:\n if x<0:\n targetx-=2*d\n\nif minx>targetx:\n print(minx)\n exit()\nif maxx<targetx:\n print(maxx)\n exit()\nprint(targetx)\n', 'x,k,d=map(int,input().split())\n\nminx=x-k*d\nmaxx=x+k*d\ntargetx=minx%(2*d)\nif targetx>d:\n targetx-=2*d\nif targetx==d:\n if x<0:\n targetx-=2*d\n\nif minx>targetx:\n print(minx)\n exit()\nif maxx<targetx:\n print(maxx)\n exit()\nprint(targetx)\n', 'x,k,d=map(int,input().split())\n\nminx=x-k*d\nmaxx=x+k*d\ntargetx=minx%(2*d)\nif targetx>d:\n targetx-=2*d\nif targetx==d:\n if x<0:\n targetx-=2*d\n\nif minx>targetx:\n print(abs(minx))\n exit()\nif maxx<targetx:\n print(abs(maxx))\n exit()\nprint(abs(targetx))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s230623352', 's368787565', 's796350604']
[9164.0, 9176.0, 9192.0]
[29.0, 34.0, 33.0]
[257, 256, 271]
p02584
u741579801
2,000
1,048,576
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.
['X, K, D = [int(n) for n in input()]\n\n#X = 10\n#K = 1\n#D = 2\n\n\nstartN = (D * K - X) // (2 * D)\n\nN1 = startN + 1\nN2 = startN\nN3 = startN - 1\n\nif N1 < 0:\n N1 = 0\nif N2 < 0:\n N2 = 0\nif N3 < 0:\n N3 = 0\n\ndef getScore(n):\n score = X + n * D - D * (K - n)\n if score < 0:\n score = score * -1\n return score\n\nscore1 = getScore(N1)\nscore2 = getScore(N2)\nscore3 = getScore(N3)\n\nminScore = score1\nif minScore > score2:\n minScore = score2\nif minScore > score3:\n minScore = score3\n\nprint(minScore)', 'X, K, D = [int(n) for n in input().split(" ")]\n\n#X = 10\n#K = 1\n#D = 2\n\n\nstartN = (D * K - X) // (2 * D)\n\nN1 = startN + 1\nN2 = startN\nN3 = startN - 1\n\nif N1 < 0:\n N1 = 0\nif N2 < 0:\n N2 = 0\nif N3 < 0:\n N3 = 0\nif N1 > K:\n N1 = K\nif N2 > K:\n N2 = K\nif N3 > K:\n N3 = K\n\ndef getScore(n):\n score = X + n * D - D * (K - n)\n if score < 0:\n score = score * -1\n return score\n\nscore1 = getScore(N1)\nscore2 = getScore(N2)\nscore3 = getScore(N3)\n\nminScore = score1\nif minScore > score2:\n minScore = score2\nif minScore > score3:\n minScore = score3\n\nprint(minScore)']
['Runtime Error', 'Accepted']
['s033682190', 's793279980']
[9232.0, 9228.0]
[27.0, 30.0]
[511, 588]
p02584
u765758367
2,000
1,048,576
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.
['x, k,d = map(int, input().split())\nx = abs(x)\nprint(x)\nans = 0\nif x//d>k:\n ans = abs(x-d*k)\nelse:\n tmp = x//d\n k -= tmp\n x -= tmp*d\n if k%2 == 1:\n ans = abs(x-d)\n else:\n ans = abs(x)\nprint(ans)', 'x, k,d = map(int, input().split())\nx = abs(x)\nprint(x)\nans = 0\nif x//d>0:\n ans = abs(x-d*k)\nelse:\n tmp = x//d\n k -= tmp\n x -= tmp*d\n if k%2 == 1:\n ans = abs(x-d)\n else:\n ans = abs(x)\nprint(ans)', 'x, k,d = map(int, input().split())\nx = abs(x)\nans = 0\nif x//d>k:\n ans = abs(x-d*k)\nelse:\n tmp = x//d\n k -= tmp\n x -= tmp*d\n if k%2 == 1:\n ans = abs(x-d)\n else:\n ans = abs(x)\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s042283343', 's910056139', 's982191988']
[9088.0, 9204.0, 9204.0]
[27.0, 31.0, 30.0]
[225, 225, 216]
p02584
u767438459
2,000
1,048,576
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.
['#C\nx,k,d=map(int, input().split())\n\n\ns = abs(x)//d\n\n\nif s >= k:\n print(abs(x) - k*d)\n\n\nelse:\n if (k-s) %2 == 0:\n print(abs(x) - s*d)\n else:\n print(d-(abs(x) - k*d)) ', 'x,k,d=map(int, input().split())\n\n\ns = x//d\n\n\nif s >= k:\n print(abs(x) - abs(k*d))\n\n\nelse:\n if (k-s) %2 == 0:\n print(abs(x) - s*d)\n else:\n print(d-(abs(x) - abs(k*d))) ', '#C\nx,k,d=map(int, input().split())\n \n\ns = abs(x)//d\n \n\nif s >= k:\n print(abs(x) - k*d)\n \n\nelse:\n if (k-s) %2 == 0:\n print(abs(x) - s*d)\n else:\n print(d-(abs(x) - s*d)) ']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s486177133', 's870533313', 's774026402']
[9028.0, 9176.0, 9076.0]
[35.0, 34.0, 32.0]
[356, 358, 353]
p02584
u767664985
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\n\n\nif abs(X) >= K*D:\n if X >= 0:\n ans = X - K*D\n else:\n ans = X + K*D\nelse:\n if X >= 0:\n if (K - X//D)%2 == 0:\n ans = X%D\n else:\n ans = X%D - D\n else:\n if (K - X//D)%2 == 0:\n ans = X%D - D\n else:\n ans = X%D\n\nprint(ans)', 'X, K, D = map(int, input().split())\n\n\n\nif abs(X) >= K*D:\n ans = abs(X) - K*D\nelse:\n if (K - X//D)%2 == 0:\n ans = X%D\n else:\n ans = X%D - D\n\nprint(ans)', 'X, K, D = map(int, input().split())\n\n\n\nif abs(X) >= K*D:\n ans = abs(X) - K*D\nelse:\n if (K - X//D)%2 == 0:\n ans = X%D\n else:\n ans = X%D - D\n ans = abs(ans)\n\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s452164640', 's734663384', 's909933522']
[9088.0, 9172.0, 9108.0]
[27.0, 29.0, 33.0]
[389, 210, 229]
p02584
u772029934
2,000
1,048,576
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.
[',K,D = map(int,input().split())\n\ny = abs(X)//D\n\nif K<=y:\n print(abs(abs(X)-K*D))\n\nelse :\n a = (X-y*D)\n b = (X-(y+1)*D)\n \n C = abs(a)\n D = abs(b)\n \n if (K-y)%2==0:\n print(C)\n else:\n print(D)\n\n\n#print(y+1)\n#print(1000000000000000)', 'X,K,D = map(int,input().split())\n\ny = abs(X)//D\n\nif K<=y:\n print(abs(abs(X)-K*D))\n\nelse :\n a = (abs(X)-y*D)\n b = (abs(X)-(y+1)*D)\n \n C = abs(a)\n D = abs(b)\n \n if (K-y)%2==0:\n print(C)\n else:\n print(D)\n\n\n#print(y+1)\n#print(1000000000000000)']
['Runtime Error', 'Accepted']
['s000041036', 's454210115']
[8928.0, 9164.0]
[23.0, 28.0]
[270, 281]
p02584
u773440446
2,000
1,048,576
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.
['x,k,d = map(int,input().split())\nans_1 = x%d \nans_2 = abs(ans_1-d) \n\nif x//d > k:\n print(x-(d*k))\n exit()\nif ans_1 > ans_2:\n if (k-(x//d)-1)%2 == 0:\n print(min(ans_1,ans_2))\n else:\n print(max(ans_1,ans_2))\n \n \nelif ans_1 < ans_2:\n if (k-(x//d))%2 == 0:\n print(int(ans_1))\n else:\n print(int(ans_2))\n\n ', 'x,k,d = map(int,input().split())\nx = abs(x)\nnum = x//d\na = x-d*num\nb = abs(a-d)\nif x >= (d*k):\n print(x-(d*k))\n exit()\nelse:\n if min(a,b) == b:\n num += 1\n if (k-num) % 2 == 0:\n print(min(a,b))\n else:\n print(max(a,b))\n ']
['Wrong Answer', 'Accepted']
['s568975905', 's268713278']
[9200.0, 9088.0]
[28.0, 30.0]
[408, 233]
p02584
u793225228
2,000
1,048,576
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.
["def Qc():\n x, k, d = map(int, input().split())\n x = abs(x)\n print(x,k,d)\n for v in range(k):\n x -= d\n ans = x\n if x <= 0:\n ans = min(abs(x-d), abs(x+d))\n break\n print(ans)\n\n\nif __name__ == '__main__':\n Qc()\n", "def Qc():\n x, k, d = map(int, input().split())\n x = abs(x)\n all_minus = abs(x) - (k * d)\n if 0 <= all_minus:\n ans = all_minus\n else:\n point = abs(all_minus) // d\n all_minus += d * point\n ans = abs(all_minus)\n if point % 2 != 0:\n ans = min(abs(all_minus - d), abs(all_minus + d))\n print(ans)\n\n\nif __name__ == '__main__':\n Qc()\n"]
['Wrong Answer', 'Accepted']
['s632072921', 's380354547']
[9140.0, 9180.0]
[2206.0, 31.0]
[268, 393]
p02584
u798260206
2,000
1,048,576
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.
['X,K,D = map(int,input().split())\n\nX = abs(X)\n\nif X-K*D <= 0:\n d = X//D\n K -= d\n x -= D*d\n if K%2 == 0:\n print(a)\n else:\n print(abs(a-d))\nelse:\n print(X-K*D)', 'X,K,D = map(int,input().split())\n\nX = abs(X)\n\nif X-K*D <= 0:\n d = X//D\n K -= d\n X -= D*d\n if K%2 == 0:\n print(X)\n else:\n print(abs(X-D))\nelse:\n print(X-K*D)\n']
['Runtime Error', 'Accepted']
['s855490489', 's313003202']
[9076.0, 8996.0]
[23.0, 27.0]
[188, 189]
p02584
u799978560
2,000
1,048,576
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.
['##C - Walking Takahash\n\n\nX,K,D = map(int,input().split())\nR = K - X // D\n\nif X < 0:\n X = -X\nif X > 0 and X-K*D >= 0:\n print(X-K*D)\nelif X == 0:\n if K % 2 == 0:\n print(0)\n else:\n print(D)\nelse:\n if R % 2 == 0:\n print(X - D*(X//D))\n else:\n print(X - D*((X//D)+1))', '##C - Walking Takahash\n\n\nX,K,D = map(int,input().split())\nR = K - X // D\n\nif X < 0:\n X = -X\nif X > 0 and X-K*D >= 0:\n print(X-K*D)\nelse:\n if R % 2 == 0:\n print(X - D*(X//D))\n else:\n print(X - D*((X//D)+1))', '##C - Walking Takahash\n\n\nX,K,D = map(int,input().split())\n\nif X < 0:\n X = -X\nR = K - X // D\nif X-K*D >= 0:\n print(X-K*D)\nelse:\n if R % 2 == 0:\n print(X - D*(X//D))\n else:\n print(abs(X - D*(X//D)-D))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s484266810', 's531635752', 's114698886']
[9080.0, 9132.0, 9120.0]
[29.0, 31.0, 34.0]
[540, 464, 457]
p02584
u800058906
2,000
1,048,576
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.
['import sys\nx,k,d=map(int,input().split())\n\nx=abs(x)\n\na=x//d\n\nif a>=k:\n ans=x-k*d\n\nelif (k-a)%2==0:\n ans=x-d*m\n\nelse:\n ans=x-d*m-d\n\nprint(abs(ans)', 'import sys\nx,k,d=map(int,input().split())\n\nx=abs(x)\n\nif k*d<=x:\n print(x-k*d)\n sys.exit()\n\nif k>=x:\n\n \nelse:\n print(x%d)', 'import sys\nx,k,d=map(int,input().split())\n\nx=abs(x)\n\na=x//d\n\nif a>=k:\n ans=x-k*d\n\nelif (k-a)%2==0:\n ans=x-d*a\n\nelse:\n ans=x-d*a-d\n\nprint(abs(ans))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s058309551', 's983462068', 's048384610']
[9000.0, 9016.0, 9184.0]
[30.0, 25.0, 32.0]
[154, 132, 155]
p02584
u808572836
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\nif abs(X) <= D * K:\n for i in range(K):\n a = abs(X) - (D * (i + 1))\n b = abs(X) - (D * i)\n if a < 0:\n break\n if abs(a) < abs(b):\n c = K - (i + 1)\n if c % 2 == 0:\n if 0 <= X:\n goal = a\n else:\n goal = -a\n else:\n if 0 <= X:\n goal = b\n else:\n goal = -b\n\n if abs(b) <= abs(a):\n c = K - i\n if c % 2 == 0:\n if 0 <= X:\n goal = b\n else:\n goal = -b\n else:\n if 0 <= X:\n goal = a\n else:\n goal = -a\nelse:\n if 0 <= X:\n goal = X - D * K\n else:\n goal = X + D * K\n\nprint(goal)', 'X, K, D = map(int, input().split())\n\nif abs(X) <= D * K:\n for i in range(K):\n a = abs(X) - (D * (i + 1))\n b = abs(X) - (D * i)\n print(a,b)\n if a < 0:\n break\n if abs(a) < abs(b):\n c = K - (i + 1)\n if c % 2 == 0:\n if 0 <= X:\n goal = a\n else:\n goal = -a\n else:\n if 0 <= X:\n goal = b\n else:\n goal = -b\n\n if abs(b) <= abs(a):\n c = K - i\n if c % 2 == 0:\n if 0 <= X:\n goal = b\n else:\n goal = -b\n else:\n if 0 <= X:\n goal = a\n else:\n goal = -a\nelse:\n if 0 <= X:\n goal = X - D * K\n else:\n goal = X + D * K\n\nprint(goal)', 'X, K, D = map(int, input().split())\n\nif abs(X) < (K * D):\n a = abs(X) % D\n b = abs(D - a)\n c = abs(X) // D + 1\n if (K - c) % 2 == 0:\n goal = b\n else:\n goal = a\nelse:\n goal = abs(X) - ( D * K )\n\nprint(goal)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s065760899', 's414633104', 's229458921']
[9180.0, 78212.0, 9144.0]
[2206.0, 2286.0, 31.0]
[807, 870, 237]
p02584
u833871588
2,000
1,048,576
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.
['x,k,d = [int(i) for i in input().split()]\nfor i in range(k):\n x+=d if x<0 else -d\n if abs(x)<d:\n x=(abs(x)-d)*x/abs(x) if (k-1-i)&1==1 else x\n break\nprint(x)', 'x,k,d = [int(i) for i in input().split()]\nx=x-k*d*x//abs(x) if abs(x)>=k*d else x-(abs(x)//d)*d*x//abs(x)-(d if abs(x)//d%2==1 else 0)*x//abs(x)\nprint(x)', 'x,k,d = [int(i) for i in input().split()]\nfor _ in range(k):\n x+=d if x<0 else -d\nprint(x)', 'x,k,d = [int(i) for i in input().split()]\nx=abs(x)\nx=x-k*d if x>=k*d else abs(x%d-(k-x//d)%2*d)\nprint(x)']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s665445095', 's691266020', 's769563554', 's836576134']
[8968.0, 8940.0, 9080.0, 9112.0]
[2205.0, 34.0, 2206.0, 27.0]
[165, 153, 91, 104]
p02584
u834832056
2,000
1,048,576
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.
['import math\n\ndef solve(x, k, d):\n x = math.fabs(x)\n if x - k * d >= 0:\n return x - k * d\n else:\n cur = x - x // d * d\n k = k - x // d\n if k % 2 == 0:\n return cur\n else:\n return abs(cur - d)\n\nif __name__ == "__main__":\n x, k, d = map(int, input().split(\' \'))\n print(solve(x, k, d))\n', 'import math\n\ndef solve(x, k, d):\n x = math.fabs(x)\n if x - k * d >= 0:\n return int(x - k * d)\n else:\n cur = x - x // d * d\n k = k - x // d\n if k % 2 == 0:\n return int(cur)\n else:\n return int(abs(cur - d))\n\nif __name__ == "__main__":\n x, k, d = map(int, input().split(\' \'))\n print(solve(x, k, d))\n']
['Wrong Answer', 'Accepted']
['s828398210', 's538271441']
[9144.0, 9120.0]
[31.0, 32.0]
[353, 368]
p02584
u837507786
2,000
1,048,576
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.
['import sys\nX,K,D = map(int, input().split())\nif X < 0: X = abs(X) \n\nif X // D > K:\n X = X - (K * D)\n print(X)\n sys.exit() \n\nif (X // D) + 1 < K:\n if X % D >= abs((X % D)-D):\n if (K - (X // D)) % 2 == 1:\n print(abs((X % D)-D))\n sys.exit()\n else:\n print(X % D)\n sys.exit()\n else:\n print(X % D)\n sys.exit()\n\n\n\n', 'import sys\nX,K,D = map(int, input().split())\nif X < 0: X = abs(X) \n\nif X // D > K:\n X = X - (K * D)\n print(X)\n sys.exit() \n\nif (X // D) + 1 < K:\n if X % D >= abs((X % D)-D):\n print(abs((X % D)-D))\n sys.exit()\n else:\n print(X%D)\n sys.exit()\n\n\n\n', 'import sys\nX,K,D = map(int, input().split())\nif X < 0: X = abs(X) \n\nif X // D > K:\n X = X - (K * D)\n print(X)\n sys.exit() \n\nif (X // D) <= K:\n if X % D >= abs((X % D)-D):\n if (K - (X // D)) % 2 == 1:\n print(abs((X % D)-D))\n sys.exit()\n else:\n print(X % D)\n sys.exit()\n else:\n if (K - (X // D)) % 2 == 1:\n print(abs((X % D)-D))\n sys.exit()\n else:\n print(X % D)\n sys.exit()\n\n\n\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s135638063', 's587387092', 's513311698']
[9088.0, 9016.0, 9032.0]
[33.0, 28.0, 31.0]
[459, 351, 571]
p02584
u854931881
2,000
1,048,576
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.
['x,k,d=map(int,input().split())\nmini=0\nif abs(x)>=k*d:\n mini=abs(x)-k*d\n print(mini)\nelse:\n q=abs(x)//d\n s=abs(x)%d\n if (k-q)%2==0:\n print(s)\n else:\n print(s-d)', 'x,k,d=map(int,input().split())\nmini=0\nif abs(x)>=k*d:\n mini=abs(x)-k*d\n print(mini)\nelse:\n q=abs(x)//d\n s=abs(x)%d\n if (k-q)%2==0:\n print(s)\n else:\n print(abs(s-d))']
['Wrong Answer', 'Accepted']
['s613104120', 's216549515']
[9148.0, 9160.0]
[29.0, 29.0]
[161, 166]
p02584
u855057563
2,000
1,048,576
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.
['x,k,d=map(int,input().split())\ncur=abs(x)\ncount=min(cur//d,k)\ncur-=d*count\ns=k-count\nif s%2==1:\n cur-=-d\nprint(abs(cur))\n', 'x,k,d=map(int,input().split())\ncur=abs(x)\ncount=min(cur//d,k)\ncur-=d*count\nk-=count\nif k%2==1:\n cur-=-d\nprint(abs(cur))', 'x,k,d=map(int,input().split())\ncur=abs(x)\ncount=min(cur//d,k)\ncur-=d*count\nk-=count\nif k%2==1:\n cur-=d\nprint(abs(cur))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s004053633', 's899158298', 's040488358']
[9120.0, 9168.0, 9168.0]
[30.0, 29.0, 29.0]
[122, 120, 120]
p02584
u861886710
2,000
1,048,576
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.
['X, K, D = list(map(int, input().split()))\n\ni = min(X//D, K) \nk = X%D\n\nif k == 0:\n #print("1")\n print(X - i*D)\nelse:\n n = K - i\n if n%2==0:\n #print("2")\n print(X - i*D)\n else:\n #print("3")\n print(X - i*D - D)', '\nX, K, D = list(map(int, input().split()))\nX = abs(X)\n\ni = min(X//D, K) \nX = X - i*D\nK = K - i\n\nif K > 0:\n if K % 2 == 1:\n X = X - D\nprint(abs(X))']
['Wrong Answer', 'Accepted']
['s032690380', 's332272950']
[9112.0, 9100.0]
[31.0, 28.0]
[331, 299]
p02584
u864090097
2,000
1,048,576
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.
['#include <bits/stdc++.h>\nusing namespace std;\n\nint main(void)\n{\n long long X,K,D;\n long long ans = 0;\n cin >> X >> K >> D;\n\n if(K * D < abs(X)){\n ans = abs(X) - K * D;\n }else{\n if( (abs(X) / D) % 2 == 0 ){\n if( K % 2 == 0){\n ans = abs(X) % D;\n }else{\n ans = abs(abs(X) % D - D);\n }\n \n }else{\n if( K % 2 == 0){\n ans = abs(abs(X) % D - D);\n }else{\n ans = abs(X) % D;\n }\n }\n }\n\n cout << ans << endl;\n\n}\n', 'X, K, D = map(int ,input().split())\n\nX = abs(X)\nif X / D > K:\n ans = X - K * D\nelse:\n if X // D % 2 == K % 2:\n ans = X % D\n else:\n ans = abs(X % D - D)\nprint(ans)']
['Runtime Error', 'Accepted']
['s350025556', 's012566716']
[9004.0, 9160.0]
[31.0, 28.0]
[589, 185]
p02584
u865343871
2,000
1,048,576
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.
['X,K,D = map(int,input().split())\n\nK -= int(X/D)\nX -= int(X/D)*D\n\nfor i in range(K):\n if X > 0:\n X -= D\n else:\n X += D\nprint(X)', 'X,K,D = map(int,input().split())\n\nfor i in range(K):\n if X > 0:\n X -= D\n else:\n X += D\nprint(X)', 'X,K,D = map(int,input().split())\na = int(X/D)\nif a < K:\n K -= a\n X -= a*D\n\nK %= 2\n\nfor i in range(K):\n if X > 0:\n X -= D\n else:\n X += D\nprint(X)', 'X,K,D = map(int,input().split())\nX = abs(X)\na = int(X/D)\nif a < K:\n K -= a\n X -= a*D\n\nif K*D <= X:\n X -= K*D\nelse:\n K %= 2\n for i in range(K):\n if X > 0:\n X -= D\n else:\n X += D\nprint(abs(X))']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s450319898', 's718189031', 's757285705', 's270048870']
[9092.0, 9004.0, 9100.0, 9196.0]
[2206.0, 2205.0, 30.0, 28.0]
[146, 115, 170, 249]
p02584
u867200256
2,000
1,048,576
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.
["# coding: utf-8\n# Your code here!\n\nimport collections\nimport sys\nimport copy\nimport re\nimport math\n\n\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\n\ndef main():\n X, K, D = LI()\n X = abs(X)\n\n a = math.ceil(X/D)\n\n if K < a:\n print(X-D*K)\n return\n else:\n K -= a\n X -= D*a\n if K % 2 == 0:\n print(X)\n return\n else:\n print(X+D)\n\n\nif __name__ == '__main__':\n main()\n", "# coding: utf-8\n# Your code here!\n\nimport collections\nimport sys\nimport copy\nimport re\nimport math\n\n\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\n\n\ndef main():\n X, K, D = LI()\n X = abs(X)\n\n a = math.ceil(X/D)\n\n if K < a:\n print(abs(X-D*K))\n return\n else:\n K -= a\n X -= D*a\n if K % 2 == 0:\n print(abs(X))\n return\n else:\n print(abs(X+D))\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s465133274', 's313347038']
[10012.0, 9988.0]
[44.0, 39.0]
[670, 685]
p02584
u888582202
2,000
1,048,576
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.
['x,k,d= map(int,input().split())\ns=[]\nif x//d>k:\n print(x-d*k)\nelse:\n for i in range(k):\n s.append(abs(x-d*i))\n print(min(s))', 'x,k,d= map(int,input().split())\nx=abs(x)\nif x>d*k:\n print(x-d*k)\nelse:\n m=x//d\n k=(k-m)%2\n print(abs((x%d)-k*d))']
['Wrong Answer', 'Accepted']
['s468142868', 's057485898']
[10388.0, 9076.0]
[2206.0, 28.0]
[132, 116]
p02584
u889919275
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\nlow = 0\nhigh = K\n\nwhile low <= high:\n mid = (low + high) //2\n i = mid\n j = K-mid\n ans_pre = (X + D*i - D*j)\n if ans_pre > 0:\n high = mid-1\n else:\n low = mid+1\n \n\nif low > K :\n low = high\n \nans_l = min(abs((X + D*low - D*(K-low))), abs(X + D*(K-low)-D*low))\n \nprint(ans_l)', 'X, K, D = map(int, input().split())\n\nlow = 0\nhigh = K\n\nwhile low <= high:\n mid = (low + high) //2\n i = mid\n j = K-mid\n ans_pre = (X + D*i - D*j)\n if ans_pre > 0:\n high = mid-1\n else:\n low = mid+1\n \n\nif high < 0:\n high = 0\n\n\nans_l = min(abs((X + D*low - D*(K-low))), abs(X + D*(K-low)-D*low))\n \nprint(ans_l)', 'X, K, D = map(int, input().split())\n\nlow = 0\nhigh = K\n\nwhile low <= high:\n mid = (low + high) //2\n i = mid\n j = K-mid\n ans_pre = (X + D*i - D*j)\n if ans_pre > 0:\n high = mid-1\n else:\n low = mid+1\n \n\nif low > K :\n low = high\nif high < 0:\n high = low\n \nans_h = min(abs((X + D*high - D*(K-high))), abs(X + D*(K-high)-D*high))\nans_l = min(abs((X + D*low - D*(K-low))), abs(X + D*(K-low)-D*low))\n \nprint(min(ans_l, ans_h))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s125685481', 's155009218', 's520349786']
[9140.0, 9140.0, 9228.0]
[31.0, 32.0, 33.0]
[356, 423, 468]
p02584
u891847179
2,000
1,048,576
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.
["# # Make IO faster\n# import sys\n# input = sys.stdin.readline\n\n\n# X = input()\n\n\n# N = int(input())\n\n# X, Y = map(int, input().split())\n for N lines\n# XY = [list(map(int, input().split())) for _ in range(N)]\n\n# from IPython import embed; embed(); exit();\n\n\nimport sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom itertools import accumulate, permutations, combinations, product\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left\nfrom fractions import gcd\nfrom heapq import heappush, heappop\nfrom functools import reduce\nimport numpy as np\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nX, K, D = MAP()\nN = X // D\n\nif K <= N:\n print(abs(X - K * D))\nelse:\n K -= N\n if K % 2 == 1:\n print(min(abs(X - (N + 1) * D), abs(X - (N - 1) * D)))\n else:\n print(min(abs(X - (N + 2) * D), abs(X - N * D), abs(X - (N - 2) * D)))\n", 'x, k, d = map(int, input().split())\nx = abs(x)\nif x > d:\n c = min(x//d, k)\n x -= d*c\n k -= c\nif k%2: x = d - x\nprint(x)\n']
['Wrong Answer', 'Accepted']
['s221550086', 's922449475']
[27188.0, 9168.0]
[121.0, 31.0]
[1405, 129]
p02584
u913662443
2,000
1,048,576
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.
['X, K, D = list(map(int,input().rstrip().split()))\nX = abs(X)\na = X//D\nif K <= a:\n print(abs(X-(D*K)))\nelif (K-a)a%2 == 0:\n print(abs(X-(D*a)))\nelse:\n print(abs(D*(a+1)-X))', 'X, K, D = list(map(int,input().rstrip().split()))\nX = abs(X)\na = X//D\nif K <= a:\n print(abs(X-(D*K)))\nelif (K-a)%2 == 0:\n print(abs(X-(D*a)))\nelse:\n print(abs(D*(a+1)-X))']
['Runtime Error', 'Accepted']
['s933645824', 's799962501']
[9020.0, 9180.0]
[29.0, 33.0]
[180, 179]
p02584
u929996201
2,000
1,048,576
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.
['def isEven(num):\n if num%2 == 0:\n \treturn True\n return False\n\ndef isOdd(num):\n if num%2 == 1:\n return True\n return False\n\nif __name__ == "__main__":\n x,k,d = map(int, input().split())\n div = x//d\n cmp = x\n defo = x\n if isOdd(k):\n if x > d:\n if k%div != 0:\n div = min(div,k%div)\n for i in [d,-d]:\n cmp = min(cmp,abs(defo+div*i))\n print(cmp)\n else:\n for i in [d,-d]:\n cmp = min(cmp,abs(defo+i))\n print(cmp)\n if isEven(k):\n div = x//(2*d)\n if x > d:\n div = min(div,k)\n for j in range(1,div):\n for i in [d,-d]:\n cmp = min(cmp,abs(defo+(2*j)*i))\n print(cmp)\n else:\n print(cmp)', 'def isEven(num):\n if num%2 == 0:\n \treturn True\n return False\n\ndef isOdd(num):\n if num%2 == 1:\n return True\n return False\n\nif __name__ == "__main__":\n x,k,d = map(int, input().split())\n div = x//d\n cmp = x\n defo = x\n if isOdd(k):\n if x > d:\n if k%div != 0:\n div = min(div,k%div)\n for i in [d,-d]:\n cmp = min(cmp,abs(defo+div*i))\n print(cmp)\n else:\n for i in [d,-d]:\n cmp = min(cmp,abs(defo+i))\n print(cmp)\n if isEven(k):\n div = x//(2*d)\n if x > d:\n div = min(div,k)\n for j in range(1,div)\n for i in [d,-d]:\n cmp = min(cmp,abs(defo+(2*j)*i))\n print(cmp)\n else:\n print(cmp)', 'x,k,d = map(int, input().split())\nwhile(x > 0):\n x -= d\n k -= 1\nif k%2 == 0:\n print(x)\nelse:\n print(x-d)', 'x,k,d = map(int,input().split())\nx = abs(x)\ndiv = min(x//d,k)\ncnt = 0\nk-=div\nx -= div*d\nif k%2 == 0:\n print(x)\nelse:\n print(abs(x-d))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s036907117', 's746496170', 's904519061', 's118944775']
[9116.0, 8968.0, 9128.0, 9180.0]
[32.0, 26.0, 2206.0, 27.0]
[682, 681, 108, 135]
p02584
u942356554
2,000
1,048,576
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.
['for i in range(5,0,-1):\n', 'x, k, d = map(int, input().split())\nif x < k*d:\n L = []\n s = x\n for i in range(k):\n L.append(s)\n L = sorted(L)\n s = abs(x) - d\n if s >= L[0] or s == 0:\n break\n x = s\n if k%2 == 0:\n if len(L)>1:\n res = L[1]\n else:\n res = L[0]\n else:\n res = L[0]\nelif abs(x) >= k*d:\n res = abs(abs(x)-k*d)\nprint(res)', 'x, k, d = map(int, input().split())\nx = abs(x)\nif x > k*d:\n print(x-k*d)\nelse:\n p = x//d\n if p == 0 or p==1:\n for i in range(1,k+1):\n p2 = x-i*d\n c = k-i\n if p2 <= 0:\n if c%2 != 0:\n print(abs(d+p2))\n break\n elif c%2 == 0:\n print(abs(p2))\n break\n c = k-p\n elif c%2 == 0:\n print(abs(x-p*d))\n else:\n print(abs(d-abs(x-p*d)))', 'x, k, d = map(int, input().split())\nx = abs(x)\nif x > k*d:\n print(x-k*d)\nelse:\n p = x//d\n c = k-p\n if (c%2 == 0):\n print(abs(x-p*d))\n else:\n print(abs(d-abs(x-p*d)))\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s139318308', 's292835196', 's464835934', 's461791382']
[8876.0, 9072.0, 9064.0, 9204.0]
[25.0, 32.0, 24.0, 27.0]
[24, 404, 501, 195]
p02584
u944396627
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\ncurrent_position = X\n\ntimes = abs(X) // D\n\nif times < K:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\n K = K - times\n\n for k in range(K):\n if current_position >=0:\n current_position = current_position - D\n elif current_position< 0 :\n current_position = current_position + D\n\n if abs(current_position) <= D:\n if (K - k + 1) % 2 == 0:\n break\n elif (K - k + 1) % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0 :\n current_position = current_position + D\n break\nelse:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\nprint(current_position)\n\n', 'X, K, D = map(int, input().split())\ncurrent_position = X\n\ntimes = abs(X) // D\n\nif times < K:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\n K = K - times\n if K % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0:\n current_position = current_position + D\nelse:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0:\n current_position = current_position + D\nprint(current_position)\n\n', 'X, K, D = map(int, input().split())\ncurrent_position = X\n\ntimes = abs(X) // D\n\nif times < K:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\n K = K - times\n if abs(current_position) <= D:\n if K % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0:\n current_position = current_position + D\nelse:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\nprint(current_position)\n\n', 'X, K, D = map(int, input().split())\ncurrent_position = X\n\ntimes = abs(X) // D\n\nif times < K:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\n K = K - times\n if K % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0:\n current_position = current_position + D\nelse:\n if K % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0:\n current_position = current_position + D\nprint(current_position)\n\n', 'X, K, D = map(int, input().split())\ncurrent_position = X\n\ntimes = abs(X) // D\n\nif times < K:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\n K = K - times\n if K % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0:\n current_position = current_position + D\nelse:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\nprint(current_position)\n\n', 'X, K, D = map(int, input().split())\ncurrent_position = X\n\ntimes = abs(X) // D\n\nif times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\nK = K - times\nfor k in range(K):\n if current_position >=0:\n current_position = current_position - D\n elif current_position< 0 :\n current_position = current_position + D\n\n if abs(current_position) <= D:\n if (K - k + 1) % 2 == 0:\n break\n elif (K - k + 1) % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0 :\n current_position = current_position + D\n break\n\nprint(current_position)\n\n', 'X, K, D = map(int, input().split())\ncurrent_position = X\n\ntimes = abs(X) // D\n\nif times < K:\n if times > 0 :\n if current_position >= 0:\n current_position = current_position - D*times\n elif current_position < 0:\n current_position = current_position + D*times\n K = K - times\n if K % 2 == 1:\n if current_position >= 0:\n current_position = current_position - D\n elif current_position < 0:\n current_position = current_position + D\nelse:\n if current_position >= 0:\n current_position = current_position - D * K\n elif current_position < 0:\n current_position = current_position + D * K\nprint(abs(current_position))\n\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s307776106', 's366901924', 's452179887', 's534677681', 's774360436', 's778207749', 's984067539']
[9164.0, 9144.0, 9020.0, 9132.0, 9144.0, 9200.0, 9188.0]
[31.0, 36.0, 28.0, 35.0, 31.0, 31.0, 32.0]
[1112, 730, 777, 730, 742, 808, 708]
p02584
u945065638
2,000
1,048,576
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.
['c = x // d\n\nk_r = k - c\n\nans_2 = x - d * c\n\n\nif c >= k:\n print(x - k * d )\n exit()\n\nx_l = x - d * c\n\n\nif k_r % 2 == 0:\n print(ans_2)\n exit()\nelse :\n x_l -= d\n x_l =abs(x_l)\n print(x_l)', 'x ,k ,d = map(int,input().split())\n\nx = abs(x)\nc = x // d\n\nk_r = k - c\n\nans_2 = x - d * c\n\n\nif c >= k:\n print(x - k * d )\n exit()\n\nx_l = x - d * c\n\n\nif k_r % 2 == 0:\n print(ans_2)\n exit()\nelse :\n x_l -= d\n x_l =abs(x_l)\n print(x_l)']
['Runtime Error', 'Accepted']
['s698242368', 's780497784']
[9064.0, 9184.0]
[27.0, 25.0]
[355, 402]
p02584
u945405878
2,000
1,048,576
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.
['X, K, D = map(int, input().split(" "))\nK_s = str(K)\nK2 = int(K_s[len(K_s) - 1])\n\nif K2 % 2 == 1:\n if X < 0:\n ans = X + D\n else:\n ans = X - D\nelse:\n ans = X\n\nprint(ans)\n', 'X, K, D = map(int, input().split(" "))\nX = abs(X)\n\nnow = X\nfor _ in range(K):\n now = min(abs(now), now - D)\n \nprint(now)', 'X, K, D = map(int, input().split(" "))\nX = abs(X)\n\na = X // D\nb = X % D\n\nremain_count = K - a\n\nif remain_count < 0:\n ans = X - K * D\nelse:\n if remain_count % 2 == 0:\n ans = b\n else:\n ans = abs(b - D)\n \nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s873569614', 's943333314', 's111294294']
[9212.0, 9180.0, 9196.0]
[31.0, 2206.0, 28.0]
[195, 126, 238]
p02584
u951289777
2,000
1,048,576
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.
['x, move, d = map(int, input().split())\n\nfor k in range(move):\n move_plus = x + d\n move_minus = x - d\n\n if abs(move_plus) > abs(move_minus):\n x = move_minus\n else:\n x = move_plus\n\n if abs(x) <= d/2 and move-(k+1)%2==0:\n break\n else:\n x = x+d\n break\n\nprint(abs(x))\n', 'import numpy as np\n\nx, move, d = map(int, input().split())\n\nnum = int(abs(x)/d)\nans = 0\n\nif move <= num:\n if np.sign(x) == 1:\n ans = x-d*move\n else:\n ans = x+d*move\n\nelif (move-num)%2==0:\n if np.sign(x) == 1:\n ans = x-d*num\n else:\n ans = x+d*num\n\nelif (move-num)%2!=0:\n if np.sign(x) == 1:\n ans = x-d*(num+1)\n else:\n ans = x+d*(num+1)\n\n\nprint(abs(ans))\n']
['Wrong Answer', 'Accepted']
['s456372147', 's384015383']
[9180.0, 27004.0]
[33.0, 132.0]
[316, 413]
p02584
u952669998
2,000
1,048,576
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.
['X, K, D = list(map(int, input().split()))\nX = abs(X)\nif K * D >= X:\n cgoal = X % D\n fgoal = abs(abs(cgoal) - D)\n times2cgoal = (X - cgoal) // D\n print(cgoal, fgoal, times2cgoal)\n if times2cgoal % 2 == K % 2:\n print(min(cgoal, fgoal))\n else:\n if X >= 0:\n print(fgoal)\nelse:\n print(X - K * D)', 'X, K, D = list(map(int, input().split()))\nX = abs(X)\nsyo = X // D\n#print(syo, amari)\nif X <= K * D:\n K -= syo\n X -= D * syo\n if K % 2 == 0:\n print(X)\n else:\n print(abs(X - D))\nelse:\n print(X - K * D)\n \n ']
['Wrong Answer', 'Accepted']
['s831109390', 's338712860']
[9056.0, 9024.0]
[30.0, 32.0]
[336, 238]
p02584
u953655640
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\ncount1 = X // D\ncount2 = (X // D)-1\nif count1 < K:\n if (K - count1) %2 ==0:\n print(abs(abs(X)-abs(D*count1)))\n else:\n print(abs(abs(X)-abs(D*count2)))\nelse:\n print(abs(abs(X)-abs(D*K)))', 'X, K, D = map(int, input().split())\ncount1 = abs(X) // D\ncount2 = (abs(X) // D)+1\nif count1 < K:\n if (K - count1) %2 ==0:\n print(abs(abs(X)-abs(D*count1)))\n \n else:\n print(abs(abs(X)-abs(D*count2)))\nelse:\n print(abs(abs(X)-abs(D*K)))']
['Wrong Answer', 'Accepted']
['s908489491', 's873023972']
[9212.0, 9176.0]
[33.0, 32.0]
[244, 263]
p02584
u956318161
2,000
1,048,576
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.
['x, k, d=map(int,input().split())\nx=abs(x)\n\nif x//d>=k:\n print(x-k*d)\n\nelif k%2!=0:\n print(x%d)\nelse:\n print(x)', 'x, k, d=map(int,input().split())\nx=abs(x)\n\nif x//d>=k:\n print(x-k*d)\nelif (k-x//d)%2==0:\n print(x%d)\nelse:\n print(abs(x-x//d*d-d))']
['Wrong Answer', 'Accepted']
['s953997308', 's559931299']
[9128.0, 8960.0]
[26.0, 30.0]
[206, 189]
p02584
u957843607
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\nif X < 0:\n if K % 2 == 1:\n print(min(abs(X), abs(X+D)))\n else:\n print(abs(X))\nelse:\n if K % 2 == 1:\n print(min(abs(X), abs(X-D)))\n else:\n print(abs(X))', 'X, K, D = map(int, input().split())\n\nif X+K*D < 0:\n print(abs(X+K*D))\nelif X-K*D > 0:\n print(abs(X-K*D))\nelif X+K*D == 0:\n print(0)\nelif X-K*D == 0:\n print(0)\nelse:\n if X < 0:\n K1 = int(-X/D)+1\n K2 = K-K1\n if not K2 % 2:\n print(abs(X+K1*D))\n else:\n print(min(abs(X+K1*D+D), abs(X+K1*D-D)))\n else:\n K1 = int(X/D)+1\n K2 = K-K1\n if not K2 %2:\n print(abs(X-K1*D))\n else:\n print(min(abs(X-K1*D+D), abs(X-K1*D-D)))']
['Wrong Answer', 'Accepted']
['s588274280', 's825670879']
[9180.0, 9236.0]
[29.0, 30.0]
[204, 458]
p02584
u959682393
2,000
1,048,576
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.
['X,K,D = map(int, input().split())\n\n\nif K %2 == 0:\n if X//D > K:\n print(X%D)\n else:\n print(X%D + (X//D -K)*D)\nelse:\n if X//D > K:\n if abs(X%D-D) < abs(X%D +D):\n print(abs(X%D-D))\n else:\n print(abs(X%D +D))\n else:\n print(X%D + (X//D -K)*D)', 'x,k,d = map(int,input().split())\n\nn = abs(x)//d \n\nif n < k:\n if (k-n) % 2 == 1:\n print(abs(abs(x) - n*d - d))\n else:\n print(abs(abs(x) - n*d))\nelse:\n print(abs(abs(x) - k*d))']
['Wrong Answer', 'Accepted']
['s569905473', 's287751223']
[9188.0, 9220.0]
[32.0, 28.0]
[282, 183]
p02584
u964635736
2,000
1,048,576
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.
['x,k,d=map(int,input().split())\nkai=x//d\nk-=kai\nif k%2 ==0:\n y=x-(kai*d)\nelse:\n y=x-(kai*d+1)\nprint(abs(y))', 'x,k,d=map(int,input().split())\nx=abs(x)\nkai=x//d\nif k < kai:\n print(x-d*k)\nelse:\n k-=kai\n if k%2 ==0:\n y=x-(d*kai)\n else:\n y=x-(d*(kai+1))\n print(abs(y))']
['Wrong Answer', 'Accepted']
['s881606147', 's760440634']
[9168.0, 9204.0]
[32.0, 29.0]
[112, 182]
p02584
u964904181
2,000
1,048,576
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.
['X, K, D = map(int, input().split())\n\ndef sign(x):\n return 1 if x >= 0 else -1\n\n\nans = abs(X) - K * D\n\nif abs(X) - K * D < 0:\n divs = abs(X) // D\n mods = abs(X) % D\n nums = K - divs\n\n print(divs, mods, nums)\n\n ans = abs(mods - (nums%2) * D)\n\n # if nums % 2 == 0:\n # ans = mods\n # else:\n # ans = min(mods, abs(mods - D))\n\n\nprint(ans)\n\n\n\n# \n# print(ans)\n', 'X, K, D = map(int, input().split())\n\n\ndef sign(x):\n return 1 if x >= 0 else -1\n\n\nif abs(X) >= D * K:\n ans = X - sign(X) * D * K\nelse:\n l = abs(X) // D\n mod = abs(X) % D\n\n residual = K - l\n\n if residual % 2 == 0:\n ans = mod\n else:\n ans = mod - sign(mod) * D\n\nprint(abs(ans))\n\n\n']
['Wrong Answer', 'Accepted']
['s104175340', 's881898386']
[9132.0, 9152.0]
[33.0, 29.0]
[441, 311]
p02584
u969081133
2,000
1,048,576
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.
['x,k,d=map(int,input().split())\nfor n in range(k):\n a=abs(x-d)\n b=abs(x+d)\n if a<=b:\n x=x-d\n else:\n x=x+d\nprint(x)', 'x,k,d=map(int,input().split())\nx=abs(x)\na=x//d\nif a>=k:\n ans=x-(k*d)\nelse:\n b=x%d\n c=d-b\n if b<=c:\n if (k-a)%2==0:\n ans=b\n else:\n ans=c\n else:\n if (k-a)%2==0:\n ans=b\n else:\n ans=c\nprint(ans)']
['Wrong Answer', 'Accepted']
['s175765836', 's803119086']
[9096.0, 9120.0]
[2205.0, 27.0]
[123, 227]
p02584
u971091945
2,000
1,048,576
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.
['x, k, d = map(int, input().split())\n\nif abs(x)//d>=k:\n print(abs(x)-k*d)\n exit()\n\ns = x\n\nwhile k>0:\n s = s-d\n print(s,x)\n if abs(s)>=abs(x):\n break\n x = s\n k -= 1\n\nif k == 0:\n print(abs(s))\n exit()\n\nif d%2 == 0:\n print(abs(s))\nelse:\n print(abs(x))', 'x, k, d = map(int, input().split())\nx = abs(x)\ne = x//d\n\nif e>k:\n print(x-d*k)\nelse:\n if (k-e)%2 == 0:\n print(abs(x-d*e))\n else:\n print(abs(x-d*(e+1)))']
['Wrong Answer', 'Accepted']
['s414180416', 's434032023']
[9200.0, 9140.0]
[31.0, 32.0]
[287, 174]
p02584
u972658925
2,000
1,048,576
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.
['x,k,d = map(int,input().split())\n\nx = abs(x)\nans = 0\nsyo = x//d\namari = x%d\nif x == 0:\n if syo >= k:\n ans = x -k*d\n elif syo < k:\n if x-syo*d > 0:\n if k%2==0:\n ans = x-syo*d\n else:\n ans = abs(x - d)\n elif x-syo*d ==0:\n if k%2==0:\n ans = x\n else:\n ans = 0\n else:\n x = x - syo * d\n k = k-syo\n if k%2 == 0:\n ans = x\n else:\n ans = abs(x - d)\nelse:\n ans = 0\n\nprint(ans) ', 'x,k,d = map(int,input().split())\n\nx = abs(x)\nsyo = x//d\nkk = k - syo\nxx = x - syo*d\n\nif k <= syo:\n ans = x-d*k\nelse:\n if kk%2 == 0:\n ans = xx\n else:\n ans = abs(xx-d)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s716380475', 's206725065']
[9148.0, 9144.0]
[31.0, 32.0]
[582, 200]
p02584
u972991614
2,000
1,048,576
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.
['\nx,k,d = map(int,input().split())\nx = abs(x)\nif (x//d) >=k:\n ans = x - d*k\ny = x-(x//d)*d\nelif k- (x//d)%2 != 0:\n ans = y\nelse:\n ans = y-d\nprint(abs(ans))', '\nx,k,d = map(int,input().split())\nx = abs(x)\nif (x//d) > k:\n ans = x - d*k\nelif (k-(x//d))%2 == 0:\n y = x-(x//d)*d\n ans = y\nelse:\n y = x-(x//d)*d\n ans = y-d\nprint(abs(ans))']
['Runtime Error', 'Accepted']
['s991459921', 's977960440']
[9028.0, 9132.0]
[30.0, 28.0]
[199, 223]