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
// https://atcoder.jp/contests/abc175/tasks/abc175_c #include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) FOR(i, 0, n) #define REPR(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() ...
// https://atcoder.jp/contests/abc175/tasks/abc175_c #include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) FOR(i, 0, n) #define REPR(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
215
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; x = abs(x); long long tmp = min(k, x / d); x -= tmp * d; k = tmp; if (k % 2 != 0) { x = abs(x - d); } cout << x << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; x = abs(x); long long tmp = min(k, x / d); x -= tmp * d; k -= tmp; if (k % 2 != 0) { x = abs(x - d); } cout << x << endl; return 0; }
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 110]]
1
90
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) def inp():return stdin.readline() def out(x):return stdout.write(x) import math INT_MIN=-10**13 import bisect as B ###############################################################################\ x,k,d=INPUT() if x<0: if ...
from sys import stdin,stdout def INPUT():return list(int(i) for i in stdin.readline().split()) def inp():return stdin.readline() def out(x):return stdout.write(x) import math INT_MIN=-10**13 import bisect as B ###############################################################################\ x,k,d=INPUT() x=abs(x) if x<0...
[["+", 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
299
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll x, k, d; cin >> x >> k >> d; ll y = abs(x); ll a, b, c; if (x >= 0) { a = x / d; b = k - a; if (k < a) { cout << x - k * d << endl; } else { c = x - (x / d) * d; if (b & 1) { c -= d; ...
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll x, k, d; cin >> x >> k >> d; ll y = abs(x); ll a, b, c; if (x >= 0) { a = x / d; b = k - a; if (k < a) { cout << x - k * d << endl; } else { c = x - (x / d) * d; if (b & 1) { c -= 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]]
1
212
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define mod 1000000007 int main() { ll i, x, k, d, z, dist; cin >> x >> k >> d; if (x < 0) x = x * (-1); if (d >= x && k % 2 == 1) dist = d - x; else if (d >= x && k % 2 == 0) dist = x; else if (d < x) { z = x / d; ll mi...
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define mod 1000000007 int main() { ll i, x, k, d, z, dist; cin >> x >> k >> d; if (x < 0) x = x * (-1); if (d >= x && k % 2 == 1) dist = d - x; else if (d >= x && k % 2 == 0) dist = x; else if (d < x) { z = x / d; ll mi...
[["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
173
x, k, d = map(int, input().split()) ml = min(x//d, k) mu = min(ml+1, k) diff_ml = k - ml diff_mu = k - mu print(x-ml*d if diff_ml%2 == 0 else mu*d-x)
x, k, d = map(int, input().split()) x = abs(x) ml = min(x//d, k) mu = min(ml+1, k) diff_ml = k - ml diff_mu = k - mu print(x-ml*d if diff_ml%2 == 0 else mu*d-x)
[["+", 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
68
x,k,d=map(int,input().split()) x=abs(x) m=min(k,x//d) x-=d*m k-=m k%=2 print(abs(x))
x,k,d=map(int,input().split()) x=abs(x) m=min(k,x//d) x-=d*m k-=m k%=2 x-=d*k print(abs(x))
[["+", 36, 36, 0, 656, 0, 1, 0, 677, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 677, 17, 110], ["+", 0, 656, 0, 1, 0, 677, 12, 657, 31, 22], ["+", 0, 656, 0, 1, 0, 677, 12, 657, 17, 48], ["+", 0, 656, 0, 1, 0, 677, 12, 657, 12, 22]]
5
52
x,k,d=map(int,input().split()) x=abs(x) sa=x//d ans=x pbk,mbk=0,0 bk1,bk2,bk3=1,1,1 mansbk,pansbk=0,0 if sa>=k: ans=x-d*k else: ans=x-d*sa k=k-sa for i in range(k): mansbk=abs(ans-d) pansbk=abs(ans+d) if mansbk!=pansbk: ans=min(mansbk,pansbk) if bk3!=1: bk1=min(mansbk,pansbk) ...
x,k,d=map(int,input().split()) x=abs(x) sa=x//d ans=x pbk,mbk=0,0 bk1,bk2,bk3=1,1,1 mansbk,pansbk=0,0 if sa>=k: ans=x-d*k else: ans=x-d*sa k=k-sa for i in range(k): mansbk=abs(ans-d) pansbk=abs(ans+d) if mansbk!=pansbk: ans=min(mansbk,pansbk) if bk3!=1: bk1=min(mansbk,pansbk) ...
[["-", 64, 196, 0, 1, 0, 662, 12, 41, 0, 22], ["+", 64, 196, 0, 1, 0, 662, 12, 41, 0, 22], ["-", 0, 1, 0, 662, 12, 41, 0, 666, 0, 612], ["+", 0, 1, 0, 662, 12, 41, 0, 666, 0, 612]]
5
205
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int l...
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int l...
[["-", 75, 76, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 75, 76, 0, 1, 0, 16, 31, 16, 12, 22]]
1
388
a,b,c=map(int,input().split()) if abs(a)>=abs(b*c): print(abs(abs(a)-abs(b*c))) exit() n=abs(a) m=n//c if abs(a)-abs(c*m)>abs(a)-abs(c*(m+1)): m=m+1 print(m) if (b-m)%2==0: print(abs(abs(a)-abs(c*m))) else: print(min(abs(abs(a)-abs(c*(m+1))),abs(abs(a)-abs(c*(m-1)))))
a,b,c=map(int,input().split()) if abs(a)>=abs(b*c): print(abs(abs(a)-abs(b*c))) exit() n=abs(a) m=n//c if abs(a)-abs(c*m)>abs(a)-abs(c*(m+1)): m=m+1 if (b-m)%2==0: print(abs(abs(a)-abs(c*m))) else: print(min(abs(abs(a)-abs(c*(m+1))),abs(abs(a)-abs(c*(m-1)))))
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
173
#include <bits/stdc++.h> using namespace std; /******* All Required define Pre-Processors and typedef Constants *******/ #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, a, b) for (int i = a; i <= (b); ++i) #define rep3(i, a, b) for (int i = a; i >= (b); --i) #define all(cont) cont.begin(), cont.end() #...
#include <bits/stdc++.h> using namespace std; /******* All Required define Pre-Processors and typedef Constants *******/ #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, a, b) for (int i = a; i <= (b); ++i) #define rep3(i, a, b) for (int i = a; i >= (b); --i) #define all(cont) cont.begin(), cont.end() #...
[["+", 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,120
X, K, D = map(int, input().split()) X= abs(X) min_pos = X%D min_neg = min_pos - D if(X/D >= K): print(X-D*K) else: if(((X-min_pos)/D)%2 == 0): print("A", min_pos) else: print(abs(min_neg))
X, K, D = map(int, input().split()) X= abs(X) min_pos = X%D min_neg = min_pos - D if(X/D >= K): print(X-D*K) else: if((K - (X-min_pos)/D)%2 == 0): print(min_pos) else: print(abs(min_neg))
[["+", 0, 666, 0, 657, 31, 23, 0, 657, 31, 22], ["+", 0, 666, 0, 657, 31, 23, 0, 657, 17, 33], ["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 21]]
5
87
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); ll x; cin >> x; ll k; cin >> k; ll d; cin >> d; ll absx = x; if (absx < 0) { absx *= -1; } if (absx / d > k) { cout << (absx - k * d) << endl; } else { ll t...
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); ll x; cin >> x; ll k; cin >> k; ll d; cin >> d; ll absx = x; if (absx < 0) { absx *= -1; } if (absx / d > k) { cout << (absx - k * d) << endl; } else { ll t...
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22]]
1
157
#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() { int64_t x, k, d; cin >> x >> k >> d; if (x < 0) x = -x; int64_t res = 0; if (x > k * d) { res = x - k * d; cout << res << endl; return 0;...
#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() { int64_t x, k, d; cin >> x >> k >> d; if (x < 0) x = -x; int64_t res = 0; if (x / d >= k) { res = x - k * d; cout << res << endl; return 0...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
161
#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() { int64_t x, k, d; cin >> x >> k >> d; x = abs(x); int64_t res = 0; if (x >= k * d) { res = x - k * d; cout << res << endl; return 0; } //...
#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() { int64_t x, k, d; cin >> x >> k >> d; x = abs(x); int64_t res = 0; if (x / d > k) { res = x - k * d; cout << res << endl; return 0; } // ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
144
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vector<int>> vvi; #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, s, n) for (int i = (s); i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vector<int>> vvi; #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, s, n) for (int i = (s); i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (...
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
179
#include <bits/stdc++.h> using namespace std; void Main() { long x, k, d; cin >> x >> k >> d; if (x < 0) x = -x; if (x > k * d) { cout << x - k * d << endl; return; } k -= x / d; x = x - (x / d * d); if (k % 2 == 0) cout << x << endl; else cout << d - x << endl; } int main(int ar...
#include <bits/stdc++.h> using namespace std; void Main() { long x, k, d; cin >> x >> k >> d; if (x < 0) x = -x; if (x / d > k) { cout << x - k * d << endl; return; } k -= x / d; x = x - (x / d * d); if (k % 2 == 0) cout << x << endl; else cout << d - x << endl; } int main(int ar...
[["+", 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
137
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, t, x, k, d; int main() { cin >> x >> k >> d; x = abs(x); if (k * d <= x) { cout << x - k * d << endl; } else if (x % d == 0) { ll t = x / d; k -= t; if (k & 1) cout << d << endl; else cout << 0 << endl; }...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, t, x, k, d; int main() { cin >> x >> k >> d; x = abs(x); if (k < x / d) { cout << x - k * d << endl; } else if (x % d == 0) { ll t = x / d; k -= t; if (k & 1) cout << d << endl; else cout << 0 << endl; } ...
[["-", 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, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
151
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { long long X, K, D; cin >> X >> K >> D; if (abs(X) / D >= K) { cout << abs(X) - D * K << endl; } else { long long rest = abs(X) - D * abs(X / D); long long num = K - abs(X) / D; if (K % 2 != 0) { cout << ab...
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { long long X, K, D; cin >> X >> K >> D; if (abs(X) / D >= K) { cout << abs(X) - D * K << endl; } else { long long rest = abs(X) - D * abs(X / D); long long num = K - abs(X) / D; if (num % 2 != 0) { cout << ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22]]
1
121
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #...
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
245
#include <bits/stdc++.h> using namespace std; int main() { int64_t X, K, D; cin >> X >> K >> D; abs(X); int64_t dis = X / D; int64_t ans; if (dis > K) { ans = X - K * D; } else { if ((dis % 2) == (K % 2)) { ans = X % D; } else { ans = (X % D) - D; } } cout << abs(ans) << e...
#include <bits/stdc++.h> using namespace std; int main() { int64_t X, K, D; cin >> X >> K >> D; X = abs(X); int64_t dis = X / D; int64_t ans; if (dis > K) { ans = X - K * D; } else { if ((dis % 2) == (K % 2)) { ans = X % D; } else { ans = (X % D) - D; } } cout << abs(ans) ...
[["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32]]
1
108
#include <bits/stdc++.h> using namespace std; int main() { long long X, K, D; cin >> X >> K >> D; long long llabs(X); long long dis = X / D; long long ans; if (dis >= K) { ans = X - K * D; } else { if ((dis % 2) == (K % 2)) { ans = X % D; } else { ans = D - (X % D); } } c...
#include <bits/stdc++.h> using namespace std; int main() { long long X, K, D; cin >> X >> K >> D; X = abs(X); long long dis = X / D; long long ans; if (dis >= K) { ans = X - K * D; } else { if ((dis % 2) == (K % 2)) { ans = X % D; } else { ans = D - (X % D); } } cout << an...
[["-", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 14, 8, 9, 0, 43, 49, 53, 49, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22]]
1
110
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; const int INF = 100000000...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; const int INF = 100000000...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 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
186
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(k, i, n) for (ll i = k; i < n; ++i) int main(void) { ll x, k, d; cin >> x >> k >> d; x = abs(x); if (x - k * d >= 0) { cout << x - k * d; } else { ll ans = (k % 2 == x / d % 2) ? (x % d) : (abs(x % d - d)); cout << ans...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(k, i, n) for (ll i = k; i < n; ++i) int main(void) { ll x, k, d; cin >> x >> k >> d; x = abs(x); if (x / d - k >= 0) { cout << x - k * d; } else { ll ans = (k % 2 == x / d % 2) ? (x % d) : (abs(x % d - d)); cout << ans...
[["+", 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, 16, 17, 48], ["-", 15, 339, 51, 16, 31, 16, 12, 16, 12, 22]]
1
109
#include <algorithm> #include <iostream> #include <list> #include <queue> #include <string> #include <vector> #define rep(i, n) for (i = 0; i < (n); i++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define MOD 1000000007 #define PI 3.14159265358979323846 #define INF 1 << 30 using namespace std;...
#include <algorithm> #include <iostream> #include <list> #include <queue> #include <string> #include <vector> #define rep(i, n) for (i = 0; i < (n); i++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define MOD 1000000007 #define PI 3.14159265358979323846 #define INF 1 << 30 using namespace std;...
[["+", 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
156
def li(): return [int(x) for x in input().split()] x, k, d = li() x = abs(x) if k * d < x: ans = x - k * d print(ans) exit() xr = x % d xl = xr - d r_parity = (x - xr) // d % 2 k_parity = k % 2 if r_parity == k_parity: print(xr) else: print(xl)
def li(): return [int(x) for x in input().split()] x, k, d = li() x = abs(x) if k * d < x: ans = x - k * d print(ans) exit() xr = x % d xl = xr - d r_parity = (x - xr) // d % 2 k_parity = k % 2 if r_parity == k_parity: print(xr) else: print(abs(xl))
[["+", 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
99
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: dis = x % d dis_p = d - dis c = k - x // d if c % 2 == 0: print(dis) else: print(dis_p)
x, k, d = map(int,input().split()) if x - k * d >= 0: print(x - k * d) elif x + k * d <= 0: print(abs(x + k * d)) else: dis = x % d dis_p = d - dis c = k - x // d if c % 2 == 0: print(dis) else: print(dis_p)
[["+", 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
88
x, k, d = map(int, input().split()) if abs(x) >= k * d: print(abs(x) - k * d) else: q, mod = divmod(x, d) if k - q % 2 == 0: print(mod) else: print(abs(mod - d))
x, k, d = map(int, input().split()) if abs(x) >= k * d: print(abs(x) - k * d) else: q, mod = divmod(x, d) if (k - q) % 2 == 0: print(mod) else: print(abs(mod - d))
[["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 24], ["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 25]]
5
75
x, k, d = map(int, input().split()) if x == 0: if k % 2 == 0: print(0) else: print(d) elif x > 0: if x >= k * d: print(x - k * d) else: q, mod = divmod(x, d) k -= q if k % 2 == 0: print(mod) else: print(abs(mod - d)) elif x...
x, k, d = map(int, input().split()) if x == 0: if k % 2 == 0: print(0) else: print(d) elif x > 0: if x >= k * d: print(x - k * d) else: q, mod = divmod(x, d) k -= q if k % 2 == 0: print(mod) else: print(abs(mod - d)) elif x...
[["+", 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
160
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int(i) = 0; (i) < (n); ++(i)) #define REPR(i, n) for (int(i) = (n); (i) >= 0; --(i)) #define FOR(i, n, m) for (int(i) = (n); (i) < (m); ++(i)) constexpr int INF = 1e9; // constexpr ll INF = 1LL<<61; constexpr ll mod = 1e9 + 7; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int(i) = 0; (i) < (n); ++(i)) #define REPR(i, n) for (int(i) = (n); (i) >= 0; --(i)) #define FOR(i, n, m) for (int(i) = (n); (i) < (m); ++(i)) constexpr int INF = 1e9; // constexpr ll INF = 1LL<<61; constexpr ll mod = 1e9 + 7; ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
180
#include <algorithm> #include <cassert> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <tuple> #include <vector> #define _LIBCPP_DEBUG 0 using namespace std; int main() { long long int x, k, d; cin >> x >> k >> d; if (x < 0) { x = (-1) * x; } long long r = x / d; ...
#include <algorithm> #include <cassert> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <tuple> #include <vector> #define _LIBCPP_DEBUG 0 using namespace std; int main() { long long int x, k, d; cin >> x >> k >> d; if (x < 0) { x = (-1) * x; } long long r = x / d; ...
[["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 110], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
138
X, K, D = map(int, input().split()) cnt = abs(X) // D ans1 = X - cnt * D ans2 = abs(ans1 - D) if cnt < K: if (K - cnt)%2 == 0: print(ans1) else: print(ans2) else: print(X - K * D)
X, K, D = map(int, input().split()) X = abs(X) cnt = X // D ans1 = X - cnt * D ans2 = abs(ans1 - D) if cnt < K: if (K - cnt)%2 == 0: print(ans1) else: print(ans2) else: print(X - K * D)
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 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, 657, 31, 22]]
5
77
x, k, d = map(int, input().split()) cnt = abs(x) // d if k % 2 == cnt % 2: ans = min(abs(x - d * min(k,cnt)), abs(x + d * min(k,cnt))) elif k % 2 != cnt % 2: ans = min(abs(x - d * min(k,(cnt + 1))), abs(x - d * min(k,(cnt + 1)))) print(ans)
x, k, d = map(int, input().split()) cnt = abs(x) // d x = abs(x) if k % 2 == cnt % 2: ans = min(abs(x - d * min(k,cnt)), abs(x + d * min(k,cnt))) elif k % 2 != cnt % 2: ans = min(abs(x - d * min(k,(cnt + 1))), abs(x - d * min(k,(cnt + 1)))) print(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
120
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; long long x, k, d; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> x >> k >> d; x = abs(x); long long req = (x % d) ? x / d + 1 : x / d...
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; long long x, k, d; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> x >> k >> d; x = abs(x); long long req = (x % d) ? x / d + 1 : x / 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]]
1
140
#include <bits/stdc++.h> using namespace std; int main() { long long x, K, D, ans, cnt; cin >> x >> K >> D; if (x < 0) x = -x; if (x >= K * D) { ans = x - K * D; } else { K -= x / D; cnt = x % D; if (K % 2 == 0) { ans = cnt; } else { ans = D - cnt; } } cout << ans...
#include <bits/stdc++.h> using namespace std; int main() { long long x, K, D, ans, cnt; cin >> x >> K >> D; if (x < 0) x = -x; if (x / D >= K) { ans = x - K * D; } else { K -= x / D; cnt = x % D; if (K % 2 == 0) { ans = cnt; } else { ans = D - cnt; } } cout << ans...
[["+", 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
105
import math x,k,d = map(int,input().split()) if x-k*d > 0: print(x-k*d) exit elif x+k*d < 0: print(x+k*d) exit else: m = 2 * math.ceil(((k-2)*d-x)/(2*d))- k print(min(abs(x+m*d), abs(x+(m+2)*d)))
import math x,k,d = map(int,input().split()) if x-k*d > 0: print(x-k*d) exit elif x+k*d < 0: print(-1*(x+k*d)) exit else: m = 2 * math.ceil(((k-2)*d-x)/(2*d))- k print(min(abs(x+m*d), abs(x+(m+2)*d)))
[["+", 0, 652, 3, 4, 0, 657, 31, 664, 17, 33], ["+", 0, 652, 3, 4, 0, 657, 31, 664, 28, 612], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 48], ["+", 0, 652, 3, 4, 0, 657, 12, 23, 0, 24], ["+", 0, 652, 3, 4, 0, 657, 12, 23, 0, 25]]
5
113
X, K, D = map(int, input().split()) t = abs(X) // D now = X - t*D if K <= t: ans = X - D*K else: if (K - t) % 2 == 0: ans = now else: ans = abs(now - D) print(ans)
X, K, D = map(int, input().split()) X = abs(X) t = X // D now = X - t*D if K <= t: ans = X - D*K else: if (K - t) % 2 == 0: ans = now else: ans = abs(now - D) print(ans)
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 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, 657, 31, 22]]
5
75
#include <bits/stdc++.h> #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, k, d; cin >> x...
#include <bits/stdc++.h> #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, k, d; cin >> 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
177
l = list(map(int,input().split())) x = l[0] k = l[1] d = l[2] prev = 0 n = x//d if k%2 == 0 and n%2 == 1: n += 1 elif k%2 == 1 and n%2 == 0: n += 1 if n>k: n = k ans = abs(x-n*d) print(ans)
l = list(map(int,input().split())) x = abs(l[0]) k = l[1] d = l[2] prev = 0 n = x//d if k%2 == 0 and n%2 == 1: n += 1 elif k%2 == 1 and n%2 == 0: n += 1 if n>k: n = k ans = abs(x-n*d) print(ans)
[["+", 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
97
X, K, D = map(int, input().split()) X = abs(X) a = X/D ans = 0 if a>=K: ans = X-(D*K) else: if K%2==0: if a%2==0: ans = X-(D*a) else: ans = X-(D*a)-D else: if a%2==0: ans = X-(D*a)-D else: ans = X-(D*a) ans = int(abs(ans)) print(ans)
X, K, D = map(int, input().split()) X = abs(X) a = int(X/D) ans = 0 if a>=K: ans = X-(D*K) else: if K%2==0: if a%2==0: ans = X-(D*a) else: ans = X-(D*a)-D else: if a%2==0: ans = X-(D*a)-D else: ans = X-(D*a) ans = int(abs(ans)) print(ans)
[["+", 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
128
#include <bits/stdc++.h> using namespace std; int main() { long long X, K, D, t, ans; cin >> X >> K >> D; t = abs(X) / D; if (t >= K) { if (X > 0) ans = X - D * K; else ans = X + D * K; } else { K -= t; K %= 2; // cout << D << " " << K << endl; if (X > 0) ans = min...
#include <bits/stdc++.h> using namespace std; int main() { long long X, K, D, t, ans; cin >> X >> K >> D; t = abs(X) / D; if (t >= K) { if (X > 0) ans = X - D * K; else ans = X + D * K; } else { K -= t; K %= 2; // cout << D << " " << K << endl; if (X > 0) ans = min...
[["+", 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
162
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; ll x, k, d; bool f(ll a) { ld ret = (ld)x / (ld)d; return ret <= (k - 2 * a); } int main() { cin >> x >> k >> d; ll lo = -k, hi = k, ans = 0, mid; while (lo <= hi) { mid = (lo + hi) / 2; if (f(mid)) an...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; ll x, k, d; bool f(ll a) { ld ret = (ld)x / (ld)d; return ret <= (k - 2 * a); } int main() { cin >> x >> k >> d; ll lo = 0, hi = k, ans = 0, mid; while (lo <= hi) { mid = (lo + hi) / 2; if (f(mid)) ans...
[["-", 8, 9, 0, 43, 49, 50, 51, 91, 17, 33], ["-", 8, 9, 0, 43, 49, 50, 51, 91, 28, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
1
252
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <set> #include <stdio.h> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int main() { ll p, k, d; cin >> p >> k >> d; ll abs_p = abs(p); if (abs_p / d >= k...
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <set> #include <stdio.h> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int main() { ll p, k, d; cin >> p >> k >> d; ll abs_p = abs(p); if (abs_p / d >= k...
[["+", 15, 339, 51, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 31, 16, 31, 23, 0, 25]]
1
181
# import sys # readline = sys.stdin.readline # generator = (readline().strip() for _ in range(N)) # N, M = map(int, input().split()) # As = list(map(int, input().split())) # queries = (input() for _ in range(N)) def solve(): x, k, d = map(int, input().split()) pmin = x - k * d if pmin >= 0: retu...
# import sys # readline = sys.stdin.readline # generator = (readline().strip() for _ in range(N)) # N, M = map(int, input().split()) # As = list(map(int, input().split())) # queries = (input() for _ in range(N)) def solve(): x, k, d = map(int, input().split()) x = abs(x) pmin = x - k * d if pmin >= ...
[["+", 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
109
X, K, D = map(int, input().split()) X = abs(X) a = X % D X -= min(a, K) * D K -= min(a, K) if K > 0 and abs(X) > abs(X - D): X -= D K -= 1 K %= 2 if K == 1: if abs(X + D) < abs(X - D): X += D else: X -= D result = abs(X) print(result)
X, K, D = map(int, input().split()) X = abs(X) a = X // D X -= min(a, K) * D K -= min(a, K) if K > 0 and abs(X) > abs(X - D): X -= D K -= 1 K %= 2 if K == 1: if abs(X + D) < abs(X - D): X += D else: X -= D result = abs(X) print(result)
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 17, 109], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 676]]
5
111
if __name__ == "__main__": X, K, D = list(map(int, input().split())) if abs(X) // D >= K: print(abs(X) - D * K) else: t = abs(X) // D if X == 0 and K % 2 != 0: print(D) elif X == 0 and K % 2 == 0: print("0") else: if abs(X) - D*t <...
if __name__ == "__main__": X, K, D = list(map(int, input().split())) if abs(X) // D >= K: print(abs(X) - D * K) else: t = abs(X) // D if X == 0 and K % 2 != 0: print(D) elif X == 0 and K % 2 == 0: print("0") else: if abs(X) - D*t <...
[["+", 0, 657, 31, 23, 0, 657, 12, 23, 0, 24], ["+", 31, 23, 0, 657, 12, 23, 0, 657, 17, 72], ["+", 31, 23, 0, 657, 12, 23, 0, 657, 12, 612], ["+", 0, 657, 31, 23, 0, 657, 12, 23, 0, 25]]
5
205
# 初期入力 import sys input = sys.stdin.readline #文字列では使わない X,K,D = map(int, input().split()) q1,min1 =divmod(X,D) q1 =abs(q1) if min1 >=0: min2 =min1 -D else: min2 =min1 +D ans =0 if K <= q1: ans =abs(X) -K *D elif K %2 ==0 and q1 %2 ==0: ans =abs(min1) elif K %2 ==1 and q1 %2 ==1: ans =abs(min2) eli...
# 初期入力 import sys input = sys.stdin.readline #文字列では使わない X,K,D = map(int, input().split()) q1,min1 =divmod(X,D) q1 =abs(q1) if min1 >=0: min2 =min1 -D else: min2 =min1 +D ans =0 if K <= q1: ans =abs(X) -K *D elif K %2 ==0 and q1 %2 ==0: ans =abs(min1) elif K %2 ==1 and q1 %2 ==1: ans =abs(min1) eli...
[["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22]]
5
160
class Main { public static void main(String[] args) { Main main = new Main(); java.util.Scanner sc = new java.util.Scanner(System.in); long X = sc.nextLong(); long K = sc.nextLong(); long D = sc.nextLong(); long nowplace = X; if (X > 0) { long count = X / D; if (X % D != ...
class Main { public static void main(String[] args) { Main main = new Main(); java.util.Scanner sc = new java.util.Scanner(System.in); long X = sc.nextLong(); long K = sc.nextLong(); long D = sc.nextLong(); long nowplace = X; if (X > 0) { long count = X / D; if (X % D != ...
[["+", 0, 503, 49, 200, 51, 16, 31, 492, 500, 22], ["+", 0, 503, 49, 200, 51, 16, 31, 492, 0, 131], ["+", 0, 503, 49, 200, 51, 16, 31, 492, 141, 22], ["+", 49, 200, 51, 16, 31, 492, 3, 4, 0, 24], ["+", 49, 200, 51, 16, 31, 492, 3, 4, 0, 25]]
3
361
x,k,d = map(int, input().split()) mx = x + d*k mn = x - d*k if (x < 0 and mx > 0) or (x > 0 and mn < 0): if k%2 == 0: if x < 0: b = min(abs(abs(x)%(2*d)),abs(x%(2*d)-2*d)) else: b = min(abs(x%(2*d)),abs(x%(2*d)-2*d)) b = min(abs(b),abs(mx),abs(mn)) else: if x > 0: b = min(abs(abs(...
x,k,d = map(int, input().split()) mx = x + d*k mn = x - d*k if (x <= 0 and mx > 0) or (x >= 0 and mn < 0): if k%2 == 0: if x < 0: b = min(abs(abs(x)%(2*d)),abs(abs(x)%(2*d)-2*d)) else: b = min(abs(x%(2*d)),abs(x%(2*d)-2*d)) b = min(abs(b),abs(mx),abs(mn)) else: if x > 0: b = min(...
[["-", 15, 679, 31, 23, 0, 679, 31, 666, 667, 18], ["+", 15, 679, 31, 23, 0, 679, 31, 666, 667, 19], ["-", 15, 679, 12, 23, 0, 679, 31, 666, 667, 47], ["+", 15, 679, 12, 23, 0, 679, 31, 666, 667, 20], ["+", 3, 4, 0, 657, 31, 657, 31, 652, 63, 22], ["+", 0, 657, 31, 657, 31, 652, 3, 4, 0, 24], ["+", 0, 657, 31, 657, 31,...
5
277
x,k,d = map(int,input().split()) c = abs(x)//d if c < k: if (k-c) % 2 == 0: print(abs(x)%d) else: print(min(abs(x%d+d),abs(x%d-d))) else: print(abs(x)-d*k)
x,k,d = map(int,input().split()) c = abs(x)//d if c < k: if (k-c) % 2 == 0: print(abs(x)%d) else: print(min(abs(abs(x)%d+d),abs(abs(x)%d-d))) else: print(abs(x)-d*k)
[["+", 3, 4, 0, 657, 31, 657, 31, 652, 63, 22], ["+", 0, 657, 31, 657, 31, 652, 3, 4, 0, 24], ["+", 0, 657, 31, 657, 31, 652, 3, 4, 0, 25], ["+", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24]]
5
89
x,k,d = gets.split(" ").map(&:to_i) min_steps = x.abs / d min1 = x - min_steps * d * (x>0 ? 1 : -1) min2 = min1 + d * (min1>0 ? -1 : 1) if k < min_steps then puts x - k * d * (x>0 ? 1 : -1) elsif k == min_steps then puts min1.abs else puts (k - min_steps) % 2 == 0 ? min1.abs : min2.abs end
x,k,d = gets.split(" ").map(&:to_i) min_steps = x.abs / d min1 = x - min_steps * d * (x>0 ? 1 : -1) min2 = min1 + d * (min1>0 ? -1 : 1) if k < min_steps then puts (x - k * d * (x>0 ? 1 : -1)).abs elsif k == min_steps then puts min1.abs else puts (k - min_steps) % 2 == 0 ? min1.abs : min2.abs end
[["+", 0, 652, 3, 4, 0, 652, 486, 739, 0, 24], ["+", 486, 739, 0, 738, 12, 738, 12, 739, 0, 25], ["+", 64, 749, 0, 652, 3, 4, 0, 652, 17, 131], ["+", 64, 749, 0, 652, 3, 4, 0, 652, 735, 22]]
4
112
import sys X, K, D = map(int,input().split()) if X > K * D: print(abs(X - K * D)) sys.exit() Appr = X // D Near = X - (X // D) * D if (K - Appr) % 2 != 0: print(abs(Near - D)) else: print(abs(Near))
import sys X, K, D = map(int,input().split()) if abs(X) > K * D: print(abs(abs(X) - K * D)) sys.exit() Appr = X // D Near = X - (X // D) * D if (K - Appr) % 2 != 0: print(abs(Near - D)) else: print(abs(Near))
[["+", 0, 656, 0, 57, 15, 666, 0, 652, 63, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 24], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25]]
5
88
// >>> TEMPLATES #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; #define int ll #define double ld #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <=...
// >>> TEMPLATES #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; #define int ll #define double ld #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <=...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
1,293
x, k, d = map(int,input().split()) max_length = k * d xx = abs(x) answer = 0 if xx >= max_length: answer = xx - max_length else: if (k - xx // d) % 2 == 0: answer = xx - xx // d * k else: answer = xx - (xx // d + 1) * k print(abs(answer))
x, k, d = map(int,input().split()) max_length = k * d xx = abs(x) answer = 0 if xx >= max_length: answer = xx - max_length else: if (k - xx // d) % 2 == 0: answer = xx - xx // d * d else: answer = xx - (xx // d + 1) * d print(abs(answer))
[["-", 0, 1, 0, 662, 12, 657, 12, 657, 12, 22], ["+", 0, 1, 0, 662, 12, 657, 12, 657, 12, 22]]
5
88
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1000000007; const ll INF = 10000000000000; #define all(v) v.begin(), v.end() int main() { ll X, K, D; cin >> X >> K >> D; X = abs(X); if (X > K * D) {...
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1000000007; const ll INF = 10000000000000; #define all(v) v.begin(), v.end() int main() { ll X, K, D; cin >> X >> K >> D; X = abs(X); if (X / D > K) {...
[["+", 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
178
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int x, k, d; cin >> x >> k >> d; if (x == 0) { if (k % 2 == 0) { cout << "0"; } else { cout << d; } } else if (x < 0) { long long int l = abs(x); long long ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int x, k, d; cin >> x >> k >> d; if (x == 0) { if (k % 2 == 0) { cout << "0"; } else { cout << d; } } else if (x < 0) { long long int l = abs(x); long long ...
[["+", 0, 9, 0, 1, 0, 16, 12, 2, 63, 22], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 24], ["+", 12, 2, 3, 4, 0, 16, 12, 23, 0, 25]]
1
292
#include <bits/stdc++.h> using namespace std; int main() { long long int x, k, d; cin >> x >> k >> d; if (x < 0) { x *= -1; } if (k < x / d) { x -= k * d; } else { if ((k - x / d) % 2 == 0) { x = x % d; } else { x -= x % d; } } cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int x, k, d; cin >> x >> k >> d; if (x < 0) { x *= -1; } if (k < x / d) { x -= k * d; } else { if ((k - x / d) % 2 == 0) { x = x % d; } else { x = d - x % d; } } cout << x << endl; return 0; }
[["-", 75, 76, 0, 9, 0, 1, 0, 11, 17, 110], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 17, 33]]
1
100
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll x, k, d; cin >> x >> k >> d; if (x > 0) { ll p = x % d; ll z = (x - p) / d; if (k <= z) { cout << x - (k * d) << endl; } else { if ((k - z) % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll x, k, d; cin >> x >> k >> d; if (x > 0) { ll p = x % d; ll z = (x - p) / d; if (k <= z) { cout << x - (k * d) << endl; } else { if ((k - z) % 2 == 0) { ...
[["+", 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, 12, 23, 0, 25]]
1
240
def main(): X, K, D = map(int, input().split()) r = X // D if r > K: print(abs(X - K * D)) exit() a = X - r * D if (K - r) % 2 == 0: print(a) else: print(abs(D - a)) if __name__ == '__main__': main()
def main(): X, K, D = map(int, input().split()) r = X // D if abs(r) > K: print(abs(X) - K * D) exit() a = X - r * D if (K - r) % 2 == 0: print(a) else: print(abs(D - a)) if __name__ == '__main__': main()
[["+", 8, 196, 0, 57, 15, 666, 0, 652, 63, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 24], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 25], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
90
#include <bits/stdc++.h> using namespace std; long long int modPow(long long int a, long long int n) { //繰り返し自乗法(a^n mod p)。計算量 O(logN) long long int p = pow(10, 9) + 7; //任意のp(素数) modのやつで使える if (n == 0) { return 1; } if (n == 1) { return a % p; } if (n % 2 == 1) { return (a * modPow(a, ...
#include <bits/stdc++.h> using namespace std; long long int modPow(long long int a, long long int n) { //繰り返し自乗法(a^n mod p)。計算量 O(logN) long long int p = pow(10, 9) + 7; //任意のp(素数) modのやつで使える if (n == 0) { return 1; } if (n == 1) { return a % p; } if (n % 2 == 1) { return (a * modPow(a, ...
[["+", 0, 1, 0, 11, 12, 16, 31, 2, 63, 22], ["+", 0, 11, 12, 16, 31, 2, 3, 4, 0, 24], ["+", 0, 11, 12, 16, 31, 2, 3, 4, 0, 25], ["+", 0, 11, 12, 16, 31, 16, 31, 2, 63, 22], ["+", 12, 16, 31, 16, 31, 2, 3, 4, 0, 24], ["+", 12, 16, 31, 16, 31, 2, 3, 4, 0, 25]]
1
365
#include "bits/stdc++.h" using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rrep(i, n) for (int i = ((int)n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define INF 2e15 #define MOD 10e9 + 7 typedef vector<int> vint; typedef long long ll; int...
#include "bits/stdc++.h" using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rrep(i, n) for (int i = ((int)n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define INF 2e15 #define MOD 10e9 + 7 typedef vector<int> vint; typedef long long ll; int...
[["+", 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
223
#include <bits/stdc++.h> using namespace std; int main() { long long x, a, k, d; cin >> x >> k >> d; if ((abs(x) > k * d) || (((k * d) % 1000000007 - (k % 1000000007) * (d % 1000000007)) % 1000000007 != 0)) { if (x > 0) a = x - k * d; else a = abs(k * d + x); } else {...
#include <bits/stdc++.h> using namespace std; int main() { long long x, a, k, d; cin >> x >> k >> d; if ((abs(x) > k * d) && (((k * d) % 1000000007 - (k % 1000000007) * (d % 1000000007)) % 1000000007 == 0)) { if (x > 0) a = abs(x - k * d); else a = abs(k * d + x); } e...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 15, 339, 51, 16, 12, 23, 0, 16, 17, 79], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 60], ["+", 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
179
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { long long int x, k, d; scanf("%lld %lld %lld", &x, &k, &d); long long int i, y; y = x / d; if (y > k) { printf("%lld\n", labs(x) - d * k); return 0; } if (x > 0) x = x % d; else x = -(labs(x) % d)...
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { long long int x, k, d; scanf("%lld %lld %lld", &x, &k, &d); long long int i, y; y = x / d; if (labs(y) > k) { printf("%lld\n", labs(x) - d * k); return 0; } if (x > 0) x = x % d; else x = -(labs(x...
[["+", 0, 57, 15, 23, 0, 16, 31, 2, 63, 22], ["+", 15, 23, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 23, 0, 16, 31, 2, 3, 4, 0, 25]]
0
189
#include <bits/stdc++.h> using namespace std; int main() { int X, K, D; cin >> X >> K >> D; int a = abs(X / D), ans; if (K <= a) { ans = abs(abs(X) - K * D); } else { if ((K - a) % 2 == 0) { ans = abs(X) % D; } else { ans = min(abs(abs(X) % D + D), abs(abs(X) % D - D)); } } c...
#include <bits/stdc++.h> using namespace std; int main() { long long X, K, D; cin >> X >> K >> D; long long a = abs(X / D), ans; if (K <= a) { ans = abs(abs(X) - K * D); } else { if ((K - a) % 2 == 0) { ans = abs(X) % D; } else { ans = min(abs(abs(X) % D + D), abs(abs(X) % D - D)); ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
125
X, K, D = map(int, input().split()) abs_x = abs(X) num = int(abs_x / D) def calc_min(): if K < num: # マイナス方面or+方面に向かうだけで回数の上限 if X < 0: return X + D * K return X - D * K # これより先は距離Dを行ったり来たりするだけ base_pos = X - D * num if X > 0 else X + D * num if num % 2 == 0: ...
X, K, D = map(int, input().split()) abs_x = abs(X) num = int(abs_x / D) def calc_min(): if K < num: # マイナス方面or+方面に向かうだけで回数の上限 if X < 0: return X + D * K return X - D * K # これより先は距離Dを行ったり来たりするだけ base_pos = X - D * num if X > 0 else X + D * num if (K - num) % 2 == ...
[["+", 0, 57, 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], ["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 25]]
5
110
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author houghstc */ #include <fstream> #include <iostream> #include <algorithm> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #includ...
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author houghstc */ #include <fstream> #include <iostream> #include <algorithm> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #includ...
[["-", 8, 123, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 8, 123, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 57, 75, 76, 0, 9, 0, 43, 39, 40], ["+", 0, 57, 75, 76, 0, 9, 0, 43, 39, 78]]
1
231
x,k,d = map(int,input().split()) if x>=k*d: print(x-k*d) else: temp = x//d if temp%2==k%2: min_ = temp max_ = temp+2 else: min_ = temp-1 max_ = temp+1 if max_ > k: max_ = min_ #print(min_,max_) ans = min(abs(x-d*min_),abs(x-d*max_)) print(ans)
x,k,d = map(int,input().split()) x = abs(x) if x>=k*d: print(x-k*d) else: temp = x//d if temp%2==k%2: min_ = temp max_ = temp+2 else: min_ = temp-1 max_ = temp+1 if max_ > k: max_ = min_ #print(min_,max_) ans = min(abs(x-d*min_),abs(x-d*max_)) prin...
[["+", 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
104
x,k,d = map(int,input().split()) if k * d <= abs(x): if x > 0: ans = x - (k*d) elif x < 0: ans = x + (k*d) elif k % 2 == 0: t = x // d if t % 2 == 1: t += 1 ans = abs(x - t * d) elif k % 2 == 1: t = x // d if t % 2 == 0: t += 1 ans = abs(x - t * d) print...
x,k,d = map(int,input().split()) if k * d <= abs(x): if x > 0: ans = x - (k*d) elif x < 0: ans = x + (k*d) elif k % 2 == 0: t = x // d if t % 2 == 1: t += 1 ans = abs(x - t * d) elif k % 2 == 1: t = x // d if t % 2 == 0: t += 1 ans = abs(x - t * d) 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]]
5
124
#include <bits/stdc++.h> using namespace std; int main() { long long int X; long long int K; long long int D; cin >> X >> K >> D; X = abs(X); if (log(K) + log(D) < log(X)) { cout << abs(X - K * D); } else { if ((X / K) % 2 == K % 2) { cout << X % D; } else { cout << D - X % D; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int X; long long int K; long long int D; cin >> X >> K >> D; X = abs(X); if (log(K) + log(D) < log(X)) { cout << abs(X - K * D); } else { if ((X / D) % 2 == K % 2) { cout << X % D; } else { cout << D - X % D; ...
[["-", 51, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 51, 16, 31, 16, 31, 23, 0, 16, 12, 22]]
1
108
/* * Author: .-O_O-. */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long #define pb push_back #define vi vector<int> #define rep0(a, b) for (int a = 0; a < b; a++) #define rep1(a, b) for (int a ...
/* * Author: .-O_O-. */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long #define pb push_back #define vi vector<int> #define rep0(a, b) for (int a = 0; a < b; a++) #define rep1(a, b) for (int a ...
[["-", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22]]
1
645
# -*- coding: utf-8 -*- import io, sys def main(): X,K,D = list(map(int, sys.stdin.readline().split())) quo = X // D if quo >= K: X = X - K*D print( abs(X) ) else: X %= D K -= quo if K % 2 == 0: print( abs(X) ) else: ...
# -*- coding: utf-8 -*- import io, sys def main(): X,K,D = list(map(int, sys.stdin.readline().split())) X = abs(X) quo = X // D if quo >= K: X = X - K*D print( abs(X) ) else: X %= D K -= quo if K % 2 == 0: print( abs(X) ) ...
[["+", 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
102
X, K, D = map(int, input().split()) d = int(abs(X)/D) if X > 0: r = X - d*D if abs(r-D) < abs(r): r = r-D min_count = int((X-r)/D) else: r = X + d*D if abs(r+D) < abs(r): r = r+D min_count = int(abs(X-r)/D) if K < min_count: print(int(abs(X) - K*D)) else: if (K - min_co...
X, K, D = map(int, input().split()) d = int(abs(X)/D) if X > 0: r = X - d*D if abs(r-D) < abs(r): r = r-D min_count = int((X-r)/D) else: r = X + d*D if abs(r+D) < abs(r): r = r+D min_count = int(abs(X-r)/D) if K < min_count: print(int(abs(X)) - K*D) else: if (K - min_co...
[["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 0, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24]]
5
167
import sys input = sys.stdin.readline x, k, d = map(int, input().split()) sho, amari = abs(x)//d, abs(x)%d if k <= sho: print(abs(x-(k*d))) sys.exit() else: x = amari k = k-sho if x == abs(x-d): print(x) elif x < abs(x-d): if k%2==0: print(x) else: print(abs(x-d)) else: if k%2==1: print(...
import sys input = sys.stdin.readline x, k, d = map(int, input().split()) sho, amari = abs(x)//d, abs(x)%d if k <= sho: print((abs(x)-(k*d))) sys.exit() else: x = amari k = k-sho if x == abs(x-d): print(x) elif x < abs(x-d): if k%2==0: print(x) else: print(abs(x-d)) else: if k%2==1: prin...
[["+", 0, 1, 0, 652, 3, 4, 0, 23, 0, 24], ["+", 0, 23, 0, 657, 31, 652, 3, 4, 0, 25]]
5
147
X, K, D = map(int, input().split()) ans = 0 if abs(X) < (K * D): q = abs(X) // D r = abs(X) % D if (K - q) % 2 == 0: ans = r else: ans = min(abs(r + D), abs(r - D)) elif X > 0: ans = X - (K * D) elif X < 0: ans = -(abs(X) - (K * D)) print(ans)
X, K, D = map(int, input().split()) ans = 0 if abs(X) < (K * D): q = abs(X) // D r = abs(X) % D if (K - q) % 2 == 0: ans = r else: ans = min(abs(r + D), abs(r - D)) elif X > 0: ans = X - (K * D) elif X < 0: ans = abs(-(abs(X) - (K * D))) print(ans)
[["+", 64, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 664, 28, 23, 0, 657, 12, 23, 0, 25]]
5
121
x, k, d = map(int, input().split()) moves = x//d if moves >= k: print(abs(x-k*d)) else: k -= moves if k%2 == 0: print(abs(x-moves*d)) else: print(abs(x-(moves+1)*d))
x, k, d = map(int, input().split()) x = abs(x) moves = x//d if moves >= k: print(abs(x-k*d)) else: k -= moves if k%2 == 0: print(abs(x-moves*d)) else: print(abs(x-(moves+1)*d))
[["+", 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()) x=abs(x) i=x//d print(i) if i>=k: print(x-d*k) else: if (k-i)%2==0: print(x-d*i) else: print(abs(x-d*(i+1)))
x,k,d=map(int,input().split()) x=abs(x) i=x//d if i>=k: print(x-d*k) else: if (k-i)%2==0: print(x-d*i) else: print(abs(x-d*(i+1)))
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
84
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep2(i, n) for (int i = 0; i <= n; i++) #define repr(i, a, n) for (int i = a; i < n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, ...
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep2(i, n) for (int i = 0; i <= n; i++) #define repr(i, a, n) for (int i = a; i < n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, ...
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 31, 22]]
1
357
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; #define ...
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; #define ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 109], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 17, 85], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 12, 22], ["+", 0,...
1
304
#include <bits/stdc++.h> using namespace std; long long xabs(long long x) { if (x < 0) x = x * -1; return x; } int main() { long long x, k, d; cin >> x >> k >> d; x = xabs(x); if (x > 0) { long long _k = x / d; if (_k < k) k -= _k; else { cout << xabs(x - k * d) << endl; ...
#include <bits/stdc++.h> using namespace std; long long xabs(long long x) { if (x < 0) x = x * -1; return x; } int main() { long long x, k, d; cin >> x >> k >> d; x = xabs(x); if (x >= 0) { long long _k = x / d; if (_k < k) k -= _k; else { cout << xabs(x - k * d) << endl; ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
147
X,D,C = map(int,input().split()) count=abs(X) a = X//C b = X%C if a>D: print(count-D*C) elif a==D: print(b) elif a<D: D = D-a if D%2==0: print(b) else: print(min(abs(b-C),abs(b+C)))
X,D,C = map(int,input().split()) count=abs(X) a = abs(X//C) b = abs(X%C) if a>D: print(count-D*C) elif a==D: print(b) elif a<D: D = D-a if D%2==0: print(b) else: print(min(abs(b-C),abs(b+C)))
[["+", 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
98
xx, kk, dd= list(map(int,input().split())) xx = abs(xx) if dd * kk <= xx: ans = xx - dd*kk else: aa_int = int(xx/dd) remaining_move = kk - aa_int if (aa_int % 2) == 0: ans = xx - dd*aa_int else: ans = xx - dd*(aa_int+1) print(abs(ans))
xx, kk, dd= list(map(int,input().split())) xx = abs(xx) if dd * kk <= xx: ans = xx - dd*kk else: aa_int = int(xx/dd) remaining_move = kk - aa_int if (remaining_move % 2) == 0: ans = xx - dd*aa_int else: ans = xx - dd*(aa_int+1) print(abs(ans))
[["-", 0, 57, 15, 666, 0, 23, 0, 657, 31, 22], ["+", 0, 57, 15, 666, 0, 23, 0, 657, 31, 22]]
5
92
X, K, D = map(int, input().split()) ans = 0 if X > 0: tmp = abs(X) % D if tmp >= K: ans = X - D*K elif tmp < K: nK = K - tmp X1 = X- D*tmp X2 = X1 - D if nK %2 == 0: ans = X1 else : ans = X2 elif X < 0: tmp = abs(X) % D if tmp...
X, K, D = map(int, input().split()) ans = 0 if X > 0: tmp = abs(X) // D if tmp >= K: ans = X-D*K elif tmp < K: nK = K - tmp X1 = X- D*tmp X2 = X1 - D if nK %2 == 0: ans = X1 else : ans = X2 elif X < 0: tmp = abs(...
[["-", 64, 196, 0, 1, 0, 662, 12, 657, 17, 109], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 17, 676]]
5
169
#include <bits/stdc++.h> using namespace std; #define nl '\n' #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; #define nl '\n' #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
136
inp=map(int,input().split()) X,K,D=map(abs,inp) goal=X-K*D y1=X%D y2=y1-D if y1<=goal: print(int(goal)) else: if y1<=abs(y2): L=(X-y1)/D else: L=(X-y2)/D if L%2==0: print(int(min(y1,abs(y2)))) else: print(int(max(y1,abs(y2))))
#print(3.0/2) #print(3.0%2) inp=map(int,input().split()) X,K,D=map(abs,inp) goal=X-K*D y1=X%D y2=y1-D if y1<=goal: print(int(goal)) else: if y1<=abs(y2): L=(X-y1)/D else: L=(X-y2)/D if (K-L)%2==0: print(int(min(y1,abs(y2)))) else: print(int(max(y1,abs(y2))))
[["+", 0, 57, 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], ["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 25]]
5
124
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> // if(strcmp(s[i],"AC")==0) // if(s[l]=='#') /*小文字判定 if((moji>= 'a') && (moji<='z')){ printf("a\n"); return 0; } */ int W_Length(char *str) { int length = 0; while (*str++ != '\0') length++; return length; } void swap(i...
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> // if(strcmp(s[i],"AC")==0) // if(s[l]=='#') /*小文字判定 if((moji>= 'a') && (moji<='z')){ printf("a\n"); return 0; } */ int W_Length(char *str) { int length = 0; while (*str++ != '\0') length++; return length; } void swap(i...
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["-", 64, 9, 0, 1, 0, 11, 12, 91, 28, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 91, 28, 22]]
0
433
#if __has_include("D:/dhiraj/Programming/debug.h") #include "D:/dhiraj/Programming/debug.h" #else #include <bits/stdc++.h> using namespace std; #define d(...) 11 #define cerr \ if (0) ...
#if __has_include("D:/dhiraj/Programming/debug.h") #include "D:/dhiraj/Programming/debug.h" #else #include <bits/stdc++.h> using namespace std; #define d(...) 11 #define cerr \ if (0) ...
[["+", 3, 4, 0, 23, 0, 16, 31, 2, 63, 22], ["-", 0, 23, 0, 16, 31, 23, 0, 91, 17, 33], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22]]
1
460
// I don't want to do this....pls help!! #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; ++i) #define ed end() #define bg begin() #define ld long double #define ll long long #define ub(v, a) upper_bound(all(v), a) #define lb(v, a) lower_bound(all(v), a) #define sz(a) (int)(a.size()...
// I don't want to do this....pls help!! #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; ++i) #define ed end() #define bg begin() #define ld long double #define ll long long #define ub(v, a) upper_bound(all(v), a) #define lb(v, a) lower_bound(all(v), a) #define sz(a) (int)(a.size()...
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 13]]
1
663
// // AtCoder Beginner Contest 175 // C // #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define REP(i, n) ...
// // AtCoder Beginner Contest 175 // C // #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define REP(i, n) ...
[["+", 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
335
def main(): x, k, d = map(int, input().split()) if k >= abs(x) // d: a = abs(x) - abs(d) * (x // d) b = abs(a - d) left_number = k - (abs(x) // d) if left_number % 2 == 0: minimum = a else: minimum = b else: minimum = abs(x) - k * d ...
def main(): x, k, d = map(int, input().split()) if k >= abs(x) // d: a = abs(x) - d * (abs(x) // d) b = abs(a - d) left_number = k - (abs(x) // d) if left_number % 2 == 0: minimum = a else: minimum = b else: minimum = abs(x) - k * d ...
[["-", 0, 662, 12, 657, 12, 657, 31, 652, 63, 22], ["-", 12, 657, 12, 657, 31, 652, 3, 4, 0, 24], ["-", 12, 657, 12, 657, 31, 652, 3, 4, 0, 25], ["+", 0, 662, 12, 657, 12, 657, 12, 23, 0, 24], ["+", 12, 657, 12, 23, 0, 657, 31, 652, 63, 22], ["+", 12, 23, 0, 657, 31, 652, 3, 4, 0, 25]]
5
111
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { scan_init() x := scanInt() k := scanInt() d := scanInt() // x:= 初期値 // d = 変数 keisan := x / d //回数 min := x check := keisan % 2 == k % 2 // fmt.Println("check", check) if k > keisan { min = x % d if !check { if -(min...
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { scan_init() x := abs(scanInt()) k := scanInt() d := scanInt() // x:= 初期値 // d = 変数 keisan := x / d //回数 min := x check := keisan % 2 == k % 2 // fmt.Println("check", check) if k > keisan { min = x % d if !check { if ...
[["+", 8, 196, 0, 431, 12, 432, 0, 2, 63, 22], ["+", 0, 431, 12, 432, 0, 2, 3, 4, 0, 24], ["+", 0, 431, 12, 432, 0, 2, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 15, 16, 31, 91, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 31, 2, 63, 22]]
7
525
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int64_t x, k, d, a, b, c; cin >> x >> k >> d; a = x / d; b = x % d; c = k - a; // cout << c << endl; if (c > 0) { if (c % 2 == 0) cout << abs(b) << endl; else { if (b < 0) ...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int64_t x, k, d, a, b, c; cin >> x >> k >> d; a = abs(x / d); b = x % d; c = k - a; // cout << a << endl; if (c > 0) { if (c % 2 == 0) cout << abs(b) << endl; else { if (b < ...
[["+", 8, 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
155
#C - Walking Takahashi x, k, d = map(int, input().split()) p = abs(x) if p/d < k: k = k - (p // d) p = p % d if k % 2 == 0: print(abs(p)) elif p < 0: print(abs(p + d)) else: print(abs(p - d)) elif x >= 0: print(x - (k * d)) else: print(x + (k * d))
#C - Walking Takahashi x, k, d = map(int, input().split()) p = abs(x) if p/d < k: k = k - (p // d) p = p % d if k % 2 == 0: print(abs(p)) elif p < 0: print(abs(p + d)) else: print(abs(p - d)) elif x >= 0: print(abs(x - (k * d))) else: print(abs(x + (k * 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, 657, 12, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
112
// Shinchan Loves Coding :))) #include <bits/stdc++.h> #include <map> #include <set> #include <stack> using namespace std; #define night_rider \ ios::sync_with_stdio(false); \ cin.tie(NULL); #define int long ...
// Shinchan Loves Coding :))) #include <bits/stdc++.h> #include <map> #include <set> #include <stack> using namespace std; #define night_rider \ ios::sync_with_stdio(false); \ cin.tie(NULL); #define int long ...
[["-", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22]]
1
686
x,k,d=map(int,input().split()) if d==0: print(abs(x)) exit() s=abs(x)//d if s>=k: if x>=0: print(abs(x-k*d)) else: print(abs(x+k*d)) elif k>s and (k-s)%2==0: if x>=0: print(abs(x-s*d)) else: print(abs(x+s*d)) else: if x>=0: y=x-s*d else: y=x+s+d print(min(abs(y+d),abs(y-d)))
x,k,d=map(int,input().split()) if d==0: print(abs(x)) exit() s=abs(x)//d if s>=k: if x>=0: print(abs(x-k*d)) else: print(abs(x+k*d)) elif k>s and (k-s)%2==0: if x>=0: print(abs(x-s*d)) else: print(abs(x+s*d)) else: if x>=0: y=x-s*d else: y=x+s*d print(min(abs(y+d),abs(y-d)))
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 0, 1, 0, 662, 12, 657, 12, 657, 17, 48]]
5
161
x, k, d = map(int, input().split()) if x >= k * d: print(x - k * d) elif -x >= k * d: print(x + k * d) else: a = x // d b = x % d if b <= abs(b-d): if a % 2 == k % 2: print(b) else: print(abs(b-d)) else: if (a+1) % 2 == k % 2: print(ab...
x, k, d = map(int, input().split()) if x >= k * d: print(x - k * d) elif -x >= k * d: print(abs(x + k * d)) else: a = x // d b = x % d if b <= abs(b-d): if a % 2 == k % 2: print(b) else: print(abs(b-d)) else: if (a+1) % 2 == k % 2: pri...
[["+", 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
125
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define fi first #define se second #define pb push_back typedef long long ll; typedef unsigned long long ull; int main() { ll x, k, d; scanf("%lld%lld%lld", &x, &k, &d); ll ans = 0; if (k <= abs(x) / d) { if (x > 0) ans = x - ...
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define fi first #define se second #define pb push_back typedef long long ll; typedef unsigned long long ull; int main() { ll x, k, d; scanf("%lld%lld%lld", &x, &k, &d); ll ans = 0; if (k <= abs(x) / d) { if (x > 0) ans = x - ...
[["-", 0, 57, 75, 76, 0, 9, 0, 57, 0, 121], ["-", 75, 76, 0, 9, 0, 57, 15, 339, 0, 24], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 75, 76, 0, 9, 0, 57, 15, 339, 0, 25]]
1
164
(X,K,D) = map(int,input().split()) X = abs(X) if X-K*D>0: print(X-K*D) else: if K%2==0: print(min(abs(X%(2*D)),abs(X%(2*D)-2*D))) else: print(min(abs((X+D)%(2*D),abs((X+D)%(2*D)-2*D))))
(X,K,D) = map(int,input().split()) X = abs(X) if X-K*D>0: print(X-K*D) else: if K%2==0: print(min(abs(X%(2*D)),abs(X%(2*D)-2*D))) else: print(min(abs((X+D)%(2*D)),abs((X+D)%(2*D)-2*D)))
[["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
124
X, K, D = map(int, input().split()) if X >= K * D: print(abs(X - K * D)) exit() m = X % D if m != 0: a = X // D if (K - a) % 2 == 0: print(m) else: print(D - m) else: a = X // D if (K - a) % 2 == 0: print(0) else: print(D)
X, K, D = map(int, input().split()) X = abs(X) if X >= K * D: print(abs(X - K * D)) exit() m = X % D if m != 0: a = X // D if (K - a) % 2 == 0: print(m) else: print(D - m) else: a = X // D if (K - a) % 2 == 0: print(0) else: print(D)
[["+", 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
105
X, K, D = map(int, input().split()) B, A = divmod(X, D) if B <= K: print(abs((A - ((K-B)%2) * D ))) else: print(X-K*D)
X, K, D = map(int, input().split()) B, A = divmod(abs(X), D) if B <= K: print(abs((A - ((K-B) % 2) * D))) else: print(abs(X)-K*D)
[["+", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25]]
5
64
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define ll long long int main(void) { ll x, k, d, i; scanf("%lld %lld %lld", &x, &k, &d); ll abx = (x > 0) ? x : -x; ll div = x / d; if (div > k) div = k; if (x < 0) x += div * d; else if (x > 0) x -= div * d; //...
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define ll long long int main(void) { ll x, k, d, i; scanf("%lld %lld %lld", &x, &k, &d); ll abx = (x > 0) ? x : -x; ll div = abx / d; if (div > k) div = k; if (x < 0) x += div * d; else if (x > 0) x -= div * d; ...
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 31, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 31, 22]]
0
158