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
p02582
u985929170
2,000
1,048,576
We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is `S`, it means it was sunny on the i-th day; if that character is `R`, it means it was rainy on that day. Find the maximum number of consecutive rainy days in this period.
["S = input()\nif S = 'RRR':print(3)\nif S = 'RRS':print(2)\nif S = 'RSR':print(1)\nif S = 'RSS':print(1)\nif S = 'SRR':print(2)\nif S = 'SRS':print(1)\nif S = 'SSR':print(1)\nif S = 'SSS':print(0)", "S = input()\nif S == 'SSS':print(0)\nif S == 'SSR':print(1)\nif S == 'SRS':print(1)\nif S == 'RSS':print(1)\nif S == 'SRR':print(2)\nif S == 'RRS':print(2)\nif S == 'RSR':print(1)\nif S == 'RRR':print(3)"]
['Runtime Error', 'Accepted']
['s819969900', 's609067973']
[9008.0, 9044.0]
[22.0, 27.0]
[187, 195]
p02582
u988661952
2,000
1,048,576
We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is `S`, it means it was sunny on the i-th day; if that character is `R`, it means it was rainy on that day. Find the maximum number of consecutive rainy days in this period.
["S = input()\n\nif S == 'RRR':\n print(3)\nelif S == 'RSR' or 'SSR' or 'RSS':\n print(1)\nelif S == 'RRS' or S=='SRR':\n print(2)\nelse:\n print(0)", "S = input()\n\nif S == 'RRR':\n print(3)\nelif S == 'RSR' or S=='SSR' or S=='RSS' or S=='SRS':\n print(1)\nelif S == 'RRS' or S=='SRR':\n print(2)\nelse:\n print(0)"]
['Wrong Answer', 'Accepted']
['s735036734', 's885933322']
[9024.0, 9100.0]
[35.0, 33.0]
[149, 167]
p02582
u994935583
2,000
1,048,576
We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is `S`, it means it was sunny on the i-th day; if that character is `R`, it means it was rainy on that day. Find the maximum number of consecutive rainy days in this period.
['W = input()\nans = 0\ncount = 0\nfor i in range(len(W)):\n if W[i] == R:\n count += 1\n ans = max(ans,count)\n else:\n count = 0\nprint(ans)', 'W = input()\nans = 0\ncount = 0\nfor i in range(len(W)):\n if W[i] == "R":\n count += 1\n ans = max(ans,count)\n else:\n count = 0\nprint(ans)']
['Runtime Error', 'Accepted']
['s984123132', 's417414613']
[8996.0, 8944.0]
[28.0, 30.0]
[142, 144]
p02582
u999327182
2,000
1,048,576
We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is `S`, it means it was sunny on the i-th day; if that character is `R`, it means it was rainy on that day. Find the maximum number of consecutive rainy days in this period.
['S = input()\n\nif S =="SSS":\n print(0)\nelif S[1] == "S":\n print(1)\nelif S = "SRS":\n print(1)\nelif S == "RRR":\n print(3)\nelse:\n print(2)', 'S = input()\n\nif S =="SSS":\n print(0)\nelif S[1] == "S":\n print(1)\nelif S == "SRS":\n print(1)\nelif S == "RRR":\n print(3)\nelse:\n print(2)']
['Runtime Error', 'Accepted']
['s471793965', 's179452822']
[9008.0, 9036.0]
[29.0, 34.0]
[138, 139]
p02584
u000040786
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-d*k > 0:\n print(x-d*k)\nelse:\n print(x+d*k)', 'x, k, d = map(int, input().split())\nx=abs(x)\nif x-d*k > 0:\n print(x-d*k)\nelse:\n n=x//d\n x-=n*d\n if (k-n)%2==0:\n print(x)\n else:\n print(abs(x-d))']
['Wrong Answer', 'Accepted']
['s244720519', 's791421440']
[9160.0, 9152.0]
[26.0, 31.0]
[98, 173]
p02584
u013105797
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.
['print(-1 // 2)\n\nX, K, D = map(int, input().split())\n\nans = 0\ncount = X // D\n\n\n\nif X >= 0:\n if K <= count:\n ans = X - D * K\n else:\n ans = X - D * count\n if ((K - count) % 2 == 1):\n ans = ans - D\nelse:\n if K <= (-1) * count:\n ans = X + D * K\n elif X % D == 0:\n ans = X - D * count \n if ((K + count) % 2 == 1):\n ans = ans + D\n else:\n ans = X - D * (count + 1) \n if ((K + count + 1) % 2 == 1):\n ans = ans + D\n\nif ans < 0:\n ans = ans * (-1)\n\nprint(ans)\n\n\n', 'X, K, D = map(int, input().split())\n\nans = 0\ncount = X // D\n\n\n\nif X >= 0:\n if K <= count:\n ans = X - D * K\n else:\n ans = X - D * count\n if ((K - count) % 2 == 1):\n ans = ans - D\nelse:\n if K <= (-1) * count:\n ans = X + D * K\n elif X % D == 0:\n ans = X - D * count \n if ((K + count) % 2 == 1):\n ans = ans + D\n else:\n ans = X - D * (count + 1) \n if ((K + count + 1) % 2 == 1):\n ans = ans + D\n\nif ans < 0:\n ans = ans * (-1)\n\nprint(ans)\n\n\n']
['Wrong Answer', 'Accepted']
['s451126280', 's847103984']
[9108.0, 9216.0]
[33.0, 35.0]
[557, 541]
p02584
u013864607
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 valid(value1, value2, diff):\n if diff%2==0:\n return value1\n else:\n return value2\n\nif abs(X)>K:\n tmp = abs(X)//D\n if D>K:\n tmp=K\n print(tmp)\n if X < 0:\n X += tmp*D\n else:\n X -= tmp*D\n K -= tmp\n\nmin_score = abs(X)\nfor i in range(K):\n if abs(X-D)>abs(X+D):\n X = X+D\n else:\n X = X-D\n if min_score > abs(X):\n min_score=abs(X)\n else:\n a = min([abs(X-D), abs(X+D)])\n min_score = valid(a, abs(X), K-i)\n break\nprint(min_score)\n', 'X,K,D=map(int,input().split())\n\ndef valid(value1, value2, diff):\n if diff%2==0:\n return value1\n else:\n return value2\n\nif abs(X)>K:\n tmp = abs(X)//D\n if tmp>K:\n tmp=K\n if X < 0:\n X += tmp*D\n else:\n X -= tmp*D\n K -= tmp\n\nmin_score = abs(X)\nfor i in range(K):\n if abs(X-D)>abs(X+D):\n X = X+D\n else:\n X = X-D\n if min_score > abs(X):\n min_score=abs(X)\n else:\n a = min([abs(X-D), abs(X+D)])\n min_score = valid(a, abs(X), K-i)\n break\nprint(min_score)\n']
['Wrong Answer', 'Accepted']
['s012989789', 's530562319']
[9176.0, 9212.0]
[29.0, 27.0]
[567, 554]
p02584
u017271555
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 math import abs\nx,k,d=input().split()\nx=int(x)\nk=int(k)\nd=int(d)\nif(x<=0):\n if(x+k*d<=0):print(x+k*d)\n else:\n res=x%d\n k-=abs(res-x)//d\n if(k%2):\n ans1=res+d\n ans2=res-d\n if(abs(ans1)>abs(ans2)):print(ans2)\n else:print(ans1)\n else:print(res)\nelse:\n if(x-k*d>=0):print(x-k*d)\n else:\n res=x%d\n k-=abs(res-x)//d\n if(k%2):\n ans1=res+d\n ans2=res-d\n if(abs(ans1)>abs(ans2)):print(ans2)\n else:print(ans1)\n else:print(res)\n \n', '#from math import abs\nx,k,d=input().split()\nx=int(x)\nk=int(k)\nd=int(d)\nif(x<=0):\n if(x+k*d<=0):print(x+k*d)\n else:\n res=x%d\n k-=abs(res-x)//d\n if(k%2):print(res-d)\n else:print(res)\nelse:\n if(x-k*d>=0):print(x-k*d)\n else:\n res=x%d\n k-=abs(res-x)//d\n if(k%2):print(res-d)\n else:print(res)\n \n', '#from math import abs\nx,k,d=input().split()\nx=int(x)\nk=int(k)\nd=int(d)\nif(x<=0):\n if(x+k*d<=0):print(abs(x+k*d))\n else:\n res=x%d\n k-=abs(res-x)//d\n if(k%2):\n ans1=res+d\n ans2=res-d\n if(abs(ans1)>abs(ans2)):print(abs(ans2))\n else:print(abs(ans1))\n else:print(abs(res))\nelse:\n if(x-k*d>0):print(abs(x-k*d))\n else:\n res=x%d\n k-=abs(res-x)//d\n if(k%2):\n ans1=res+d\n ans2=res-d\n if(abs(ans1)>abs(ans2)):print(abs(ans2))\n else:print(abs(ans1))\n else:print(abs(res))\n \n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s145372085', 's549247690', 's625417603']
[9224.0, 9204.0, 9236.0]
[31.0, 33.0, 31.0]
[586, 364, 625]
p02584
u018808362
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= list(map(int,input().split()))\t \nX, K, D=li[0], li[1], li[2]\nif abs(X)>K*D:\n print(min(abs(X-K*D), abs(X+K*D)))\nelse:\n N=abs(X)//D\n Min=10**16\n n=0\n for i in range(N-1, N+2):\n M=abs(X-i*D)\n if M<Min:\n Min=M\n n=i\n if (K-n)%2==0:\n print (abs(Min))\n else:\n print(min(abs(Min+D), abs(Min-D)))\n \nN=X//D\nMin=10**16\nn=0\nfor i in range(K+1):\n M=abs(X-i*D)\n if M<Min:\n Min=M\n n=i\nif (K-n)%2==0:\n print (abs(Min))\nelse:\n print(min(abs(Min+D), abs(Min-D)))', 'li= list(map(int,input().split()))\t \nX, K, D=li[0], li[1], li[2]\nif abs(X)>K*D:\n print(min(abs(X-K*D), abs(X+K*D)))\nelse:\n X=abs(X)\n N=X//D\n Min=10**16\n n=0\n for i in range(N-1, N+2):\n M=abs(X-i*D)\n if M<Min:\n Min=M\n n=i\n if (K-n)%2==0:\n print (Min)\n else:\n print(min(abs(Min+D), abs(Min-D)))']
['Wrong Answer', 'Accepted']
['s580646159', 's507295409']
[9188.0, 9216.0]
[2206.0, 34.0]
[574, 373]
p02584
u035210736
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 decimal import *\nx, k, d = map(Decimal, input().split())\n\nif x >= 0:\n if x-k*d >= 0:\n print(abs(x-k*d))\n else:\n if d%2 == k%2:\n print(abs(k-x%d))\n else:\n print(abs(x%d))\nelse:\n if x+k*d <= 0:\n print(abs(x+k*d))\n else:\n if d%2 == k%2:\n print(abs(k+x%d))\n else:\n print(abs(-x%d))', 'from decimal import *\nx, k, d = map(Decimal, input().split())\n\nif x >= 0:\n if x-k*d >= 0:\n print(abs(x-k*d))\n else:\n if d%2 == k%2:\n print(abs(k-x%d))\n else:\n print(abs(x%d))\nelse:\n if -x+k*d <= 0:\n print(abs(-x+k*d))\n else:\n if d%2 == k%2:\n print(abs(k+x%d))\n else:\n print(abs(-x%d))', 'from decimal import *\nx, k, d = map(Decimal, input().split())\n\nif x >= 0:\n if x-k*d >= 0:\n print(abs(x-k*d))\n else:\n if x//d%2 == k%2:\n print(abs(x%d))\n else:\n print(abs(k-x%d))\nelse:\n if x+k*d <= 0:\n print(abs(x+k*d))\n else:\n if x//d%2 == k%2:\n print(abs(-x%d))\n else:\n print(abs(k+x%d))', 'from decimal import *\nx, k, d = map(Decimal, input().split())\n\nif x >= 0:\n if x-k*d >= 0:\n print(abs(x-k*d))\n else:\n if x//d%2 == k%2:\n print(abs(x%d))\n else:\n print(abs(d-x%d))\nelse:\n if x+k*d <= 0:\n print(abs(x+k*d))\n else:\n if -x//d%2 == k%2:\n print(abs(-x%d))\n else:\n print(abs(d+x%d))']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s541639426', 's623133911', 's638172530', 's141275261']
[9876.0, 9872.0, 9852.0, 9928.0]
[36.0, 39.0, 36.0, 40.0]
[324, 326, 330, 331]
p02584
u043170743
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:\n print(X-K*D)\nelse:\n y=X//D\n z=K-y\n if z%2==0:\n print(K-y*D)\n else:\n print(K-(y+1)*D)', 'X,K,D = map(int, input().split())\nX=abs(X)\nif X>=K*D:\n print(X-K*D)\nelse:\n y=X//D\n z=K-y\n if z%2==0:\n print(K-y*D)\n else:\n print(K-(y+1)*D)', 'X,K,D = map(int, input().split())\nX=abs(X)\nif X>=K*D:\n print(X-K*D)\nelse:\n y=X//D\n z=K-y\n if z%2==0:\n print(K-y*D)\n else:\n print(abs(K-(y+1)*D))', 'X,K,D = map(int, input().split())\nX=abs(X)\nif X>=K*D:\n print(X-K*D)\nelse:\n y=X//D\n z=K-y\n j=y*D\n if z%2==0:\n print(abs(X-j))\n else:\n print(abs(X-j-D))']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s333333943', 's762358287', 's850621990', 's074730010']
[9176.0, 9180.0, 9184.0, 9092.0]
[28.0, 31.0, 30.0, 30.0]
[150, 150, 155, 162]
p02584
u050622763
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 = list(map(int,input().split()))\n\n\n\ncapa_iter = abs(x) // abs(d)\nif capa_iter < k:\n if (k - capa_iter) % 2 == 0:\n print(x - capa_iter*d)\n else:\n print(max([abs(x - capa_iter*d-d),abs(x - capa_iter*d+d)]))\n exit()\n\n\nans = min([abs(x-d),abs(x+d)])\n\nprint(ans)\n', 'import numpy as np\n\nx,k,d = np.array(list(map(int,input().split())))\n\n\n\ncapa_iter = np.abs(x) // np.abs(d)\nif capa_iter < k:\n if (k - capa_iter) % 2 == 0:\n print(x - capa_iter*d)\n else:\n print(max([np.abs(x - capa_iter*d-d),np.abs(x - capa_iter*d+d)]))\n exit()\n\n\nans = min([np.abs(x-d),np.abs(x+d)])\n\nprint(ans)\n', '\nx,k,d = list(map(int,input().split()))\n\n\n\nif x >= 0:\n capa_iter = x // d\n if capa_iter < k:\n if (k - capa_iter) % 2 == 0:\n print(x - capa_iter*d)\n else:\n print(min([abs(x - capa_iter*d-d),x - capa_iter*d+d]))\n exit()\n\n ans =x-d*k\n print(ans)\n\nif x < 0:\n capa_iter = abs(-x // d)\n if capa_iter < k:\n if (k - capa_iter) % 2 == 0:\n print(abs(x + capa_iter*d))\n else:\n print(min([abs(x + capa_iter*d+d),abs(x + capa_iter*d - d)]))\n exit()\n\n ans =abs(x+d*k)\n print(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s335598421', 's406629868', 's243450186']
[9180.0, 26884.0, 9076.0]
[33.0, 137.0, 34.0]
[348, 395, 586]
p02584
u051174463
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()]\nprint(min([abs(x // d), abs(x // d - d)]))', 'x, k, d = [int(i) for i in input().split()]\nif x < 0:\n x = -x\nl = min(k, x // d)\nk -= l\nx -= l * d\nif k % 2 == 0:\n print(x)\nelse:\n print(d - x)']
['Wrong Answer', 'Accepted']
['s812139555', 's290682594']
[9164.0, 9060.0]
[29.0, 27.0]
[86, 146]
p02584
u051261043
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, d = map(int, input().split())\nn = abs(n)\nok = n // d\nleft = k - (ok)\nif left % 2:\n print(d - (n%d))\n else:\n print(n%d)', 't = int(input())\n\nfor i in range(t):\n n, k, d = map(int, input().split())\n n = abs(n)\n ok = n // d\n left = k - (ok)\n if left % 2:\n print(d - (n%d))\n else:\n print(n%d)', 'n, k, d = map(int, input().split())\nn = abs(n)\nok = n // d\nif k < ok:\n print(n - (k*d))\nelse:\n left = k - (ok)\n if left % 2:\n \tprint(d - (n%d))\n else:\n print(n%d)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s286600752', 's444038324', 's093063225']
[9044.0, 9096.0, 9168.0]
[26.0, 25.0, 32.0]
[129, 198, 170]
p02584
u054825571
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())\ndef solve(X,K,D):\n if abs(X)>D:\n a=abs(X)//D\n if K>a:\n X=X%D\n K-=a\n else:\n if X>0:\n return X-D*K\n else:\n return -1*(X+D*K)\n if K%2==0:\n return X\n else:\n if X>0:\n return X-D\n else:\n return -1*(X+D)\nprint(solve(X,K,D))', 'X,K,D=map(int,input().split())\ndef solve(X,K,D):\n if abs(X)>D:\n a=abs(X)//D\n if K>a:\n X=X%D\n K-=a\n else:\n if X>0:\n return X-D*K\n else:\n return X+D*K\n if K%2==0:\n return X\n else:\n if X>0:\n return X-D\n else:\n return X+D\nprint(solve(X,K,D)) ', 'X,K,D=map(int,input().split())\ndef solve(X,K,D):\n X=abs(X)\n if X>D:\n a=X//D\n if K>a:\n X=X%D\n K-=a\n else:\n return abs(X-D*K)\n if K%2==0:\n return X\n else:\n return abs(X-D)\nprint(solve(X,K,D))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s220090762', 's312640147', 's530442850']
[9192.0, 9188.0, 9172.0]
[30.0, 30.0, 28.0]
[312, 304, 223]
p02584
u065079240
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 X + K * D <= 0:\n print(-X - K * D)\n elif X - K * D >= 0:\n print(X - K * D)\n else:\n mod = abs(X) // D\n if (K-mod) % 2 == 0:\n print(abs(abs(X) - K * mod))\n else:\n print(abs(abs(X) - K * (mod + 1)))', 'X, K, D = map(int, input().split())\nif X + K * D <= 0:\n print(-X - K * D)\nelif X - K * D >= 0:\n print(X - K * D)\nelse:\n div = abs(X) // D\n if (K-div) % 2 == 0:\n print(abs(X) - D * div)\n else:\n print(abs(abs(X) - D * (div + 1)))\n']
['Runtime Error', 'Accepted']
['s306116289', 's133136316']
[9012.0, 9104.0]
[29.0, 29.0]
[271, 257]
p02584
u066413086
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 point(x):\n return (abs(x), x)\n\ndef main():\n X, K, D = map(int, input().split())\n\n if X < 0:\n k = abs(X) // D\n k = min(k, K)\n ans = X + D*k\n K -= k\n \n if K >= 1 and point(ans + D) < point(ans):\n ans += D\n K -= 1\n \n if K % 2 == 1:\n ans = ans - D if ans > 0 else ans + D\n\n else:\n k = X // D\n k = min(k, K)\n ans = X - D*k\n K -= k\n\n \n if K >= 1 and point(ans - D) < point(ans):\n ans -= D\n K -= 1\n \n if K % 2 == 1:\n ans = ans - D if ans > 0 else ans + D\n\n print(ans)\n\nif __name__ == '__main__':\n main()", "def point(x):\n return (abs(x), x)\n\ndef main():\n X, K, D = map(int, input().split())\n\n if X < 0:\n k = abs(X) // D\n k = min(k, K)\n ans = X + D*k\n K -= k\n \n if K >= 1 and point(ans + D) < point(ans):\n ans += D\n K -= 1\n \n if K % 2 == 1:\n ans = ans - D if ans > 0 else ans + D\n\n else:\n k = X // D\n k = min(k, K)\n ans = X - D*k\n K -= k\n\n \n if K >= 1 and point(ans - D) < point(ans):\n ans -= D\n K -= 1\n \n if K % 2 == 1:\n ans = ans - D if ans > 0 else ans + D\n\n print(abs(ans))\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s847123501', 's742474992']
[9228.0, 9192.0]
[33.0, 31.0]
[756, 761]
p02584
u068538925
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\ninit = 10**15\n\nfor i in range(abs(k) // abs(d)):\n tempx = x + i*d - (k-i)*d\n init = min(init, abs(tempx))\n\nprint(init)', 'x,k,d = map(int,input().split())\nif abs(x)//abs(d) >= k:\n print(abs(x)-abs(d)*k)\n exit()\n\nstep = abs(x)//abs(d)\ny = abs(x)-abs(d)*step\nk = k-step\n\nif k%2 == 0:\n print(y)\nelse:\n print(y+d)', 'x,k,d = map(int,input().split())\nif abs(x)//abs(d) >= k:\n print(abs(x)-abs(d)*k)\n exit()\n\nstep = abs(x)//abs(d)\ny = abs(x)-abs(d)*step\nk = k-step\n\nif k%2 == 0:\n print(y)\nelse:\n print(abs(y-d))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s054398114', 's332370680', 's763884562']
[9168.0, 8980.0, 9192.0]
[2206.0, 26.0, 28.0]
[158, 199, 204]
p02584
u069486477
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:\n print(X-K*D)\nelse:\n if (K-X//D) % 2 ==1:\n print(D-(X-K*D))\n else:\n print(X-X//D*D)', 'X,K,D = map(int,input().split()) \nmlist = []\nfor i in range(K+1):\n t = X + i*D - (K-i)*D\n if t < 0 :\n t = -t\n mlist.append(t)\nprint(mlist)\nprint(min(mlist))', 'X,K,D = map(int,input().split()) \nif X >= K*D:\n print(X-K*D)\nelse:\n if (K-X//D) % 2 ==1:\n print(D-(X-K*D))\n else:\n print(X-X//D*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(D-(X-X//D*D))\n else:\n print(X-X//D*D)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s390087130', 's519753769', 's682789401', 's074857263']
[9180.0, 395852.0, 9196.0, 9172.0]
[31.0, 2216.0, 29.0, 31.0]
[164, 172, 153, 168]
p02584
u075317232
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 WalkingTakahashi():\n \n data = list(map(int,input().split()))\n \n position = data[0]\n\n print(data[1]%2)\n \n if data[0] == data[2] and data[1]%2 == 0:\n print(data[2])\n \n elif data[0] == data[2] and data[1]%2 == 1:\n print(0)\n \n else:\n for i in range(data[1]):\n \n if abs(position + data[2]) < abs(position - data[2]):\n position = position + data[2]\n \n else:\n position = position - data[2]\n \n print(abs(position))\n \nif __name__ == '__main__':\n WalkingTakahashi()\n\n\n", "def WalkingTakahashi():\n \n data = list(map(int,input().split()))\n \n position = abs(data[0])\n \n m = min(data[1], position//data[2])\n \n position = position - data[2]*m\n \n data[1] = data[1] - m\n \n data[1] %= 2\n \n position = position - data[2]*data[1]\n \n print(abs(position))\n \nif __name__ == '__main__':\n WalkingTakahashi()\n"]
['Wrong Answer', 'Accepted']
['s154818000', 's498904656']
[9060.0, 9144.0]
[2206.0, 37.0]
[630, 375]
p02584
u080885857
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 and x-k*d<0:\n tem = int(x/k)\n if (x-tem)>abs(x-(tem+1)):\n print(abs(x - d*(tem + 1)))\n\n else:\n print(x - d*tem)\n\nelse:\n print(x-k*d)', 'x,k,d = map(int,input().split())\n\n\nx=abs(x)\nif k*d<=x:\n print(x-k*d)\nelse:\n tem = int(x/d)\n x-= tem*d\n k-= tem\n if k%2==0:\n print(x)\n else:\n print(abs(x-d))\n']
['Wrong Answer', 'Accepted']
['s245739050', 's659944319']
[9084.0, 9068.0]
[33.0, 30.0]
[200, 189]
p02584
u090649502
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.
["#!/usr/bin/env python3\nimport sys\n\n\ndef solve(X: int, K: int, D: int):\n X=abs(X)\n\n ans=min(X, X - K * D)\n\n if K%2 == 1:\n X += D\n ans = min(ans, X)\n Kh=(K+1)//2\n\n N = X // (D*2)\n ans = min(ans, abs(X - D * 2 * (N - 1)))\n ans = min(ans, abs(X - D * 2 * N))\n if N < Kh:\n ans = min(ans, abs(X - D * 2 * (N+1)))\n\n print(ans)\n\n return\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n X = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n D = int(next(tokens)) # type: int\n solve(X, K, D)\n\nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(X: int, K: int, D: int):\n X=abs(X)\n\n mostl = X - K * D\n if mostl > 0:\n print(mostl)\n exit()\n\n if K%2 == 1:\n X -= D\n ans = min(abs(X), abs(X+2*D))\n else:\n ans = min(X, abs(X - K * D))\n\n Kh = K // 2\n\n N = X // (D*2)\n ans = min(ans, abs(X - D * 2 * (N - 1)))\n ans = min(ans, abs(X - D * 2 * N))\n if N < Kh:\n ans = min(ans, abs(X - D * 2 * (N + 1)))\n\n print(ans)\n\n return\n\n\n# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n X = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n D = int(next(tokens)) # type: int\n solve(X, K, D)\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s274503952', 's070913307']
[9144.0, 9192.0]
[29.0, 35.0]
[889, 1001]
p02584
u092104621
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)\nfor i in range(k,0,-1):\n if x > 0:\n x -= d\n else:\n x += d * (i % 2)\n break\nprint(x)\n', 'x,k,d = list(map(int, input().split()))\nx = abs(x)\na,b = divmod(x, d)\n\n#print(a,b)\n\n# if x > 0:\n# x -= d\n# else:\n# x += d * (i % 2)\n# break\nprint(abs(x))\n', "x,k,d = list(map(int, input().split()))\nx = abs(x)\na,b = divmod(x, d)\na = min(a, k)\nx -= a * d\n#print('a=',a)\n#print('x=',x)\n#print('ka=',k-a)\nx -= d * ((k-a) % 2)\nprint(abs(x))\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s357565529', 's625998654', 's091058022']
[9156.0, 9096.0, 9172.0]
[2205.0, 28.0, 28.0]
[146, 189, 178]
p02584
u094425865
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\nzx=x\nif abs(x)<d*k:\n wk,x=divmod(abs(x),d)\n k-=wk \nelse:\n abs(x)-=d*k\n k=0\n\nfor i in range(k):\n xm=abs(x+d)\n xu=abs(x-d)\n x=min(xm,xu)\n k-=1\n if zx+x==d:\n if k%2!=0:\n x=zx\n break\n else:\n break\n zx=x\n \nprint(x)', 'x,k,d=map(int,(input().split()))\n\nx=abs(x)\nzx=x\nif x<d*k:\n wk,x=divmod(abs(x),d)\n k-=wk \nelse:\n x-=d*k\n k=0\n\nfor i in range(k):\n xm=abs(x+d)\n xu=abs(x-d)\n x=min(xm,xu)\n k-=1\n if zx+x==d:\n if k%2!=0:\n x=zx\n break\n else:\n break\n zx=x\n \nprint(x)']
['Runtime Error', 'Accepted']
['s307878046', 's611143036']
[9136.0, 9204.0]
[25.0, 31.0]
[326, 325]
p02584
u098679988
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\nif x > 0:\n if abs(x-d) < x:\n div = x//d\n if div > k:\n print(x-d*k)\n sys.exit()\n else:\n if k%2 == 0:\n print(x)\n sys.exit()\n else:\n print(x-d)\n sys.exit()\n else:\n if k%2 == 0:\n print(x)\n sys.exit()\n else:\n print(x-d)\n sys.exit()\nelse:\n if abs(x+d) < x:\n div = x//d\n if div > k:\n print(x+d*k)\n sys.exit()\n else:\n print(x+d)\n sys.exit()\n else:\n if k%2 == 0:\n print(x)\n sys.exit()\n else:\n print(x+d)\n sys.exit()\n', 'import sys\nx, k, d = map(int, input().split())\n\n\nisEven = (k%2 == 0)\n\n\ndiv = abs(x//d)\n\n\n#0,a,b\nans = 0\nif k < div:\n if x > 0:\n \n print(abs(x-d*k))\n else:\n \n print(abs(x+d*k))\nelse:\n if x > 0:\n if (k-div) % 2 == 0:\n \n print(abs(x-d*div))\n else:\n \n hoge = x-d*div\n if hoge+d < abs(hoge-d):\n print(abs(hoge+d))\n else:\n print(abs(hoge-d))\n else:\n if (k-div) % 2 == 0:\n \n print(abs(x+d*div))\n else:\n \n hoge = x+d*div\n if hoge+d < abs(hoge-d):\n \n print(abs(hoge+d))\n else:\n # print("F")\n print(abs(hoge-d))']
['Wrong Answer', 'Accepted']
['s729962773', 's849729832']
[9224.0, 9148.0]
[31.0, 34.0]
[780, 959]
p02584
u102655885
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(lambda x: int(x), input().split()))\n\nmin_pos = x % d\nmin_neg = min_pos - d\n\nnum_to_min_pos = x // d\nif k <= num_to_min_pos:\n print(x - d * k)\n \nelse:\n if (k - num_to_min_pos) % 2 == 0:\n print(min_pos)\n else:\n print(abs(min_neg)\n', 'x, k, d = list(map(lambda x: int(x), input().split()))\n\n\nx = abs(x)\nmin_pos = x % d\nmin_neg = min_pos - d\n\nnum_to_min_pos = x // d\nif k <= num_to_min_pos:\n print(x - d * k)\n \nelse:\n if (k - num_to_min_pos) % 2 == 0:\n print(min_pos)\n else:\n print(abs(min_neg))']
['Runtime Error', 'Accepted']
['s659720457', 's604995485']
[9000.0, 9108.0]
[29.0, 32.0]
[273, 285]
p02584
u108650331
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.
['#!/usr/bin/env python3\nimport math\n\nX, K, D = map(int, input().split())\n\ncross = abs(math.ceil(X / D))\n\nif cross >= K:\n for i in range(K):\n if X >= 0:\n X -= D\n else:\n X += D\n print(X)\nelse:\n for i in range(cross):\n if X >= 0:\n X -= D\n else:\n X += D\n \n if (K-cross)%2 == 0:\n print(X)\n else:\n if X >= 0:\n print(X-D)\n else:\n print(X+D)\n\n\n\n', '#!/usr/bin/env python3\nimport math\n\nX, K, D = map(int, input().split())\n\ncross = abs(-(-X//D))\n\nif cross >= K:\n if X >= 0:\n X -= D*K\n else:\n X += D*K\n print(abs(X))\nelse:\n if X >= 0:\n X -= D*cross\n else:\n X += D*cross\n \n if (K-cross)%2 == 0:\n print(abs(X))\n else:\n if X >= 0:\n print(abs(X-D))\n else:\n print(abs(X+D))\n\n\n\n']
['Wrong Answer', 'Accepted']
['s885399368', 's398598767']
[9152.0, 9140.0]
[2206.0, 34.0]
[511, 457]
p02584
u115877451
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,b,c=map(int,input().split())\n\nif abs(a)>=abs(b*c):\n print(abs(abs(a)-abs(b*c)))\n exit()\n\nn=abs(a)\nm=n//c\nif abs(a)-abs(c*m)>abs(a)-abs(c*(m+1)):\n m=m+1\nprint(m)\nif (b-m)%2==0:\n print(abs(abs(a)-abs(c*m)))\nelse:\n print(min(abs(abs(a)-abs(c*(m+1))),abs(abs(a)-abs(c*(m-1)))))', 'a,b,c=map(int,input().split())\n\nif abs(a)>=abs(b*c):\n print(abs(abs(a)-abs(b*c)))\n exit()\n\nn=abs(a)\nm=n//c\nif abs(a)-abs(c*m)>abs(a)-abs(c*(m+1)):\n m=m+1\nprint(m)\nif (b-m)%2==0:\n print(abs(a)-abs(c*m))\nelse:\n print(min(abs(abs(a)-abs(c*(m+1))),abs(abs(a)-abs(c*(m-1)))))', 'X,K,D=map(int,input().split())\nif X>=0:\n if X-K*D>X%D:\n print(abs(X-K*D))\n else:\n if (K-X//D)%2==0:\n print(X%D)\n else:\n print(abs(X%D-D))\nelse:\n if X+K*D<X%D:\n print(abs(X+K*D))\n else:\n if (K+X//D)%2==0:\n print(X%D)\n else:\n print(abs(X%D-D))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s503078454', 's854069874', 's169302337']
[9200.0, 9136.0, 9172.0]
[34.0, 31.0, 30.0]
[290, 285, 339]
p02584
u129749062
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())\ncnt = 0\na = X\nb = 999999999\ntmp = 0\nif X == 0:\n if K % 2 == 0:\n print(0)\n else:\n print(D)\n sys.exit()\nif X >= K*D:\n print(X - K*D)\n sys.exit()\nif K % 2 == 0:\n tmp = int(X/D)\n if tmp% 2 == 0:\n a = X - D*tmp\n else:\n a = X - D*tmp + D\n if X >= 0:\n b = a - D*2\n else:\n b = a + D*2\nelse:\n tmp = int(X/D)\n if tmp% 2 == 1:\n a = X - D*tmp\n else:\n a = X - D*tmp + D\n if X >= 0:\n b = a - D*2\n else:\n b = a + D*2\nprint(tmp,a,b)\nprint(min(abs(a),abs(b)))\n', 'import sys\nX, K, D = map(int,input().split())\ncnt = 0\na = X\nb = 0\ntmp = 0\nif abs(X) >= K*D:\n if X > 0:\n print(X - K*D) \n else:\n print(abs(X + K*D))\n sys.exit()\nif K % 2 == 0:\n tmp = int(X/D)\n if tmp% 2 == 0:\n a = X - D*tmp\n else:\n a = X - D*tmp + D\n b = a - D*2\nelse:\n tmp = int(X/D)\n if tmp% 2 == 1:\n a = X - D*tmp\n else:\n a = X - D*tmp + D\n b = a - D*2\nprint(min(abs(a),abs(b)))\n\n']
['Wrong Answer', 'Accepted']
['s108760475', 's776783232']
[9068.0, 9208.0]
[33.0, 29.0]
[534, 412]
p02584
u129898499
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\nif X<0:\n X = (-1)*X\n \nif X-K*D >=0:\n ans = X-K*D\nelse:\n Y = int(X/D)\n z = X%D\n if (K-Y)%2=0:\n ans = Z\n if (K-Y)%2=1:\n ans = D-Z\nif ans<0:\n ans = (-1)*ans\nprint(ans)\n \n', 'X,K,D = map(int,input().split())\nans = 0\nif X<0:\n X = (-1)*X\n \nif X-K*D >=0:\n ans = X-K*D\nelse:\n Y = int(X/D)\n Z = X%D\n if (K-Y)%2==0:\n ans = Z\n if (K-Y)%2==1:\n ans = D-Z\nprint(ans)']
['Runtime Error', 'Accepted']
['s863645533', 's094657741']
[9028.0, 9180.0]
[27.0, 34.0]
[223, 194]
p02584
u130076114
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\nif abs(X)>=K*D:\n ans=abs(X)-K*D\nelse:\n M=abs(X)//D\n if abs(X)-M*D>abs(abs(X)-(M+1)*D):\n M=M+1\n if (K-M)%2==0:\n ans=abs(abs(X)-M*D)\n else:\n ans=abs(X)-(M-1)*D\nprint(ans)\n', 'X,K,D=map(int,input().split())\nans=0\nif abs(X)>=K*D:\n ans=abs(X)-K*D\nelse:\n M=abs(X)//D\n if abs(X)-M*D>abs(abs(X)-(M+1)*D):\n M=M+1\n if (K-M)%2==0:\n ans=abs(abs(X)-M*D)\n else:\n ans=min(abs(X)-(M-1)*D,abs(abs(X)-(M+1)*D))\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s833415562', 's734639470']
[9172.0, 9196.0]
[32.0, 31.0]
[242, 267]
p02584
u131881594
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)>=k*d: print(abs(x)-k*d)\nelse:\n if (k-abs(x)//d)%2==0: print(abs(x)-d*x//d)\n else: print(abs(abs(x)-d*x//d-d))\n', 'x,k,d=map(int,input().split())\n\nif abs(x)>=k*d: print(abs(x)-k*d)\nelse:\n if (k-abs(x)//d)%2==0: print(abs(x)-d*(abs(x)//d))\n else: print(abs(abs(x)-d*(abs(x)//d)-d))\n']
['Wrong Answer', 'Accepted']
['s503190392', 's288909109']
[9112.0, 9172.0]
[35.0, 30.0]
[158, 172]
p02584
u137038354
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 = abs(X)\nans = 0\nif A >= D*K:\n print( A - (D * K))\nelse :\n e = A//D\n K -= e\n x %= D\n if K%2 == 0:\n print(x)\n else:\n print(D-x)', 'X,K,D = map(int,input().split())\nA = abs(X)\nans = 0\nif A >= D*K:\n print( A - (D * K))\nelse :\n e = A//D\n K -= e\n A %= D\n if K%2 == 0:\n print(A)\n else:\n print(D-A)']
['Runtime Error', 'Accepted']
['s065775222', 's406709921']
[9200.0, 9184.0]
[28.0, 27.0]
[193, 193]
p02584
u137316733
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\nb = round(a)\n\nc = K - b\n\nif c < 0:\n print(X-(K*D))\nelif c % 2 != 0:\n if a > b:\n b = b + 1\n else:\n b = b - 1\n d = abs(X - (D*b))\n print(d)', 'X,K,D=map(int, input().split())\n\nX = abs(X)\na = X / D\nb = round(a)\n\nc = K - b\ne = 0\n\nif c < 0:\n print(X-(K*D))\n e = 1\nelif c % 2 != 0:\n if a > b:\n b = b + 1\n else:\n b = b - 1\nif e == 0:\n d = abs(X - (D*b))\n print(d)']
['Wrong Answer', 'Accepted']
['s511496523', 's150640052']
[9176.0, 9200.0]
[32.0, 26.0]
[220, 247]
p02584
u139940813
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\na = [abs(x // d), x % d]\n\nif a[0] > k:\n ans = min(abs(x+k*d) ,abs(x-k*d))\nelse:\n b = (k- a[0]) % 2\n ans = min(abs(a[1]+b*d) ,abs(a[1]-b*d))\n\nprint(ans))', 'x, k, d = map(int, input().split())\n\na = [abs(x // d), x % d]\n\nif a[0] > k:\n ans = min(abs(x+k*d) ,abs(x-k*d))\nelse:\n b = (k- a[0]) % 2\n ans = min(abs(a[1]+b*d) ,abs(a[1]-b*d))\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s785133723', 's876629692']
[9032.0, 9088.0]
[26.0, 27.0]
[197, 196]
p02584
u141574039
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 K%2==0:\n if abs(2*D)>=abs(X):\n print(X)\n else:\n p=K*D\n q=abs(X-p)\n r=min(q%D,abs(q%D-D))\n print(r) \nelse:\n if K==1:\n print(min(X,min(X+D,X-D)))\n else:\n if abs(D)>=abs(X):\n print(X)\n else:\n p=K*D\n q=abs(X-p)\n r=min(q%D,abs(q%D-D))\n print(r) ', 'X,K,D=map(int,input().split())\na=abs(X)//D\nb=abs(X)-a*D\nif K<a:\n print(abs(X)-K*D)\nelse:\n if (K-a)%2==0:\n print(b)\n else:\n print(min(abs(b-D),abs(b+D)))']
['Wrong Answer', 'Accepted']
['s318863552', 's614640485']
[9200.0, 9136.0]
[33.0, 29.0]
[330, 161]
p02584
u153686508
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 X<0:\n X*=-1\nif X-K*D>0:\n print(X-K*D)\nelif 2*X>D:\n print(X)\nelse:\n p=X-(X//D)*D\n p=min(abs(p-D),p)\n print(p)\n', 'X,K,D=map(int,input().split())\nif X<0:\n X*=-1\nif X-K*D>0:\n print(X-K*D)\nelse:\n p=X-(X//D)*D\n K-=X//D\n q=abs(p-D)\n if K%2==0:\n print(p)\n else:\n print(q)\n']
['Wrong Answer', 'Accepted']
['s241008010', 's467854156']
[9172.0, 9172.0]
[31.0, 32.0]
[149, 165]
p02584
u163971674
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\nx,k,d=map(int,input().split(" "))\n\n\nif x<0:\n x=(-1)*x\nif d<0:\n d=(-1)*d\n \ns=math.floor(x/d)\n\nif k<s:\n print(x-d*k)\nelse:\n w=k-s\n v=x-d*s\n if w%2==0:\n print(v)\n else:\n print(v-d)\n ', 'import math\nx,k,d=map(int,input().split(" "))\n\n\nif x<0:\n x=(-1)*x\nif d<0:\n d=(-1)*d\n \ns=math.floor(x/d)\n\nif k<s:\n print(x-d*k)\nelse:\n w=k-s\n v=x-d*s\n if w%2==0:\n print(v)\n else:\n print(abs(v-d))\n ']
['Wrong Answer', 'Accepted']
['s952717227', 's955400949']
[9204.0, 9180.0]
[33.0, 30.0]
[206, 211]
p02584
u165114979
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 = int(x)\nk = int(k)\nd = int(d)\nx = abs(x)\nif x > d:\n if x // d > k:\n x = x - k*d\n print(x)\n exit()\n else:\n \tk -= x // d\n x = x % d\n \n \nif k % 2 == 1:\n x = abs(x-d)\n\nprint(x)\n ', 'x, k, d = input().split()\nx = int(x)\nk = int(k)\nd = int(d)\nx = abs(x)\nif x > d:\n if x // d > k:\n x = x - k*d\n print(x)\n exit()\n else:\n \tk -= x // d\n \tx = x % d\n \n \nif k % 2 == 1:\n x = abs(x-d)\n\nprint(x)\n ']
['Runtime Error', 'Accepted']
['s288104997', 's032444304']
[9020.0, 9184.0]
[25.0, 32.0]
[229, 228]
p02584
u165318982
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())\nprint(X)\ntime = X // D\nX = X - (D * time)\nK = K - time\nprint(X)\nprint(K)\n\nif K % 2 == 0:\n print(X)\nelse:\n print(abs(X - D))', 'X, K, D = map(int,input().split())\nX = abs(X)\ntime = X // D\ntime = min(K, time)\nX = X - (D * time)\nK = K - time\n\nif K % 2 == 0:\n print(X)\nelse:\n print(abs(X - D))']
['Wrong Answer', 'Accepted']
['s456548991', 's439454780']
[9044.0, 9056.0]
[34.0, 31.0]
[160, 164]
p02584
u173178698
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:\n ans = x-k*d\nelse:\n cnt = x//d\n if (k-cnt)%2==0:\n ans = x-cnt*d\n else:\n if x > 0:\n ans = x-cnt*d-d\n else:\n ans = x-cnt*d+d\nprint(ans)', 'x, k, d = map(int,input().split())\nx = x\nif x>k*d:\n ans = x-k*d\nelse:\n cnt = x//d\n if (k-cnt)%2==0:\n ans = x-cnt*d\n else:\n if x > 0:\n ans = x-cnt*d-d\n else:\n ans = x-cnt*d+d\nprint(ans)', 'x, k, d = map(int,input().split())\nx = abs(x)\nif x>k*d:\n ans = x-k*d\nelse:\n cnt = x//d\n if (k-cnt)%2==0:\n ans = x-cnt*d\n else:\n if x>0:\n ans = abs(x-cnt*d-d)\n else:\n ans = abs(x-cnt*d+d)\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s043480591', 's939043054', 's396039589']
[9176.0, 9192.0, 9196.0]
[30.0, 30.0, 29.0]
[285, 280, 293]
p02584
u174394352
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(X) - K * D) >= 0:\n print(abs(X) - K * D)\nelse:\n print(min(X%D, abs(X%D - D))\n', 'X, K, D = map(int, input.split())\nif (abs(X) - K * D) > = 0:\n print(abs(X) - K * D)\nelse:\n print(min(X%D, D-X%D))', 'X, K, D = map(int, input().split())\nif (abs(X) - K * D) >= 0:\n print(abs(X) - K * D)\nelse:\n if (X // D - K) %2 == 0:\n \tprint(X%D)\n else:\n print(abs(X%D - D))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s241770663', 's856066016', 's161117410']
[9020.0, 8916.0, 9184.0]
[27.0, 28.0, 31.0]
[123, 115, 164]
p02584
u175590965
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 = ,ap(int,input().split())\nx = abs(x)\nif x-k*d>0:\n print(x-k*d)\nelif (k-x//d)%2 ==1:\n print(abs(x%d-d))\nelse:\n print(x%d)', 'x,k,d = map(int,input().split())\nx = abs(x)\nif x-k*d>0:\n print(x-k*d)\nelif (k-x//d)%2 ==1:\n print(abs(x%d-d))\nelse:\n print(x%d)']
['Runtime Error', 'Accepted']
['s453962087', 's880482834']
[8872.0, 9080.0]
[29.0, 29.0]
[136, 136]
p02584
u177182853
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 numpy as np\nimport math\nimport scipy as sp\nimport queue\nimport collections\n\nMOD = 10 ** 9 + 7\nINF = 10 ** 9\n\ndef main(kwargs):\n x = kwargs["x"]\n k = kwargs["k"]\n d = kwargs["d"]\n if k * d < abs(x):\n res = abs(x) - k * d\n else:\n res_1 = abs(x) % d\n res_2 = res_1 - k * (abs(x) // d % 2)\n res = abs(res_2)\n\n return res\n\nif __name__ == "__main__":\n kwargs = {}\n\n cin = input().split()\n kwargs["x"], kwargs["k"], kwargs["d"] = [int(i) for i in cin]\n\n cout = main(kwargs)\n print(cout)', 'import numpy as np\nimport math\nimport scipy as sp\nimport queue\nimport collections\n\nMOD = 10 ** 9 + 7\nINF = 10 ** 9\n\ndef main(kwargs):\n x = kwargs["x"]\n k = kwargs["k"]\n d = kwargs["d"]\n if k * d <= abs(x):\n res = abs(x) - k * d\n else:\n res = abs(abs(x) % d - (k - abs(x) // d) % 2 * d)\n\n return res\n\nif __name__ == "__main__":\n kwargs = {}\n\n cin = input().split()\n kwargs["x"], kwargs["k"], kwargs["d"] = [int(i) for i in cin]\n\n cout = main(kwargs)\n print(cout)']
['Wrong Answer', 'Accepted']
['s424151649', 's309059496']
[31180.0, 30940.0]
[152.0, 157.0]
[547, 508]
p02584
u185042816
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,k,d = map(int, input().split())\n\nif a < 0:\n x = -a\nelse:\n x = a\n\ny = x % d\nl = x // d\nm = k - l\n\nif m < 0:\n ans = x - (k * d)\nelif m % 2 ==0:\n ans = y\nelse :\n ans = y - d', 'a,k,d = map(int, input().split())\n\nif a < 0:\n x = -a\nelse:\n x = a\n\ny = x % d\nl = x // d\nm = k - l\n\nif m < 0:\n ans = x - (k * d)\nelif m % 2 ==0:\n ans = y\nelse :\n ans = y - d\n\nprint(abs(ans))']
['Wrong Answer', 'Accepted']
['s191559102', 's091726369']
[9124.0, 9128.0]
[28.0, 30.0]
[187, 204]
p02584
u185405877
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()))\na=x//d\nif k>=a:\n if (k-a)%2==0:\n x=abs(x)\n print(x%d)\n else:\n x=abs(x)\n if x%d>d-(x%d):\n print(d-(x%d))\n else:\n print(d+(x%d))\nelse:\n x=abs(x)\n print(x-(k*d))\n\n ', 'x,k,d= list(map(int, input().split())\nx=abs(x)\na=x//d\nif k>=a:\n if (k-a)%2==0:\n print(x%d)\n else:\n print(d-(x%d))\nelse:\n print(x-(k*d))\n', 'x,k,d= list(map(int, input().split()))\nx=abs(x)\na=x//d\nif k>=a:\n if (k-a)%2==0:\n print(x%d)\n else:\n print(d-(x%d))\nelse:\n print(x-(k*d))\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s223552347', 's525876252', 's958881549']
[9096.0, 9036.0, 9160.0]
[27.0, 27.0, 29.0]
[272, 159, 160]
p02584
u188305619
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())\nabsX = abs(X)\nt = K % 2\nif t == 0:\n a = abs(X - (D * 2))\n b = abs(X + (D * 2))\n if absX < a:\n a = absX\n if absX < b:\n a = absX\nelse:\n a = abs(X - D)\n b = abs(X + D)\n\nif a < b:\n print(a)\nelse:\n print(b)', 'X, K, D = map(int,input().split())\nabsX = abs(X)\nt = abs(X // D)\nremain_K = K - t\nl = X % D\nif remain_K < 0:\n a = abs(X - (K * D))\n b = abs(X + (K * D))\n if a < b:\n ans = a\n else:\n ans = b\nelse:\n if remain_K % 2 == 0:\n a = abs(l - (D * 2))\n b = abs(l + (D * 2))\n if a < b and a < l:\n ans = a\n elif a > b and b < l:\n ans = b\n else:\n ans = l\n else:\n a = abs(l - D)\n b = abs(l + D)\n if a < b:\n ans = a\n else:\n ans = b\nprint(ans)']
['Wrong Answer', 'Accepted']
['s027844887', 's855823371']
[9148.0, 9124.0]
[33.0, 32.0]
[274, 575]
p02584
u190167135
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(' '))\ntime=0\nif X>=0:\n while X>0:\n X-=D\n time+=1\n if time==K:\n break\n if (K-time)%2==0:\n print(abs(X))\nelse:\n print(X+D)\nelse:\n while X<0:\n X+=D\n time+=1\n if time==K:\n break\n if (K-time)%2==0:\n print(abs(X))\nelse:\n print(X-D)", "X,K,D=map(int,input().split(' '))\nif X>=0:\n time=X//D\n if time>K:\n print(X-K*D)\n elif (K-time)%2==0:\n print(X%D)\n else:\n print(abs((X%D)-D))\nelse:\n time=-(X//D)\n if time>K:\n print(abs(X+K*D))\n elif (K-time)%2==0:\n print(X%D)\n else:\n print(abs((X%D)-D))"]
['Runtime Error', 'Accepted']
['s910117312', 's422561783']
[9008.0, 9132.0]
[28.0, 33.0]
[341, 318]
p02584
u196297781
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()]\n\nx=abs(x)\n\nt=x\n\nif k%2==1:\n t-=d\n k-=1\n\nmin=abs(t)\n\nif t-k*d>0:\n print(t-k*d)\n exit(0)\n\nif t-k*d<0:\n s=int(t/(d*2))\n print(s)\n k-=s*2\n t-=d*s*2\n min=abs(t)\n\nwhile(-x<t and k>0):\n t-=d*2\n k-=2\n if min < abs(t):\n break\n else:\n min=abs(t)\n\nprint(min)\n', 'x,k,d=[int(i) for i in input().split()]\n\nx=abs(x)\n\nt=x\n\nif k%2==1:\n t-=d\n k-=1\n\nmin=abs(t)\n\nif abs(x-k*d)<min:\n print(x-k*d)\n exit(0)\n\nif x-k*d<0:\n k-=(x/(d*2))*2\n\n\nwhile(-x<t and k>0):\n t-=d*2\n k-=2\n if min < abs(t):\n break\n else:\n min=abs(t)\n\nprint(min)\n', 'x,k,d=[int(i) for i in input().split()]\n\nx=abs(x)\n\nt=x\n\nif k%2==1:\n t-=d\n k-=1\n\nmin=abs(t)\n\nif t-k*d>0:\n print(t-k*d)\n exit(0)\n\nif t-k*d<0:\n s=(x/(d*2))*2\n k-=s\n t-=d*s\n\nwhile(-x<t and k>0):\n t-=d*2\n k-=2\n if min < abs(t):\n break\n else:\n min=abs(t)\n\nprint(min)\n', 'x,k,d=[int(i) for i in input().split()]\n\nx=abs(x)\n\na=int(x/d)\n\n\nif a>k:\n a=k\n\nk-=a\n\nx-=a*d\n\nif k%2==1:\n x=abs(x-d)\n k-=1\n\nprint(x)\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s767517209', 's959569679', 's961987558', 's303009745']
[9200.0, 9192.0, 9192.0, 9104.0]
[33.0, 2205.0, 31.0, 28.0]
[341, 297, 308, 140]
p02584
u198073053
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())\nc = abs(x)//d\nif c < k:\n if (k-c) % 2 == 0:\n print(abs(x)%d)\n else:\n print(abs(x)%d+d)\nelse:\n print(abs(x)-d*k)', 'x,k,d = map(int,input().split())\nc = abs(x)//d\nif c < k:\n if (k-c) % 2 == 0:\n print(abs(x)%d)\n else:\n print(min(abs(abs(x)%d+d),abs(abs(x)%d-d)))\nelse:\n print(abs(x)-d*k)']
['Wrong Answer', 'Accepted']
['s194528650', 's999803454']
[9152.0, 9088.0]
[26.0, 31.0]
[167, 193]
p02584
u208308361
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.
['xkd = list(map(int,input().split()))\nxkd[0] = abs(xkd[0])\nx = xkd[0] // xkd[2]\nx = abs(x)\nxkd[0] -= xkd[2] * x\nxkd[1] -= x\nif xkd[1] < 1:\n xkd[0] += abs(xkd[1]) * xkd[2]\n print(xkd[0])\nelse:\n ans = xkd[0]\n if xkd[1] % 2 != 0:\n ans -= xkd[2]\n if ans > xkd[0] + xkd[2]:\n ans += xkd[2] * 2\n print(abs(ans))', 'X,K,D=map(int,input().split())\nX=abs(X)\nstraight=min(K,X//D)\nK-=straight\nX-=straight*D\nif K%2==0:\n print(X)\nelse:\n print(D-X)']
['Wrong Answer', 'Accepted']
['s754592882', 's830012070']
[9112.0, 9088.0]
[28.0, 28.0]
[347, 131]
p02584
u216392490
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\nn = int(x / d + 0.5)\nif n > k:\n ans = x - k*d\nelse:\n a = x - n*d\n if (k - n) % 2:\n if a > 0:\n ans = a - d\n else:\n ans = a + d\n else:\n ans = a\n \nprint(ans)', 'x, k, d = map(int, input().split())\n\nax = abs(x)\nn = ax // d\nif n >= k:\n ans = ax - k*d\nelse:\n a = ax - n*d\n if (k - n) % 2:\n ans = abs(a - d)\n else:\n ans = abs(a)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s998847723', 's353377466']
[9116.0, 9080.0]
[29.0, 31.0]
[254, 202]
p02584
u223904637
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:\n print(x-k*d)\nelse:\n p=x//k\n if p%2==k%2:\n print(x-k*p)\n else:\n print(abs(x-(k+1)*p))', '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%2==k%2:\n print(x-p*d)\n else:\n print(abs(x-(p+1)*d))']
['Wrong Answer', 'Accepted']
['s416493649', 's905423426']
[9180.0, 9180.0]
[29.0, 32.0]
[161, 161]
p02584
u225702362
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\n\nx = abs(int(input()))\nk = int(input())\nd = int(input())\n\nmove_cnt = int(x / d)\nif (move_cnt <= k):\n k -= move_cnt\n amari = x - move_cnt * d\n\nelse:\n amari = x - k * d\n k = 0\n\nif (k > 0):\n if (k % 2 == 1):\n if (amari > 0):\n amari -= d\n else:\n amari += d\n\nprint(abs(amari))', 'import sys\n\nx = abs(int(input()))\nk = int(input())\nd = int(input())\n\nmove_cnt = float(x / d)\nif (move_cnt <= k):\n k -= move_cnt\n amari = x - move_cnt * d\n\nelse:\n k = 0\n amari = x - move_cnt * d\n\nif (k > 0):\n if (k % 2 == 1):\n if (amari > 0):\n amari -= d\n else:\n amari += d\n\nprint(int(abs(amari)))', 'import sys\n\n# x = abs(int(input()))\n\n# d = int(input())\n\narray = list(map(int, input().strip().split()))\nx = abs(array[0])\nk = array[1]\nd = array[2]\nif (d == 0):\n amari = abs(x)\n\nelse:\n move_cnt = int(x / d)\n if (move_cnt <= k):\n k -= move_cnt\n amari = x - move_cnt * d\n\n else:\n amari = x - k * d\n k = 0\n\n if (k > 0):\n if (k % 2 == 1):\n if (amari > 0):\n amari -= d\n else:\n amari += d\n\nprint(abs(amari))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s124164861', 's599329207', 's293344437']
[9116.0, 9136.0, 9140.0]
[25.0, 26.0, 31.0]
[333, 347, 522]
p02584
u231570044
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.
['IN = list(map(int, input().split()))\nX, K, D = IN[0], IN[1], IN[2]\n\nmv = int(-X / D + 0.5)\nif (abs(mv)>K): mv = mv * K / abs(mv)\nresidual_moves = K - abs(mv)\n\nif residual_moves % 2 == 0:\n print (int(abs(X + D * mv)))\nelse:\n posa = X+D*(mv+1)\n posb = X+D*(mv-1)\n posc = X+D*(mv+2)\n posd = X+D*(mv-2)\n print(int(abs(min(posa, posb, posc, posd))))\n\n \n', 'IN = list(map(int, input().split()))\nX, K, D = IN[0], IN[1], IN[2]\n\n#mv = int(-X / D + 0.5)\nmv = round(-X / D, 0)\nif (abs(mv)>K): mv = mv * K / abs(mv)\nresidual_moves = K - abs(mv)\n\nif residual_moves % 2 == 0:\n print (int(abs(X + D * mv)))\nelse:\n posa = abs(X+D*(mv+1))\n posb = abs(X+D*(mv-1))\n posc = abs(X+D*(mv+2))\n posd = abs(X+D*(mv-2))\n print(int(min(posa, posb, posc, posd)))\n']
['Wrong Answer', 'Accepted']
['s486347934', 's545793144']
[9212.0, 9212.0]
[30.0, 33.0]
[369, 401]
p02584
u233254147
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\ninput = sys.stdin.readline\n\nx, k, d = map(int, input().split())\n\na = abs(x) // d\nb = abs(x) // d + 1\n\nif a > k:\n print(abs(x) - k * d)\nelse:\n if b < a:\n a = b\n\n if (k - a) % 2 == 0:\n print(abs(x) - a * d)\n else:\n print(abs(x) - a * k + d)\n', 'import sys\ninput = sys.stdin.readline\n\nx, k, d = map(int, input().split())\n\na = abs(x) // d\nb = abs(x) // d + 1\n\nif a > k:\n print(abs(x) - k * d)\nelse:\n if b < a:\n a = b\n\n if (k - a) % 2 == 0:\n print(abs(x) - a * d)\n else:\n print(min(abs(abs(x) - a * d + d), abs(abs(x) - a * d - d)))\n']
['Wrong Answer', 'Accepted']
['s859728173', 's128221347']
[9176.0, 9212.0]
[34.0, 27.0]
[283, 318]
p02584
u250734103
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 int(abs(X) / D) > K:\n if abs(X) < abs(X) % D:\n if K % 2 == 0:\n print(abs(X))\n else:\n print(min(abs(X - D), abs(X + D)))\n else:\n if int(K - int(abs(X) / D)) % 2 == 0:\n print(abs(X) % D)\n else:\n print(min(abs(abs(X) % D - D), abs(abs(X) % D + D)))\nelse:\n print(abs(X) - D * K)', 'X, K, D = map(int, input().split())\n\nif int(abs(X) / D) < K:\n if int(K - int(abs(X) / D)) % 2 == 0:\n print(abs(X) % D)\n else:\n print(abs(abs(X) % D - D))\nelse:\n print(abs(X) - D * K)']
['Wrong Answer', 'Accepted']
['s339136443', 's670930957']
[9216.0, 9028.0]
[30.0, 28.0]
[395, 209]
p02584
u252405453
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 abc175c_walking_takahashi():\n x, k, d = map(int, input().split())\n x = -x if x < 0 else x\n num = math.ceil(x / d)\n if num > k:\n print(x-k*d)\n return\n else:\n k -= num\n x -= num*d\n if k % 2 == 0:\n print(abs(x))\n else:\n print(x+d)\nabc175c_walking_takahashi()', 'import math\n\ndef abc175c_walking_takahashi():\n x, k, d = map(int, input().split())\n x = -x if x < 0 else x\n num = math.ceil(x / d)\n if num > k:\n print(x-k*d)\n return\n else:\n k -= num\n x -= num*d\n if k % 2 == 0:\n print(abs(x))\n else:\n print(x+d)\nabc175c_walking_takahashi()\n']
['Runtime Error', 'Accepted']
['s839221750', 's427475012']
[9212.0, 9176.0]
[25.0, 32.0]
[338, 352]
p02584
u258807490
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 = abs(X)\nk = min(X//D,K)\nans -= k*D\nK -= k\nif k % 2 == 0:\n print(ans)\nelse:\n ans += D\n print(ans)\n\n\n', 'X, K, D = map(int,input().split())\nans = abs(X)\nk = min(X//D,K)\nans -= k*D\nK -= k\nif K % 2 == 0:\n print(ans)\nelse:\n ans += D\n print(ans)\n\n\n', 'X, K, D = map(int,input().split())\nans = abs(X)\nrem = K\nk = min(X//D,K)\nans -= k*D\nrem -= k\nif rem > 0:\n if rem % 2 == 1:\n ans = ans - D\n print(abs(ans))\nprint(abs(ans))\n\n', 'X, K, D = map(int,input().split())\nans = abs(X)\nrem = K\nk = min(ans//D,K)\nans -= k*D\nrem -= k\nif rem > 0:\n if rem % 2 == 1:\n ans = ans - D\n print(abs(ans))\nprint(abs(ans))\n\n', 'X, K, D = map(int,input().split())\nans = abs(X)\nrem = K\nk = min(ans//D,K)\nans -= k*D\nrem -= k\nif rem > 0:\n if rem % 2 == 1:\n ans = ans - D\n # print(abs(ans))\nprint(abs(ans))\n\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s025059112', 's281014190', 's716456310', 's846059788', 's506909172']
[9024.0, 8976.0, 9128.0, 9104.0, 9076.0]
[29.0, 29.0, 29.0, 32.0, 29.0]
[148, 148, 188, 190, 192]
p02584
u272754211
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\nx = abs(x)\n\nmod = x % d\n\nif mod >= k:\n ans = x - (d*k)\n\nelif (k-mod) % 2 == 0:\n ans = x - (d*mod)\n\nelse:\n ans = x - (d*mod) - d\n\nprint(ans)', 'x,k,d = list(map(int,input().split()))\n\nx = abs(x)\n\nm = x // d\n\nif m >= k:\n ans = x - (d*k)\n\nelif (k-m) % 2 == 0:\n ans = x - (d*m)\n\nelse:\n ans = x - (d*m) - d\n\nprint(abs(ans))']
['Wrong Answer', 'Accepted']
['s220660391', 's371262655']
[9160.0, 9176.0]
[30.0, 28.0]
[188, 184]
p02584
u276941198
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)\nmin_pos = X%D\nmin_neg = min_pos - D\n\nif(X/D > K):\n print(X-D*K)\nelse:\n if(int(X/D)%2 == 0):\n print(int(X/D))\n print("A", min_pos)\n else:\n print(int(X/D))\n print("B", abs(min_neg))', 'X, K, D = map(int, input().split())\n\nX= abs(X)\nmin_pos = X%D\nmin_neg = min_pos - D\n\nif(X/D >= K):\n print(X-D*K)\nelse:\n if((K - (X-min_pos)/D)%2 == 0):\n print(min_pos)\n else:\n print(abs(min_neg))\n ']
['Wrong Answer', 'Accepted']
['s836659141', 's871595845']
[9060.0, 9164.0]
[29.0, 27.0]
[241, 208]
p02584
u285891772
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, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left, insort, insort_left\nfrom heapq import heappush, heappop\nfrom functools import reduce, lru_cache\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 TUPLE(): return tuple(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#mod = 998244353\nfrom decimal import *\n#import numpy as np\n#decimal.getcontext().prec = 10\n\nX, K, D = MAP()\n\nif X == 0:\n\tif K%2 == 0:\n\t\tprint(0)\n\telse:\n\t\tprint(D)\n\texit()\n\nif K - abs(X)//D*D <= 0:\n\tif X < 0:\n\t\tprint(X+D*K)\n\telse:\n\t\tprint(X-D*K)\n\texit()\n\n\nK -= abs(X)//D\nif X < 0:\n\tX += D*(abs(X)//D)\nelse:\n\tX -= D*(abs(X)//D)\n\n\nif K%2 == 0:\n\tprint(X)\nelse:\n\tif X <= 0:\n\t\tprint(X+D)\n\telse:\n\t\tprint(abs(X-D))\n\n", "import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left, insort, insort_left\nfrom heapq import heappush, heappop\nfrom functools import reduce, lru_cache\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 TUPLE(): return tuple(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#mod = 998244353\nfrom decimal import *\n#import numpy as np\n#decimal.getcontext().prec = 10\n\nX, K, D = MAP()\n\nif X == 0:\n\tif K%2 == 0:\n\t\tprint(0)\n\telse:\n\t\tprint(D)\n\texit()\n\nflg = X//abs(X)\nn = abs(X)//D\n\nif abs(X-n*D*flg) > abs(X-(n+1)*D*flg):\n\tn += 1\n\nif K <= n:\n\tprint(abs(X-K*D*flg))\n\texit()\n\nX -= flg*n*D\nif X == 0:\n\tflg = 1\nelse:\n\tflg = X//abs(X)\nK -= n\n\nif K%2 == 0:\n\tprint(abs(X))\nelse:\n\tprint(abs(X-flg*D))"]
['Wrong Answer', 'Accepted']
['s126455383', 's606819272']
[10568.0, 10540.0]
[45.0, 43.0]
[1304, 1309]
p02584
u298976461
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 x >= k * d:\n print(x - k * d)\n else:\n func(x, k, d)\n \n \n \n # print(mod)\n # else:\n # print(abs(mod - d))\nelse:\n if abs(x) >= k * d:\n print(abs(x) - k * d)\n else:\n func(x, k, d)\n \n \n \n # print(mod)\n # else:\n # print(abs(mod - d))\n\n\ndef func(x, k, d):\n q, mod = divmod(abs(x), d)\n k -= q\n if k % 2 == 0:\n print(mod)\n else:\n print(abs(mod - d))\n', 'x, k, d = map(int, input().split())\n\nif x >= 0:\n if x >= k * d:\n print(x - k * d)\n else:\n func(x, k, d)\n \n \n \n # print(mod)\n # else:\n # print(abs(mod - d))\nelse:\n if abs(x) >= k * d:\n print(abs(x) - k * d)\n else:\n func(x, k, d)\n \n \n \n # print(mod)\n # else:\n # print(abs(mod - d))\n\n\ndef func(x, k, d):\n q, mod = divmod(abs(x), d)\n k -= q\n if k % 2 == 0:\n print(mod)\n else:\n print(abs(mod - d))\n return 0\n', 'x, k, d = map(int, input().split())\n\n# if x == 0:\n\n# print(0)\n# else:\n# print(d)\nelif x >= 0:\n if x >= k * d:\n print(x - k * d)\n else:\n q, mod = divmod(x, d)\n k -= q\n if k % 2 == 0:\n print(mod)\n else:\n print(abs(mod - d))\nelif x < 0:\n if abs(x) >= k * d:\n print(abs(x + k * d))\n else:\n q, mod = divmod(abs(x), d)\n k -= q\n if k % 2 == 0:\n print(mod)\n else:\n print(abs(mod - d))\n', 'x, k, d = map(int, input().split())\n\nif abs(x) >= k * d:\n print(abs(x) - k * d)\nelse:\n q, mod = divmod(x, d)\n if (k - q) % 2 == 0:\n print(mod)\n else:\n print(abs(mod - d))\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s001953276', 's134555516', 's266517052', 's467947512']
[9128.0, 9104.0, 9024.0, 9092.0]
[36.0, 27.0, 26.0, 39.0]
[658, 671, 543, 197]
p02584
u304058693
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\nans = 0\nif x == 0:\n if k%2 == 0:\n ans = 0\n elif k%2 == 0:\n ans = abs(d)\nelse :\n if abs(x) - k*d >= 0:\n ans = x - k*d\n #if abs(x) - k*d == 0:\n \n \n #else:\n \n elif abs(x) - k*d < 0:\n if abs(x) - d*(abs(x) // d) != 0:\n if (k - (math.ceil(abs(x) / d) )) % 2 == 1:\n ans = abs(abs(x) - d*(abs(x) // d))\n else:\n ans = (abs(x) - d*(abs(x) // d + 1))\n else:\n if (k - (math.ceil(abs(x) // d) ) ) % 2 == 1:\n ans = d\n else:\n ans = 0\nprint(ans)\n', 'x, k ,d = map(int, input().split())\n\nx = abs(x)\ny = k * d\nans = x + d\nif(x > y):\n ans = min(ans , x - y)\nelse:\n mar = x % d\n if (x // d) % 2 == (k % 2):\n ans = min(ans , mar)\n else:\n ans = min(ans , abs(d - mar))\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s614914413', 's588339541']
[9152.0, 9200.0]
[36.0, 32.0]
[746, 250]
p02584
u310286716
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 -*-\nx, k, d = map(int, input().split())\nx = abs(x)\nt = x // d\nif t >= k:\n answer = x - (t * d)\nelse:\n if (k - t) % 2 == 0:\n answer = x - (t * d)\n else:\n answer = x - (t - 1) * d\n \nprint(answer)', '# -*- coding: utf-8 -*-\nx, k, d = map(int, input().split())\nx = abs(x)\nt = x // d\nif t >= k:\n answer = x - (k * d)\nelse:\n if (k - t) % 2 == 0:\n answer = x - (t * d)\n else:\n answer = x - (t - 1) * d\n \nprint(answer)', '# -*- coding: utf-8 -*-\nx, k, d = map(int, input().split())\nx = abs(x)\nt = x // d\nif t >= k:\n answer = x - (k * d)\nelse:\n if (k - t) % 2 == 0:\n answer = x - (t * d)\n else:\n answer = x - (t + 1) * d\n \nprint(abs(answer))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s195872399', 's715267491', 's855270708']
[9176.0, 9180.0, 9160.0]
[31.0, 32.0, 29.0]
[243, 243, 248]
p02584
u313445895
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)\ns = x//d\nelif s>k:\n print(x-d*k)\nelif s<k:\n if (k-s)%2==0:\n print(x-d*s)\n elif (k-s)%2==1:\n print(abs(x-d*(s+1)))', 'x, k, d = map(int, input().split())\nend = False\nplus =True\nif x >= 0:\n for i in range(k):\n if x >= 0 and plus == False:\n if (k-(i+1))%2 == 1:\n print(abs(x))\n end = True\n break\n elif (k-(i+1))%2 == 0:\n print(abs(x-d))\n end = True\n break\n elif x >= 0:\n x=x-d\n elif x < 0:\n x=x+d\n plus = False\nif x < 0:\n for i in range(k):\n if x < 0 and plus == False:\n if (k-(i+1))%2 == 1:\n print(abs(x))\n end = True\n break\n elif (k-(i+1))%2 == 0:\n print(abs(x-d))\n end = True\n break\n elif x >= 0:\n x=x-d\n plus = False\n elif x < 0:\n x=x+d\nif end == False:\n print(x)', 'x, k, d = map(int, input().split())\nminus=False\nif x<0:\n minus = True\nx = abs(x)\ns = x//d\nif s==0:\n k%2==0:\n if minus==True\n print(-x)\n else: print(x)\n k%2==1:\n if minus==True\n print(-x+d)\n else: print(x-d)\nelif s>k:\n if minus==True\n print(x-d*k)\n else: print(-x+d*k)\nelif s<k:\n (k-s)%2==0:\n if minus==True\n print(-x+d*s)\n else: print(x-d*s)\n (k-s)%2==1:\n if minus==True\n print(-x+d*(s+1))\n else: print(x-d*(s+1))', 'x, k, d = map(int, input().split())\nx = abs(x)\ns = x//d\nif s>k:\n print(x-d*k)\nelif s<=k:\n if (k-s)%2==0:\n print(x-d*s)\n elif (k-s)%2==1:\n print(abs(x-d*(s+1)))']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s544986957', 's619330145', 's993271205', 's671204584']
[9008.0, 9140.0, 8796.0, 9120.0]
[26.0, 2206.0, 28.0, 30.0]
[183, 888, 541, 182]
p02584
u321605735
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\nN=input().split()\nX=int(math.fabs(int(N[0])))\nK=int(N[1])\nD=int(N[2])\nif X-K*D>=0:\n print(X-K*D)\nelse:\n x=X%D\n y=X-X%D\n ans_pre=min(x,y)\n i=int((X-ans_pre)/D)\n if i%2==K%2:\n print(ans_pre)\n else:\n print(max(x,y))', 'import math\nN=input().split()\nX=int(math.fabs(int(N[0])))\nK=int(N[1])\nD=int(N[2])\nif X-K*D>=0:\n print(X-K*D)\nelse:\n x=X%D\n y=X-X%D\n a=int((X-x)/D)\n b=int((X-y)/D)\n if K%2==0:\n if a%2==0:\n print(x)\n else:\n print(y)\n else:\n if a%2==1:\n print(x)\n else:\n print(y)', 'import math\nN=input().split()\nX=int(math.fabs(int(N[0])))\nK=int(N[1])\nD=int(N[2])\nif X-K*D>=0:\n print(X-K*D)\nelse:\n syou=X//D\n x=X-syou*D\n y=X-(syou+1)*D\n if K%2==0:\n if syou%2==0:\n print(x)\n else:\n print(int(math.fabs(y)))\n else:\n if syou%2==0:\n print(int(math.fabs(y)))\n else:\n print(x)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s284906975', 's853277564', 's751377666']
[9228.0, 9052.0, 9212.0]
[32.0, 34.0, 32.0]
[259, 352, 378]
p02584
u325492232
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 abc175_c_1():\n x, k, d = map(int, input().split())\n\n def solve(x, k, d):\n to_l_max = x - (k * d)\n to_r_max = x + (k * d)\n\n if to_l_max > 0:\n return to_l_max\n if to_r_max < 0:\n return to_r_max\n\n current_x = x\n\n for i in range(k):\n current_x = min(abs(current_x + d), abs(current_x - d))\n print(current_x)\n\n ans = solve(x, k, d)\n print(ans)\n\nif __name__ == '__main__':\n abc175_c_1()", "def abc175_c_3():\n x, k, d = map(int, input().split())\n\n def solve(x, k, d):\n \n\n x = abs(x)\n\n straight = int(min(k, x / d))\n k -= straight\n x -= straight * d\n\n if k % 2 == 0:\n return x\n else:\n return abs(x - d)\n\n ans = solve(x, k, d)\n print(ans)\n\nif __name__ == '__main__':\n abc175_c_3()"]
['Wrong Answer', 'Accepted']
['s626394726', 's914486296']
[9076.0, 9116.0]
[2206.0, 28.0]
[481, 444]
p02584
u329730886
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\nn = X // D\nm = K - n\n\nA1 = abs(X - n*D)\nA2 = abs(X - (n+1)*D)\n\nAns = A2\n\nif m > 1:\n if A1 <= A2:\n if m % 2 == 0:\n Ans = A1\n else:\n if m-1 % 2 != 0:\n Ans = A2\nelse:\n Ans = X - K*D\n\nprint(Ans)', 'X, K, L = map(int, input().split())\nmin_dist = inf\nfor p_num in range(K+1):\n dist = L*p_num + (-1)*L*(K-p_num)\n if dist < min_dist:\n min_dist = dist\nprint(min_dist)\n', 'X, K, D = map(int, input().split())\n\nX = abs(X)\n\nn = X // D\nm = K - n\n\nA1 = abs(X - n*D)\nA2 = abs(X - (n+1)*D)\n\nAns = A2\n\nif n+1 < K:\n if (A1 < A2 and m % 2 == 0) or (A1 > A2 and m % 2 != 0):\n Ans = A1\nelse:\n Ans = X - K*D\n\nprint(Ans)', 'X, K, D = map(int, input().split())\n\nX = abs(X)\n\nn = X // D\nm = K - n\n\nA1 = abs(X - n*D)\nA2 = abs(X - (n+1)*D)\n\nAns = A2\n\nif m > 1:\n if A1 <= A2:\n if m % 2 == 0:\n Ans = A1\n else:\n if m-1 % 2 != 0:\n Ans = A2\nelse:\n Ans = X - K*D\n\nprint(Ans)', 'X, K, D = map(int, input().split())\n\nX = abs(X)\n\nn = X // D\nm = K - n\n\nA1 = abs(X - n*D)\nA2 = abs(X - (n+1)*D)\n\nAns = A2\n\nif m > 1:\n if A1 <= A2:\n if m % 2 == 0:\n Ans = A1\n else:\n if m % 2 == 0:\n Ans = A1\nelse:\n Ans = abs(X - K*D)\n\nprint(Ans)\n ']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s339766868', 's356559325', 's461572533', 's727795320', 's464402054']
[9144.0, 9028.0, 9200.0, 9120.0, 9096.0]
[28.0, 29.0, 36.0, 31.0, 29.0]
[284, 178, 251, 284, 289]
p02584
u335406314
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(' '))))\ndX = np.arange(-K,K+1,2)\nnew_X = X + D * dX\nprint(np.min(np.abs(new_X)))", "import numpy as np\nX, K, D = (list(map(int, input('').split(' '))))\nX = np.abs(X)\n\nif np.abs(X)/D <= K:\n new_K = K - int(X/D)\n new_X = X - D*int(X/D)\n if new_K%2==0:\n print(new_X)\n else:\n print(np.abs(new_X-D))\nelse:\n print(np.abs(X-D*K))"]
['Runtime Error', 'Accepted']
['s634934699', 's474859965']
[9128.0, 27020.0]
[24.0, 123.0]
[121, 267]
p02584
u344888046
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 X < 0:\n X = -X\nk = X // D\nX -= K * D\nif k >= K:\n print(abs(X))\nelse:\n K -= k\n if K % 2 == 0:\n print(abs(X))\n else:\n print(abs(X - D))', 'X, K, D = map(int, input().split())\nif X < 0:\n X = -X\nk = X // D\nif k >= K:\n X -= K * D\n print(abs(X))\nelse:\n X -= k * D\n K -= k\n if K % 2 == 0:\n print(abs(X))\n else:\n print(abs(X - D))']
['Wrong Answer', 'Accepted']
['s526836326', 's248075067']
[9172.0, 9072.0]
[33.0, 37.0]
[201, 220]
p02584
u345621867
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 = map(int, input().split())\nP = list(map(int, input().split()))\nC = list(map(int, input().split()))\n\nans = -float('inf')\nfor s in range(N):\n ### Step1\n S = [] \n \n i = P[s] - 1\n S.append(C[i])\n \n while i != s:\n i = P[i] - 1\n S.append(S[-1] + C[i])\n\n \n \n if K <= len(S):\n score = max(S[:K])\n \n elif S[-1] <= 0:\n score = max(S)\n \n else:\n \n score1 = S[-1] * (K // len(S) - 1)\n score1 += max(S)\n \n score2 = S[-1] * (K // len(S))\n r = K % len(S)\n if r != 0:\n score2 += max(0, max(S[:r]))\n \n score = max(score1, score2)\n\n ans = max(ans, score)\n\nprint(ans)", 'X, K, D = map(int,input().split())\nres = 0\nX = abs(X)\nif X >= K * D:\n res = X - K * D\nelse:\n i = X // D\n j = K - i\n if j % 2 == 0:\n res = X - D * i\n else:\n res = X - D * (i + 1)\nprint(abs(res))']
['Runtime Error', 'Accepted']
['s350071092', 's322417178']
[9296.0, 9188.0]
[25.0, 29.0]
[1369, 222]
p02584
u346207191
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())\nx=abs(X)\na=x//D\n\nb=x-a*D\nB=abs(x-(a+1)*D)\n\nif b>B:\n a=a+1\n\nif a>=K:\n print(abs(x-K*D))\n\nelse:\n c=K-a\n if c%2 == 0:\n print(abs(x-a*D))\n elif:\n d=abs(x-(a-1)*D)\n e=abs(x-(a+1)*D)\n print(min(d,e))', 'X,K,D=(int(x) for x in input().split())\nx=abs(X)\na=x//D\n\nb=x-a*D\nB=abs(x-(a+1)*D)\n\nif b>B:\n a=a+1\n\nif a>=K:\n print(abs(x-K*D))\n\nelse:\n c=K-a\n if c%2 == 0:\n print(abs(x-a*D))\n else:\n d=abs(x-(a-1)*D)\n e=abs(x-(a+1)*D)\n print(min(d,e))']
['Runtime Error', 'Accepted']
['s818093482', 's992049953']
[8868.0, 9200.0]
[28.0, 30.0]
[250, 250]
p02584
u348137609
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()\nans = 0\nif abs(x) > abs(k*d):\n ans = abs(x) - abs(k*d)\nelse:\n kaisuu = abs(x)/d \n k_2 = k - kaisuu\n if k_2/2 == 2:\n ans = abs(x) - d*kaisuu \n else:\n ans = (abs(x) - d*kaisuu) - d\nprint(ans)\n', 'x,k,d = input().split()\nx = int(x)\nk = int(k)\nd = int(d)\nans = 0\nif abs(x) > abs(k*d):\n ans = abs(x) - abs(k*d)\nelse:\n kaisuu = abs(x)/d\n k_2 = k - kaisuu\n if k_2/2 == 2:\n ans = abs(x) - d*kaisuu \n else:\n ans = (abs(x) - d*kaisuu) - d\nprint(ans)\n', 'x,k,d = input().split()\nx = int(x)\nk = int(k)\nd = int(d)\nans = 0\nif abs(x) >= abs(k*d):\n ans = abs(x) - abs(k*d)\nelse:\n kaisuu = abs(x)/d\n k_2 = k - kaisuu\n if k_2/2 == 0:\n ans = abs(x) - d*kaisuu \n else:\n ans = abs((abs(x) - d*kaisuu) - abs(d))\nprint(int(ans))\n', 'x,k,d = input().split()\nx = int(x)\nk = int(k)\nd = int(d)\nans = 0\nif abs(x) >= abs(k*d):\n ans = abs(x) - abs(k*d)\nelse:\n kaisuu = abs(x)/d\n k_2 = k - kaisuu\n if k_2/2 == 0:\n ans = abs(x) - d*kaisuu \n else:\n ans = abs((abs(x) - d*kaisuu) - abs(d))\nprint(ans)\n', 'x,k,d = input().split()\nx = int(x)\nk = int(k)\nd = int(d)\nans = 0\nif abs(x) > abs(k*d):\n ans = abs(x) - abs(k*d)\nelse:\n kaisuu = abs(x)/d\n k_2 = k - kaisuu\n if k_2/2 == 0:\n ans = abs(x) - d*kaisuu \n else:\n ans = (abs(x) - d*kaisuu) - d\nprint(ans)\n', 'x,k,d = input().split()\nx = int(x)\nk = int(k)\nd = int(d)\nans = 0\nif abs(x) >= abs(k*d):\n ans = abs(x) - abs(k*d)\nelse:\n kaisuu = int(abs(x)/d)\n k_2 = k - kaisuu\n if k_2%2 == 0:\n ans = abs(x) - d*kaisuu \n else:\n ans = abs((abs(x) - d*kaisuu) - abs(d))\nprint(int(ans))']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s077391343', 's330472226', 's389426193', 's748381021', 's763318376', 's907277541']
[9056.0, 9132.0, 9096.0, 9140.0, 9188.0, 9220.0]
[30.0, 30.0, 30.0, 30.0, 28.0, 26.0]
[244, 276, 292, 287, 276, 296]
p02584
u354174235
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.
['param_x, param_k, param_d = map(int, input().split())\n\nparam_x_tmp = param_x\n\nif param_x > 0:\n int_times_nega_posi = -1\nelse:\n int_times_nega_posi = 1\n\ncount = 0\nwhile param_x_tmp*param_x > 0:\n \n param_x_tmp = param_x_tmp + param_d*int_times_nega_posi\n \n count = count + 1\n \n if param_k - count == 0:\n print(param_x_tmp*int_times_nega_posi*-1)\n\nif count < param_k:\n int_move = param_k - count \n int_move_devide_2_no_amari = int_move % 2\n print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi*-1))', 'param_x, param_k, param_d = map(int, input().split())\n\nparam_x_tmp = param_x\n\nif param_x > 0:\n int_times_nega_posi = -1\nelse:\n int_times_nega_posi = 1\n \nif (param_x*int_times_nega_posi*-1) - (param_k*param_d) > 0:\n print((param_x*int_times_nega_posi*-1) - (param_k*param_d))\n \nelse:\n int_time_before_cross_0 = int((param_x*int_times_nega_posi*-1) / param_d)\n # print(int_time_before_cross_0)\n \n param_x_tmp = param_x + int_time_before_cross_0*param_d*int_times_nega_posi\n # print(param_x_tmp)\n \n int_move = param_k - int_time_before_cross_0 \n int_move_devide_2_no_amari = int_move % 2\n print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi))\n \n #count = 0\n \n # \n \n # \n # count = count + 1\n # \n # if param_k - count == 0:\n # print(abs(param_x_tmp))\n #\n #if count < param_k:\n # int_move = param_k - count \n # int_move_devide_2_no_amari = int_move % 2\n ']
['Wrong Answer', 'Accepted']
['s273027769', 's895939615']
[9200.0, 9088.0]
[2205.0, 31.0]
[546, 1110]
p02584
u355853184
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\nans_list = []\n\nif X+K*D <= 0:\n ans = abs(X+K*D)\nelse:\n if D>0:\n a = int((X+K*D)/(2*D))\n ans = abs(X+(K-(a+i))*D - (a+i)*D)\nprint(ans)', 'X, K, D = map(int, input().split())\n\nans_list = []\n\nif X+K*D <= 0:\n ans = abs(X+K*D)\nelse:\n if D>0:\n a = int((X+K*D)/(2*D))\n ans = abs(X+(K-a)*D - a*D)\nprint(ans)', 'X, K, D = map(int, input().split())\nans_list = []\n\nif X+K*D <= 0:\n ans = abs(X+K*D)\nelse:\n a = (X+K*D)//(2*D)\n if a >= K:\n a = K\n ans = abs(X-K*D)\n else:\n ans_1 = abs(X+K*D-2*a*D)\n ans_2 = abs(X+K*D-2*(a+1)*D)\n ans = min(ans_1, ans_2)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s501637863', 's572232063', 's727523908']
[9016.0, 9004.0, 9184.0]
[30.0, 30.0, 29.0]
[194, 186, 292]
p02584
u363207161
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\ndef is_even(num):\n if num % 2 == 0:\n return True\n else:\n return False\n\n\nans = 0\n\nif 2 * x < d:\n ans = x\nelse:\n t = x // d\n if k > t - 2:\n if (k - t) / 2 == 0:\n t0 = abs(x - (t - 2) * d)\n t1 = abs(x - (t) * d)\n t2 = abs(x - (t + 2) * d)\n ans = min(t0, min(t1, t2))\n else:\n t0 = abs(x - (t - 1) * d)\n t2 = abs(x - (t + 1) * d)\n ans = min(t0, min(t1, t2))\n else:\n ans = abs(x- (k) * d)\n\nprint(ans)\n', 'x, k, d = map(int, input().split())\n\nx = abs(x)\n\nans = 0\n\nt = x // d\ns = x % d\n\nif abs(x) > k * d:\n print(abs(x) - k * d)\nelif t % 2 == k % 2:\n print(s)\nelse:\n print(d - s)\n']
['Runtime Error', 'Accepted']
['s569992805', 's945390395']
[9120.0, 9068.0]
[37.0, 31.0]
[561, 182]
p02584
u363320559
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)\nE=X%D\nA=(X-E)/D\nA=K-A\nif X>=K*D:\n print(X-K*D)\neise:\n E=X%D\n A=(X-E)/D\n A=K-A\n A=A%2\n if A==0:\n print(E)\n eise:\n print(D-E)\n', 'X,K,D=map(int,input().split())\nX=abs(X)\nE=X%D\nA=(X-E)/D\nA=K-A\nif X>=K*D:\n print(X-K*D)\nelse:\n E=X%D\n A=(X-E)/D\n A=K-A\n A=A%2\n if A==0:\n print(E)\n else:\n print(D-E)\n']
['Runtime Error', 'Accepted']
['s102320704', 's601491320']
[9036.0, 9188.0]
[24.0, 31.0]
[177, 177]
p02584
u363421241
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 d*k < x:\n print(abs(x)-abs(d*k))\nelse:\n if abs(x%d-d) > abs(x%d):\n if (k-x//d)%2 == 0:\n print(abs(x%d))\n else:\n print(abs(x%d-d))\n elif abs(x%d-d) < abs(x%d)\n if (k-x//(d+1))%2 == 0:\n print(abs(x%d-d))\n else:\n print(abs(x%d))\n', 'x, k, d = map(int, input().split())\nx = abs(x)\n\nif d*k < x:\n print(abs(x)-abs(d*k))\nelse:\n if abs(x%d-d) > abs(x%d):\n if (k-x//d)%2 == 0:\n print(abs(x%d))\n else:\n print(abs(x%d-d))\n elif abs(x%d-d) < abs(x%d):\n if (k-x//(d+1))%2 == 0:\n print(abs(x%d-d))\n else:\n print(abs(x%d))', 'x, k, d = map(int, input().split())\nx = abs(x)\n\nif d*k < x:\n print(x-d*k)\nelse:\n if (k-x//d)%2 == 0:\n print(x%d)\n else:\n print(abs(x%d-d))']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s594273490', 's850544480', 's862531517']
[8960.0, 9204.0, 9172.0]
[29.0, 29.0, 29.0]
[358, 358, 161]
p02584
u367323774
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(int(x))\nk=int(k)\nd=int(d)\na=x//d\nb=x-a*d\nc=(x-b)/d\ni=int(c)\nif k<=i:\n print(abs(x)-d*k)\n print('a')\nelse:\n if (k-(i))%2==0:\n print(abs(x)-d*(i))\n print('b')\n else:\n print(abs(abs(x)-d*(i+1)))\n print('c')", 'x,k,d=input().split()\nx=int(x)\nk=int(k)\nd=int(d)\na=x//d\nb=x-a*d\nc=(x-b)/d\nprint(int(c))\ni=int(c)\nif k<=i:\n print(abs(x)-d*k)\nelse:\n if (k-(i))%2==0:\n print(abs(x)-d*(i))\n else:\n print(abs(abs(x)-d*(i+1)))', 'x,k,d=input().split()\nx=abs(int(x))\nk=int(k)\nd=int(d)\na=x//d\nb=x-a*d\nc=(x-b)/d\ni=int(c)\nif k<=i:\n print(abs(x)-d*k)\nelse:\n if (k-(i))%2==0:\n print(abs(x)-d*(i))\n else:\n print(abs(abs(x)-d*(i+1)))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s748635918', 's790176028', 's157881356']
[9076.0, 9112.0, 9208.0]
[29.0, 36.0, 30.0]
[247, 213, 204]
p02584
u372802746
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 D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif D<X and K*D<X:\n ans=X-K*D\nelse:\n if X<K*D-X:\n ans=X\n for i in range(0,K):\n ans=ans-D\n if ans<0 and (K-i)%2==0:\n ans=ans+D\n break\n elif ans<0 and (K-i)%2==1:\n ans=-ans\n break\n else:\n ans=K*D-X\n for i in range(0,K):\n ans=ans+D\n if ans>0 and (K-i)%2==0:\n ans=-ans+D\n break\n elif ans>0 and (K-i)%2==1:\n ans=ans\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif D<X and K*D<X:\n ans=X-K*D\nelse:\n if X<K*D-X:\n ans=X\n for i in range(0,K):\n ans=ans-D\n if ans<0 and (K-i)%2==0:\n ans=ans+D\n break\n elif ans<0 and (K-i)%2==1:\n ans=-ans\n break\n else:\n ans=K*D-X\n for i in range(0,K):\n ans=ans+D\n if ans>0 and (K-i)%2==0:\n ans=-ans+D\n break\n elif ans>0 and (K-i)%2==1:\n ans=ans\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif D<X and K*D<X:\n ans=X-K*D\nelse:\n X=X%D\n ans=min(X,K-X)\n for i in range(0,K):\n ans=ans-1\n if ans<0 and (K-i)%2==0:\n ans=(ans+1)*D\n break\n elif ans<0 and (K-i)%2==1:\n ans=(-ans)*D\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif D<X and K*D<X:\n ans=X-K*D\nelse:\n if X<K*D-X:\n ans=X\n for i in range(0,K):\n ans=ans-D\n if ans<0 and (K-i)%2==0:\n ans=ans+D\n break\n elif ans<0 and (K-i)%2==1:\n ans=-ans\n break\n else:\n ans=K*D-X\n for i in range(0,K):\n ans=ans-D\n if ans<0 and (K-i)%2==0:\n ans=ans-D\n break\n elif ans<0 and (K-i)%2==1:\n ans=-ans\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif D<X and K*D<X:\n ans=X-K*D\nelse:\n ans=min(X,K*D-X)%D\n for i in range(0,K):\n ans=ans-1\n if ans<0 and (K-i)%2==0:\n ans=(ans+1)*D\n break\n elif ans<0 and (K-i)%2==1:\n ans=(-ans)*D\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif X==0 and K%2==0:\n ans=0\nelif X==0 and K%2==1:\n ans=D\nelif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif X>0 and D<X :\n if K*D<X:\n ans=X-K*D\n else:\n for i in range(0,K):\n if X-i*D<0:\n if (K-i)%2==0:\n ans=X-(i-1)*D\n break\n else:\n ans=i*D-X\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif D<X and K*D<X:\n ans=X-K*D\nelse:\n ans=min(X,K*D-X)%D\n for i in range(0,K):\n ans=ans-1\n if ans<0 and (K-i)%2==0:\n ans=ans+1\n ans=ans*D\n break\n elif ans<0 and (K-i)%2==1:\n ans=-ans*D\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif X==0 and K%2==0:\n ans=0\nelif X==0 and K%2==1:\n ans=D\nelif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif X>0 and D<X :\n if K*D<X:\n ans=X-K*D\n else:\n for i in range(1,K):\n if X-i*D<0:\n if (K-i)%2==0:\n ans=X-(i-1)*D\n break\n else:\n ans=i*D-X\n break\nprint(ans)', 'X, K, D = map(int, input().split())\nX=abs(X)\nif D>=X and K%2==0:\n ans=X\nelif D>=X and K%2==1:\n ans=D-X\nelif D<X and K*D<X:\n ans=X-K*D\nelse:\n ans=X%D\n if (X-ans)%2!=K%2:\n ans=D-ans\nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s192225967', 's212171122', 's318783527', 's480976182', 's502189932', 's568960721', 's615748032', 's872165550', 's864999346']
[9268.0, 9060.0, 9140.0, 9244.0, 9120.0, 9204.0, 9036.0, 9160.0, 9120.0]
[2206.0, 28.0, 2206.0, 2206.0, 2206.0, 2206.0, 2205.0, 2206.0, 27.0]
[661, 637, 386, 661, 380, 466, 396, 466, 212]
p02584
u376324032
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(input()) for i in range(3)]\nprint(2)', 'X,K,D = list(map(int, input().split()))\nco,ans = divmod(abs(X),D)\nif (K - co) > 0:\n if (K - co) % 2 == 0:\n pass\n else:\n ans = abs(ans) - D\nelse:\n ans = abs(X) - K*D\n\nprint(abs(ans))']
['Runtime Error', 'Accepted']
['s392810096', 's072826865']
[9108.0, 9148.0]
[26.0, 30.0]
[49, 204]
p02584
u388862071
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 = int(input())\nk = int(input())\nd = int(input())\n\nif ((k * d) > abs(x)):\n y = x // d\n if ((k - y) % 2 == 0):\n ans = abs(x) - y * d\n else:\n ans = abs(x - (x // abs(x)) * (y + 1) * d)\nelse:\n ans = abs(x) - k * d\n\n\nprint(ans)', '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\n\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s892776127', 's550085409']
[9196.0, 9180.0]
[27.0, 31.0]
[250, 346]
p02584
u392361133
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 ans1 = x % d\n check = x // d\n ans2 = ans1 - d\n if((k-check%2)==0):\n print(ans1)\n else:\n print(ans2)\n', 'x, k, d= map(int, input().split())\nx = abs(x)\nif x - k * d >= 0:\n print(x - k * d)\nelse:\n ans1 = x % d\n check = x // d\n ans2 = ans1 - d\n if(check%2==k%2):\n print(ans1)\n else:\n print(ans2)\n', 'x, k, d= map(int, input().split())\nx = abs(x)\nif x - k * d >= 0:\n print(x - k * d)\nelse:\n ans1 = x % d\n check = x // d\n ans2 = ans1 - d\n if((k-check)%2==0):\n print(ans1)\n else:\n print(ans2)\n', 'x, k, d= map(int, input().split())\nx = abs(x)\nif x - k * d >= 0:\n print(x - k * d)\nelse:\n ans1 = x % d\n check = x // d\n ans2 = ans1 - d\n if((k-check)%2==0):\n print(ans1)\n else:\n print(abs(ans2))\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s582010268', 's620931553', 's661409837', 's088387219']
[9104.0, 9068.0, 9008.0, 9096.0]
[32.0, 30.0, 34.0, 32.0]
[222, 220, 222, 227]
p02584
u402629484
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\nsys.setrecursionlimit(1000000000)\nimport math\nfrom math import gcd\ndef lcm(a, b): return a * b // gcd(a, b)\nfrom itertools import count, permutations, combinations, chain, product\nfrom functools import lru_cache\nfrom collections import deque, defaultdict\nfrom operator import itemgetter\nfrom pprint import pprint\nii = lambda: int(input())\nmis = lambda: map(int, input().split())\nlmis = lambda: list(mis())\nINF = float('inf')\nN1097 = 10**9 + 7\nDEBUG = sys.argv[-1]!='ONLINE_JUDGE'\n\ndef meg(f, ok, ng):\n while abs(ok-ng)>1:\n mid = (ok+ng)//2\n if f(mid):\n ok=mid\n else:\n ng=mid\n return ok\n\ndef get_inv(n, modp):\n return pow(n, modp-2, modp)\n\ndef factorials_list(n, modp): # 10**6\n fs = [1]\n for i in range(1, n+1):\n fs.append(fs[-1] * i % modp)\n return fs\n\ndef invs_list(n, fs, modp): # 10**6\n invs = [get_inv(fs[-1], modp)]\n for i in range(n, 1-1, -1):\n invs.append(invs[-1] * i % modp)\n invs.reverse()\n return invs\n\ndef comb(n, k, modp):\n num = 1\n for i in range(n, n-k, -1):\n num = num * i % modp\n den = 1\n for i in range(2, k+1):\n den = den * i % modp\n return num * get_inv(den, modp) % modp\n\ndef comb_from_list(n, k, modp, fs, invs):\n return fs[n] * invs[n-k] * invs[k] % modp\n\n#\n\nclass UnionFindEx:\n def __init__(self, size):\n \n self.roots = [-1] * size\n def getRootID(self, i):\n r = self.roots[i]\n if r < 0: \n return i\n else:\n r = self.getRootID(r)\n self.roots[i] = r\n return r\n def getGroupSize(self, i):\n return -self.roots[self.getRootID(i)]\n def connect(self, i, j):\n r1, r2 = self.getRootID(i), self.getRootID(j)\n if r1 == r2:\n return False\n if self.getGroupSize(r1) < self.getGroupSize(r2):\n r1, r2 = r2, r1\n self.roots[r1] += self.roots[r2] \n self.roots[r2] = r1\n return True\n\nYes = 'Yes'\nNo = 'No'\n\ndef dprint(*args, **kwargs):\n if DEBUG:\n print(*args, **kwargs)\n\ndef main():\n X,K,D=mis()\n X = abs(X)\n ZP = X%D\n if abs(X - ZP)//D > K:\n dprint('too far')\n print(X - D*K)\n return\n ZN = ZP - D\n X, K = ZP, K - abs(X - ZP)//D\n if K&1:\n dprint('odd')\n print(abs(ZN))\n else:\n dprint('even')\n print(abs(ZP))\n\n\nmain()\n\n", "import sys\nsys.setrecursionlimit(1000000000)\nimport math\nfrom math import gcd\ndef lcm(a, b): return a * b // gcd(a, b)\nfrom itertools import count, permutations, combinations, chain, product\nfrom functools import lru_cache\nfrom collections import deque, defaultdict\nfrom operator import itemgetter\nfrom pprint import pprint\nii = lambda: int(input())\nmis = lambda: map(int, input().split())\nlmis = lambda: list(mis())\nINF = float('inf')\nN1097 = 10**9 + 7\nDEBUG = not (len(sys.argv)>=2 and sys.argv[1]=='ONLINE_JUDGE')\n\ndef meg(f, ok, ng):\n while abs(ok-ng)>1:\n mid = (ok+ng)//2\n if f(mid):\n ok=mid\n else:\n ng=mid\n return ok\n\ndef get_inv(n, modp):\n return pow(n, modp-2, modp)\n\ndef factorials_list(n, modp): # 10**6\n fs = [1]\n for i in range(1, n+1):\n fs.append(fs[-1] * i % modp)\n return fs\n\ndef invs_list(n, fs, modp): # 10**6\n invs = [get_inv(fs[-1], modp)]\n for i in range(n, 1-1, -1):\n invs.append(invs[-1] * i % modp)\n invs.reverse()\n return invs\n\ndef comb(n, k, modp):\n num = 1\n for i in range(n, n-k, -1):\n num = num * i % modp\n den = 1\n for i in range(2, k+1):\n den = den * i % modp\n return num * get_inv(den, modp) % modp\n\ndef comb_from_list(n, k, modp, fs, invs):\n return fs[n] * invs[n-k] * invs[k] % modp\n\n#\n\nclass UnionFindEx:\n def __init__(self, size):\n \n self.roots = [-1] * size\n def getRootID(self, i):\n r = self.roots[i]\n if r < 0: \n return i\n else:\n r = self.getRootID(r)\n self.roots[i] = r\n return r\n def getGroupSize(self, i):\n return -self.roots[self.getRootID(i)]\n def connect(self, i, j):\n r1, r2 = self.getRootID(i), self.getRootID(j)\n if r1 == r2:\n return False\n if self.getGroupSize(r1) < self.getGroupSize(r2):\n r1, r2 = r2, r1\n self.roots[r1] += self.roots[r2] \n self.roots[r2] = r1\n return True\n\nYes = 'Yes'\nNo = 'No'\n\ndef dprint(*args, **kwargs):\n if DEBUG:\n print(*args, **kwargs)\n\ndef main():\n X,K,D=mis()\n X = abs(X)\n ZP = X%D\n if abs(X - ZP)//D > K:\n dprint('too far')\n print(X - D*K)\n return\n ZN = ZP - D\n X, K = ZP, K - abs(X - ZP)//D\n if K&1:\n dprint('odd')\n print(abs(ZN))\n else:\n dprint('even')\n print(abs(ZP))\n\n\nmain()\n\n", "import sys\nsys.setrecursionlimit(1000000000)\nimport math\nfrom math import gcd\ndef lcm(a, b): return a * b // gcd(a, b)\nfrom itertools import count, permutations, combinations, chain, product\nfrom functools import lru_cache\nfrom collections import deque, defaultdict\nfrom operator import itemgetter\nfrom pprint import pprint\nii = lambda: int(input())\nmis = lambda: map(int, input().split())\nlmis = lambda: list(mis())\nINF = float('inf')\nN1097 = 10**9 + 7\nDEBUG = 'ONLINE_JUDGE' not in sys.argv\n\ndef meg(f, ok, ng):\n while abs(ok-ng)>1:\n mid = (ok+ng)//2\n if f(mid):\n ok=mid\n else:\n ng=mid\n return ok\n\ndef get_inv(n, modp):\n return pow(n, modp-2, modp)\n\ndef factorials_list(n, modp): # 10**6\n fs = [1]\n for i in range(1, n+1):\n fs.append(fs[-1] * i % modp)\n return fs\n\ndef invs_list(n, fs, modp): # 10**6\n invs = [get_inv(fs[-1], modp)]\n for i in range(n, 1-1, -1):\n invs.append(invs[-1] * i % modp)\n invs.reverse()\n return invs\n\ndef comb(n, k, modp):\n num = 1\n for i in range(n, n-k, -1):\n num = num * i % modp\n den = 1\n for i in range(2, k+1):\n den = den * i % modp\n return num * get_inv(den, modp) % modp\n\ndef comb_from_list(n, k, modp, fs, invs):\n return fs[n] * invs[n-k] * invs[k] % modp\n\n#\n\nclass UnionFindEx:\n def __init__(self, size):\n \n self.roots = [-1] * size\n def getRootID(self, i):\n r = self.roots[i]\n if r < 0: \n return i\n else:\n r = self.getRootID(r)\n self.roots[i] = r\n return r\n def getGroupSize(self, i):\n return -self.roots[self.getRootID(i)]\n def connect(self, i, j):\n r1, r2 = self.getRootID(i), self.getRootID(j)\n if r1 == r2:\n return False\n if self.getGroupSize(r1) < self.getGroupSize(r2):\n r1, r2 = r2, r1\n self.roots[r1] += self.roots[r2] \n self.roots[r2] = r1\n return True\n\nYes = 'Yes'\nNo = 'No'\n\ndef dprint(*args, **kwargs):\n if DEBUG:\n print(*args, **kwargs)\n\ndef main():\n X,K,D=mis()\n X = abs(X)\n ZP = X%D\n if abs(X - ZP)//D > K:\n dprint('too far')\n print(X - D*K)\n return\n ZN = ZP - D\n X, K = ZP, K - abs(X - ZP)//D\n if K&1:\n dprint('odd')\n print(abs(ZN))\n else:\n dprint('even')\n print(abs(ZP))\n\n\nmain()\n\n", "import sys\nsys.setrecursionlimit(1000000000)\nimport math\nfrom math import gcd\ndef lcm(a, b): return a * b // gcd(a, b)\nfrom itertools import count, permutations, combinations, chain, product\nfrom functools import lru_cache\nfrom collections import deque, defaultdict\nfrom operator import itemgetter\nfrom pprint import pprint\nii = lambda: int(input())\nmis = lambda: map(int, input().split())\nlmis = lambda: list(mis())\nINF = float('inf')\nN1097 = 10**9 + 7\nDEBUG = sys.argv[-1]!='ONLINE_JUDGE'\n\ndef meg(f, ok, ng):\n while abs(ok-ng)>1:\n mid = (ok+ng)//2\n if f(mid):\n ok=mid\n else:\n ng=mid\n return ok\n\ndef get_inv(n, modp):\n return pow(n, modp-2, modp)\n\ndef factorials_list(n, modp): # 10**6\n fs = [1]\n for i in range(1, n+1):\n fs.append(fs[-1] * i % modp)\n return fs\n\ndef invs_list(n, fs, modp): # 10**6\n invs = [get_inv(fs[-1], modp)]\n for i in range(n, 1-1, -1):\n invs.append(invs[-1] * i % modp)\n invs.reverse()\n return invs\n\ndef comb(n, k, modp):\n num = 1\n for i in range(n, n-k, -1):\n num = num * i % modp\n den = 1\n for i in range(2, k+1):\n den = den * i % modp\n return num * get_inv(den, modp) % modp\n\ndef comb_from_list(n, k, modp, fs, invs):\n return fs[n] * invs[n-k] * invs[k] % modp\n\n#\n\nclass UnionFindEx:\n def __init__(self, size):\n \n self.roots = [-1] * size\n def getRootID(self, i):\n r = self.roots[i]\n if r < 0: \n return i\n else:\n r = self.getRootID(r)\n self.roots[i] = r\n return r\n def getGroupSize(self, i):\n return -self.roots[self.getRootID(i)]\n def connect(self, i, j):\n r1, r2 = self.getRootID(i), self.getRootID(j)\n if r1 == r2:\n return False\n if self.getGroupSize(r1) < self.getGroupSize(r2):\n r1, r2 = r2, r1\n self.roots[r1] += self.roots[r2] \n self.roots[r2] = r1\n return True\n\nYes = 'Yes'\nNo = 'No'\n\ndef dprint(*args, **kwargs):\n pass\n # if DEBUG:\n # print(*args, **kwargs)\n\ndef main():\n X,K,D=mis()\n X = abs(X)\n ZP = X%D\n if abs(X - ZP)//D > K:\n dprint('too far')\n print(X - D*K)\n return\n ZN = ZP - D\n X, K = ZP, K - abs(X - ZP)//D\n if K&1:\n dprint('odd')\n print(abs(ZN))\n else:\n dprint('even')\n print(abs(ZP))\n\n\nmain()\n\n"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s002857922', 's439639423', 's630726563', 's071318107']
[9988.0, 9988.0, 9972.0, 9992.0]
[46.0, 47.0, 42.0, 45.0]
[2494, 2520, 2496, 2507]
p02584
u405137387
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())\ni = 1\n\nif k*d <= x:\n print(x-k*d)\nelse:\n while(d*i < x):\n i += 1\n print(i)\n if (k-i)%2 == 0:\n print(abs(x-d*i))\n else:\n print(x-d*i + d)\n', 'x, k, d = map(int, input().split())\ni = 1\nx = abs(x)\n\nif k*d <= x:\n print(x-k*d)\nelse:\n i = x//d + 1\n #print(i)\n if (k-i)%2 == 0:\n print(abs(x-d*i))\n else:\n print(x-d*i + d)\n']
['Wrong Answer', 'Accepted']
['s877561708', 's989202011']
[9192.0, 9116.0]
[30.0, 30.0]
[209, 203]
p02584
u406138190
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())\nx1=abs(x)%d\nx2=abs(abs(x1)-d)\nnum=abs(x)//d\nif((k-num>=0):\n\tif((k-num)%2==0):\n \tprint(x1)\n\telse:\n \tprint(x2)\nelse:\n print(abs(x)-k*d)', 'x,k,d=map(int,input().split())\nx1=abs(x)%d\nx2=abs(abs(x1)-d)\nnum=abs(x)//d\nif((k-num)>=0):\n\tif((k-num)%2==0):\n \tprint(x1)\n\telse:\n \tprint(x2)\nelse:\n print(abs(x)-k*d)', 'x,k,d=map(int,input().split())\nx1=abs(x)%d\nx2=abs(abs(x1)-d)\nnum=abs(x)//d\nif((k-num)>=0):\n if((k-num)%2==0):\n print(x1)\n else:\n print(x2)\nelse:\n print(abs(x)-k*d)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s693228943', 's883615507', 's570575507']
[8932.0, 9032.0, 9188.0]
[28.0, 28.0, 27.0]
[172, 173, 186]
p02584
u410558877
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.
['line = input()\n\nstrL = line.split()\nX = abs(int(strL[0]))\nK = int(strL[1])\nD = int(strL[2])\n\nmod = X % D\ndiv = int(X / D)\n\nif div > K:\n ans = X - K * D\nelif (K - div) % 2 != 0:\n ans = mod - D\nelse:\n ans = mod\n\nprint(int(ans))', 'line = input()\n\nstrL = line.split()\nX = abs(int(strL[0]))\nK = int(strL[1])\nD = int(strL[2])\n\nmod = X % D\ndiv = int(X / D)\n\nif div > K:\n ans = X - K * D\nelif (K - div) % 2 != 0:\n ans = mod - D\nelse:\n ans = mod\n\nprint(abs(int(ans)))']
['Wrong Answer', 'Accepted']
['s755927103', 's427825053']
[9220.0, 9108.0]
[28.0, 28.0]
[234, 239]
p02584
u413021823
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\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\nX,K,D = LI()\n\nsho = X // D\namari = X % D\n\nif (sho>=K):\n saigo = X - (K*D)\n print(abs(saigo))\nelse:\n nokori = K - ans(sho)\n if nokori % 2 == 0:\n print(abs(amari))\n else:\n ans = min(amari+D,amari-D)\n print(abs(ans))\n ', 'import sys\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\nX,K,D = LI()\nX = abs(X)\nsho = X // D\namari = X % D\n\nif (sho>=K):\n saigo = X - (K*D)\n print(abs(saigo))\nelse:\n nokori = K - abs(sho)\n if nokori % 2 == 0:\n print(abs(amari))\n else:\n ans = min(amari+D,amari-D)\n print(abs(ans))\n ']
['Runtime Error', 'Accepted']
['s212742095', 's193141625']
[9208.0, 9204.0]
[31.0, 34.0]
[499, 509]
p02584
u413278979
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())\nX = abs(X)\n\nstraight = min(K, X // D)\nK -= straight\nX -= straight * D\n\nif K % 2 == 0:\n print(X)\nelse:\n print(D+X)', 'X, K, D = (int(x) for x in input().split())\nX = abs(X)\n\nstraight = min(K, X // D)\nK -= straight\nX -= straight * D\n\nif K % 2 == 0:\n print(X)\nelse:\n print(D-X)']
['Wrong Answer', 'Accepted']
['s216054267', 's383666096']
[9172.0, 9104.0]
[29.0, 31.0]
[163, 163]
p02584
u418197217
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 \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)', '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', 'Accepted']
['s295886015', 's173568786']
[9132.0, 8892.0]
[28.0, 30.0]
[225, 241]
p02584
u418826171
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\nX, K, D = map(int,input().split())\nX = math.fabs(X)\nans = 0\nE = X//D\nif E > K:\n ans = X - K * D\nelif K%2 == E%2:\n ans = X-E*D\nelse:\n ans = -X+(E+1)*D\nprint(ans)', 'import math\nX, K, D = map(int,input().split())\nX = math.fabs(X)\nans = 0\nif X - K*D > math.fabs(X- (K+1)*D):\n ans = X - K * D\nelif K%2 == X//D%2:\n ans = int(X-(X//D)*D) \nelse:\n ans = math.fabs(int(X-(X//D+1)*D))\nprint(ans)', 'import math\nX, K, D = map(int,input().split())\nX = math.fabs(X)\nans = 0\nE = X//D\nif X - K*D > math.fabs(X- (K+1)*D):\n ans = X - K * D\nelif K%2 == X//D%2:\n ans = X-E*D\nelse:\n ans = -X+(E+1)*D\nprint(ans)', '\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)\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s614105677', 's761153048', 's766645613', 's459260696']
[8872.0, 9152.0, 9244.0, 9164.0]
[30.0, 29.0, 29.0, 28.0]
[181, 230, 210, 188]
p02584
u433375322
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=round(abs(X/D))\nif K<a:\n print(abs(abs(X)-K*abs(D)))\nelif (K-a)%2==0:\n l=[]\n l.append(abs(abs(X)-a*abs(D)))\n l.append(abs(abs(X)-(a+2)*abs(D)))\n l.append(abs(abs(X)-(a-2)*abs(D)))\n print(min(l))\nelif (K-a)%2!=0:\n l=[]\n l.append(abs(abs(X)-(a+1)*abs(D)))\n l.append(abs(abs(X)-(a-1)*abs(D))) \n print(min(l))', 'x,k,d=map(int,input().split())\nif abs(x) >= k*d:\n print(abs(x)-k*d)\nelse:\n just=abs(x)//d\n if (k-just)%2==0:\n print(min(abs(abs(x)-just*d),abs(abs(x)-(just+2)*d)))\n else:\n print(min(abs(abs(x)-(just+1)*d),abs(abs(x)-(just-1)*d)))\n ']
['Runtime Error', 'Accepted']
['s700952542', 's631049451']
[9028.0, 9036.0]
[27.0, 30.0]
[353, 264]
p02584
u459104414
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.
['nums = [int(e) for e in input().split()]\ncurrent = nums[0]\nnum = nums[1]\nmove = nums[2]\n\n\ncurrent = abs(current)\nif num%2 == 1:\n current -= move\n\nres = current / move\nif res < num:\n tmp = current - res*move\n if abs(tmp) > abs(tmp-move):\n print(abs(tmp-move))\n else:\n print(tmp)\nelse:\n print(current - num*move)\n', 'nums = [int(e) for e in input().split()]\ncurrent = nums[0]\nnum = nums[1]\nmove = nums[2]\n\n\ncurrent = abs(current)\n\nres = current // move\n\nif res >= num:\n print(current - move*num)\nelse:\n current = current - move * res\n num -= res\n if num%2 == 0:\n print(current)\n else:\n print(abs(current-move))\n']
['Wrong Answer', 'Accepted']
['s521906913', 's128168974']
[9100.0, 9112.0]
[29.0, 30.0]
[340, 323]
p02584
u464912173
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)\ns = x//d\nif x-k*d>0:\n print(x-k*d>0)\nelse:\n if (K-s)%2==0:\n print(X-s*D)\n else:\n print(-X+(s+1)*D)\n', 'x, k, d = map(int,input().split())\nx =abs(x)\ns = x//d\nif x-k*d>0:\n print(x-k*d)\nelse:\n if (k-s)%2==0:\n print(x-s*d)\n else:\n print(-x+(s+1)*d)\n']
['Runtime Error', 'Accepted']
['s830779043', 's717684041']
[8940.0, 9172.0]
[29.0, 28.0]
[165, 163]
p02584
u472534477
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)\nq=X//D\nmod=X%D\n\nif q <= K:\n if (K-q)%2==0:\n ans=mod\n print("A")\n else:\n ans=D-mod\n print("B")\nelse:\n ans=X-K*D\nprint(ans)\n', 'X,K,D = map(int,input().split())\nX=abs(X)\nq=X//D\nmod=X%D\n\nif q <= K:\n if (K-q)%2==0:\n ans=mod\n else:\n ans=D-mod\nelse:\n ans=X-K*D\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s559481370', 's671220836']
[9172.0, 9164.0]
[33.0, 30.0]
[201, 163]
p02584
u474137393
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())\nan = x\n\nif x < 0:\n x = -x\n \nfor i in range(k):\n x -= d\n if an > abs(x):\n an = x\n else:\n if (k-i)%2 != 0 and i!=0:\n print((k-i)%2)\n an = x\n break\n \nprint(abs(an))', 'x,k,d = map(int,input().split())\nan = x\nfor i in range(k):\n a = x+d\n b = x-d\n if abs(a) < abs(b):\n x = a\n else:\n x = b\n \n if an > x:\n an = x\n \n if an == x:\n if (k-i)%2 == 0:\n an += d\n break\n \nprint(an)', 'x,k,d = map(int,input().split())\nan = x\n\nif x < 0:\n x = -x\n\nif k <= x/d:\n an = x-d*k\nelse:\n if (k-x//d)%2==0:\n an = x-d*(x//d)\n else:\n an = x-d*(x//d)-d\n \nprint(abs(an))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s020612751', 's148107362', 's572688785']
[9212.0, 9108.0, 9172.0]
[2206.0, 2206.0, 31.0]
[259, 282, 202]
p02584
u475402977
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\nN=int(input())\nA=list(map(int, input().split()))\nans=0\nfor any_pair in itertools.combinations(A, 3):\n pair=sorted(any_pair)\n print(type(pair))\n if pair[0]+pair[1]>pair[2] and pair[0]!=pair[1] and pair[1]!=pair[2]:\n ans+=1\n print(pair)\nprint(ans)', 'import itertools\nN=int(input())\nA=list(map(int, input().split()))\nans=0\nfor any_pair in itertools.combinations(A, 3):\n pair=sorted(any_pair)\n \n if pair[0]+pair[1]>pair[2] and pair[0]!=pair[1] and pair[1]!=pair[2]:\n ans+=1\n \nprint(ans)', 'X,K,D=map(int, input().split())\nn=(K*D-X)//(2*D)\n#print(n)\nif n<0:\n ans=abs(X-K*D)\nelif n>=K:\n ans=abs(X+K*D)\nelse:\n ans1=abs(X+(2*n-K)*D)\n ans2=abs(X+(2*(n+1)-K)*D)\n ans=min(ans1,ans2)\n #print(n,ans1,ans2)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s126401257', 's901325216', 's580481275']
[9112.0, 9204.0, 9200.0]
[29.0, 29.0, 28.0]
[313, 315, 235]
p02584
u475966842
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==0:\n minNear = x%d + d\n minFar = x%d\n minTransitionToNear = (x-minNear)/d\nelse:\n minNear = x%d\n minFar = x%d - d\n minTransitionToNear = (x-minPlus)/d\n \nif k<minTransitionToNear:\n print(x-k*d)\nelse:\n if (k-minTransitionToNear)%2==0:\n print(minNear)\n else:\n print(minFar)', 'x,k,d=map(int,input().split())\nx=abs(x) \n\nif x%d==0:\n minNear = x%d + d\n minFar = x%d\n minTransitionToNear = (x-minNear)/d\n #print(minNear)\n #print(minFar)\n #print(minTransitionToNear)\n \nelse:\n minNear = x%d\n minFar = x%d - d\n minTransitionToNear = (x-minNear)/d\n #print(minNear)\n #print(minFar)\n #print(minTransitionToNear)\n \nif k<minTransitionToNear:\n print(x-k*d)\nelse:\n if (k-minTransitionToNear)%2==0:\n print(abs(minNear))\n else:\n print(abs(minFar))']
['Runtime Error', 'Accepted']
['s296941143', 's009238048']
[9268.0, 9256.0]
[26.0, 32.0]
[364, 521]
p02584
u478719560
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\n#import string\n#from collections import defaultdict, deque, Counter\n\n#import heapq\n#import math\n#from itertools import accumulate\n#from itertools import permutations as perm\n#from itertools import combinations as comb\n#from itertools import combinations_with_replacement as combr\n#from fractions import gcd\n#import numpy as np\n\nstdin = sys.stdin\nsys.setrecursionlimit(10 ** 7)\nMIN = -10 ** 9\nMOD = 10 ** 9 + 7\nINF = float("inf")\nIINF = 10 ** 18\n\ndef solve():\n #n = int(stdin.readline().rstrip())\n x,k,d = map(int, stdin.readline().rstrip().split())\n #L = list(map(int, stdin.readline().rstrip().split()))\n #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]\n #word = [stdin.readline().rstrip() for _ in range(n)]\n #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]\n \n if abs(x) >= k*d:\n print(abs(x) - k*d)\n exit()\n else:\n a = abs(x) // d\n print(a)\n if abs(abs(x) - d*a) >= abs(abs(x) - d*(a+1)) and (k-a-1)%2 == 0:\n print(abs(abs(x) - d*(a+1)))\n exit()\n elif abs(abs(x) - d*a) >= abs(abs(x) - d*(a+1)) and (k-a-1)%2 == 1:\n print(abs(abs(x) - d*a))\n exit()\n elif abs(abs(x) - d*a) <= abs(abs(x) - d*(a+1)) and (k-a)%2 == 0:\n print(abs(abs(x) - d*a))\n exit()\n elif abs(abs(x) - d*a) <= abs(abs(x) - d*(a+1)) and (k-a)%2 == 1:\n print(abs(abs(x) - d*(a+1)))\n exit()\n\nif __name__ == \'__main__\':\n solve()\n', 'import sys\n#import string\n#from collections import defaultdict, deque, Counter\n\n#import heapq\n#import math\n#from itertools import accumulate\n#from itertools import permutations as perm\n#from itertools import combinations as comb\n#from itertools import combinations_with_replacement as combr\n#from fractions import gcd\n#import numpy as np\n\nstdin = sys.stdin\nsys.setrecursionlimit(10 ** 7)\nMIN = -10 ** 9\nMOD = 10 ** 9 + 7\nINF = float("inf")\nIINF = 10 ** 18\n\ndef solve():\n #n = int(stdin.readline().rstrip())\n x,k,d = map(int, stdin.readline().rstrip().split())\n #L = list(map(int, stdin.readline().rstrip().split()))\n #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]\n #word = [stdin.readline().rstrip() for _ in range(n)]\n #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]\n \n if abs(x) >= k*d:\n print(abs(x) - k*d)\n exit()\n else:\n a = abs(x) // d\n if abs(abs(x) - d*a) >= abs(abs(x) - d*(a+1)) and (k-a-1)%2 == 0:\n print(abs(abs(x) - d*(a+1)))\n exit()\n elif abs(abs(x) - d*a) >= abs(abs(x) - d*(a+1)) and (k-a-1)%2 == 1:\n print(abs(abs(x) - d*a))\n exit()\n elif abs(abs(x) - d*a) <= abs(abs(x) - d*(a+1)) and (k-a)%2 == 0:\n print(abs(abs(x) - d*a))\n exit()\n elif abs(abs(x) - d*a) <= abs(abs(x) - d*(a+1)) and (k-a)%2 == 1:\n print(abs(abs(x) - d*(a+1)))\n exit()\n\nif __name__ == \'__main__\':\n solve()\n']
['Wrong Answer', 'Accepted']
['s302039655', 's388209409']
[9284.0, 9212.0]
[30.0, 33.0]
[1574, 1557]