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 <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int x, k, d; cin >> x >> k >> d; x = abs(x); if (k * d <= x) { cout << x - k * d << '\n'; return 0; } int l...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int x, k, d; cin >> x >> k >> d; x = abs(x); if (k <= x / d) { cout << x - k * d << '\n'; return 0; } int l...
[["-", 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
154
x,k,d = map(int,input().split()) ans = 0 if abs(x) >= k*d: ans = min(abs(x-k*d),abs(x+k*d)) else: b = abs(x)%d c = abs(x)//d if (k-c) %2 == 0: if x < 0: ans = -b else: ans = b else: if x < 0: ans = abs(b-d) else: ans = -...
x,k,d = map(int,input().split()) ans = 0 if abs(x) >= k*d: ans = min(abs(x-k*d),abs(x+k*d)) else: b = abs(x)%d c = abs(x)//d if (k-c) %2 == 0: if x < 0: ans = b else: ans = b else: if x < 0: ans = abs(b-d) else: ans = ab...
[["-", 64, 196, 0, 1, 0, 662, 12, 664, 17, 33], ["-", 8, 196, 0, 1, 0, 662, 12, 664, 17, 33]]
5
126
#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 Xa = abs(X); if (Xa / D >= K) { if (X > 0) cout << abs(X - K * D) << endl; else cout << abs(X + K * ...
#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 Xa = abs(X); if (Xa / D >= K) { if (X >= 0) cout << abs(X - K * D) << endl; else cout << abs(X + K *...
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 109], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, ...
1
211
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: if x>=0: count=x//d if (k-count)%2 == 0: print(x-d*count) else: print(d*(count+1)-x) else: count=abs(x)//d if (k-count)%2 == ...
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: if x>=0: count=x//d if (k-count)%2 == 0: print(x-d*count) else: print(d*(count+1)-x) else: count=abs(x)//d if (k-count)%2 ==...
[["+", 0, 652, 3, 4, 0, 657, 31, 664, 17, 33], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
140
X, K, D = map(int, input().split()) X = abs(X) if X > K*D: print(X-K*D) exit() K -= X//D if K%2 == 0: print(abs(X-(X//D)*D)) else: print(abs((X//D)*2*D-X))
X, K, D = map(int, input().split()) X = abs(X) if X > K*D: print(X-K*D) exit() K -= X//D if K%2 == 0: print(abs(X-(X//D)*D)) else: print(abs(X-(X//D)*D-D))
[["+", 0, 652, 3, 4, 0, 657, 31, 657, 31, 22], ["+", 0, 652, 3, 4, 0, 657, 31, 657, 17, 33], ["-", 3, 4, 0, 657, 31, 657, 31, 657, 17, 48], ["-", 3, 4, 0, 657, 31, 657, 31, 657, 12, 612], ["-", 3, 4, 0, 652, 3, 4, 0, 657, 12, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 12, 22]]
5
88
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <climits> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <utility> #include <vector>...
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <climits> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <utility> #include <vector>...
[["+", 75, 76, 0, 1, 0, 16, 12, 2, 63, 22], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 25]]
1
194
x,k,d= map(int,input().split()) if abs(x)>abs(k*d): print(abs(x-k*d)) else: if (k-abs(x)//d)%2==0: print(abs(x)%d) else: print(abs(d-abs(x)%d))
x,k,d= map(int,input().split()) if abs(x)>abs(k*d): print(abs(x)-k*d) else: if (k-abs(x)//d)%2==0: print(abs(x)%d) else: print(abs(d-abs(x)%d))
[["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
85
X,K,D=map(int,input().split()) if K*D<=X: print(X-(K*D)) exit() else: div=X//D if (K-div)%2==0: print(X%D) else: print(abs(X%D-D))
X,K,D=map(int,input().split()) X=abs(X) if K*D<=X: print(X-(K*D)) exit() else: div=X//D if (K-div)%2==0: print(X%D) else: print(abs(X%D-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
75
import java.io.*; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; public class Main { public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UT...
import java.io.*; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; public class Main { public static void main(String[] args) throws IOException { InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UT...
[["+", 0, 235, 8, 498, 0, 124, 49, 200, 0, 32], ["+", 0, 235, 8, 498, 0, 124, 49, 200, 51, 499], ["-", 0, 57, 15, 15, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 15, 0, 16, 31, 16, 31, 22]]
3
337
X,K,D = list(map(int,input_[0].split())) N = abs(X)//D if N >= K: ans = abs(X) - K*D elif (K-N)%2 == 0: ans = abs(X) - N*D else: ans = D - (abs(X) - N*D) print(ans)
X,K,D = list(map(int,input().split())) N = abs(X)//D if N >= K: ans = abs(X) - K*D elif (K-N)%2 == 0: ans = abs(X) - N*D else: ans = D - (abs(X) - N*D) print(ans)
[["-", 3, 4, 0, 652, 63, 319, 500, 206, 51, 22], ["-", 3, 4, 0, 652, 63, 319, 500, 206, 0, 70], ["-", 3, 4, 0, 652, 63, 319, 500, 206, 206, 612], ["-", 3, 4, 0, 652, 63, 319, 500, 206, 0, 73], ["+", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22], ["+", 0, 652, 63, 319, 500, 652, 3, 4, 0, 24], ["+", 0, 652, 63, 319, 500, 652,...
5
86
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define REP(i, a) for (int i = 0; i < (a); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i >= (b); --i) #define ALL(obj) (obj)....
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define REP(i, a) for (int i = 0; i < (a); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i >= (b); --i) #define ALL(obj) (obj)....
[["+", 0, 57, 15, 339, 51, 16, 31, 2, 63, 22], ["+", 31, 2, 3, 4, 0, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25]]
1
183
x,k,d = map(int,input().split()) #print(x,k,d) a = x//d b = x%d if k <= a: print(abs(x-k*d)) else: tmp = k-a if tmp%2 == 0: print(x-a*d) else: print(abs(x-(a+1)*d))
x,k,d = map(int,input().split()) #print(x,k,d) x=abs(x) a = x//d b = x%d if k <= a: print(abs(x-k*d)) else: tmp = k-a if tmp%2 == 0: print(x-a*d) else: print(abs(x-(a+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
84
x,k,d=map(int,input().split()) if abs(x)//d < k: #最小までいく。 if (k-abs(x)//d)%2==0: if x>=0: print(abs(x-(x//d)*d)) else: print(abs(x+(x//d)*d)) else: if x>=0: print(abs(x-(x//d)*d-d)) else: print(abs(x+(x//d)*d+d)) else: if x>=0: print(abs(x-k*d)) else: print(abs...
x,k,d=map(int,input().split()) if abs(x)//d < k: #最小までいく。 if (k-abs(x)//d)%2==0: if x>=0: print(abs(x-(x//d)*d)) else: print(abs(x+(abs(x)//d)*d)) else: if x>=0: print(abs(x-(x//d)*d-d)) else: print(abs(x+(abs(x)//d)*d+d)) else: if x>=0: print(abs(x-k*d)) else: ...
[["+", 12, 657, 31, 23, 0, 657, 31, 652, 63, 22], ["+", 31, 23, 0, 657, 31, 652, 3, 4, 0, 24], ["+", 31, 23, 0, 657, 31, 652, 3, 4, 0, 25], ["+", 0, 657, 31, 657, 12, 657, 31, 23, 0, 24]]
5
156
x, k, d = map(int, input().split()) if x == 0: print(0 if k % 2 == 0 else d) elif x > 0: p = x // d if p >= k: print(x - k * d) else: q = 0 if (k-p)%2 == 0 else 1 print(abs(x - ((p+q) * d))) else: p = abs(x) // d if p >= k: print(x + k * d) else: q = ...
x, k, d = map(int, input().split()) if x == 0: print(0 if k % 2 == 0 else d) elif x > 0: p = x // d if p >= k: print(x - k * d) else: q = 0 if (k-p) % 2 == 0 else 1 print(abs(x - ((p+q) * d))) else: p = abs(x) // d if p >= k: print(abs(x + k * d)) else: ...
[["+", 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
149
#include <bits/stdc++.h> #define rep(i, s, n) for (int i = s; i < n; i++) #define rp(i, n) for (int i = 0; i < n; i++) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define all_acc(x) (x).begin(), (x).end(), 0LL #define int long long #define absSort(v) ...
#include <bits/stdc++.h> #define rep(i, s, n) for (int i = s; i < n; i++) #define rp(i, n) for (int i = 0; i < n; i++) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define all_acc(x) (x).begin(), (x).end(), 0LL #define int long long #define absSort(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, 25]]
1
453
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): x,k,d = map(int,input().split()) if x < 0: y = x+k*d else: y = x-k*d if x==0: if k%2: print(d) else: print(0) elif y*x >= 0:...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): x,k,d = map(int,input().split()) if x < 0: y = x+k*d else: y = x-k*d if x==0: if k%2: print(d) else: print(0) elif y*x >= 0:...
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 109], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
5
605
x,k,d = map(int,input().split()) if abs(x)-k*d >= 0: # 0の反対側へ行けない ans = abs(x)-k*d else: c = x//d#0を超えないときの移動回数 ans1 = abs(x) - c*d ans2 = abs(x) - (c+1)*d if (k-c)%2 == 0: ans = abs(ans1) else: ans = abs(ans2) print(ans)
x,k,d = map(int,input().split()) if abs(x)-k*d >= 0: # 0の反対側へ行けない ans = abs(x)-k*d else: c = abs(x)//d#0を超えないときの移動回数 ans1 = abs(x) - c*d ans2 = abs(x) - (c+1)*d if (k-c)%2 == 0: ans = abs(ans1) else: ans = abs(ans2) print(ans)
[["+", 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
102
# = int(input()) # = str(input()) X, K, D = map(int, input().split()) # = list(map(int, input().split())) # = [int(input()) for i in range(N)] # = [list(map(int, input().split())) for i in range(N)] if X == 0: ans = [D, 0] exit() elif X>0: if X == D: ans = [0, D] elif X-D<0: ans = [D-X...
# = int(input()) # = str(input()) X, K, D = map(int, input().split()) # = list(map(int, input().split())) # = [int(input()) for i in range(N)] # = [list(map(int, input().split())) for i in range(N)] if X == 0: ans = [D, 0] elif X>0: if X == D: ans = [0, D] elif X-D<0: ans = [D-X, X] el...
[["-", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
256
<?php list($x,$k,$d) = explode(" ", trim(fgets(STDIN))); if($x >= 0 && $k*$d <= $x){ echo $x - $k*$d; }else if($x >= 0 && $k*$d > $x){ $p = intdiv($x+$d-1,$d); $r=$k-$p; if($r%2==0){ echo abs($x-$d*$p); }else{ echo abs($x-$d*$p+$d); } }else if($x < 0 && $k*$d <= abs($x)){ ...
<?php list($x,$k,$d) = explode(" ", trim(fgets(STDIN))); if($x >= 0 && $k*$d <= $x){ echo $x - $k*$d; }else if($x >= 0 && $k*$d > $x){ $p = intdiv($x+$d-1,$d); $r=$k-$p; if($r%2==0){ echo abs($x-$d*$p); }else{ echo abs($x-$d*$p+$d); } }else if($x < 0 && $k*$d <= abs($x)){ ...
[["-", 0, 613, 3, 3, 0, 28, 0, 16, 17, 72], ["+", 0, 613, 3, 3, 0, 28, 0, 16, 17, 33]]
6
254
#include <bits/stdc++.h> typedef long long ll; #define ALL(l) (l).begin(), (l).end() #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) using namespace std; // const ll mod = 1000000007; // const ll maxn = 1000000000; //---------------------------------------...
#include <bits/stdc++.h> typedef long long ll; #define ALL(l) (l).begin(), (l).end() #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) using namespace std; // const ll mod = 1000000007; // const ll maxn = 1000000000; //---------------------------------------...
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
249
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline sys.setrecursionlimit(500*500) import itertools from collections import Counter,deque def main(): x,k,d = map(int, input().split()) n = x//d ans = x if n >= k: print(x-k*d) exit() x -= n*d ...
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline sys.setrecursionlimit(500*500) import itertools from collections import Counter,deque def main(): x,k,d = map(int, input().split()) x = abs(x) n = x//d ans = x if n >= k: print(x-k*d) exit() ...
[["+", 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
132
X,K,D = map(int, input().split()) X = abs(X) if X >= K*D: print(X - K*D) else: if K%2 == 1: X -= D k -= 1 x1 = X%(2*D) print(min(x1, (2*D-x1)))
X,K,D = map(int, input().split()) X = abs(X) if X >= K*D: print(X - K*D) else: if K%2 == 1: X -= D x1 = X%(2*D) print(min(x1, (2*D-x1)))
[["-", 0, 57, 64, 196, 0, 1, 0, 677, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 677, 17, 110], ["-", 0, 57, 64, 196, 0, 1, 0, 677, 12, 612]]
5
78
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pi pair<int, int> #define pb push_back // dont forget to initialize global variables inside main() ; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; while (tt-...
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pi pair<int, int> #define pb push_back // dont forget to initialize global variables inside main() ; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; while (tt-...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
144
#include <bits/stdc++.h> #define ll long long using namespace std; ll x, k, d; int main() { scanf("%lld %lld %lld", &x, &k, &d); if (x < 0) { ll cnt = abs(x) / d; if (k < cnt) { printf("%lld", abs(x + d * k)); return 0; } x += cnt * d; k -= cnt; ll tmp = x + d; ll tmp2 = x...
#include <bits/stdc++.h> #define ll long long using namespace std; ll x, k, d; int main() { scanf("%lld %lld %lld", &x, &k, &d); if (x < 0) { ll cnt = abs(x) / d; if (k < cnt) { printf("%lld", abs(x + d * k)); return 0; } x += cnt * d; k -= cnt; ll tmp = x + d; ll tmp2 = x...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22]]
1
253
x,k,d = map(int,input().split()) if x >= 0: if x >= k*d: print(x-k*d) else: a = x%d b = a-d c = x//d if (k-c)%2 ==0: print(a) else: print(-1*b) else: if -1*x >=k*d: print(-1*x-k*d) else: a = -1*x%d b = a-d ...
x,k,d = map(int,input().split()) if x >= 0: if x >= k*d: print(x-k*d) else: a = x%d b = a-d c = x//d if (k-c)%2 ==0: print(a) else: print(-1*b) else: if -1*x >=k*d: print(-1*x-k*d) else: a = -1*x%d b = a-d ...
[["-", 75, 76, 8, 196, 0, 57, 15, 666, 0, 612], ["+", 75, 76, 8, 196, 0, 57, 15, 666, 0, 612]]
5
149
x,k,d = map(int,input().split()) n = abs(x)//d if n>k: ans = min(x-k*d,x+k*d) else: ans = min(abs(x+min(k,n)*d),abs(x-min(k,n)*d)) if (k-n)%2: ans = min(abs(ans-d),abs(ans+d)) print(ans)
x,k,d = map(int,input().split()) n = abs(x)//d if n>k: ans = min(abs(x-k*d),abs(x+k*d)) else: ans = min(abs(x+min(k,n)*d),abs(x-min(k,n)*d)) if (k-n)%2: ans = min(abs(ans-d),abs(ans+d)) print(ans)
[["+", 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]]
5
112
import sys input = sys.stdin.readline X,K,D=(int(x) for x in input().rstrip('\n').split()) if X>0 and X-K*D>=0: print(X-K*D) elif X<0 and X+K*D<=0: print(X+K*D) else: if X>0: x = X%D y=X//D if (K-y)%2==0: print(x) else: print(D-x) elif X<0: a = (-1)*X x = a%D y = a//D ...
import sys input = sys.stdin.readline X,K,D=(int(x) for x in input().rstrip('\n').split()) if X>0 and X-K*D>=0: print(X-K*D) elif X<0 and X+K*D<=0: print(-X-K*D) else: if X>0: x = X%D y=X//D if (K-y)%2==0: print(x) else: print(D-x) elif X<0: a = (-1)*X x = a%D y = a//D ...
[["+", 0, 652, 3, 4, 0, 657, 31, 664, 17, 33], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
185
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); long X = s.nextLong(); long K = s.nextLong(); long D = s.nextLong(); if (X / D < K) { if ((K - X / D) % 2 == 0) { Syst...
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); long X = s.nextLong(); long K = s.nextLong(); long D = s.nextLong(); if (Math.abs(X) / D < K) { if ((K - X / D) % 2 == 0) { ...
[["+", 15, 15, 0, 16, 31, 16, 31, 492, 500, 22], ["+", 15, 15, 0, 16, 31, 16, 31, 492, 0, 131], ["+", 15, 15, 0, 16, 31, 16, 31, 492, 141, 22], ["+", 0, 16, 31, 16, 31, 492, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 31, 492, 3, 4, 0, 25]]
3
165
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL) typedef long long ll; typedef long double ld; #define rep(i, a) for (ll i = 0; i < a; i++) #defi...
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL) typedef long long ll; typedef long double ld; #define rep(i, a) for (ll i = 0; i < a; i++) #defi...
[["-", 49, 50, 51, 16, 31, 23, 0, 16, 17, 33], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 17, 72]]
1
287
#!/usr/bin/env python # coding: utf-8 # In[23]: X,K,D = map(int, input().split()) # In[24]: if abs(X) >= K*D: ans = abs(X) - K*D else: cnt = X//D if (K-cnt)%2 == 0: ans = abs(X) - cnt*D else: ans = min(abs(abs(X) - (cnt+1)*D), abs(X) - (cnt-1)*D) print(ans) # In[ ]:
#!/usr/bin/env python # coding: utf-8 # In[23]: X,K,D = map(int, input().split()) # In[25]: if abs(X) >= K*D: ans = abs(X) - K*D else: cnt = abs(X)//D if (K-cnt)%2 == 0: ans = abs(X) - cnt*D else: ans = min(abs(abs(X) - (cnt+1)*D), abs(X) - (cnt-1)*D) print(ans) # In[ ]:
[["+", 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
110
X,K,D=map(int,input().split()) if X>0 and abs(X)>abs(K*D): print(X-K*D) exit() elif X<0 and abs(X)>abs(K*D): print(abs(X-K*D)) exit() d,r=divmod(abs(X),D) if (K-d)%2==0: print(abs(r)) else: print(abs(D-r))
X,K,D=map(int,input().split()) if X>0 and abs(X)>abs(K*D): print(X-K*D) exit() elif X<0 and abs(X)>abs(K*D): print(abs(X)-abs(K*D)) exit() d,r=divmod(abs(X),D) if (K-d)%2==0: print(abs(r)) else: print(abs(D-r))
[["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["+", 0, 652, 3, 4, 0, 657, 12, 652, 63, 22], ["+", 3, 4, 0, 657, 12, 652, 3, 4, 0, 24]]
5
119
X, K, D = map(int, input().split()) ans = 0 if X == 0: if K % 2 != 0: ans = D elif X > 0: a = int(X/D) if K > a: diff = K - a X_temp = X - a * D if abs(X_temp - D) < X_temp: if (diff - 1) % 2 == 0: ans = abs(X_temp - D) else: ...
X, K, D = map(int, input().split()) ans = 0 if X == 0: if K % 2 != 0: ans = D elif X > 0: a = int(X/D) if K > a: diff = K - a X_temp = X - a * D if abs(X_temp - D) < X_temp: if (diff - 1) % 2 == 0: ans = abs(X_temp - D) else: ...
[["+", 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
239
// Problem Link: // Tutorial Link: #include <bits/stdc++.h> using namespace std; #define LL long long #define ll long long #define all(v) v.begin(), v.end() #define pb push_back #define pLL pair<LL, LL> #define ff first #define ss second #define rep(i, a, b) for (LL i = a; i < b; ++i) #define repb(i, a, b) for (LL i...
// Problem Link: // Tutorial Link: #include <bits/stdc++.h> using namespace std; #define LL long long #define ll long long #define all(v) v.begin(), v.end() #define pb push_back #define pLL pair<LL, LL> #define ff first #define ss second #define rep(i, a, b) for (LL i = a; i < b; ++i) #define repb(i, a, b) for (LL i...
[["-", 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
187
#c x, k, d=map(int, input().split()) rest = k - (abs(x) // abs(d)) if abs(x) >= k*d: if x >= 0: print(x-(k*d)) else: print(x+(k*d)) else: if x >= 0: near = x- d*(abs(x) // abs(d)) else: near = x+ d*(abs(x) // abs(d)) if rest % 2 == 0: print(abs(near)) e...
#c x, k, d=map(int, input().split()) rest = k - (abs(x) // abs(d)) if abs(x) >= k*d: if x >= 0: print(abs(x-(k*d))) else: print(abs(x+(k*d))) else: if x >= 0: near = x- d*(abs(x) // abs(d)) else: near = x+ d*(abs(x) // abs(d)) if rest % 2 == 0: print(abs(ne...
[["+", 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
155
import math x,k,d=map(int,input().split(" ")) if x<0: x=(-1)*x if d<0: d=(-1)*d s=math.floor(x/d) if k<s: print(x-d*k) else: w=k-s v=x-d*s if w%2==0: print(v) else: print(v-d)
import math x,k,d=map(int,input().split(" ")) if x<0: x=(-1)*x if d<0: d=(-1)*d s=math.floor(x/d) if k<s: print(x-d*k) else: w=k-s v=x-d*s if w%2==0: print(v) else: print(abs(v-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
105
// This template belongs to Juan Carlo Vieri /* ____ __ / _/ | | __ __ __| |__ | | /_/ | | |__ __| | | __ ____ | | __ ___ _ ___ | | | | | | / _/ | |/ / / _ \ | |/ _/ | | | | | | | |_ | \ | __/ | / |__| |__| |__| \___\ |__|\__\ ...
// This template belongs to Juan Carlo Vieri /* ____ __ / _/ | | __ __ __| |__ | | /_/ | | |__ __| | | __ ____ | | __ ___ _ ___ | | | | | | / _/ | |/ / / _ \ | |/ _/ | | | | | | | |_ | \ | __/ | / |__| |__| |__| \___\ |__|\__\ ...
[["+", 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,157
x,k,d=map(int,input().split()) x=abs(x) if x>k*d: print(x-(k*d)) else: nk=x//d x%=d if nk%2: print(abs(x-d)) else: print(x)
x,k,d=map(int,input().split()) x=abs(x) if x>=k*d: print(x-(k*d)) else: nk=k-x//d x%=d if nk%2: print(abs(x-d)) else: print(x)
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 47], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 20], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 31, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 33]]
5
71
x,k,d = map(int,input().split()) if k*d <= x: print(x - k*d) else: if (k - x//d) %2 == 0: print(x%d) else: print(abs(x%d-d))
x,k,d = map(int,input().split()) x = abs(x) if k*d <= x: print(x - k*d) else: if (k - x//d) %2 == 0: print(x%d) else: print(abs(x%d-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
67
//😄😄😄😄😄😄😄😄😄😄😄😄😄 // Apno Swagat che// #include <bits/stdc++.h> using namespace std; #define ll long long #define vll vector<ll> #define vi vector<int> #define pi pair<int, int> #define vp vector<pi> #define pb push_back #define mp make_pair #define F first #define S second #define For(i, a, b) for (ll i = a...
//😄😄😄😄😄😄😄😄😄😄😄😄😄 // Apno Swagat che// #include <bits/stdc++.h> using namespace std; #define ll long long #define vll vector<ll> #define vi vector<int> #define pi pair<int, int> #define vp vector<pi> #define pb push_back #define mp make_pair #define F first #define S second #define For(i, a, b) for (ll i = a...
[["+", 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
334
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) const ll MAX = 1001001; const ll MOD = 1000000007; int main() { ll x, k, d; cin >> x >> k >> d; if (abs(x) / d > k...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) const ll MAX = 1001001; const ll MOD = 1000000007; int main() { ll x, k, d; cin >> x >> k >> d; if (abs(x) / d > k...
[["+", 64, 9, 0, 1, 0, 16, 12, 2, 63, 22], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 25]]
1
160
x, k, d = map(int, input().split()) if x > k*d or -x > k*d: print(abs(abs(x) -k*d)) else: num = x // d rest = k - num if rest%2 == 1: print(abs(abs(x)%d -d)) else: print(abs(abs(x)%d))
x, k, d = map(int, input().split()) if x > k*d or -x > k*d: print(abs(abs(x) -k*d)) else: num = abs(x) // d rest = k - num if rest%2 == 1: print(abs(abs(x)%d -d)) else: print(abs(abs(x)%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]]
5
93
"""MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWO:,'..'xXWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO. .:kOo.,kNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO. .lNWWo..lXMMMMMMMMMMMM...
"""MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWO:,'..'xXWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO. .:kOo.,kNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMO. .lNWWo..lXMMMMMMMMMMMM...
[["+", 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
497
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } #de...
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } #de...
[["-", 64, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 64, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22]]
1
403
X, K, D = map(int,input().split()) X = abs(X) if K * D >= X: if (X // D) % 2 == 0: print(abs(X - X // D * D)) else: print(abs(X - (X // D + 1) * D)) else: print(abs(X - K * D))
X, K, D = map(int,input().split()) X = abs(X) if K * D >= X: if (K - X // D) % 2 == 0: print(abs(X - X // D * D)) else: print(abs(X - (X // D + 1) * D)) else: print(abs(X - K * D))
[["+", 15, 666, 0, 657, 31, 23, 0, 657, 31, 22], ["+", 15, 666, 0, 657, 31, 23, 0, 657, 17, 33]]
5
87
/* Dont BLUNDER */ #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("-ffloat-store") #pragma GCC optimization("unroll-loops") // for n2 loops #include <bits/stdc++.h> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> // Common file #inclu...
/* Dont BLUNDER */ #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("-ffloat-store") #pragma GCC optimization("unroll-loops") // for n2 loops #include <bits/stdc++.h> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> // Common file #inclu...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22]]
1
442
#include <bits/stdc++.h> using namespace std; #define int long long #define all(c) c.begin(), c.end() #define FAST ios_base::sync_with_stdio(false), cin.tie(NULL); #define pii pair<int, int> #define pb push_back #define F first #define S second #define endl "\n" #define bitcnt(n) __builtin_popcountll(n) #define setpre(...
#include <bits/stdc++.h> using namespace std; #define int long long #define all(c) c.begin(), c.end() #define FAST ios_base::sync_with_stdio(false), cin.tie(NULL); #define pii pair<int, int> #define pb push_back #define F first #define S second #define endl "\n" #define bitcnt(n) __builtin_popcountll(n) #define setpre(...
[["+", 51, 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], ["+", 51, 2, 3, 4, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 2, 63, 22], ["+", 0, 16, 31, 16, 31, 2, 3, 4, 0, 25]]
1
551
import sys X, K, D = map(int, sys.stdin.readline().split()) if K*D <= abs(X): if 0 <= X: print(X - K*D) else: print(abs(X + K*D)) else: dist = abs(X) a = dist // D # 残りの移動回数 r = K - a if 0 <= X: pos1 = X - a * D pos2 = pos1 - D else: pos1 = X + a...
import sys X, K, D = map(int, sys.stdin.readline().split()) if K*D <= abs(X): if 0 <= X: print(X - K*D) else: print(abs(X + K*D)) else: dist = abs(X) a = dist // D # 残りの移動回数 r = K - a if 0 <= X: pos1 = X - a * D pos2 = pos1 - D else: pos1 = X + a...
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 31, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 31, 22]]
5
133
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> #pragma GCC optimize(3, "Ofast", "inline") #pragm...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> #pragma GCC optimize(3, "Ofast", "inline") #pragm...
[["+", 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
298
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; #define ll long long int #define ld long double using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>...
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; #define ll long long int #define ld long double using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>...
[["-", 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, 19], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 20]]
1
368
X, K, D = map(int, input().split()) min_abs = 10**15 min_step = X // D if K <= min_step: min_abs = X - D*K else: lowest_plus = X - D*min_step highest_minus = abs(lowest_plus - D) if (K - min_step) % 2 == 0: min_abs = lowest_plus else: min_abs = highest_minus print(min_abs)
X, K, D = map(int, input().split()) X = abs(X) min_abs = 10**15 min_step = X // D if K <= min_step: min_abs = X - D*K else: lowest_plus = X - D*min_step highest_minus = abs(lowest_plus - D) if (K - min_step) % 2 == 0: min_abs = lowest_plus else: min_abs = highest_minus print(min_ab...
[["+", 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
80
x, k, d = map(int, input().split()) if abs(x) > d: tmp = min(abs(x) // d, k) if x < 0: x += d * tmp k -= tmp else: x -= d * tmp k -= tmp ans = x if k > 0 and x >= 0: if k % 2 != 0: ans = x - d else: ans = x elif k > 0: if k % 2 != 0: ans =...
x, k, d = map(int, input().split()) if abs(x) > d: tmp = min(abs(x) // d, k) if x < 0: x += d * tmp k -= tmp else: x -= d * tmp k -= tmp ans = x if k > 0 and x >= 0: if k % 2 != 0: ans = x - d else: ans = x elif k > 0: if k % 2 != 0: ans =...
[["-", 64, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 17, 72]]
5
120
X, K, D = [int(i) for i in input().split()] ans = 0 if K*D < X: ans = X - K * D elif X//D%2 == 0 and K%2 == 0 or X//D%2 * K%2 == 1: ans = X%D else: ans = D - X % D print(ans)
X, K, D = [abs(int(i)) for i in input().split()] ans = 0 if K*D < X: ans = X - K * D elif X//D%2 == 0 and K%2 == 0 or X//D%2 * K%2 == 1: ans = X%D else: ans = D - X % D print(ans)
[["+", 0, 1, 0, 662, 12, 658, 8, 652, 63, 22], ["+", 0, 662, 12, 658, 8, 652, 3, 4, 0, 24], ["+", 8, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
84
x,k,d=input().split(" ") x=int(x) k=int(k) d=int(d) x=abs(x) if x>k*d: print(x-k*d) else: t=x/d x=x%d k-=t if k%2==1: print(d-x) else: print(x)
x,k,d=input().split(" ") x=int(x) k=int(k) d=int(d) x=abs(x) if x>k*d: print(x-k*d) else: t=x//d x=x%d k-=t if k%2==1: print(d-x) else: print(x)
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 85], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 676]]
5
89
# import sys # input = sys.stdin.readline def mp(): return map(int, input().split()) def lmp(): return list(map(int, input().split())) x,k,d = mp() if x - k*d >= 0: print(x-k*d) else: u = x % d l = abs(u - d) if (k - x//d) % 2 == 0: print(u) else: print(l)
# import sys # input = sys.stdin.readline def mp(): return map(int, input().split()) def lmp(): return list(map(int, input().split())) x,k,d = mp() x = abs(x) if x - k*d >= 0: print(x-k*d) else: u = x % d l = abs(u - d) if (k - x//d) % 2 == 0: print(u) else: print(l)
[["+", 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
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c)) #define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c)) #define MOD 1000000007 #define inf 3e18 #define ld long double #define mp make_pair #define vpll vector<pair<...
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c)) #define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c)) #define MOD 1000000007 #define inf 3e18 #define ld long double #define mp make_pair #define vpll vector<pair<...
[["+", 8, 9, 0, 1, 0, 16, 12, 2, 63, 22], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 25]]
1
770
X,K,D = map(int,input().split()) if K*D<=X: print(abs(X)-K*D) exit() move_num_before = abs(X)//D move_num_after = move_num_before+1 if (K - move_num_after)%2 == 0: print(abs(abs(X)-move_num_after*D)) exit() print(abs(X)-move_num_before*D)
X,K,D = map(int,input().split()) if K*D<=abs(X): print(abs(X)-K*D) exit() move_num_before = abs(X)//D move_num_after = move_num_before+1 if (K - move_num_after)%2 == 0: print(abs(abs(X)-move_num_after*D)) exit() print(abs(X)-move_num_before*D)
[["+", 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]]
5
91
import sys input = sys.stdin.readline n, k = map(int, input().split()) p = [int(x) - 1 for x in input().split()] c = list(map(int, input().split())) #高々N回で1周する class UnionFind(object): def __init__(self, n): self._par = list(range(n)) self.size = [1] * n def root(self, v): if self._p...
import sys input = sys.stdin.readline n, k = map(int, input().split()) p = [int(x) - 1 for x in input().split()] c = list(map(int, input().split())) #高々N回で1周する class UnionFind(object): def __init__(self, n): self._par = list(range(n)) self.size = [1] * n def root(self, v): if self._p...
[["-", 0, 652, 3, 4, 0, 206, 206, 663, 0, 102], ["-", 3, 4, 0, 206, 206, 663, 0, 657, 31, 22], ["-", 3, 4, 0, 206, 206, 663, 0, 657, 17, 72], ["+", 0, 652, 3, 4, 0, 206, 206, 663, 0, 102]]
5
503
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; int n, k; ll sum[maxn], c[maxn], p[maxn]; bool vis[maxn]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &p[i]); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); ll ans = -1e18...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; int n, k; int sum[maxn], c[maxn], p[maxn]; bool vis[maxn]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &p[i]); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); ll ans = -1e1...
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 78], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40]]
1
336
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<int> p(n); vector<ll> c(n); for (auto &e : p) { cin >> e; e--; } for (auto &e : c) cin >> e; vector<ll> s1(n), s2(n), d1(n), d2(n); for (int i = 0; i < n; i++) { if (d1[i]...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<int> p(n); vector<ll> c(n); for (auto &e : p) { cin >> e; e--; } for (auto &e : c) cin >> e; vector<ll> s1(n), s2(n), d1(n), d2(n); for (int i = 0; i < n; i++) { if (d1[i]...
[["+", 64, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["+", 64, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
432
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <vector> using namespace std; int64_t mod = 998244353; vector<int> getprime(int n) { vector<int> p(0); vector<bool> table(n + 1, 0); for (int i = 2; i <= n; i++) { if (tabl...
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <vector> using namespace std; int64_t mod = 998244353; vector<int> getprime(int n) { vector<int> p(0); vector<bool> table(n + 1, 0); for (int i = 2; i <= n; i++) { if (tabl...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13]]
1
415
//高知能系Vtuberの高井茅乃です。 // Twitter: https://twitter.com/takaichino // YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i, n) for (int i = 0; i < n; i++) #define REP1(i, n) for (int...
//高知能系Vtuberの高井茅乃です。 // Twitter: https://twitter.com/takaichino // YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i, n) for (int i = 0; i < n; i++) #define REP1(i, n) for (int...
[["+", 12, 16, 31, 2, 3, 4, 0, 16, 17, 33], ["+", 12, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
1
316
#if 1 #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <cmath> #include <cstdint> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #incl...
#if 1 #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <cmath> #include <cstdint> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #incl...
[["-", 10, 43, 49, 50, 51, 2, 3, 4, 0, 13], ["+", 10, 43, 49, 50, 51, 2, 3, 4, 0, 13]]
1
510
/*input 5 2 2 4 5 1 3 3 4 -10 -8 8 */ /* ______________ | ) | ) / |______/ ...
/*input 5 2 2 4 5 1 3 3 4 -10 -8 8 */ /* ______________ | ) | ) / |______/ ...
[["+", 8, 9, 0, 7, 15, 16, 12, 2, 63, 22], ["+", 0, 7, 15, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 2, 3, 4, 0, 21], ["+", 0, 7, 15, 16, 12, 2, 3, 4, 0, 22], ["+", 0, 7, 15, 16, 12, 2, 3, 4, 0, 25]]
1
937
//#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("fma,avx,avx2") #include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define x first #define y second mt19937 rnd(chro...
//#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("fma,avx,avx2") #include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define x first #define y second mt19937 rnd(chro...
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 69, 28, 22], ["+", 31, 23, 0, 16, 12, 69, 341, 342, 0, 70], ["+", 31, 23, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 23, 0, 16, 12, 69, 341, 342, 0, 73]]
1
555
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, k = map(int, readline().split()) p = list(map(int, readline().split())) p = [x - 1 for x in p] c = list(map(int, readline().split())) ans = -INF for i in range(n): ...
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n, k = map(int, readline().split()) p = list(map(int, readline().split())) p = [x - 1 for x in p] c = list(map(int, readline().split())) ans = -INF for i in range(n): ...
[["-", 0, 662, 12, 657, 31, 23, 0, 657, 17, 676], ["-", 0, 662, 12, 657, 31, 23, 0, 657, 12, 22], ["-", 0, 1, 0, 662, 12, 657, 31, 23, 0, 25], ["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 25], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 17, 676], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 22]]
5
254
#include <bits/stdc++.h> #define rep(a, b, c) for (int a = b; a <= c; a++) #define per(a, b, c) for (int a = b; a >= c; a--) #define ios \ ; \ ios::sync_with_stdio(false); ...
#include <bits/stdc++.h> #define rep(a, b, c) for (int a = b; a <= c; a++) #define per(a, b, c) for (int a = b; a >= c; a--) #define ios \ ; \ ios::sync_with_stdio(false); ...
[["+", 31, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 12, 13], ["+", 31, 16, 12, 23, 0, 16, 31, 23, 0, 25]]
1
560
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)) ; return a; } const ll INF = numeric_limits<ll>::min(); ll n, k; ll p[5001]; ll c[5001]; int cache[5001]; int main() { ios::sync_wi...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)) ; return a; } const ll INF = numeric_limits<ll>::min(); ll n, k; ll p[5001]; ll c[5001]; int cache[5001]; int main() { ios::sync_wi...
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 15, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 15, 16, 12, 2, 3, 4, 0, 16, 12, 13]]
1
442
#include <bits/stdc++.h> // ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); // clock_t start=clock();clock_t // end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<int, int> pii; typedef pair<pii...
#include <bits/stdc++.h> // ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); // clock_t start=clock();clock_t // end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int ui; typedef pair<int, int> pii; typedef pair<pii...
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
1,119
#pragma region template 2.4 #include <bits/stdc++.h> using namespace std; template <typename T> using pq_asc = priority_queue<T, vector<T>, greater<T>>; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> ii; typedef vector<ii> vii; typedef vector<string> vs; #define REP(i, n) for ...
#pragma region template 2.4 #include <bits/stdc++.h> using namespace std; template <typename T> using pq_asc = priority_queue<T, vector<T>, greater<T>>; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> ii; typedef vector<ii> vii; typedef vector<string> vs; #define REP(i, n) for ...
[["+", 51, 2, 3, 4, 0, 16, 31, 16, 31, 22], ["+", 51, 2, 3, 4, 0, 16, 31, 16, 17, 85], ["-", 51, 2, 3, 4, 0, 16, 31, 16, 17, 85], ["-", 51, 2, 3, 4, 0, 16, 31, 16, 12, 22]]
1
795
#pragma GCC optimize("Ofast") #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <complex> // complex #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include...
#pragma GCC optimize("Ofast") #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <complex> // complex #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include...
[["+", 0, 43, 49, 50, 51, 16, 31, 23, 0, 24], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 17, 33], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 43, 49, 50, 51, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
1
515
#include <bits/stdc++.h> #define debug printf("%d %s\n", __LINE__, __FUNCTION__) typedef long long ll; typedef std::pair<int, int> pii; #define pb push_back #define mk make_pair #define fi first #define se second int _w; FILE *_f; using namespace std; const int N = 3001; int R, C, K, val[N][N]; ll f[N][N][4], ans;...
#include <bits/stdc++.h> #define debug printf("%d %s\n", __LINE__, __FUNCTION__) typedef long long ll; typedef std::pair<int, int> pii; #define pb push_back #define mk make_pair #define fi first #define se second int _w; FILE *_f; using namespace std; const int N = 3001; int R, C, K, val[N][N]; ll f[N][N][4], ans;...
[["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25], ["-", 12, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
1
294
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vll; #define PI (2 * acos(0.0)) #define eps 1e-9 #define pb push_back #define endl "\n" #define watch(x) cout << (#x) << " ...
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vll; #define PI (2 * acos(0.0)) #define eps 1e-9 #define pb push_back #define endl "\n" #define watch(x) cout << (#x) << " ...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13]]
1
495
#include <stdio.h> long long maxMy(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long DP[3001][3001][4]; long long Gift[3001][3001]; long long r, c, k; int main() { scanf("%lld %lld %lld", &r, &c, &k); int i; for (i = 0; i <= r; i++) { for (int j = 0; j <= c; ...
#include <stdio.h> long long maxMy(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long DP[3001][3001][4]; long long Gift[3001][3001]; long long r, c, k; int main() { scanf("%lld %lld %lld", &r, &c, &k); int i; for (i = 0; i <= r; i++) { for (int j = 0; j <= c; ...
[["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, ...
0
614
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_poizcy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #defin...
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_poizcy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #defin...
[["+", 8, 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, 13], ["-", 0, 14, 8, 9, 0, 57, 64, 37, 0, 13], ["+", 0, 14, 8, 9, 0, 57, 64, 37, 0, 13]]
1
463
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <vector> using namespace std; typedef long long ll; const int N = 3333; int a[N][N]; ll f[N][N][3]; int n, m, k; int main() { int x, y, v; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= k; i++) { scanf("%d%d%d", &x, &y, &v)...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <vector> using namespace std; typedef long long ll; const int N = 3333; int a[N][N]; ll f[N][N][4]; int n, m, k; int main() { int x, y, v; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= k; i++) { scanf("%d%d%d", &x, &y, &v)...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13]]
1
410
#include <bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll, ll> #define mod 1000000007 // 998244353 #define f(i, a, b) for (ll i = a; i < b; i++) #define fb(i, a, b) for (ll i = a; i > b; i--) #define ff first #define ss second #define PI 3.14159...
#include <bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll, ll> #define mod 1000000007 // 998244353 #define f(i, a, b) for (ll i = a; i < b; i++) #define fb(i, a, b) for (ll i = a; i > b; i--) #define ff first #define ss second #define PI 3.14159...
[["+", 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, 13], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 0, 16, 12, 74, 51, 2, 3, 4, 0, 25]]
1
798
#include <bits/stdc++.h> using namespace std; int n, k; int p[5010], c[5010]; int siz[5010]; long long sum[5010]; long long dp[5001][10000]; int st[5010], it, mar[5010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &p[i]); for (int i = 1; i <= n; ++i) scanf("%d", &c[i]); ...
#include <bits/stdc++.h> using namespace std; int n, k; int p[5010], c[5010]; int siz[5010]; long long sum[5010]; long long dp[5001][10000]; int st[5010], it, mar[5010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &p[i]); for (int i = 1; i <= n; ++i) scanf("%d", &c[i]); ...
[["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 35], ["-", 341, 342, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 341, 342, 0, 2, 3, 4, 0, 16, 12, 13]]
1
608
#include <bits/stdc++.h> using namespace std; #define pi 2 * asin(1.0) // template functions ///////////////////////// long Comb(long N, long M) { // nCm long ans = 1; for (long i = N; i > N - M; i--) { ans = ans * i; } for (long i = M; i > 0; i--) { ans = ans / i; } return ans; } long Perm(long N,...
#include <bits/stdc++.h> using namespace std; #define pi 2 * asin(1.0) // template functions ///////////////////////// long Comb(long N, long M) { // nCm long ans = 1; for (long i = N; i > N - M; i--) { ans = ans * i; } for (long i = M; i > 0; i--) { ans = ans / i; } return ans; } long Perm(long N,...
[["-", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
1
772
n,k = map(int,input().split()) p = list(map(int,input().split())) c = tuple(map(int,input().split())) for i in range(n): p[i] -= 1 ans = -float('inf') v = [False for _ in range(n)] for i in range(n): j = i if v[j]: continue r = [] while(v[j] == False): r.append(j) v[j] = True j = p[j] cr = ...
n,k = map(int,input().split()) p = list(map(int,input().split())) c = tuple(map(int,input().split())) for i in range(n): p[i] -= 1 ans = -float('inf') v = [False for _ in range(n)] for i in range(n): j = i if v[j]: continue r = [] while(v[j] == False): r.append(j) v[j] = True j = p[j] cr = ...
[["+", 0, 656, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 612], ["+", 0, 656, 0, 7, 8, 196, 0, 57, 0, 102]]
5
313
#include <bits/stdc++.h> using namespace std; using llong = long long; using ldbl = long double; using lpair = pair<llong, llong>; #define ALL(x) x.begin(), x.end() constexpr llong mod = 1e9 + 7; constexpr llong inf = mod * mod; int main() { llong N, K; vector<llong> P, C; cin >> N >> K; P.resize(N + 1); ...
#include <bits/stdc++.h> using namespace std; using llong = long long; using ldbl = long double; using lpair = pair<llong, llong>; #define ALL(x) x.begin(), x.end() constexpr llong mod = 1e9 + 7; constexpr llong inf = mod * mod; int main() { llong N, K; vector<llong> P, C; cin >> N >> K; P.resize(N + 1); ...
[["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13]]
1
353
import sys readline = sys.stdin.readline N,K = map(int,readline().split()) P = list(map(lambda x:x - 1, map(int,readline().split()))) C = list(map(int,readline().split())) # 全ての頂点からスタートして、ループを探す # ループを一周したときの得点が正であれば、 # ・[可能な限り - 1]回ループを回して、あとは得点が最大になるところまで歩く # (-1回は、最後のループは回し切らないほうが良いパターンがあるため) ans = - (10 ** 10) f...
import sys readline = sys.stdin.readline N,K = map(int,readline().split()) P = list(map(lambda x:x - 1, map(int,readline().split()))) C = list(map(int,readline().split())) # 全ての頂点からスタートして、ループを探す # ループを一周したときの得点が正であれば、 # ・[可能な限り - 1]回ループを回して、あとは得点が最大になるところまで歩く # (-1回は、最後のループは回し切らないほうが良いパターンがあるため) ans = - (10 ** 10) f...
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 0, 612], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 102]]
5
283
#include <bits/stdc++.h> #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--) #define rep(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; constexpr ll Mod = 998244353; constexpr ll mod = 1e9 + 7; constexpr ll inf...
#include <bits/stdc++.h> #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++) #define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--) #define rep(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; constexpr ll Mod = 998244353; constexpr ll mod = 1e9 + 7; constexpr ll inf...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
375
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; using ll = long long; constexpr ll mod = 1000000007; constexpr int inf = 1000000000; constexpr ll linf = 1000000000000000000; int main() { int n, k; cin >> n >> k; int p[n]; rep(i, n) { cin >> p[i]; --p[i]; } ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; using ll = long long; constexpr ll mod = 1000000007; constexpr int inf = 1000000000; constexpr ll linf = 1000000000000000000; int main() { int n, k; cin >> n >> k; int p[n]; rep(i, n) { cin >> p[i]; --p[i]; } ...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22]]
1
577
#include <algorithm> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> //#include<bits/stdc++.h> #define rep(i, x) for (ll i = 0; i < x; i...
#include <algorithm> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> //#include<bits/stdc++.h> #define rep(i, x) for (ll i = 0; i < x; i...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
520
#include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; typedef long long int ll; typedef long double ld; #define PI 3.141592653589793 #define MOD 1000000007 #define ALL(obj) (obj).begin(), (obj).end() template <class T> inline bool chmax(T &...
#include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; typedef long long int ll; typedef long double ld; #define PI 3.141592653589793 #define MOD 1000000007 #define ALL(obj) (obj).begin(), (obj).end() template <class T> inline bool chmax(T &...
[["-", 8, 9, 0, 1, 0, 11, 31, 69, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 31, 69, 28, 22], ["-", 0, 11, 12, 2, 3, 4, 0, 69, 28, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 69, 28, 22]]
1
760
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef pair<int, int> P; typedef long long ll; const int INF = 1001001001; const int MOD = 1000000007; const double PI = acos(-1); int main() { int N; ll K; cin >> N >> K; ll P[N], C[N]; rep(i, N) { ll p; ...
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef pair<int, int> P; typedef long long ll; const int INF = 1001001001; const int MOD = 1000000007; const double PI = acos(-1); int main() { int N; ll K; cin >> N >> K; ll P[N], C[N]; rep(i, N) { ll p; ...
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 16, 12, 23, 0, 25]]
1
303
import sys sys.setrecursionlimit(10**9) N,K = map(int,input().split()) P = [ i-1 for i in list(map(int,input().split())) ] C = list(map(int,input().split())) ans = -float('inf') for i in range(N): cycle = [] tot = 0 nex = i while True: nex = P[nex] cycle.append(C[nex]) tot += C[nex] if nex == ...
import sys sys.setrecursionlimit(10**9) N,K = map(int,input().split()) P = [ i-1 for i in list(map(int,input().split())) ] C = list(map(int,input().split())) ans = -float('inf') for i in range(N): cycle = [] tot = 0 nex = i while True: nex = P[nex] cycle.append(C[nex]) tot += C[nex] if nex == ...
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 20], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 72], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 1, 0, 677, 12, 657, 12, 23, 0, 24], ["+", 0, 1, 0, 677, 12, 657, 12, 23, 0, 25]]
5
189
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) ans = -10**18 for i in range(n): tmp_score = 0 pos = i cycle = 0 for j in range(k): pos = p[pos]-1 tmp_score += c[pos] ans = max(ans,tmp_score) cycle += 1 if...
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) ans = -10**18 for i in range(n): tmp_score = 0 pos = i cycle = 0 for l in range(k): pos = p[pos]-1 tmp_score += c[pos] ans = max(ans,tmp_score) cycle += 1 if...
[["-", 0, 656, 0, 7, 8, 196, 0, 7, 31, 22], ["+", 0, 656, 0, 7, 8, 196, 0, 7, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 22]]
5
179
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] nexts = new int[n]; for (int i = 0; i < n; i++) { nexts[i] = sc.nextInt() - 1; } int[] arr = new int[n]; for (i...
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] nexts = new int[n]; for (int i = 0; i < n; i++) { nexts[i] = sc.nextInt() - 1; } int[] arr = new int[n]; for (i...
[["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 492, 3, 4, 0, 16, 12, 23, 0, 25]]
3
356
def res(n): pos = n cnt = 1 while 1: pos = P[pos]-1 if pos == n: break cnt += 1 tmp = 0 ans = -float("inf") pos = n for _ in range(min(K,cnt)): pos = P[pos]-1 tmp += C[pos] ans = max(ans,tmp) ##ループして0以上なら(K//cnt)回ループしてあまり...
def res(n): pos = n cnt = 1 while 1: pos = P[pos]-1 if pos == n: break cnt += 1 tmp = 0 ans = -float("inf") pos = n for _ in range(min(K,cnt)): pos = P[pos]-1 tmp += C[pos] ans = max(ans,tmp) ##ループして0以上なら(K//cnt)回ループしてあまり...
[["+", 0, 662, 12, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 12, 612], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 22]]
5
231
#include <bits/stdc++.h> #define rep(a, n) for (ll a = 0; a < (n); ++a) using namespace std; typedef long long ll; using ll = long long; typedef pair<ll, ll> P; typedef pair<ll, P> PP; using Graph = vector<vector<ll>>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } retur...
#include <bits/stdc++.h> #define rep(a, n) for (ll a = 0; a < (n); ++a) using namespace std; typedef long long ll; using ll = long long; typedef pair<ll, ll> P; typedef pair<ll, P> PP; using Graph = vector<vector<ll>>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } retur...
[["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 51, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 51, 16, 12, 16, 31, 23, 0, 16, 12, 13]]
1
443
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> pes, color, ces, sz; vector<ll> points; void dfs(int u, int z) { color[u] = z; points[color[u]] += ces[u]; sz[color[u]]++; int v = pes[u]; if (color[v] == -1) dfs(v, z); } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> pes, color, ces, sz; vector<ll> points; void dfs(int u, int z) { color[u] = z; points[color[u]] += ces[u]; sz[color[u]]++; int v = pes[u]; if (color[v] == -1) dfs(v, z); } int main() { ios_base::sync_with_stdio(false); ...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22]]
1
472
from itertools import accumulate n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) p = [i-1 for i in p] seen = [False]*n ans = -float('inf') for i in range(n): if not seen[i]: sc = [] stop = i while True: seen[i] = True ...
from itertools import accumulate n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) p = [i-1 for i in p] seen = [False]*n ans = -float('inf') for i in range(n): if not seen[i]: sc = [] stop = i while True: seen[i] = True ...
[["-", 0, 657, 31, 657, 12, 23, 0, 657, 12, 22], ["+", 0, 657, 31, 657, 12, 23, 0, 657, 12, 22], ["-", 0, 657, 31, 206, 206, 663, 0, 657, 12, 22], ["+", 0, 657, 31, 206, 206, 663, 0, 657, 12, 22]]
5
279
#include <bits/stdc++.h> using namespace std; long long arr[1000000], arr1[1000000], val[1000000], val1[1000000]; long long int mmm(long long int x, long long int y) { if (x > y) { return x; } else { return y; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", ...
#include <bits/stdc++.h> using namespace std; long long arr[1000000], arr1[1000000], val[1000000], val1[1000000]; long long int mmm(long long int x, long long int y) { if (x > y) { return x; } else { return y; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", ...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
1
548
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define endl '\n' typedef long long ll; // Table is the complete reverse of dp // Always think of the pattern (LCM, GCD) // Be careful of unsigned // Think of a solution that gets TLE and optimize it // Use binary search // ...
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define endl '\n' typedef long long ll; // Table is the complete reverse of dp // Always think of the pattern (LCM, GCD) // Be careful of unsigned // Think of a solution that gets TLE and optimize it // Use binary search // ...
[["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 17, 32]]
1
1,141
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #includ...
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #includ...
[["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 13]]
1
537
#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>; ll N, K; ll score(ll x, vector<ll> &P, vector<ll> &C, vector<ll> &sum, vector<ll> &cycle) { ll res = -100000000000000000; ll point = 0; ll location = x; for (...
#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>; ll N, K; ll score(ll x, vector<ll> &P, vector<ll> &C, vector<ll> &sum, vector<ll> &cycle) { ll res = -100000000000000000; ll point = 0; ll location = x; for (...
[["-", 31, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 12, 13]]
1
407
// In the name of Allah :) #include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char *s) { return (string)s; } string to_string(string s) { return s; } template <class A> string to_string(complex<...
// In the name of Allah :) #include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char *s) { return (string)s; } string to_string(string s) { return s; } template <class A> string to_string(complex<...
[["-", 3, 4, 0, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 12, 2, 3, 4, 0, 91, 17, 33], ["+", 0, 16, 12, 2, 3, 4, 0, 91, 28, 22]]
1
859
// Author : ps41 #include <bits/stdc++.h> using namespace std; #define ll int64_t const ll M = 1e9 + 7, N = 1e6 + 5; ll p[N], a[N], tmp, var, cnt, t2, var2; void func(ll i, ll node) { cnt++; tmp += a[p[i]]; if (p[i] == node) return; func(p[i], node); } void func2(ll i, ll node) { cnt++; tmp += a[p[i]...
// Author : ps41 #include <bits/stdc++.h> using namespace std; #define ll int64_t const ll M = 1e9 + 7, N = 1e6 + 5; ll p[N], a[N], tmp, var, cnt, t2, var2; void func(ll i, ll node) { cnt++; tmp += a[p[i]]; if (p[i] == node) return; func(p[i], node); } void func2(ll i, ll node) { cnt++; tmp += a[p[i]...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 355], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
404
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm = 1000000000; ll MM = mm + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.141592653589793 int main() { int n; ll k; cin >> n >> k; VI p(n); vector<ll> c(n); ll ans = -pow(10, 17); rep(i, n) c...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm = 1000000000; ll MM = mm + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.141592653589793 int main() { int n; ll k; cin >> n >> k; VI p(n); vector<ll> c(n); ll ans = -pow(10, 17); rep(i, n) c...
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
358