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
a = input() a, b = a.split(' ') a = int(a) b = int(b) a = a % b print(a if a < b - a else b)
a = input() a, b = a.split(' ') a = int(a) b = int(b) a = a % b print(a if a < b - a else b - a)
[["+", 0, 652, 3, 4, 0, 41, 0, 657, 17, 33], ["+", 0, 652, 3, 4, 0, 41, 0, 657, 12, 22]]
5
46
import math n,k=map(int,input().split()) num=math.floor(n/k) n=n-num*k ans=min(abs(k-n),n) print(ans)
import math n,k=map(int,input().split()) num=n//k n=n-num*k ans=min(abs(k-n),n) print(ans)
[["-", 0, 1, 0, 662, 12, 652, 63, 319, 500, 22], ["-", 0, 1, 0, 662, 12, 652, 63, 319, 0, 131], ["-", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 676], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25...
5
52
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, A, B; cin >> N >> K; A = N % K; B = (A - K > 0) ? A - K : K - A; cout << ((A > K) ? K : A) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, A, B; cin >> N >> K; A = N % K; B = (A - K > 0) ? A - K : K - A; cout << ((A > B) ? B : A) << endl; }
[["-", 12, 23, 0, 41, 15, 23, 0, 16, 12, 22], ["+", 12, 23, 0, 41, 15, 23, 0, 16, 12, 22], ["-", 0, 16, 31, 16, 12, 23, 0, 41, 64, 22], ["+", 0, 16, 31, 16, 12, 23, 0, 41, 64, 22]]
1
68
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << min(N % K, abs(N % K - K)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; cout << min(N % K, abs(N % K - K)) << endl; return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
44
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << min(N % K, abs(N % K - K)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; cout << min(N % K, abs(N % K - K)); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
44
#include <algorithm> #include <iostream> #include <limits.h> #include <map> #include <string> #include <vector> using namespace std; int main(void) { int N, K; cin >> N >> K; int res = N % K; N = res; if (res == 0) { cout << "0" << endl; return 0; } while (res > abs(N - K)) { N = abs(N - K...
#include <algorithm> #include <iostream> #include <limits.h> #include <map> #include <string> #include <vector> using namespace std; int main(void) { long long N, K; cin >> N >> K; long long res = N % K; N = res; if (res == 0) { cout << "0" << endl; return 0; } while (res > abs(N - K)) { N...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
99
N,K=map(int,input().split()) r=N%K print(max(r,K-r))
N,K=map(int,input().split()) r=N%K print(min(r,K-r))
[["-", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22]]
5
32
def absolute(N,K): return abs(N-K) N,K=map(int,input().split()) N=N%K valuelist = [N%K] for i in range (0,1): i+=1 N=absolute(N,K) valuelist.append(absolute(N,K)) print(min(valuelist))
def absolute(N,K): return abs(N-K) N,K=map(int,input().split()) N=N%K valuelist = [N%K] for i in range (0,3): i+=1 N=absolute(N,K) valuelist.append(absolute(N,K)) print(min(valuelist))
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612]]
5
82
#AtCoder N, K = map(int, input().split()) q, mod = divmod(N, K) print(min(q, mod))
#AtCoder N, K = map(int, input().split()) q, mod = divmod(N, K) print(min(mod, K-mod))
[["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 17, 33]]
5
36
n, k = map(int, input().split()) n %= m print(min(n, k - n))
n, k = map(int, input().split()) n %= k print(min(n, k - n))
[["-", 36, 36, 0, 656, 0, 1, 0, 677, 12, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 677, 12, 22]]
5
30
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repr(i, a, n) for (int i = n - 1; i >= a; i--) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; ll min1 = n % k; ll min2 = abs...
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repr(i, a, n) for (int i = n - 1; i >= a; i--) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; ll min1 = n % k; ll min2 = abs...
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 12, 22], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 12, 22]]
1
101
package main import ( "bufio" "fmt" "log" "math" "os" "strconv" "strings" ) func abs(v int64) int64 { if v < 0 { return -v } return v } func getans(n, k int64) int64 { if n > k { n = n % k } if n == k { return 0 } if n < k/2 { return n } else { return abs(n - k) } } func main() { scanner...
package main import ( "bufio" "fmt" "log" "math" "os" "strconv" "strings" ) func abs(v int64) int64 { if v < 0 { return -v } return v } func getans(n, k int64) int64 { if n > k { n = n % k } if n == k { return 0 } if n <= k/2 { return n } else { return abs(n - k) } } func main() { scanne...
[["-", 0, 435, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 435, 8, 196, 0, 57, 15, 16, 17, 19]]
7
1,046
N,K=map(int, input().split()) y = int(N/K) x = N - y*K ans = min(x, abs(x-K)) print(ans)
N,K=map(int, input().split()) y = int(N//K) x = N - y*K ans = min(x, abs(x-K)) print(ans)
[["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 17, 676]]
5
48
N,K=map(int, input().split()) y = int(N/K) x = N - y*K ans = min(x, abs(x-K)) print(ans)
N,K=map(int, input().split()) y = N//K x = N - y*K #x = N%K ans = min(x, abs(x-K)) print(ans)
[["-", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 676], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
48
#include <bits/stdc++.h> #define ll long long int #define MOD1 1000000007 #define MOD2 998244353 #define BOOST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) using namespace std; int main() { ll n, k...
#include <bits/stdc++.h> #define ll long long int #define MOD1 1000000007 #define MOD2 998244353 #define BOOST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) using namespace std; int main() { ll n, k...
[["+", 0, 16, 12, 2, 3, 4, 0, 16, 17, 109], ["+", 0, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
1
52
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, abs(k - n % k)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; cout << min(n % k, abs(k - n % k)); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
44
N,K = map(int, input().split()) x = abs(N - K*(int(N/K)-1)) ans = N for i in range(0,5): x = abs(x-K) ans = min(ans,x) print(ans)
N,K = map(int, input().split()) x = abs(N - K*(int(N/K)-1)) ans = N for i in range(0,100000): x = abs(x-K) ans = min(ans,x) print(ans)
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612]]
5
68
#include <algorithm> #include <iostream> using namespace std; int main() { long long n, m; int f = 0; cin >> n >> m; if (n == 0) { cout << 0; return 0; } int p = n % m; if (p == 0) { cout << 0; return 0; } if (n >= m) { int t = n / m; while (t != 0) { n = n - t * m; ...
#include <algorithm> #include <iostream> using namespace std; int main() { long long n, m; int f = 0; cin >> n >> m; if (n == 0) { cout << 0; return 0; } int p = n % m; if (p == 0) { cout << 0; return 0; } if (n >= m) { long long t = n / m; // cout << t; while (t != 0) { ...
[["-", 8, 9, 0, 57, 64, 9, 0, 43, 39, 40], ["+", 0, 57, 64, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 57, 75, 76, 0, 9, 0, 43, 39, 40], ["+", 75, 76, 0, 9, 0, 43, 39, 86, 0, 96]]
1
148
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long k = sc.nextLong(); long buf = n / k; long ans = Math.min(k * buf - n, k * (buf + 1) - n); System.out.println(ans); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long k = sc.nextLong(); long buf = n / k; long ans = Math.min(n - k * buf, k * (buf + 1) - n); System.out.println(ans); } }
[["+", 49, 200, 51, 492, 3, 4, 0, 16, 31, 22], ["+", 49, 200, 51, 492, 3, 4, 0, 16, 17, 33], ["-", 49, 200, 51, 492, 3, 4, 0, 16, 17, 33], ["-", 49, 200, 51, 492, 3, 4, 0, 16, 12, 22]]
3
93
N, K = map(int, input().split()) N = N % K if (N > abs(N - K)): N = abs(N - K) else: print(N) break
N, K = map(int, input().split()) N = N % K if (N > abs(N - K)): N = abs(N - K) print(N)
[["-", 36, 36, 0, 656, 0, 57, 75, 76, 0, 95], ["-", 36, 36, 0, 656, 0, 57, 75, 76, 0, 102], ["-", 0, 57, 75, 76, 8, 196, 0, 93, 0, 94]]
5
48
N,K = map(int, input().split()) syou = int(N/K) min_1 = N - syou*K min_2 = -(N - (syou+1)*K) if min_1 < min_2: print(min_1) else : print(min_2)
N,K = map(int, input().split()) syou = N//K min_1 = N - syou*K min_2 = -(N - (syou+1)*K) if min_1 < min_2: print(min_1) else : print(min_2)
[["-", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 676], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
60
#include <stdio.h> int main(void) { int n, k, s, t; scanf("%d%d", &n, &k); s = n % k; t = k - s; if (s >= t) printf("%d", t); else printf("%d", s); return 0; }
#include <stdio.h> int main(void) { long int n, k, s, t; scanf("%ld%ld", &n, &k); s = n % k; t = k - s; if (s >= t) printf("%ld", t); else printf("%ld", s); return 0; }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
71
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vd = vector<double>; using vvi = vector<vi>; using vvll = vector<vll>; using vvd = ve...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vd = vector<double>; using vvi = vector<vi>; using vvll = vector<vll>; using vvd = ve...
[["-", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22]]
1
143
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, c; cin >> n >> k; a = n % k; b = min(a, k - a); cout << b << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, a, b; cin >> n >> k; a = n % k; b = min(a, k - a); cout << b << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22]]
1
52
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int A = N % K; cout << min(A, K - A) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N, K; cin >> N >> K; long long int A = N % K; cout << min(A, K - A) << endl; }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
43
#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() { int N, K, M; cin >> N >> K; M = min(N % K, K - N % K); cout << M << 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() { ll N, K, M; cin >> N >> K; M = min(N % K, K - N % K); cout << M << endl; return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78]]
1
73
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { int n, k; cin >> n >> k; int t = n % k; cout << min(n, t); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { long n, k; cin >> n >> k; long t = n % k; cout << min(t, k - t); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 1, 0, 16, 12, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 16, 12, 2, 3, 4, 0, 22], ["+", 0, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 16, 12, 2, 3, 4, 0, 16, 17, 33]]
1
50
#include <bits/stdc++.h> #define REP(i, n) for ((int)(i) = 0; (i) < (int)(n); (i)++) #define ll long long using namespace std; int main() { ll N, K, diff, ans; cin >> N >> K; diff = N % K; ans = min(diff, diff - K); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for ((int)(i) = 0; (i) < (int)(n); (i)++) #define ll long long using namespace std; int main() { ll N, K, diff, ans; cin >> N >> K; diff = N % K; ans = min(diff, K - diff); cout << ans << endl; return 0; }
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 22]]
1
64
n,k=map(int,input().split()) if n>=k:n%=k print(min(k,k-n))
n,k=map(int,input().split()) if n>=k:n%=k print(min(n,k-n))
[["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22]]
5
35
#include <iostream> #include <stdio.h> using namespace std; int main() { int N, K; int min; cin >> N >> K; min = N % K; if (min > K - min) min = K - min; cout << min << endl; return 0; }
#include <iostream> #include <stdio.h> using namespace std; int main() { long N, K; long min; cin >> N >> K; min = N % K; if (min > K - min) min = K - min; cout << min << endl; return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
57
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n >= k) n = n % k; cout << min(n, k - n); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (n >= k) n = n % k; cout << min(n, k - n); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
49
N, K = map(int, input().split()) E = N % K if (E == 0): print('0') else: if (E > K): print(E) else: print(abs(E - K))
N, K = map(int, input().split()) E = N % K if (E == 0): print('0') else: if E < abs(E - K): print(E) else: print(abs(E - K))
[["+", 75, 76, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 75, 76, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 8, 196, 0, 57, 15, 666, 0, 652, 63, 22], ["-", 8, 196, 0, 57, 15, 23, 0, 666, 667, 47], ["+", 15, 666, 0, 652, 3, 4, 0, 657, 17, 33]]
5
58
#include <iostream> using namespace std; long long solve(long long a, long long b) { if (a < b) { if (b - a > a) return a; else return b; } if (a % b == 0) return 0; long long x = a - (a / b) * b; long long y = (a / b + 1) * b - a; if (x > y) return y; return x; } int main() ...
#include <iostream> using namespace std; long long solve(long long a, long long b) { if (a < b) { if (b - a > a) return a; else return b - a; } if (a % b == 0) return 0; long long x = a - (a / b) * b; long long y = (a / b + 1) * b - a; if (x > y) return y; return x; } int mai...
[["+", 0, 57, 75, 76, 0, 37, 0, 16, 17, 33], ["+", 0, 57, 75, 76, 0, 37, 0, 16, 12, 22]]
1
126
N, K = map(int, input().split()) q = N // K Na = N - q*K Nb = abs(Na - K) if Na >= Nb: print(Na) else: print(Nb)
N, K = map(int, input().split()) q = N // K Na = N - q*K Nb = abs(Na - K) if Na >= Nb: print(Nb) else: print(Na)
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
5
51
N, K = map(int, input().split()) if N%K != 0: print(min(N%K, N-N%K)) else: print(0)
N, K = map(int, input().split()) if N%K != 0: print(min(N%K, K-N%K)) else: print(0)
[["-", 3, 4, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 31, 22]]
5
44
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, k; cin >> n >> k; long long p_rem, m_rem; if (n % k == 0) cout << 0 << endl; else { p_rem = n % k; if (n >= k) { int x; x = (n / k) + 1; m_rem = x * k - n; } else { int y; y = (n / k) +...
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, k; cin >> n >> k; long long p_rem, m_rem; if (n % k == 0) cout << 0 << endl; else { p_rem = n % k; if (n >= k) { long long x; x = (n / k) + 1; m_rem = x * k - n; } else { long long y; y...
[["-", 0, 9, 0, 57, 64, 9, 0, 43, 39, 40], ["+", 0, 57, 64, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 57, 75, 76, 0, 9, 0, 43, 39, 40], ["+", 75, 76, 0, 9, 0, 43, 39, 86, 0, 96]]
1
121
#include <bits/stdc++.h> using namespace std; const int MAX = 110; int main() { long long x, y; scanf("%lld %lld", &x, &y); long long ans = x; set<long long> vstd; if (x % y == 0) { puts("0"); exit(0); } else if (y % x == 0) { printf("%lld\n", x); exit(0); } if (x > y) { long long lo...
#include <bits/stdc++.h> using namespace std; const int MAX = 110; int main() { long long x, y; scanf("%lld %lld", &x, &y); long long ans = x; set<long long> vstd; if (x % y == 0) { puts("0"); exit(0); } else if (y % x == 0) { printf("%lld\n", x); exit(0); } if (x > y) { long long lo...
[["-", 51, 16, 31, 23, 0, 16, 31, 2, 63, 22], ["-", 31, 23, 0, 16, 31, 2, 3, 4, 0, 24], ["-", 31, 23, 0, 16, 31, 2, 3, 4, 0, 25]]
1
179
n,k = map(int,input().split()) if k==1 : ln=0 elif k==0 : ln=n elif n>=k: a = n%k while 1: ln = a n = abs(n-k) if ln<=n: break else: while 1: ln = n n = abs(n-k) if ln<=n: break print(ln)
n,k = map(int,input().split()) if k==1 : ln=0 elif k==0 : ln=n elif n>=k: a = n%k n=a while 1: ln = n n = abs(a-k) if ln<=n: break else: while 1: ln = n n = abs(n-k) if ln<=n: break print(ln)
[["+", 75, 665, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 75, 665, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 75, 665, 64, 196, 0, 1, 0, 662, 12, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 662, 12, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 31, 22]]
5
88
n,k = map(int, input().split()) tmpNum = n subtraction = n if n % k == 0: print(0) else: tmp = int(n/k) subtraction = n - (tmp*k) while(1): subtraction = abs(subtraction-k) print(subtraction,tmpNum) if subtraction < tmpNum: tmpNum = subtraction else: break print(tmpNum)
n,k = map(int, input().split()) tmpNum = n subtraction = n if n % k == 0: print(0) else: tmp = int(n/k) subtraction = n - (tmp*k) while(1): subtraction = abs(subtraction-k) if subtraction < tmpNum: tmpNum = subtraction else: break print(tmpNum)
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 21], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
86
N, K = list(map(int,input().split())) d = int(N/K) S0 = N - d * K S1 = S0 - K Sa = abs(S1) if S0 <= Sa: print(S0) else: print(Sa)
N, K = list(map(int,input().split())) d = N//K S0 = N - d * K S1 = S0 - K Sa = abs(S1) if S0 <= Sa: print(S0) else: print(Sa)
[["-", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 676], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
60
#include <iostream> using namespace std; int main() { int N, K; cin >> N >> K; if (N > K) { N = N % K; } N = min(N, K - N); cout << N << endl; }
#include <iostream> using namespace std; int main() { long long N, K; cin >> N >> K; if (N > K) { N = N % K; } N = min(N, K - N); cout << N << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
54
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int temp; temp = n % k; if (temp == 0) { cout << 0 << endl; return 0; } temp = n; vector<long long int> v; for (int i = 0; i < 100000000; i++) { temp = abs(temp - k); v.push_back(t...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int temp; temp = n % k; if (temp == 0) { cout << 0 << endl; return 0; } vector<long long int> v; for (int i = 0; i < 100; i++) { temp = abs(temp - k); v.push_back(temp); } sort(v...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13]]
1
144
#include <stdio.h> int main(void) { long a, b; long check = 0; scanf("%lo %lo", &a, &b); a = a % b; for (;;) { check = a - b; if (check < 0) { check = check * (-1); } if (a > check) { a = check; } else { printf("%lo", a); break; } } return 0; }
#include <stdio.h> int main(void) { long int a, b; long int check = 0; scanf("%ld %ld", &a, &b); a = a % b; for (;;) { check = a - b; if (check < 0) { check = check * (-1); } if (a > check) { a = check; } else { printf("%ld", a); break; } } return...
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 39, 40], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
96
n, k = map(int, input().split()) min_num = n new_min = n % k while True: new_min = new_min - k if new_min < 0: new_min *= -1 if min_num > new_min: min_num = new_min else: break print(min_num)
n, k = map(int, input().split()) min_num = new_min = n % k while True: new_min = new_min - k if new_min < 0: new_min *= -1 if min_num > new_min: min_num = new_min else: break print(min_num)
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 12, 22]]
5
56
N, K = map(int, input().split()) if N > K: N = N - K*(N//K) if N==K: print(0) else: print(K-N)
N, K = map(int, input().split()) if N > K: N = N - K*(N//K) if N==K: print(0) else: print(min(N,K-N))
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 21], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
49
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; if (N == K) { cout << 0 << endl; return 0; } if (N > K) { N = N - (N / K) * K; if (N == 0) cout << 0 << endl; return 0; } long long mae = N; long long ima; ima = abs(mae - K); while (m...
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; if (N == K) { cout << 0 << endl; return 0; } if (N > K) { N = N - (N / K) * K; if (N == 0) { cout << 0 << endl; return 0; } } long long mae = N; long long ima; ima = abs(mae - K); ...
[["+", 0, 57, 64, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 57, 64, 9, 0, 57, 64, 9, 0, 46]]
1
125
#include <iostream> using namespace std; int main() { int x, k; cin >> x >> k; if (x > k) { x = x % k; } if (x > k / 2) { x = k - x; } cout << x << endl; }
#include <iostream> using namespace std; int main() { long x, k; cin >> x >> k; if (x > k) { x = x % k; } if (x > k / 2) { x = k - x; } cout << x << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
59
#include <iostream> using namespace std; int main() { int N, K; cin >> N >> K; int a, b; a = N % K; b = abs(a - K); if (a > b) { cout << b << endl; } else { cout << a << endl; } return 0; }
#include <iostream> using namespace std; int main() { long long int N, K; cin >> N >> K; long long int a, b; a = N % K; b = abs(a - K); if (a >= b) { cout << b << endl; } else { cout << a << endl; } return 0; }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
69
import sys N, K = map(int, input().split()) if N == 1 or N == 0 or K == 1 or N == K: print(0) sys.exit() if N > K: N = N%K ans = [N] for _ in range(10): ans.append(abs(N-K)) N = abs(N-K) print(min(ans))
import sys N, K = map(int, input().split()) if N == 0 or K == 1 or N == K: print(0) sys.exit() if N > K: N = N%K # elif N < K: # print(N) # sys.exit() ans = [N] for _ in range(100): ans.append(abs(N-K)) N = abs(N-K) print(min(ans))
[["-", 15, 679, 31, 679, 31, 679, 31, 666, 0, 612], ["-", 0, 57, 15, 679, 31, 679, 31, 679, 17, 354], ["-", 15, 679, 31, 679, 31, 679, 12, 666, 0, 22], ["-", 15, 679, 31, 679, 31, 679, 12, 666, 667, 60], ["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612]]
5
93
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define inputInt(a) \ int a; \ cin >> a; #define inputInt2(a, b) \...
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define inputInt(a) \ int a; \ cin >> a; #define inputInt2(a, b) \...
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22]]
1
285
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; if (N % K < (K + 1) / 2) cout << N % K << endl; else cout << K - N % K << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int long long N, K; cin >> N >> K; if (N % K < (K + 1) / 2) cout << N % K << endl; else cout << K - N % K << endl; }
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 14, 8, 9, 0, 43, 0, 42, 0, 22]]
1
56
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; if (K == 1) { cout << "0" << endl; return 0; } else { int x = N % K; cout << min(x, abs(K - x)) << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; if (K == 1) { cout << "0" << endl; return 0; } else { long long x = N % K; cout << min(x, abs(K - x)) << endl; } }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 57, 75, 76, 0, 9, 0, 43, 39, 40], ["+", 75, 76, 0, 9, 0, 43, 39, 86, 0, 96]]
1
68
#include <bits/stdc++.h> using namespace std; int main() { int N = 0, K = 0, a = 0; cin >> N >> K; if (K = 0) { a = 0; } else { a = N % K; } if (a <= K - a) { cout << a; } else { cout << K - a; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int N = 0, K = 0, a = 0; cin >> N >> K; if (K == 0) { a = 0; } else { a = N % K; } if (a <= K - a) { cout << a; } else { cout << K - a; } }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
75
#include <iostream> using namespace std; int main() { int N, K; cin >> N >> K; int p_rest, n_rest; p_rest = N % K; n_rest = p_rest - K; if (p_rest <= -n_rest) { cout << p_rest << endl; } else { cout << -n_rest << endl; } }
#include <iostream> using namespace std; int main() { long N, K; cin >> N >> K; long p_rest, n_rest; p_rest = N % K; n_rest = p_rest - K; if (p_rest <= -n_rest) { cout << p_rest << endl; } else { cout << -n_rest << endl; } }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
65
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (ll i = (a); i <= (b); ++i) #define FOD(i, a, b) for (ll i = (a); i >= (b); --i) #define name "a" #define pb push_back typedef pair<ll, ll> ii; const ll maxn = 1e5 + 7, oo = 1e18, mod = 1e9 + 7; ll n, k, t, res, tmp; int main() ...
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (ll i = (a); i <= (b); ++i) #define FOD(i, a, b) for (ll i = (a); i >= (b); --i) #define name "a" #define pb push_back typedef pair<ll, ll> ii; const ll maxn = 1e5 + 7, oo = 1e18, mod = 1e9 + 7; ll n, k, t, res, tmp; int main() ...
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
1
167
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, m, n) for (int i = m; i < n; i++) #define SORT(x) sort(x.begin(), x.end()) #define RS(x) rsort(x.begin(),x,end())) #define REVE(x) reverse(x.begin(), x.end()) #define ALL(x) (x).begin(...
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, m, n) for (int i = m; i < n; i++) #define SORT(x) sort(x.begin(), x.end()) #define RS(x) rsort(x.begin(),x,end())) #define REVE(x) reverse(x.begin(), x.end()) #define ALL(x) (x).begin(...
[["+", 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
146
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int sub = N % K; if (sub > K - sub) cout << K - sub << endl; else cout << sub << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long N, K; cin >> N >> K; long sub = N % K; if (sub > K - sub) cout << K - sub << endl; else cout << sub << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
53
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int ans1 = N % K; int ans2 = abs(ans1 - K); if (ans1 > ans2) { cout << ans2 << endl; } else cout << ans1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; long long ans1 = N % K; long long ans2 = abs(ans1 - K); if (ans1 > ans2) { cout << ans2 << endl; } else cout << ans1 << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
61
#include <bits/stdc++.h> #define endl '\n' using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; N %= K; if (N < K / 2) cout << N << endl; else cout << K - N << endl; return 0; }
#include <bits/stdc++.h> #define endl '\n' using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long int N, K; cin >> N >> K; N %= K; if (N <= K / 2) cout << N << endl; else cout << K - N << endl; return 0; }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
70
import java.util.Scanner; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long K = sc.nextLong(); long ans = 0; if (N > K) { long x = N % K; long ans1 = N - (K * x); long ans2 = (x + 1) * K - N; ans = (a...
import java.util.Scanner; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long K = sc.nextLong(); long ans = 0; if (N > K) { long x = N / K; long ans1 = N - (K * x); long ans2 = ((x + 1) * K) - N; ans = ...
[["-", 64, 196, 0, 503, 49, 200, 51, 16, 17, 109], ["+", 64, 196, 0, 503, 49, 200, 51, 16, 17, 85], ["+", 0, 503, 49, 200, 51, 16, 31, 23, 0, 24], ["+", 0, 503, 49, 200, 51, 16, 31, 23, 0, 25]]
3
158
N, K = map(int, input().split()) if N == 0: print(N) elif (K / N) > 1: print(N) else: amari = N % K mainasu_noatai = abs(amari - K) if (amari > mainasu_noatai): print(mainasu_noatai); else: print(amari)
N, K = map(int, input().split()) if N == 0: print(N) elif int(K / N) > 1: print(N) else: amari = N % K mainasu_noatai = abs(amari - K) if (amari > mainasu_noatai): print(mainasu_noatai); else: print(amari)
[["+", 0, 57, 75, 665, 15, 666, 0, 652, 63, 22]]
5
71
#include <stdio.h> #define min(a, b) a < b ? a : b #define abs(a) a >= 0 ? a : -a int main() { long long int x, k; scanf("%lld%lld", &x, &k); x = x % k; long long int ttt = x - k; if (ttt < 0) ttt *= (-1); long long int ans = min(x, abs(ttt)); printf("%lld\n", ans); return 0; }
#include <stdio.h> #define min(a, b) a < b ? a : b #define abs(a) a >= 0 ? a : -a int main() { long long int x, k; scanf("%lld%lld", &x, &k); x = x % k; long long int ttt = x - k; if (ttt < 0) ttt *= (-1); long long int ans = min(x, ttt); // printf("%lld %lld\n", x, ttt); printf("%lld\n", ans); ...
[["-", 49, 50, 51, 2, 3, 4, 0, 2, 63, 22], ["-", 51, 2, 3, 4, 0, 2, 3, 4, 0, 24], ["-", 51, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
1
97
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; int main() { ll n, m; scanf("%lld %lld", &n, &m); if (n >= m) { if (n % m == 0) printf("0\n"); else { ll minn = (n % m); minn = min(minn, abs(minn - m)); printf("%lld\n", minn); ...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; int main() { ll n, m; scanf("%lld %lld", &n, &m); if (n >= m) { if (n % m == 0) printf("0\n"); else { ll minn = (n % m); minn = min(minn, abs(minn - m)); printf("%lld\n", minn); ...
[["+", 0, 1, 0, 2, 3, 4, 0, 2, 63, 22], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 24], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 21], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 22], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
1
123
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, k - n % k) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; cout << min(n % k, k - n % k) << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
40
<?php list($x, $k) = preg_split('/ /', trim(fgets(STDIN))); print min( $x % $k , $x - ($x % $k) );
<?php list($x, $k) = preg_split('/ /', trim(fgets(STDIN))); print min( $x % $k , $k - ($x % $k) );
[["-", 3, 3, 0, 28, 0, 16, 31, 606, 0, 141], ["+", 3, 3, 0, 28, 0, 16, 31, 606, 0, 141]]
6
46
#include <stdio.h> int main() { long int n, k; scanf("%ld %ld", n, k); n = n % k; if (n % k > k - n % k) n = k - n % k; printf("%d", n); }
#include <stdio.h> int main() { long long int n, k; scanf("%ld %ld", &n, &k); n = n % k; if (n % k > k - n % k) n = k - n % k; printf("%ld", n); }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
60
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; long long ans; cin >> n >> k; ans = n % k; ans = min(ans, k - ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; long long ans; cin >> n >> k; ans = n % k; ans = min(ans, k - ans); cout << ans; return 0; }
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
48
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; cout << min(n % m, m - (n % m)) << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; cout << min(n % m, m - (n % m)) << '\n'; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
44
#include <bits/stdc++.h> using namespace std; #define ll long long //#define mod 10000000007 int main() { ll a, b, mod; mod = 1000000007; cin >> a >> b; // ll z=1000000000000000000; // cout<<z<<endl; /* if(b==1){ cout<<0<<endl; }*/ /* a=a%mod; b=b%mod; // LONG ...
#include <bits/stdc++.h> using namespace std; #define ll long long //#define mod 10000000007 int main() { ll a, b, mod; mod = 1000000007; cin >> a >> b; if (b == 1) { cout << 0 << endl; } else { ll x = a % b; x = b - x; cout << min(x, a % b) << endl; } return 0; }
[["+", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 17, 109]]
1
81
#include <stdio.h> int main(void) { int n, k, x, y; scanf("%d %d", &n, &k); x = n % k; y = k - x; if (x < y) printf("%d\n", x); else printf("%d\n", y); return 0; }
#include <stdio.h> int main(void) { long n, k, x, y; scanf("%ld %ld", &n, &k); x = n % k; y = k - x; if (x < y) printf("%ld\n", x); else printf("%ld\n", y); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
73
#include <stdio.h> #include <stdlib.h> int main() { int n, k, ans1, ans2; scanf("%d %d", &n, &k); ans1 = n % k; ans2 = abs(ans1 - k); if (ans1 <= ans2) printf("%d\n", ans1); else printf("%d\n", ans2); return 0; }
#include <stdio.h> #include <stdlib.h> int main() { long n, k, ans1, ans2; scanf("%ld %ld", &n, &k); ans1 = n % k; ans2 = labs(ans1 - k); if (ans1 <= ans2) printf("%ld\n", ans1); else printf("%ld\n", ans2); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
77
import sys import math n, k = map(int, input().split()) pre=n-math.floor(n/k)*k while 1: if pre <= abs(pre-k): print(pre) sys.exit() pre = abs(pre - k)
import sys import math n, k = map(int, input().split()) pre=n-n//k*k while 1: if pre <= abs(pre-k): print(pre) sys.exit() pre = abs(pre - k)
[["-", 12, 657, 12, 657, 31, 652, 63, 319, 500, 22], ["-", 12, 657, 12, 657, 31, 652, 63, 319, 0, 131], ["-", 12, 657, 12, 657, 31, 652, 63, 319, 319, 22], ["-", 12, 657, 12, 657, 31, 652, 3, 4, 0, 24], ["-", 12, 657, 31, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 662, 12, 657, 12, 657, 31, 657, 17, 676], ["-", 12, 657, 12, ...
5
64
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const int INF = (int)1e9; int a[1001]; int main() { #ifdef WIN32 // freopen("input.txt", "rt", stdin); #endif int n, k; scanf("%d%d", &n, &k); int m = n % k; printf("%d\n", min({n, m, ab...
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const int INF = (int)1e9; ll a[1001]; int main() { #ifdef WIN32 // freopen("input.txt", "rt", stdin); #endif ll n, k; scanf("%lld%lld", &n, &k); ll m = n % k; printf("%lld\n", min({n, m,...
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 78], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
103
#include <bits/stdc++.h> #include <cmath> using namespace std; int main() { double N, K; cin >> N >> K; double x, y; x = fmod(N, K); y = K - x; cout << min(x, y) << endl; }
#include <bits/stdc++.h> #include <cmath> using namespace std; int main() { long N, K; cin >> N >> K; long x, y; x = N % K; y = K - x; cout << min(x, y) << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 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, 21], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
1
56
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> //strcmp、strncmp関数を使うために必要 int main() { int N, K; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> //strcmp、strncmp関数を使うために必要 int main() { ll N, K; ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78]]
1
94
// Author: AnandRaj uux #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<vi> vvi; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pll> vpll; #...
// Author: AnandRaj uux #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<vi> vvi; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pll> vpll; #...
[["+", 31, 16, 12, 2, 3, 4, 0, 2, 63, 22], ["+", 12, 2, 3, 4, 0, 2, 3, 4, 0, 24], ["+", 12, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
1
344
# C import math def my_round(val, digit=0): p = 10 ** digit return (val * p * 2 + 1) // 2 / p n, k = map(int, input().split()) s = n / k print(min(n%k,k-s))
# C import math def my_round(val, digit=0): p = 10 ** digit return (val * p * 2 + 1) // 2 / p n, k = map(int, input().split()) s = n / k print(min(n%k,k-(n%k)))
[["-", 3, 4, 0, 652, 3, 4, 0, 657, 12, 22], ["+", 0, 652, 3, 4, 0, 657, 12, 23, 0, 24], ["+", 3, 4, 0, 657, 12, 23, 0, 657, 31, 22], ["+", 3, 4, 0, 657, 12, 23, 0, 657, 17, 109], ["+", 3, 4, 0, 657, 12, 23, 0, 657, 12, 22], ["+", 0, 652, 3, 4, 0, 657, 12, 23, 0, 25]]
5
66
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n == 0) cout << 0 << endl; else if (k == 0) cout << n << endl; else if (n >= k) { cout << min(n % k, k - (n % k)) << endl; } else if (n < k) cout << min(n, k - n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; if (n == 0) cout << 0 << endl; else if (k == 0) cout << n << endl; else if (n >= k) { cout << min(n % k, k - (n % k)) << endl; } else if (n < k) cout << min(n, k - n) << endl; return 0; }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
99
#include <algorithm> #include <cctype> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define out(x) cout << x << endl; #define each(e, v) for (auto &&e : v) #define clamp(v, lo, hi) min(max(...
#include <algorithm> #include <cctype> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define out(x) cout << x << endl; #define each(e, v) for (auto &&e : v) #define clamp(v, lo, hi) min(max(...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
192
nums = list(map(int, input().split())) n = nums[0] k = nums[1] x = n % k print(min(n, k - n))
nums = list(map(int, input().split())) n = nums[0] k = nums[1] n = n % k print(min(n, k - n))
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22]]
5
45
#include <algorithm> #include <iostream> using namespace std; int main() { long N, K, a, b; cin >> N >> K; a = N % K; b = N - K; if (b < 0) { b = -b; } cout << min(a, b) << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { long N, K, a, b; cin >> N >> K; a = N % K; b = a - K; if (b < 0) { b = -b; } cout << min(a, b) << endl; return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
1
68
N, K = map(int, input().split()) print(min(N%K, K(N%K)))
N, K = map(int, input().split()) print(min(N%K, K-(N%K)))
[["+", 3, 4, 0, 652, 3, 4, 0, 657, 17, 33]]
5
32
package main import ( "fmt" ) func solution(n, k int) int { t := n % k return min(t, k) } func min(x, y int) int { if x < y { return x } return y } func main() { var n, k int fmt.Scan(&n, &k) fmt.Println(solution(n, k)) }
package main import ( "fmt" ) func solution(n, k int) int { t := n % k return min(t, k-t) } func min(x, y int) int { if x < y { return x } return y } func main() { var n, k int fmt.Scan(&n, &k) fmt.Println(solution(n, k)) }
[["+", 0, 432, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 432, 0, 2, 3, 4, 0, 16, 12, 22]]
7
98
#include <bits/stdc++.h> #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, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; void Main() { ll n, k; cin >> n >> k; ll sho = n % ...
#include <bits/stdc++.h> #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, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; void Main() { ll n, k; cin >> n >> k; ll sho = n % ...
[["-", 3, 4, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 3, 4, 0, 2, 3, 4, 0, 16, 31, 22]]
1
111
import java.util.Scanner; public class Main { public static void main(String[] args) { int n, k; int ans = 0; Scanner scan = new Scanner(System.in); n = scan.nextInt(); k = scan.nextInt(); int a = n % k; if (a == 0) { System.out.println(0); } else { System.out.println(M...
import java.util.Scanner; public class Main { public static void main(String[] args) { long n, k; long ans = 0; Scanner scan = new Scanner(System.in); n = scan.nextLong(); k = scan.nextLong(); long a = n % k; if (a == 0) { System.out.println(0); } else { System.out.prin...
[["-", 0, 195, 8, 196, 0, 503, 39, 506, 0, 507], ["+", 0, 195, 8, 196, 0, 503, 39, 506, 0, 96], ["-", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22]]
3
111
n, k = map(int, input().split()) print(min(n // k, k - n % k))
n, k = map(int, input().split()) print(min(n % k, k - n % k))
[["-", 3, 4, 0, 652, 3, 4, 0, 657, 17, 676], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 17, 109]]
5
31
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll x, y, z, n, m = 0, i, j, k, p, q; cin >> n >> k; p = n % k; cout << min(p, n - p) << endl; return 0; }
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll x, y, z, n, m = 0, i, j, k, p, q; cin >> n >> k; n = n % k; cout << min(n, k - n) << endl; return 0; }
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 22], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 21], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 21], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 31, 16, 12, 2, 3, 4...
1
66
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; cout << (abs(k - (n % k)), n % k) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; cout << min(abs(k - (n % k)), n % k) << endl; }
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22]]
1
50
#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 FOR(i, x, n) for (ll i = x; i < n; i++) #define pb push_back #define pf push_front #define ll long long #define hii cout << "hii" << endl #define pii pair<int...
#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 FOR(i, x, n) for (ll i = x; i < n; i++) #define pb push_back #define pf push_front #define ll long long #define hii cout << "hii" << endl #define pii pair<int...
[["-", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
1
752
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; int n, k; signed main() { cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; return 0; }
[["+", 36, 36, 36, 36, 0, 30, 0, 58, 0, 148], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 141, 22], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40], ["+", 36, 36, 0, 30, 0, 14, 39, 86, 0, 156]]
1
45
n,k = gets.split.map(&:to_i) n %= k puts n puts [n,k-n].min
n,k = gets.split.map(&:to_i) n %= k puts [n,k-n].min
[["-", 36, 36, 0, 493, 0, 652, 3, 4, 0, 22], ["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22]]
4
28
#include <bits/stdc++.h> using namespace std; int main() { int N; int K; int min; cin >> N >> K; min = N % K; if (min > K - min) { min = K - min; } cout << min << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long N; long K; long min; cin >> N >> K; min = N % K; if (min > K - min) { min = K - min; } cout << min << endl; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
55
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, s, ans1, ans2, ans; cin >> N; cin >> K; ans1 = N % K; s = abs(N - K); ans2 = s % K; ans = min(ans1, ans2); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, s, ans1, ans2, ans; cin >> N; cin >> K; ans1 = N % K; s = abs(ans1 - K); ans2 = s % K; ans = min(ans1, ans2); cout << ans; return 0; }
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22]]
1
71
#include <stdio.h> int main() { long long int N, K, S; scanf("%lld %lld", &N, &K); if (N >= K) { N = N % K; } if (N < (double)(K / 2)) { S = N; } else { S = K - N; } printf("%lld", S); return 0; }
#include <stdio.h> int main() { long long int N, K, S; scanf("%lld %lld", &N, &K); if (N >= K) { N = N % K; } if (N < (double)(K / 2) + 1) { S = N; } else { S = K - N; } printf("%lld\n", S); return 0; }
[["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
84
a = [int(a) for a in input().split(' ')] N = a[0] K = a[1] def abs_met(N): if N > abs(N - K): N = abs(N - K) abs_met(N) else: print(N) if K == 1: print(0) else: abs_met(N)
a = [int(a) for a in input().split(' ')] N = a[0] K = a[1] def abs_met(N): N = N % K if N > abs(N - K): N = abs(N - K) abs_met(N) else: print(N) if K == 1: print(0) else: abs_met(N)
[["+", 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, 657, 31, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 109], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 22]]
5
82
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> typedef long long ll; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const...
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> typedef long long ll; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const...
[["-", 0, 57, 64, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 57, 64, 9, 0, 43, 49, 50, 51, 22]]
1
797
#include <iostream> using namespace std; int main() { int n, k, a, b; cin >> n >> k; if (n % k == 0) cout << 0 << endl; else { a = n % k; b = k - a; cout << min(a, b) << endl; } }
#include <iostream> using namespace std; int main() { long long n, k, a, b; cin >> n >> k; if (n % k == 0) cout << 0 << endl; else { a = n % k; b = k - a; cout << min(a, b) << endl; } }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
67
n,k = map(int,input().split()) r = n%k w = r%k print(min(r,w))
n,k = map(int,input().split()) r = n%k w = abs(r-k) print(min(r,w))
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 662, 12, 657, 17, 109], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 17, 33], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
35
NK = input("").split() N = int(NK[0]) K = int(NK[1]) if N == K or K==1: print(0) elif N > K: A = N % K if A > K-A: print(K-A) #elif A == K: #print(A) else: print(A) else: if N <= N-K: print(N) else: print(K-N)
NK = input("").split() N = int(NK[0]) K = int(NK[1]) if N == K or K==1: print(0) elif N > K: A = N % K if A > K-A: print(K-A) else: print(A) else: if N <= K-N: print(N) else: print(K-N)
[["-", 8, 196, 0, 57, 15, 666, 0, 657, 31, 22], ["-", 8, 196, 0, 57, 15, 666, 0, 657, 17, 33], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 33], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 22]]
5
94
import math first_input = list(map(lambda x:int(x), input().split(" "))) #second_input = list(map(lambda x:int(x), input().split(" "))) N = first_input[0] K = first_input[1] #print(int(N/K)) if N>K: first_min_N = N - K*math.floor(N/K) else: first_min_N = N print(min(first_min_N,abs(first_min_N-K)))
import math first_input = list(map(lambda x:int(x), input().split(" "))) #second_input = list(map(lambda x:int(x), input().split(" "))) N = first_input[0] K = first_input[1] #print(math.floor(N // K)) #print(K*math.floor(N // K)) if N>K: first_min_N = N - K*math.floor(N // K) else: first_min_N = N print(min(...
[["-", 12, 657, 12, 652, 3, 4, 0, 657, 17, 85], ["+", 12, 657, 12, 652, 3, 4, 0, 657, 17, 676]]
5
80