buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { long long X, K, D; cin >> X >> K >> D; // if (X < 0) X = -X; long long after; if (X / D < K) after = X % D; else { after = X - K * D; ...
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { long long X, K, D; cin >> X >> K >> D; // if (X < 0) X = -X; long long after; if (X / D < K) after = X % D; else { cout << X - K * D <<...
[["-", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["-", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 9, 0, 1, 0, 16, 31, 16, 31, 22], ["+", 0, 9, 0, 1, 0, 16, 31, 16, 17, 151], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 17, 151], ["+", 75, 76, 0, 9, 0, 1, 0, 16, 12, 22]]
1
127
X, K, D = map(int, input().split()) count = int(X / D)#移動回数内で中央をまたげるか if D > abs(X): if K % 2 == 1: last_place = abs(abs(X) - D)#Kが奇数の場合(済) else: last_place = abs(X)#(済) else: if count <= K:#移動回数内で中央をまたげる場合 if (K - count) % 2 == 1:#移動後残り移動回数が奇数の場合(済) last_place = abs(abs(...
X, K, D = map(int, input().split()) count = abs(int(X / D))#移動回数内で中央をまたげるか if D > abs(X): if K % 2 == 1: last_place = abs(abs(X) - D)#Kが奇数の場合(済) else: last_place = abs(X)#(済) else: if count <= K:#移動回数内で中央をまたげる場合 if (K - count) % 2 == 1:#移動後残り移動回数が奇数の場合(済) last_place = abs...
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
136
X, K, D = list(map(int, input().split())) if abs(X) > K*D: print(X - K*D) else: mod = X % D min_step = int((X - mod) / D) if K % 2 == min_step % 2: print(mod) else: print(D - mod)
X, K, D = list(map(int, input().split())) if abs(X) > K*D: print(abs(X) - K*D) else: mod = X % D min_step = int((X - mod) / D) if K % 2 == min_step % 2: print(mod) else: print(D - mod)
[["+", 0, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25]]
5
79
#include <bits/stdc++.h> using namespace std; int main() { int64_t x, k, d; cin >> x >> k >> d; int64_t m = 0; int64_t X = max(x, x * -1); if (X >= d * k) { m = X - d * k; } else if ((k - (X / d)) % 2 == 0) { m = X - d * (X / d); } else { m = d * (X / d + 1) - X; } cout << m << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t x, k, d; cin >> x >> k >> d; int64_t m = 0; int64_t X = max(x, x * -1); if (X / d > k) { m = X - d * k; } else if ((k - (X / d)) % 2 == 0) { m = X - d * (X / d); } else { m = d * (X / d + 1) - X; } cout << m << endl; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
116
#include <bits/stdc++.h> using namespace std; #define ll long long int a[100]; int main() { ll x, k, d; cin >> x >> k >> d; if (x >= 0) { ll div = x / d; if (div <= k) { x -= (div * d); ll moves_left = k - div; if (moves_left % 2 == 0) { cout << x << endl; } else { ...
#include <bits/stdc++.h> using namespace std; #define ll long long int a[100]; int main() { ll x, k, d; cin >> x >> k >> d; if (x >= 0) { ll div = x / d; if (div <= k) { x -= (div * d); ll moves_left = k - div; if (moves_left % 2 == 0) { cout << x << endl; } else { ...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
210
import math def main(): X, K, D = map(int, input().split()) if abs(X) >= K * D: print(X-K*D) else: Y = math.ceil(abs(X) / D) if (K-Y) % 2 == 0: print(D*Y-abs(X)) else: Z = abs(X)-D*(Y-1) print(Z) main()
import math def main(): X, K, D = map(int, input().split()) if abs(X) >= K * D: print(abs(X)-K*D) else: Y = math.ceil(abs(X) / D) if (K-Y) % 2 == 0: print(D*Y-abs(X)) else: Z = abs(X)-D*(Y-1) print(Z) main()
[["+", 0, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25]]
5
103
#include <bits/stdc++.h> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; bool b = true; if (x < 0) { x = -x; b = false; } long long dv = x / d; long long r = x % d; if (dv >= k) { if (b) cout << abs(x - d * k) << endl; else cout << abs(x + d * k) << ...
#include <bits/stdc++.h> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; bool b = true; if (x < 0) { x = -x; b = false; } long long dv = x / d; long long r = x % d; if (dv >= k) { if (b) cout << abs(x - d * k) << endl; else cout << abs(x - d * k) << ...
[["-", 31, 16, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["-", 12, 2, 3, 4, 0, 16, 31, 16, 17, 72], ["+", 12, 2, 3, 4, 0, 16, 31, 16, 17, 33]]
1
192
/* ->->->->-> Vora Mahammasasim <-<-<-<-<- */ #include <bits/stdc++.h> #include <stdio.h> #define Quick \ std ::ios_base ::sync_with_stdio(0); \ cin.tie(0); ...
/* ->->->->-> Vora Mahammasasim <-<-<-<-<- */ #include <bits/stdc++.h> #include <stdio.h> #define Quick \ std ::ios_base ::sync_with_stdio(0); \ cin.tie(0); ...
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
1
142
x,k,d=map(int,input().split()) n=x//d if k<n:n=k r=x-n*d if (k-n)%2:r-=d print(abs(r))
x,k,d=map(int,input().split()) x=abs(x) n=x//d if k<n:n=k r=x-n*d if (k-n)%2:r-=d print(abs(r))
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
57
import math while True: try: x, k, d = map(int, input().split()); if x == 0: k %= 2; if k: print(abs(x - d)); else : print(0); elif abs(x) - k * d > 0: print(abs(x) - k * d); elif x > 0: k -= ...
import math while True: try: x, k, d = map(int, input().split()); if x == 0: k %= 2; if k: print(abs(x - d)); else : print(0); elif abs(x) - k * d > 0: print(abs(x) - k * d); elif x > 0: k -= ...
[["+", 75, 76, 8, 196, 0, 1, 0, 677, 31, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 677, 17, 132], ["+", 75, 76, 8, 196, 0, 1, 0, 677, 12, 612], ["+", 8, 196, 0, 57, 75, 76, 8, 196, 0, 35]]
5
170
x, k, d = map(int, input().split()) #x = abs(x) #0に最も近い距離になる。 ans = x % d #ansへの移動回数分、kから引く if k- (x//d) < 0: print(x - k*d) exit() else: k -= x//d if k % 2 == 0: print(ans) else: t1 = abs(ans-d) t2 = abs(ans+d) print(min(t1, t2))
x, k, d = map(int, input().split()) x = abs(x) #0に最も近い距離になる。 ans = x % d #ansへの移動回数分、kから引く if k- (x//d) < 0: print(x - k*d) exit() else: k -= x//d if k % 2 == 0: print(ans) else: t1 = abs(ans-d) t2 = abs(ans+d) print(min(t1, t2))
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
93
x,k,d = map(int,input().split()) a = x // d b = k - a if b < 0: s = abs(x - k * d) else: if b % 2 == 0: s = abs(x - a * d) else: s = abs(x - (a+1) * d) print(s)
x,k,d = map(int,input().split()) x = abs(x) a = x // d b = k - a if b < 0: s = abs(x - k * d) else: if b % 2 == 0: s = abs(x - a * d) else: s = abs(x - (a+1) * d) print(s)
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
82
# Date [ 2020-08-15 21:13:42 ] # Problem [ c.py ] # Author Koki_tkg import sys; from decimal import Decimal import math; from itertools import combinations, product import bisect; from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10 ** 6 + 7 INF = 10 ** 9 PI = 3.141...
# Date [ 2020-08-15 21:13:42 ] # Problem [ c.py ] # Author Koki_tkg import sys; from decimal import Decimal import math; from itertools import combinations, product import bisect; from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10 ** 6 + 7 INF = 10 ** 9 PI = 3.141...
[["+", 3, 4, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 12, 22]]
5
317
#include <algorithm> #include <cmath> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> const double PI = acos(-1); #define rep(i, n) for (int i = 0; i < (n); i++) usi...
#include <algorithm> #include <cmath> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> const double PI = acos(-1); #define rep(i, n) for (int i = 0; i < (n); i++) usi...
[["+", 51, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 51, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
1
792
X,K,D = map(int,input().split()) a=X//D if(a<=K): X=X-(D*a) K=K-a if(K%2==0): print(X) else: print(min(abs(X-D),abs(X+D))) else: print(X-(D*K))
X,K,D = map(int,input().split()) X = abs(X) a=X//D if(a<=K): X=X-(D*a) K=K-a if(K%2==0): print(X) else: print(min(abs(X-D),abs(X+D))) else: print(X-(D*K))
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
90
x,k,d=list(map(int,input().split())) l=0 if x==0: if k%2==0: print(0) else: print(d) elif x<0: if x+d*k>=0: x=abs(x) a=x%d b=d-a e=x//d if e&1==k&1: print(a) else: print(b) else: print(x+d*k) ...
x,k,d=list(map(int,input().split())) l=0 if x==0: if k%2==0: print(0) else: print(d) elif x<0: if x+d*k>=0: x=abs(x) a=x%d b=d-a e=x//d if e&1==k&1: print(a) else: print(b) else: print(abs(x+d*k)) ...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
165
X,K,D = map(int,input().split()) X = abs(X) s = X//D if s == K: print(X%D) elif s > K: print(abs(X-D*K)) elif s % 2 == 0: print(X%D) else: print(abs(X%D-D))
X,K,D = map(int,input().split()) X = abs(X) s = X//D if s == K: print(X%D) elif s > K: print(abs(X-D*K)) elif (K-s) % 2 == 0: print(X%D) else: print(abs(X%D-D))
[["+", 75, 665, 15, 666, 0, 657, 31, 23, 0, 24], ["+", 15, 666, 0, 657, 31, 23, 0, 657, 31, 22], ["+", 15, 666, 0, 657, 31, 23, 0, 657, 17, 33], ["+", 75, 665, 15, 666, 0, 657, 31, 23, 0, 25]]
5
82
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using LL = long long; #define FOR(i, x, y) \...
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using LL = long long; #define FOR(i, x, y) \...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
833
X,K,D = map(int,input().split()) if abs(X) > K * D: if X >= 0: print(X - K * D) else: print(X + K * D) else: loop = abs(X) // D nok = K - loop if X >= 0: tmp = X - (loop * D) if nok % 2 == 0: print(tmp) else: print(abs(tmp - D)) el...
X,K,D = map(int,input().split()) if abs(X) > K * D: if X >= 0: print(X - K * D) else: print(abs(X + K * D)) else: loop = abs(X) // D nok = K - loop if X >= 0: tmp = X - (loop * D) if nok % 2 == 0: print(tmp) else: print(abs(tmp - D)) ...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
138
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <numeric> #include <string> #include <array> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #define PI 3....
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <numeric> #include <string> #include <array> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #define PI 3....
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 33], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 31, 22], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 23, 0, 2...
1
190
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using vll = vector<long lo...
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using vll = vector<long lo...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 110]]
1
564
x,k,d=map(int,input().split()) x=abs(x) if x>=d: n=x//d mina=x%d if k>=n: if (k-n)%2==0: print(mina) else: print(abs(mina-d)) else: print(x-d*k) else: if k%2==0: print(x) else: print(abs(x)-d)
x,k,d=map(int,input().split()) #xを絶対値に変換 x=abs(x) #場合分けxがdより十分に大きい。つまり近づける価値がある。 if x>=d: #ゼロ直前までは何回? n=x//d #ゼロ直前の値は? mina=x%d #場合分けゼロ直前まで十分な回数ある if k>=n: #偶数(k-nがゼロの場合含む) if (k-n)%2==0: print(mina) else: print(abs(mina-d)) #十分な回数ない else: ...
[["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
104
X, K, D = (int(x) for x in input().split()) P = X if abs(X) >= K * D: if X >= 0: P = X - K * D else: P = X + K * D else: x = int(abs(X) / D) if X >= 0: if (K - x) % 2 == 0: P = X - D * x else: P = abs(X - D * (x + 1)) else: if (K - x) %...
X, K, D = (int(x) for x in input().split()) P = X if abs(X) >= K * D: if X >= 0: P = X - K * D else: P = abs(X + K * D) else: x = int(abs(X) / D) if X >= 0: if (K - x) % 2 == 0: P = X - D * x else: P = abs(X - D * (x + 1)) else: if (K -...
[["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
151
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define Rep(i, n) for (int i = 1; i <= n; i++) #define sz(x) int(x.size()) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define YesorNo(a) printf(a ? "Yes\n" : "No\n") #define endl '\n' #define fi firs...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define Rep(i, n) for (int i = 1; i <= n; i++) #define sz(x) int(x.size()) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define YesorNo(a) printf(a ? "Yes\n" : "No\n") #define endl '\n' #define fi firs...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
351
X, K, D = map(int, input().split()) X = abs(X) if K * D <= X: ans = X - K * D else: k = X // D if k % 2 == 0: ans = X % D else: ans = abs(X % D - D) print(ans)
X, K, D = map(int, input().split()) X = abs(X) if K * D <= X: ans = X - K * D else: k = K - X // D if k % 2 == 0: ans = X % D else: ans = abs(X % D - D) print(ans)
[["+", 8, 196, 0, 1, 0, 662, 12, 657, 31, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33]]
5
73
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; int a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k, d; cin >> n >> k >> d; if (k <= abs(n / d)) cout << abs(n - k * d) << endl; e...
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; int a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k, d; cin >> n >> k >> d; if (k <= abs(n / d)) cout << abs(n) - k * d << endl; e...
[["+", 31, 16, 12, 16, 31, 2, 3, 4, 0, 25], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
154
#include <cstdio> int plus(long int a) { if (a < 0) a = -1 * a; return a; } int main() { long int X, K, D; scanf("%ld %ld %ld", &X, &K, &D); X = plus(X); long int q = (X / D) % 2; long int k_q = K % 2; long int R = X % D; long int ans; if (q == k_q) ans = R; else ans = D - R; if (...
#include <cstdio> long int plus(long int a) { if (a < 0) a = -1 * a; return a; } int main() { long int X, K, D; scanf("%ld %ld %ld", &X, &K, &D); X = plus(X); long int q = (X / D) % 2; long int k_q = K % 2; long int R = X % D; long int ans; if (q == k_q) ans = R; else ans = D - R; ...
[["+", 36, 36, 0, 30, 0, 14, 39, 86, 0, 96], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
142
from collections import deque import sys, copy,itertools input = sys.stdin.readline x ,k, d = map(int,input().split()) q = x // d mod = x % d if q >= k: ans = x - k*d else: if (k-q) % 2 ==0: ans = mod else: ans = abs(mod-d) print(abs(ans))
from collections import deque import sys, copy,itertools input = sys.stdin.readline x ,k, d = map(int,input().split()) x = abs(x) q = x // d mod = x % d if q >= k: ans = x - k*d else: if (k-q) % 2 ==0: ans = mod else: ans = abs(mod-d) print(abs(ans))
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
90
#include <bits/stdc++.h> using namespace std; int main() { int64_t X, K, D; cin >> X >> K >> D; int64_t syou, amari; syou = X / D; int64_t ans = 0; if (X < 0 && syou + K > 0) { X -= syou * D; amari = K + syou; if (amari % 2 == 0) ans = -1 * X; else ans = D + X; } else if (X <...
#include <bits/stdc++.h> using namespace std; int main() { int64_t X, K, D; cin >> X >> K >> D; int64_t syou, amari; syou = X / D; int64_t ans = 0; if (X < 0 && syou + K >= 0) { X -= syou * D; amari = K + syou; if (amari % 2 == 0) ans = -1 * X; else ans = D + X; } else if (X ...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 19]]
1
174
x, k, d = map(int, input().split()) if x - k * d > 0: print(x - k * d) elif x + k * d < 0: print(- x - k * d) else: if x > 0: cnt = (x - (x % d)) // d elif x < 0: cnt = (-x - (-x % d)) // d else: cnt = 0 if (k - cnt) % 2 == 0: if x > 0: print(x % d) elif x < 0: print(-x % d) ...
x, k, d = map(int, input().split()) if x - k * d > 0: print(x - k * d) elif x + k * d < 0: print(-x - k * d) else: if x > 0: cnt = (x - (x % d)) // d elif x < 0: cnt = (-x - (-x % d)) // d else: cnt = 0 if (k - cnt) % 2 == 0: if x > 0: print(x % d) elif x < 0: print(-x % d) ...
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
177
x, k, d = map(int, input().split()) def sol(x, k, d): temp = x // d if temp >= k: return x - d * k x -= temp * d k -= temp if k % 2 == 0: return x return abs(x - d) print (sol(x, k, d))
x, k, d = map(int, input().split()) def sol(x, k, d): x = abs(x) temp = x // d if temp >= k: return x - d * k x -= temp * d k -= temp if k % 2 == 0: return x return abs(x - d) print (sol(x, k, d))
[["+", 0, 14, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
79
#include <algorithm> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include ...
#include <algorithm> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <complex> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include ...
[["-", 15, 339, 51, 16, 31, 23, 0, 16, 12, 22], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 12, 22]]
1
371
X,K,D=map(int,input().split()) if abs(X+D)>abs(X-D): if K<=abs(int(X/D)): print(abs(X-D*K)) else: K-=abs(int(X/D)) if K%2==0: print(abs(X-D*abs(int(X/D)))) else: print(abs(X-D*(abs(int(X/D))+1))) else: if K<=int(X/D): print(abs(X+D*K)) else...
X,K,D=map(int,input().split()) if abs(X+D)>abs(X-D): if K<=abs(int(X/D)): print(abs(X-D*K)) else: K-=abs(int(X/D)) if K%2==0: print(abs(X-D*abs(int(X/D)))) else: print(abs(X-D*(abs(int(X/D))+1))) else: if K<=abs(int(X/D)): print(abs(X+D*K)) ...
[["+", 8, 196, 0, 57, 15, 666, 0, 652, 63, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
208
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, k, d; cin >> x >> k >> d; ll ans = x; if (x < 0) { ans = -x; } if (ans / d >= k) { ans -= k * d; } else { if ((k - (ans / d)) == 2) ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, k, d; cin >> x >> k >> d; ll ans = x; if (x < 0) { ans = -x; } if (ans / d >= k) { ans -= k * d; } else { if ((k - (ans / d)) % 2 =...
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 109], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
130
from math import ceil x,k,d=map(int,input().split()) x=abs(x) n=ceil(x/d) if n>=k: ans=abs(x-k*d) else: if (k-n)%2==0: ans=abs(x-n+d) else: ans=x-(n-1)*d print(ans)
from math import ceil x,k,d=map(int,input().split()) x=abs(x) n=ceil(x/d) if n>=k: ans=abs(x-k*d) else: if (k-n)%2==0: ans=abs(x-n*d) else: ans=x-(n-1)*d print(ans)
[["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 12, 652, 3, 4, 0, 657, 12, 657, 17, 48]]
5
91
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define LLINF 1e18 #define pi 3.14159265358979323 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int gcd(int a, int b) { if (a % b == 0) { return b; } else { return (gcd(b, a % b)); } } int main() { ll x, k, d; ...
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define LLINF 1e18 #define pi 3.14159265358979323 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int gcd(int a, int b) { if (a % b == 0) { return b; } else { return (gcd(b, a % b)); } } int main() { ll x, k, d; ...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
247
X,K,D = map(int, input().split()) if abs(X) > abs(D * K): if X > 0: print(X - D*K) else: print(X + D*K) else: if (K - (X // D) ) % 2 == 0: print(abs(X%D)) else: print(abs(X%D-D))
X,K,D = map(int, input().split()) if abs(X) >= abs(D * K): if X > 0: print(X - D*K) else: print(abs(X + D*K)) else: if (K - (X // D) ) % 2 == 0: print(abs(X%D)) else: print(abs(X%D-D))
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20], ["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
93
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; #define mp make_pair #define pb push_back #define f first #define s second // var LL x, k, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> x >> k >> d; if (x < 0) x = -x; if ((k * d) < x) {...
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; #define mp make_pair #define pb push_back #define f first #define s second // var LL x, k, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> x >> k >> d; if (x < 0) x = -x; if ((x / d) > k) {...
[["-", 15, 339, 51, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 339, 51, 16, 31, 23, 0, 16, 17, 48], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 17, 85], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 4...
1
160
v = input().split(" ") x = int(v[0]) k = int(v[1]) d = int(v[2]) if (x == 0): if (k % 2 == 0): ans = 0 else: ans = d else: if ((k * d) > abs(x)): y = x // d ans = abs(abs(x) - y * d) if ((k - y) % 2 == 1): ans = abs(d - ans) else: ans = abs(x)...
v = input().split(" ") x = int(v[0]) k = int(v[1]) d = int(v[2]) if (x == 0): if (k % 2 == 0): ans = 0 else: ans = d else: if ((k * d) > abs(x)): y = abs(x) // d ans = abs(abs(x) - y * d) if ((k - y) % 2 == 1): ans = abs(d - ans) else: ans = a...
[["+", 0, 1, 0, 662, 12, 657, 31, 652, 63, 22], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 25]]
5
134
x, k, d = map(int, input().split()) x = abs(x) k_needed = x // d if x > k*d: print(x-k*d) else: if (k - k_needed) // 2 == 0: print(abs(x - k_needed*d)) else: print(abs(abs(x - k_needed*d) - d))
x, k, d = map(int, input().split()) x = abs(x) k_needed = x // d if x > k*d: print(x-k*d) else: if (k - k_needed) % 2 == 0: print(abs(x - k_needed*d)) else: print(abs(abs(x - k_needed*d) - d))
[["-", 8, 196, 0, 57, 15, 666, 0, 657, 17, 676], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 109]]
5
86
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { ll x, k, d; cin >> x >> k >> d; x = abs(x); if (x - (k * d) >= 0) cout << x - (k * d) << endl; else { k -= x / d; x %= d; if (k % 2 == 0) ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { ll x, k, d; cin >> x >> k >> d; x = abs(x); if (x / d - k >= 0) cout << x - (k * d) << endl; else { k -= x / d; x %= d; if (k % 2 == 0) ...
[["+", 15, 339, 51, 16, 31, 16, 31, 16, 17, 85], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 12, 22], ["-", 15, 339, 51, 16, 31, 16, 12, 23, 0, 24], ["-", 51, 16, 31, 16, 12, 23, 0, 16, 17, 48], ["-", 51, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["-", 15, 339, 51, 16, 31, 16, 12, 23, 0, 25]]
1
119
import sys X,K,D=map(int,input().split()) if abs(X) >= K*D: print(abs(X)-K*D) else: y = X//D z = K-y X = abs(X) - (y*D) if z%2 == 0: print(abs(X)) else: print(abs(X-D))
X,K,D=map(int,input().split()) if abs(X) >= K*D: print(abs(X)-K*D) else: y = abs(X)//D z = K-y X = abs(X) - (y*D) if z%2 == 0: print(abs(X)) else: print(abs(X-D))
[["-", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["-", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22], ["+", 0, 1, 0, 662, 12, 657, 31, 652, 63, 22], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 25]]
5
90
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; const int inf = INT_MAX / 2; template <class T> bool chmax(T &a, const T &b) { if (a < b...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; const int inf = INT_MAX / 2; template <class T> bool chmax(T &a, const T &b) { if (a < b...
[["+", 12, 2, 3, 4, 0, 16, 31, 2, 63, 22], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25]]
1
225
import java.io.*; import java.util.*; public class Main { public static void main(final String[] args) { final FastReader s = new FastReader(); long x = Math.abs(s.nextLong()); long k = s.nextLong(); long d = s.nextLong(); long min = x / d; if (min > d) { System.out.println(x - (k * d...
import java.io.*; import java.util.*; public class Main { public static void main(final String[] args) { final FastReader s = new FastReader(); long x = Math.abs(s.nextLong()); long k = s.nextLong(); long d = s.nextLong(); long min = x / d; if (min > k) { System.out.println(x - (k * d...
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 22]]
3
328
x, k, d = map(int, input().split()) xdivd=x//d if xdivd+1>k: # print('a') print(abs(abs(x)-d*k)) elif (k-abs(xdivd))%2==0: # print('b') print(abs(x-d*xdivd)) else: # print('c',xdivd) print(abs(x-(xdivd+1)*d))
x, k, d = map(int, input().split()) xdivd=x//d if abs(xdivd)+1>k: # print('a') print(abs(abs(x)-d*k)) elif (k-abs(xdivd))%2==0: # print('b') print(abs(x-d*xdivd)) else: # print('c',xdivd) print(abs(x-(xdivd+1)*d))
[["+", 0, 57, 15, 666, 0, 657, 31, 652, 63, 22], ["+", 15, 666, 0, 657, 31, 652, 3, 4, 0, 24], ["+", 15, 666, 0, 657, 31, 652, 3, 4, 0, 25]]
5
89
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, j, k, sum = 0, count = 0, ans = 0, x = 0, y = 0, l, r, m; cin >> n >> m >> k; if (n == 0) { if (m % 2 == 0) cout << 0; else cout << k; return 0; } if (n > ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, j, k, sum = 0, count = 0, ans = 0, x = 0, y = 0, l, r, m; cin >> n >> m >> k; if (n == 0) { if (m % 2 == 0) cout << 0; else cout << k; return 0; } if (n > ...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
1
293
X,K,D = gets.split.map(&:to_i) if (X < 0) if (X + K*D <= 0) puts (X + K*D).abs else if (K - (-X.to_f/D).ceil).even? puts (X + (-X.to_f/D).ceil*K).abs else puts (X + (-X.to_f/D).ceil*K - K).abs end end else if (X - K*D > 0) puts (X - K*D).abs else if (K - (X.to_f/D).ceil).e...
X,K,D = gets.split.map(&:to_i) if (X < 0) if (X + K*D <= 0) puts (X + K*D).abs else if (K - (-X.to_f/D).ceil).even? puts (X + (-X.to_f/D).ceil*D).abs else puts (X + (-X.to_f/D).ceil*D - D).abs end end else if (X - K*D > 0) puts (X - K*D).abs else if (K - (X.to_f/D).ceil).e...
[["-", 0, 652, 486, 739, 0, 738, 12, 738, 12, 743], ["+", 0, 652, 486, 739, 0, 738, 12, 738, 12, 743], ["-", 486, 739, 0, 738, 31, 738, 12, 738, 12, 743], ["+", 486, 739, 0, 738, 31, 738, 12, 738, 12, 743], ["-", 3, 4, 0, 652, 486, 739, 0, 738, 12, 743], ["+", 3, 4, 0, 652, 486, 739, 0, 738, 12, 743]]
4
182
X,K,D = map(int, input().split()) absX = abs(X) if absX - K*D > 0: ans = absX - K*D else: q = absX // D mod = absX % D if K-q % 2 == 0: ans = mod else: ans = min(abs(mod-D),abs(mod+D)) print(ans)
X,K,D = map(int, input().split()) absX = abs(X) if absX - K*D > 0: ans = absX - K*D else: q = absX // D mod = absX % D if (K-q) % 2 == 0: ans = mod else: ans = min(abs(mod-D),abs(mod+D)) print(ans)
[["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 24], ["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 25]]
5
88
x, k, d = gets.split.map(&:to_i) ans = 0 if x > (k * d) ans = x - (k * d) else num = x / d if (k - num) % 2 == 0 ans = x - (d * (x / d)) else ans = x - (d * ((x / d) + 1)) end end puts ans.abs
x, k, d = gets.split.map(&:to_i) ans = 0 x = x.abs if x > (k * d) ans = x - (k * d) else num = x / d if (k - num) % 2 == 0 ans = x - (d * (x / d)) else ans = x - (d * ((x / d) + 1)) end end puts ans.abs
[["+", 36, 36, 36, 36, 0, 493, 0, 662, 31, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 0, 32], ["+", 36, 36, 0, 493, 0, 662, 12, 652, 486, 22], ["+", 36, 36, 0, 493, 0, 662, 12, 652, 17, 131], ["+", 36, 36, 0, 493, 0, 662, 12, 652, 735, 22]]
4
88
import sys import math X, K, D = map(int, input().split()) if X == 0 and K % 2 == 0: print(X) sys.exit() elif X == 0 and K % 2 == 1: print(D) sys.exit() if abs(X // D) >= K: ans = X - (D * K) * (X // abs(X)) ans = abs(ans) else: K -= abs(X//D) ans = X - (D * abs(X//D)) * (X // abs(X)) ...
import sys import math X, K, D = map(int, input().split()) if X == 0 and K % 2 == 0: print(X) sys.exit() elif X == 0 and K % 2 == 1: print(D) sys.exit() if abs(X // D) >= K: ans = X - (D * K) * (X // abs(X)) ans = abs(ans) else: K -= abs(X//D) ans = X - (D * abs(X//D)) * (X // abs(X)) ...
[["+", 0, 652, 3, 4, 0, 657, 12, 657, 17, 48], ["+", 0, 652, 3, 4, 0, 657, 12, 657, 12, 612]]
5
206
#include <bits/stdc++.h> using namespace std; #define fr(i, n) for (int i = 0; i < n; i++) #define sz(v) (int)(v.size()) #define prin(a) cout << #a << " = " << a << endl #define prinv(v) \ cout << #v << " = "; ...
#include <bits/stdc++.h> using namespace std; #define fr(i, n) for (int i = 0; i < n; i++) #define sz(v) (int)(v.size()) #define prin(a) cout << #a << " = " << a << endl #define prinv(v) \ cout << #v << " = "; ...
[["-", 64, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["-", 12, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
1
189
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; const ld pi = 3.141592653589793; ll x, k, d; int main() { cin >> x >> k >> d; if (abs(x) / d >= k) { ...
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; const ld pi = 3.141592653589793; ll x, k, d; // -10 5 3 int main() { cin >> x >> k >> d; if (abs(x) / d...
[["+", 31, 16, 12, 16, 31, 2, 3, 4, 0, 25], ["-", 3, 4, 0, 16, 12, 16, 12, 23, 0, 25]]
1
197
X, K, D = map(int, input().split()) num = X // D if num >= K and X >= 0: print(abs(X - K*D)) elif num >= K and X < 0: print(abs(X + K*D)) elif num < K and X >= 0: rest = K - num print(abs(X - num*D - D*(rest%2))) else: rest = K - num print(abs(X + num*D + D*(rest%2)))
X, K, D = map(int, input().split()) num = abs(X) // D if num >= K and X >= 0: print(abs(X - K*D)) elif num >= K and X < 0: print(abs(X + K*D)) elif num < K and X >= 0: rest = K - num print(abs(X - num*D - D*(rest%2))) else: rest = K - num print(abs(X + num*D + D*(rest%2)))
[["+", 0, 1, 0, 662, 12, 657, 31, 652, 63, 22], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 25]]
5
122
#include <algorithm> #include <climits> #include <cmath> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <unordered_set> #include <vector> using namespace std...
#include <algorithm> #include <climits> #include <cmath> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <unordered_set> #include <vector> using namespace std...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
154
x,k,d = map(int,input().split()) n = abs(x)//d if k>n: if x<0: a = x+n*d b = a+d if (k-n)%2 == 0: print(abs(a)) else: print(abs(b)) else: a = x-n*d b = a-d if (k-n)%2 == 0: print(abs(a)) else: print(...
x,k,d = map(int,input().split()) n = abs(x)//d if k>n: if x<0: a = x+n*d b = a+d if (k-n)%2 == 0: print(abs(a)) else: print(abs(b)) else: a = x-n*d b = a-d if (k-n)%2 == 0: print(abs(a)) else: print(...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
141
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const long double PI = (acos(-1)); const long long MOD = 1000000007; struct Edge { long long to; long long cost; }; using Graph = vector<vector<Edge>>; using P = pair<ll, ll>; const long long INF = 1LL << 60; #defin...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const long double PI = (acos(-1)); const long long MOD = 1000000007; struct Edge { long long to; long long cost; }; using Graph = vector<vector<Edge>>; using P = pair<ll, ll>; const long long INF = 1LL << 60; #defin...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
1,715
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI 3.14159265359 using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, k, d; cin >> x >> k >> d; x = abs(x); if (x > k * d) { cout << x - k * d << endl; return 0; } ...
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI 3.14159265359 using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, k, d; cin >> x >> k >> d; x = abs(x); if (x / d > k) { cout << x - k * d << endl; return 0; } ...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
134
x,k,d = map(int,input().split()) r = x % d m = x // d if m > k: print(x - k * d) elif (-m) > k: print(x + k * d) elif (k - m) % 2 == 0: print(r) else: print(d - r)
x,k,d = map(int,input().split()) r = x % d m = x // d if m > k: print(x - k * d) elif (-m) > k: print(abs(x + k * d)) elif (k - m) % 2 == 0: print(r) else: print(d - r)
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
80
def main2(): x, k, d = map(int, input().split()) now = x i = 0 if (now == 0): if k%2 == 0: print(0) else: print(d) elif (now > 0): if (now - d * k >=0): print(now - d * k) return i = int(now/d) now = now%d ...
def main2(): x, k, d = map(int, input().split()) now = x i = 0 if (now == 0): if k%2 == 0: print(0) else: print(d) elif (now > 0): if (now - d * k >=0): print(now - d * k) return i = int(now/d) now = now%d ...
[["+", 0, 1, 0, 652, 3, 4, 0, 664, 17, 33], ["+", 0, 652, 3, 4, 0, 664, 28, 23, 0, 24], ["+", 0, 652, 3, 4, 0, 664, 28, 23, 0, 25]]
5
199
X, K, D = map(int, input().split()) if K <= abs(X // D): print(abs(X) - D * K) elif (K - abs(X // D)) % 2 == 0: print(abs(X) % D) else: print(D - abs(X) % D)
X, K, D = map(int, input().split()) if K <= abs(X) // D: print(abs(X) - D * K) elif (K - abs(X) // D) % 2 == 0: print(abs(X) % D) else: print(D - abs(X) % D)
[["+", 15, 666, 0, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 57, 15, 666, 0, 652, 3, 4, 0, 25], ["+", 0, 657, 12, 657, 31, 652, 3, 4, 0, 25], ["-", 31, 23, 0, 657, 12, 652, 3, 4, 0, 25]]
5
77
X,K,D=map(int, input().split()) if abs(X) // abs(D) > K: print(X-(K*D)) exit() K2= K - (abs(X) // D) X= abs(X) - abs(((K-K2)*D)) if K2 % 2 == 1: X= abs(X) -D print(abs(X))
X,K,D=map(int, input().split()) if abs(X) // abs(D) > K: print(abs(X)-(K*D)) exit() K2= K - (abs(X) // D) X= abs(X) - abs(((K-K2)*D)) if K2 % 2 == 1: X= abs(X) - D print(abs(X))
[["+", 0, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25]]
5
97
X, K, D = map(int, input().split()) d, r = divmod(X, D) if K >= d: if (K - abs(d)) % 2 == 0: print(min(r, abs(X - D*K))) else: print(min(abs(r - D), abs(X - D*K))) else: print(abs(X - D*K))
X, K, D = map(int, input().split()) X = abs(X) d, r = divmod(X, D) if K >= d: if (K - abs(d)) % 2 == 0: print(min(r, abs(X - D*K))) else: print(min(abs(r - D), abs(X - D*K))) else: print(abs(X - D*K))
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
99
#Problem C X, K, D = list(map(int,input().split())) T_min = X//D ans = 0 if abs(X) > K*D: print(abs(X) - K*D) exit() elif T_min > K: print(abs(X) - K*D) exit() if (T_min-K)%2 ==0: ans = abs(X) - (T_min*D) else: ans1 = abs(abs(X) - (T_min*D) + D) ans2 = abs(abs(X) - (T_min*D) - D) an...
#Problem C X, K, D = list(map(int,input().split())) T_min = abs(X)//D ans = 0 if abs(X) > K*D: print(abs(X) - K*D) exit() elif T_min > K: print(abs(X) - K*D) exit() if (T_min-K)%2 ==0: ans = abs(abs(X) - (T_min*D)) else: ans1 = abs(abs(X) - (T_min*D) + D) ans2 = abs(abs(X) - (T_min*D) -...
[["+", 0, 1, 0, 662, 12, 657, 31, 652, 63, 22], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 657, 12, 23, 0, 25]]
5
144
x,k,d = map(int,input().split()) if x == 0: if k%2 == 0: print(0) else: print(d) elif x > 0: n = x//d if k <= n: print(x-k*d) else: if k%2 == n%2: print(abs(x-n*d)) else: print(abs(x-(n+1)*d)) else: n = abs(x)//d if k <= n: ...
x,k,d = map(int,input().split()) if x == 0: if k%2 == 0: print(0) else: print(d) elif x > 0: n = x//d if k <= n: print(abs(x-k*d)) else: if k%2 == n%2: print(abs(x-n*d)) else: print(abs(x-(n+1)*d)) else: n = abs(x)//d if k <= n:...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
166
x, k, d = map(int, input().split()) if abs(x//d) >= k: print(abs(abs(x)-abs(k*d))) else: if (x//d)%2 == 0: print(abs(x%d)) else: print(abs(abs(x%d)-abs(d)))
x, k, d = map(int, input().split()) if abs(x//d) >= k: print(abs(abs(x)-abs(k*d))) else: if (k-(x//d))%2 == 0: print(abs(x%d)) else: print(abs(abs(x%d)-abs(d)))
[["+", 15, 666, 0, 657, 31, 23, 0, 657, 31, 22], ["+", 15, 666, 0, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 657, 31, 23, 0, 657, 12, 23, 0, 24], ["+", 0, 657, 31, 23, 0, 657, 12, 23, 0, 25]]
5
86
#include "bits/stdc++.h" using namespace std; #define endl "\n" typedef long long int ll; #define f first #define s second inline void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } inline void setPrecision(int n) { cout.precision(n); } // DEBUG #define dbg(x) cerr << (#x) << ": " << x << ...
#include "bits/stdc++.h" using namespace std; #define endl "\n" typedef long long int ll; #define f first #define s second inline void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } inline void setPrecision(int n) { cout.precision(n); } // DEBUG #define dbg(x) cerr << (#x) << ": " << x << ...
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22]]
1
284
#include <algorithm> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep1(i, n) for (ll i = 1; i <...
#include <algorithm> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep1(i, n) for (ll i = 1; i <...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
230
x, k, d = gets.split.map(&:to_i) n = [x.abs / d, k].min if x > 0 x -= n * d else x += n * d end k -= n if k.even? puts x else puts [(x - d).abs, (x + d).abs].min end
x, k, d = gets.split.map(&:to_i) n = [x.abs / d, k].min if x > 0 x -= n * d else x += n * d end k -= n if k.even? puts x.abs else puts [(x - d).abs, (x + d).abs].min end
[["+", 64, 749, 0, 652, 3, 4, 0, 652, 17, 131], ["+", 64, 749, 0, 652, 3, 4, 0, 652, 735, 22]]
4
75
#include <algorithm> #include <bits/stdc++.h> #include <math.h> #include <vector> using namespace std; using UL = unsigned int; using ULL = unsigned long long; using LL = long long; #define rep(i, n) for (int i = 0; i < (n); i++) // あきらかにKがループできる回数じゃないのでmodで判定? // 座標原点を挟んで2K回移動しても位置は同じか。最初だけで決まる。 int main() { LL X,...
#include <algorithm> #include <bits/stdc++.h> #include <math.h> #include <vector> using namespace std; using UL = unsigned int; using ULL = unsigned long long; using LL = long long; #define rep(i, n) for (int i = 0; i < (n); i++) // あきらかにKがループできる回数じゃないのでmodで判定? // 座標原点を挟んで2K回移動しても位置は同じか。最初だけで決まる。 int main() { LL X,...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
159
#include <bits/stdc++.h> using namespace std; #define int long long #define INT int #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(i) (i).begin(), (i).end() #define rall(i) (i).begi...
#include <bits/stdc++.h> using namespace std; #define int long long #define INT int #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(i) (i).begin(), (i).end() #define rall(i) (i).begi...
[["+", 0, 43, 49, 50, 51, 16, 31, 2, 63, 22], ["+", 49, 50, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 49, 50, 51, 16, 31, 2, 3, 4, 0, 25]]
1
289
def main(): x, k, d= map(int, input().split()) if x == 0: if k%2 == 0: print(0) return else: print(d) return else: if x < 0: x = 1*x if k*d <= x: print(x-k*d) return else: ...
def main(): x, k, d= map(int, input().split()) if x == 0: if k%2 == 0: print(0) return else: print(d) return else: if x < 0: x = -1*x if k*d <= x: print(x-k*d) return else: ...
[["+", 0, 1, 0, 662, 12, 657, 31, 664, 17, 33]]
5
123
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> k >> m; if (n < 0) n *= -1; if (n / m >= k) cout << n - m * k << endl; else if (n % m < abs(n % m - m)) { k -= (n / m); if (k % 2 == 1) cout << abs(n % m - m) << endl; else cout << n % m <...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> k >> m; if (n < 0) n *= -1; if (n / m >= k) cout << n - m * k << endl; else if (n % m < abs(n % m - m)) { k -= (n / m); if (k % 2 == 1) cout << abs(n % m - m) << endl; else cout << n % m <...
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
194
a,b,c=map(int, input().split()) k = b*c l = abs(a) if l > 0: if l > k: print(l-k) if l == k: print(0) if l < k: d = int(l//c) e = b - d if e%2== 0: print(l-c*d) else: f = d + 1 print(f*c -l) if l == 0: if b%2==0: ...
a,b,c=map(int, input().split()) k = b*c l = abs(a) if l > 0: if l > k: print(l-k) if l == k: print(0) if l < k: d = int(l//c) e = b - d if e%2== 0: print(l-c*d) else: f = d + 1 print(f*c -l) if l == 0: if b%2==0: ...
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
5
124
X, K, D = map(int, input().split(" ")) if abs(X) >= abs(K*D): print(abs(X)-abs(K*D)) else: rK = K - int(abs(X)/abs(D)) if rK % 2 == 0: print(abs(X - D*(int(abs(X)/abs(D))))) else: print(abs(X - D*(1+int(abs(X)/abs(D)))))
X, K, D = map(int, input().split(" ")) if abs(X) >= abs(K*D): print(abs(X)-abs(K*D)) else: rK = K - int(abs(X)/abs(D)) if rK % 2 == 0: print(abs(abs(X) - D*(int(abs(X)/abs(D))))) else: print(abs(abs(X) - D*(1+int(abs(X)/abs(D)))))
[["+", 0, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22]]
5
125
X,K,D = map(int,input().split( )) X = abs(X) q, mod = divmod(X, D) if q >= K: print(X-D*q) else: cnt = K-q if cnt%2 == 0: print(mod) if cnt%2 == 1: print(D-mod)
X,K,D = map(int,input().split( )) X = abs(X) q, mod = divmod(X, D) if q >= K: print(X-D*K) else: cnt = K-q if cnt%2 == 0: print(mod) if cnt%2 == 1: print(D-mod)
[["-", 0, 652, 3, 4, 0, 657, 12, 657, 12, 22], ["+", 0, 652, 3, 4, 0, 657, 12, 657, 12, 22]]
5
78
#include <bits/stdc++.h> typedef long long lint; using namespace std; lint gcd(lint x, lint y) { if (x == 0) { return y; } else { return gcd(y % x, x); } } lint lcm(lint x, lint y) { return x / gcd(x, y) * y; } lint C(lint n, lint k) { if (n == k) { return 1; } else if (n < k) { return 0; ...
#include <bits/stdc++.h> typedef long long lint; using namespace std; lint gcd(lint x, lint y) { if (x == 0) { return y; } else { return gcd(y % x, x); } } lint lcm(lint x, lint y) { return x / gcd(x, y) * y; } lint C(lint n, lint k) { if (n == k) { return 1; } else if (n < k) { return 0; ...
[["+", 31, 16, 31, 23, 0, 16, 31, 2, 63, 22], ["+", 31, 23, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 31, 23, 0, 16, 31, 2, 3, 4, 0, 25]]
1
292
from decimal import * x, k, d = map(Decimal, input().split()) if x >= 0: if x-k*d >= 0: print(abs(x-k*d)) else: if x//d%2 == k%2: print(abs(x%d)) else: print(abs(k-x%d)) else: if x+k*d <= 0: print(abs(x+k*d)) else: if x//d%2 == k%2: print(abs(-x%d)) else: print(a...
from decimal import * x, k, d = map(Decimal, input().split()) if x >= 0: if x-k*d >= 0: print(abs(x-k*d)) else: if x//d%2 == k%2: print(abs(x%d)) else: print(abs(d-x%d)) else: if x+k*d <= 0: print(abs(x+k*d)) else: if -x//d%2 == k%2: print(abs(-x%d)) else: print(...
[["-", 3, 4, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 15, 666, 0, 657, 31, 657, 31, 664, 17, 33]]
5
140
inp = list(map(int,input().split())) x = inp[0] k = inp[1] d = inp[2] x = abs(x) if(x >= k*d): print(x-k*d) else: res=x tmp = int(x/d) for y in range(-100,100): if((y+tmp)<=k and y+tmp >=0): rem = k-y-tmp if(rem%2 == 0): res=min(res,abs(x-(y+tmp)*d)) ...
inp = list(map(int,input().split())) x = inp[0] k = inp[1] d = inp[2] x = abs(x) if(x >= k*d): print(x-k*d) else: res=10000000000000000000000000000000000000 tmp = int(x/d) for y in range(-100,100): if((y+tmp)<=k and y+tmp >=0): rem = k-y-tmp if(rem%2 == 0): ...
[["-", 75, 76, 8, 196, 0, 1, 0, 662, 12, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 12, 612]]
5
138
#include <bits/stdc++.h> using namespace std; #define _ \ ios::sync_with_stdio(false); \ cin.tie(0); #define __ \ cout << fixed; ...
#include <bits/stdc++.h> using namespace std; #define _ \ ios::sync_with_stdio(false); \ cin.tie(0); #define __ \ cout << fixed; ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 64, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
1
231
x,k,d = map(int,input().split()) sm = abs(x)//d if abs(x)-sm*d>0 : ans = abs(x)-sm*d elif abs(x)-d*k>0: ans = abs(x)-d*k elif (k-sm)%2==0: ans = min(abs(x)-sm*d,abs(abs(x)-sm*d-2*d)) else: ans = min(abs(abs(x)-sm*d-d),abs(x)-sm*d+d) print(abs(ans))
x,k,d = map(int,input().split()) sm = abs(x)//d+1 if abs(x)-sm*d>0 : ans = abs(x)-sm*d elif abs(x)-d*k>0: ans = abs(x)-d*k elif (k-sm)%2==0: ans = min(abs(x)-sm*d,abs(abs(x)-sm*d-2*d)) else: ans = min(abs(abs(x)-sm*d-d),abs(abs(x)-sm*d+d)) print(abs(ans))
[["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 3, 4, 0, 657, 31, 657, 31, 652, 63, 22], ["+", 0, 657, 31, 657, 31, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
148
[_x, _k, _d] = list(map(int, input().split(" "))) _x = abs(_x) if _x >= _d: _y = _x//_d if _k > _y: _y = _k _x = abs(_x - _d * _y) _k -= _y if _k % 2 == 1: _x = abs(_x - _d) print(_x)
[_x, _k, _d] = list(map(int, input().split(" "))) _x = abs(_x) if _x >= _d: _y = _x//_d if _k < _y: _y = _k _x = abs(_x - _d * _y) _k -= _y if _k % 2 == 1: _x = abs(_x - _d) print(_x)
[["-", 0, 57, 64, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 18]]
5
82
import sys,collections,math,random,fractions,bisect,itertools;sys.setrecursionlimit(10**7) sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n") def I(i=0): t = [int(x)-i for x in sr().split()];return t def S(): t = sr().split(); return t if len(t) > 1 else t[0] L1,L2,L3,L4, = [],[],[],[] x,k,d = I()...
import sys,collections,math,random,fractions,bisect,itertools;sys.setrecursionlimit(10**7) sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n") def I(i=0): t = [int(x)-i for x in sr().split()];return t def S(): t = sr().split(); return t if len(t) > 1 else t[0] L1,L2,L3,L4, = [],[],[],[] x,k,d = I()...
[["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["-", 12, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24], ["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25]]
5
206
#include <bits/stdc++.h> using namespace std; int main() { long X, K, D; cin >> X >> K >> D; long absx = abs(X); if (absx - K * D > 0) { cout << absx - K * D; return 0; } else { // 負値とならないギリギリまで減らす long k = absx / D; absx -= k * D; K -= k; if (K % 2 == 0) { cout << absx; ...
#include <bits/stdc++.h> using namespace std; int main() { long X, K, D; cin >> X >> K >> D; long absx = abs(X); if (absx / D > K) { cout << absx - K * D; return 0; } else { // 負値とならないギリギリまで減らす long k = absx / D; absx -= k * D; K -= k; if (K % 2 == 0) { cout << absx; ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 33], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 31, 22], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
108
#include <iostream> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; long long a, b; if (x > 0) { if (x / d <= k) { if ((k - x / d) % 2 == 0) { cout << x % d << endl; } else { cout << d - x % d << endl; } } else { cout << x - k * d << endl...
#include <iostream> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; long long a, b; if (x > 0) { if (x / d < k) { if ((k - x / d) % 2 == 0) { cout << x % d << endl; } else { cout << d - x % d << endl; } } else { cout << x - k * d << endl;...
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["-", 51, 16, 31, 16, 12, 16, 31, 23, 0, 24]]
1
202
x,k,d=[int(x) for x in input().split()] if abs(x)==d: if k%2==0: print(abs(x)) else: print(0) else: num= abs(x)//d if k<num: if x<0: x=x+k*d else: x=x-k*d print(x) else: if x<0: x=x+num*d else: x=x-num*d k=k-num if k%2==0: print(abs(x)) else: print(min(abs(x-d),abs(x+d)))...
x,k,d=[int(x) for x in input().split()] if abs(x)==d: if k%2==0: print(abs(x)) else: print(0) else: num= abs(x)//d if k<=num: if x<0: x=x+k*d else: x=x-k*d print(abs(x)) else: if x<0: x=x+num*d else: x=x-num*d k=k-num if k%2==0: print(abs(x)) else: print(min(abs(x-d),abs(...
[["-", 75, 76, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 75, 76, 8, 196, 0, 57, 15, 666, 667, 19], ["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
153
#include <bits/stdc++.h> #include <math.h> using namespace std; template <typename T> long long modpow(const T n, const T p, const T mod); template <typename T> long long modinv(const T n, const T mod); template <typename T> bool chmax(T &a, const T &b); template <typename T> bool chmin(T &a, const T &b); long long ...
#include <bits/stdc++.h> #include <math.h> using namespace std; template <typename T> long long modpow(const T n, const T p, const T mod); template <typename T> long long modinv(const T n, const T mod); template <typename T> bool chmax(T &a, const T &b); template <typename T> bool chmin(T &a, const T &b); long long ...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
399
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 //#define N 1000005 typedef long long int ll; // const int mx=1e5+7; // int n,m; // vector<int> a(mx),b(mx); // vector<int> g[mx]; // int deg[mx]; // vector<int> adj[mx]; // vector<int> ans; //---dfs-- // bool visited[mx]; // vector<ll> val(mx,0); //...
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 //#define N 1000005 typedef long long int ll; // const int mx=1e5+7; // int n,m; // vector<int> a(mx),b(mx); // vector<int> g[mx]; // int deg[mx]; // vector<int> adj[mx]; // vector<int> ans; //---dfs-- // bool visited[mx]; // vector<ll> val(mx,0); //...
[["+", 0, 57, 64, 1, 0, 11, 12, 2, 63, 22], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
1
287
X,K,D = map(int, input().split()) if X == 0: if K % 2 == 0: print(0) else: print(D) elif X > 0 : if (X // D) >= K: print(X - K*D) else: X1 = X - (X // D) * D K1 = K - (X // D) if K1 % 2 == 0: print(X1) else: prin...
X,K,D = map(int, input().split()) if X == 0: if K % 2 == 0: print(0) else: print(D) elif X > 0 : if (X // D) >= K: print(X - K*D) else: X1 = X - (X // D) * D K1 = K - (X // D) if K1 % 2 == 0: print(X1) else: prin...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
175
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x = sc.nextLong(), k = sc.nextLong(), d = sc.nextLong(); x = Math.abs(x); if (x / d >= k) { System.out.println(x - k * d); } else { long newX = x % d; ...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x = sc.nextLong(), k = sc.nextLong(), d = sc.nextLong(); x = Math.abs(x); if (x / d >= k) { System.out.println(x - k * d); } else { long newX = x % d; ...
[["+", 75, 196, 0, 503, 49, 200, 51, 16, 31, 22], ["+", 75, 196, 0, 503, 49, 200, 51, 16, 17, 33]]
3
162
#include <algorithm> #include <iostream> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <assert.h> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric...
#include <algorithm> #include <iostream> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <assert.h> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <numeric...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
2,954
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll X, K, D; cin >> X >> K >> D; ll ans = 0; if (X / D <= K) { K -= X / D; X %= D; if (K % 2 == 0) ans = X; else ans = min(abs(X - D), abs(X + D)); } else { if (X > 0) { ans = X - K * D; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll X, K, D; cin >> X >> K >> D; ll ans = 0; if (abs(X / D) <= K) { K -= abs(X / D); X %= D; if (K % 2 == 0) ans = X; else ans = min(abs(X - D), abs(X + D)); } else { if (X > 0) { ans = X ...
[["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25], ["+", 64, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
1
132
x, k, d = list(map(lambda x: int(x), input().split())) min_pos = x % d min_neg = min_pos - d num_to_min_pos = x // d if k <= num_to_min_pos: print(x - d * k) else: if (k - num_to_min_pos) % 2 == 0: print(min_pos) else: print(abs(min_neg))
x, k, d = list(map(lambda x: int(x), input().split())) x = abs(x) min_pos = x % d min_neg = min_pos - d num_to_min_pos = x // d if k <= num_to_min_pos: print(x - d * k) else: if (k - num_to_min_pos) % 2 == 0: print(min_pos) else: print(abs(min_neg))
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
81
X, K, D = map(int, input().split()) if D * K > X: if (K - X // D )% 2 == 0: print(X - D * (X // D)) else: print(abs(X - D * (X // D) - D)) else: print(X - D * K)
X, K, D = map(int, input().split()) X = abs(X) if D * K > X: if (K - X // D )% 2 == 0: print(X - D * (X // D)) else: print(abs(X - D * (X // D) - D)) else: print(X - D * K)
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
79
X, K, D = map(int, input().split()) aX = abs(X) if aX // D >= K: ans = aX - K * D else: if (aX // D ) % 2 == 0: ans = aX % D else: ans = (aX % D) - D print(abs(ans))
X, K, D = map(int, input().split()) aX = abs(X) if aX // D >= K: ans = aX - K * D else: if (K - (aX // D )) % 2 == 0: ans = aX % D else: ans = (aX % D) - D print(abs(ans))
[["+", 15, 666, 0, 657, 31, 23, 0, 657, 31, 22], ["+", 15, 666, 0, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 657, 31, 23, 0, 657, 12, 23, 0, 24], ["+", 0, 657, 31, 23, 0, 657, 12, 23, 0, 25]]
5
74
x, k, d = map(int, input().split()) r, s = divmod(x, d) if r < 0: r = abs(r) if k < r: print(x + k * d) elif r%2 == k%2: print(s) elif r%2 != k%2: print(abs(s-d)) else: if k <= r: print(x - k * d) elif r%2 == k%2: print(s) elif r%2 != k%2: pri...
x, k, d = map(int, input().split()) r, s = divmod(x, d) if r < 0: r = abs(r) if k < r: print(abs(x + k * d)) elif r%2 == k%2: print(s) elif r%2 != k%2: print(abs(s-d)) else: if k <= r: print(abs(x - k * d)) elif r%2 == k%2: print(s) elif r%2 != k%2: ...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
129
import sys x, k, d = map(int, input().split()) #偶数、奇数 isEven = (k%2 == 0) #一番いい回数 div = x//d ans = 0 if k < div: if x > 0: print(abs(x-d*k)) else: print(abs(x+d*k)) else: if x > 0: if (k-div) % 2 == 0: print(abs(x-d*div)) else: hoge = x-d*div ...
import sys x, k, d = map(int, input().split()) #偶数、奇数 isEven = (k%2 == 0) #一番いい回数 div = abs(x//d) #0,a,b ans = 0 if k < div: if x > 0: # print("0")#消す print(abs(x-d*k)) else: # print("1")#消す print(abs(x+d*k)) else: if x > 0: if (k-div) % 2 == 0: # prin...
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
208
x,k,d=list(map(int, input("").split())) x=abs(x) c=x//d m=x%d if c<k: m=abs(m) if (k-c)%2==0: x=m else: if abs(m+d) <= abs(m-d): x=m+d else: x=m-d else: x=m print(abs(x))
x,k,d=list(map(int, input("").split())) x=abs(x) c=x//d m=x%d if c<k: m=abs(m) if (k-c)%2==0: x=m else: if abs(m+d) <= abs(m-d): x=m+d else: x=m-d else: x=x-k*d print(abs(x))
[["-", 75, 76, 8, 196, 0, 1, 0, 662, 12, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 31, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 0, 1, 0, 662, 12, 657, 12, 657, 31, 22], ["+", 0, 1, 0, 662, 12, 657, 12, 657, 17, 48], ["+", 0, 1, 0, 662, 12, 657, 12, 657, 12, 22]]
5
105
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x = sc.nextLong(); long k = sc.nextLong(); long d = sc.nextLong(); sc.close(); if (x / d > k) { print(x - d * k); return; } long min = x % d;...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x = Math.abs(sc.nextLong()); long k = sc.nextLong(); long d = sc.nextLong(); sc.close(); if (x / d > k) { print(x - d * k); return; } long mi...
[["+", 8, 196, 0, 503, 49, 200, 51, 492, 500, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 0, 131], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 0, 503, 49, 200, 51, 492, 3, 4, 0, 24], ["+", 51, 492, 3, 4, 0, 492, 3, 4, 0, 25]]
3
159
import sys X, K, D = [int(x) for x in input().strip().split(" ")] X = abs(X) k, x = divmod(X, D) if K <= k: print(abs(X - D * K)) sys.exit(0) X = x K -= k if k % 2 == 0: print(abs(X)) sys.exit(0) print(abs(X - D))
import sys X, K, D = [int(x) for x in input().strip().split(" ")] X = abs(X) k, x = divmod(X, D) if K <= k: print(X - D * K) sys.exit(0) X = x K -= k if K % 2 == 0: print(abs(X)) sys.exit(0) print(abs(X - D))
[["-", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 0, 656, 0, 57, 15, 666, 0, 657, 31, 22], ["+", 0, 656, 0, 57, 15, 666, 0, 657, 31, 22]]
5
104
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll inf = 1000000007; int main() { ll x, k, d; cin >> x >> k >> d;...
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll inf = 1000000007; int main() { ll x, k, d; cin >> x >> k >> d;...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 12, 2, 3, 4, 0, 16, 31, 2, 63, 22], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
289