problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
long n, k;
cin >> n >> k;
while (n > abs(n - k)) {
n = abs(n - k);
}
cout << n << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
cout << min(N % K, K - N % K) << endl;
return 0;
}
| replace | 9 | 15 | 9 | 12 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
// sengen
int n, k;
// nyuryoku
cin >> n >> k;
// keisan
if (n % k == abs(n % k - k)) {
cout << n % k;
} else {
cout << min(n % k, abs(n % k - k));
}
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
// sengen
long n, k;
// nyuryoku
cin >> n >> k;
// keisan
if (n % k == abs(n % k - k)) {
cout << n % k;
} else {
cout << min(n % k, abs(n % k - k));
}
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02719 | C++ | Time Limit Exceeded | #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;
int main() {
ll N, K;
cin >> N >> K;
N = N % K;
ll MIN = N;
REP(i, K) {
N = K - N;
MIN = min(N, MIN);
}
cout << MIN << endl;
} | #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;
int main() {
ll N, K;
cin >> N >> K;
N = N % K;
ll MIN = N;
REP(i, 5) {
N = K - N;
MIN = min(N, MIN);
}
cout << MIN << endl;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p02719 | C++ | Time Limit Exceeded | /**
* Created by hiramekun at 20:50 on 2020-04-04.
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll rec(ll n, ll k, ll prev) {
if (n >= prev)
return prev;
return rec(abs(n - k), k, n);
}
ll lcm(ll m, ll n) {
if ((0 == m) || (0 == n))
return 0;
return ((m / gcd(m, n)) * n);
}
void solve() {
ll n, k;
cin >> n >> k;
if (n % k == 0)
cout << 0 << '\n';
else
cout << rec(n, k, ll_inf) << '\n';
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
} | /**
* Created by hiramekun at 20:50 on 2020-04-04.
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll rec(ll n, ll k, ll prev) {
if (n >= prev)
return prev;
return rec(abs(n - k), k, n);
}
ll lcm(ll m, ll n) {
if ((0 == m) || (0 == n))
return 0;
return ((m / gcd(m, n)) * n);
}
void solve() {
ll n, k;
cin >> n >> k;
if (n % k == 0)
cout << 0 << '\n';
else if (n < k)
cout << min(n, abs(n - k)) << '\n';
else {
n %= k;
cout << min(n, abs(n - k)) << '\n';
}
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
} | replace | 73 | 75 | 73 | 79 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
cout << min(n % k, k - n % k);
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
cout << min(n % k, k - n % k);
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
while (n > abs(n - k)) {
n %= k;
}
cout << n << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
n = n % k;
n = min(n, k - n);
cout << n << endl;
} | replace | 6 | 9 | 6 | 10 | TLE | |
p02719 | C++ | Time Limit Exceeded | //...Bismillahir Rahmanir Rahim...
// Code by Asad Bin Saber
// 04 04 2020
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
void task() {
long long n, k, i;
cin >> n >> k;
if (n % k == 0) {
cout << '0' << endl;
return;
} else if (k == 1) {
cout << '0' << endl;
return;
} else if (k == 2 && n % 2 == 1) {
cout << '1' << endl;
} else if (k == 2 && n % 2 == 0) {
cout << '0' << endl;
}
while (1) {
if (n == 0)
break;
else if (n < abs(k - n))
break;
n = abs(n - k);
}
cout << n << endl;
}
int main() {
task();
return 0;
}
| //...Bismillahir Rahmanir Rahim...
// Code by Asad Bin Saber
// 04 04 2020
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
void task() {
long long n, k, i;
cin >> n >> k;
n = n % k;
while (1) {
if (n == 0)
break;
else if (n < abs(k - n))
break;
n = abs(n - k);
}
cout << n << endl;
}
int main() {
task();
return 0;
}
| replace | 18 | 29 | 18 | 20 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <vector>
typedef long long int ll;
using namespace std;
int main() {
ll N, M, a, b;
cin >> N >> M;
if (M == 1) {
cout << 0 << endl;
return 0;
}
while (1) {
a = abs(N - M);
if (N < a) {
cout << N << endl;
return 0;
} else {
N = a;
}
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <vector>
typedef long long int ll;
using namespace std;
int main() {
ll N, M, a, b;
cin >> N >> M;
a = N % M;
cout << min(a, abs(a - M)) << endl;
return 0;
} | replace | 16 | 29 | 16 | 18 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N, K;
cin >> N >> K;
if (K == 0) {
cout << N << endl;
} else if (K == 1) {
cout << 0 << endl;
} else {
ll ab = abs(N - K);
while (ab < N) {
N = ab;
ab = abs(N - K);
}
cout << N << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N, K;
cin >> N >> K;
if (K == 0) {
cout << N << endl;
} else if (K == 1) {
cout << 0 << endl;
} else if (N % K == 0) {
cout << 0 << endl;
} else if (N > K) {
ll a = N % K;
if (abs(a - K) < abs(a)) {
cout << abs(a - K) << endl;
} else {
cout << abs(a);
}
} else {
ll ab = abs(N - K);
while (ab < N) {
N = ab;
ab = abs(N - K);
}
cout << N << endl;
}
} | insert | 11 | 11 | 11 | 20 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
cout << min(n % k, 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, k - (n % k));
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02719 | C++ | Runtime Error | #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>
using namespace std;
long long n, k;
int main() {
cin >> n >> k;
cout << min(n % k, k - n % k) << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02719 | C++ | Runtime Error | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int x, k, min;
cin >> x >> k;
int a = x % k;
min = fabs(a - k);
if (min > a)
min = a;
cout << min;
}
| #include <cmath>
#include <iostream>
using namespace std;
int main() {
unsigned long int x, k, min, a;
cin >> x;
cin >> k;
a = x % k;
min = k - a;
if (min > a)
min = a;
cout << min;
}
| replace | 5 | 9 | 5 | 10 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll a = 0, b = 0, n, k;
cin >> n >> k;
if (n > k && n % k == 0) {
cout << 0;
return 0;
} else {
while (b <= a) {
a = n;
n = abs(n - k);
b = n;
}
cout << a;
return 0;
}
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll a = 0, b = 0, n, k;
cin >> n >> k;
if (n > k && n % k == 0) {
cout << 0;
return 0;
} else if (n > k && n % k != 0) {
ll t;
t = n % k;
cout << k - t;
return 0;
} else {
while (b <= a) {
a = n;
n = abs(n - k);
b = n;
}
cout << a;
return 0;
}
}
| insert | 8 | 8 | 8 | 13 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int X;
X = N % K;
X = K % X;
cout << X << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
cout << min(n % k, k - n % k);
}
| replace | 4 | 11 | 4 | 7 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long n, k;
int main(void) {
long long ans, t;
scanf("%lld%lld", &n, &k);
if (n % k == 0) {
cout << "0";
return 0;
}
ans = min(n, k);
t = n / k;
t++;
for (int i = 0; i < t; i++) {
n = abs(n - k);
ans = min(ans, n);
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
long long n, k;
int main(void) {
long long ans, t;
scanf("%lld%lld", &n, &k);
if (n % k == 0) {
cout << "0";
return 0;
}
if (n > k)
n %= k;
n = min(n, abs(n - k));
cout << n;
return 0;
} | replace | 11 | 19 | 11 | 16 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ll n, k;
cin >> n >> k;
ll rem = n % k;
cout << min(rem, abs(rem - k));
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
ll rem = n % k;
cout << min(rem, abs(rem - k));
} | delete | 9 | 16 | 9 | 9 | 0 | |
p02719 | C++ | Runtime Error | #include <iostream>
#include <stdlib.h>
using namespace std;
int N, K, mod, n, a, b;
int main() {
cin >> N >> K;
mod = N % K;
n = (N - mod) / K;
a = abs(N - n * K);
b = abs(N - (n + 1) * K);
if (a < b) {
cout << a;
} else {
cout << b;
}
} | #include <iostream>
#include <stdlib.h>
using namespace std;
long long int N, K, mod, n, a, b;
int main() {
cin >> N >> K;
mod = N % K;
n = (N - mod) / K;
a = abs(N - n * K);
b = abs(N - (n + 1) * K);
if (a < b) {
cout << a;
} else {
cout << b;
}
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
using namespace std;
int main() {
long long n, k, sol;
cin >> n >> k;
if (n % k == 0) {
cout << 0 << '\n';
} else {
sol = abs(n - k);
while (true) {
if (abs(sol - k) < sol) {
sol = abs(sol - k);
continue;
}
break;
}
cout << sol << '\n';
}
}
| #include <cmath>
#include <iostream>
using namespace std;
int main() {
long long n, k, sol;
cin >> n >> k;
if (n % k == 0) {
cout << 0 << '\n';
} else {
if (n > k) {
n -= n / k * k;
}
sol = abs(n - k);
while (true) {
if (abs(sol - k) < sol) {
sol = abs(sol - k);
continue;
}
break;
}
cout << sol << '\n';
}
}
| insert | 10 | 10 | 10 | 13 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
while (n > abs(n - k)) {
n = abs(n - k);
}
cout << n << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long a = n % k;
long long ans = min(a, k - a);
cout << ans << endl;
}
| replace | 6 | 10 | 6 | 9 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
while (true) {
N = N - K;
if (N <= 0) {
if (0 - N < N + K) {
cout << 0 - N << endl;
break;
} else {
cout << N + K << endl;
break;
}
}
}
} | #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
while (true) {
N = N % K - K;
if (N <= 0) {
if (0 - N < N + K) {
cout << 0 - N << endl;
break;
} else {
cout << N + K << endl;
break;
}
}
}
} | replace | 10 | 11 | 10 | 11 | TLE | |
p02719 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ill long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
int main() {
ill n, k;
cin >> n >> k;
if (k != 1) {
cout << n % min(n - k, k);
} else {
cout << 0;
}
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ill long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
int main() {
ill n, k;
cin >> n >> k;
ill m = n % k;
cout << min(m, k - m);
} | replace | 12 | 17 | 12 | 14 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fo(i, n) for (i = 0; i < n; i++)
#define fok(i, k, n) for (i = k; i < n; i++)
#define ci(x) cin >> x;
#define ci2(x, y) cin >> x >> y;
#define co(x) cout << x << "\n";
#define co2(x, y) cout << x << " " << y << "\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int mod = 1000000007;
int main() {
ll n, k;
ci2(n, k);
if (abs(n - k) > n) {
co(n);
} else {
ll x = n % abs(n - k);
x = min(x, k - x);
co(x);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fo(i, n) for (i = 0; i < n; i++)
#define fok(i, k, n) for (i = k; i < n; i++)
#define ci(x) cin >> x;
#define ci2(x, y) cin >> x >> y;
#define co(x) cout << x << "\n";
#define co2(x, y) cout << x << " " << y << "\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int mod = 1000000007;
int main() {
ll n, k;
ci2(n, k);
cout << min(n % k, abs(n % k - k)) << "\n";
return 0;
}
| replace | 27 | 34 | 27 | 28 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define LL long long
#define inf INT_MAX / 3
#define mod 1000000007ll
#define PI acos(-1.0)
#define linf (1ll << 60) - 1
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define REP(I, N) FOR(I, 0, N)
#define For(I, N) for (int I = 1; I <= (N); I++)
#define ALL(A) ((A).begin(), (A).end())
#define set0(ar) memset(ar, 0, sizeof ar)
#define vsort(v) sort(v.begin(), v.end())
#define setinf(ar) memset(ar, 126, sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A, B) (*max_element(A, B))
#define MINEL(A, B) (*min_element(A, B))
#define ROPEN(X) freopen(X, "r", stdin)
#define WOPEN(X) freopen(X, "w", stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int, int>
// cout << fixed << setprecision(20) << p << endl;
template <class T> inline T bigmod(T p, T e, T M) {
LL ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T modinverse(T a, T M) { return bigmod(a, M - 2, M); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
n %= m;
cout << min(n, m - n) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define LL long long
#define inf INT_MAX / 3
#define mod 1000000007ll
#define PI acos(-1.0)
#define linf (1ll << 60) - 1
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define REP(I, N) FOR(I, 0, N)
#define For(I, N) for (int I = 1; I <= (N); I++)
#define ALL(A) ((A).begin(), (A).end())
#define set0(ar) memset(ar, 0, sizeof ar)
#define vsort(v) sort(v.begin(), v.end())
#define setinf(ar) memset(ar, 126, sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A, B) (*max_element(A, B))
#define MINEL(A, B) (*min_element(A, B))
#define ROPEN(X) freopen(X, "r", stdin)
#define WOPEN(X) freopen(X, "w", stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int, int>
// cout << fixed << setprecision(20) << p << endl;
template <class T> inline T bigmod(T p, T e, T M) {
LL ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T modinverse(T a, T M) { return bigmod(a, M - 2, M); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
LL n, m;
cin >> n >> m;
n %= m;
cout << min(n, m - n) << endl;
return 0;
}
| replace | 53 | 54 | 53 | 54 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
ll N, K;
cin >> N >> K;
if (N % K == 0) {
cout << 0 << endl;
return 0;
}
ll pre = INF;
while (N < pre) {
pre = N;
N = abs(N - K);
}
cout << pre << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
ll N, K;
cin >> N >> K;
if (N % K == 0) {
cout << 0 << endl;
return 0;
}
if (N > K)
N = N % K;
ll pre = abs(N - K);
cout << min(N, pre);
return 0;
}
| replace | 16 | 22 | 16 | 20 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define um unordered_map
#define F first
#define S second
#define MOD 1000000007
#define TC \
int t; \
cin >> t; \
while (t--)
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define count_bits(val) __builtin_popcount(val)
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
cout << min(n % k, (k - (n % k))) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define um unordered_map
#define F first
#define S second
#define MOD 1000000007
#define TC \
int t; \
cin >> t; \
while (t--)
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define count_bits(val) __builtin_popcount(val)
signed main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt" , "r" , stdin);
// freopen("output.txt" , "w" , stdout);
// #endif
int n, k;
cin >> n >> k;
cout << min(n % k, (k - (n % k))) << endl;
return 0;
} | replace | 23 | 27 | 23 | 27 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
if (N == 0) {
cout << 0 << endl;
return 0;
}
if (N % K < K - N % K)
cout << N % K << endl;
else
cout << K - N % K << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
if (N == 0) {
cout << 0 << endl;
return 0;
}
if (N % K < K - N % K)
cout << N % K << endl;
else
cout << K - N % K << endl;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
const int MOD = 1e9 + 7;
const int N = 1e5;
const int INF = 1e9 + 5;
int main(void) {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ll n, k;
cin >> n >> k;
if (n >= k)
n %= k;
ll mini = n;
while (true) {
ll tmp = abs(n - k);
if (tmp >= mini)
break;
mini = tmp;
}
cout << mini << '\n';
return false;
}
| #include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
const int MOD = 1e9 + 7;
const int N = 1e5;
const int INF = 1e9 + 5;
int main(void) {
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
#endif
ll n, k;
cin >> n >> k;
if (n >= k)
n %= k;
ll mini = n;
while (true) {
ll tmp = abs(n - k);
if (tmp >= mini)
break;
mini = tmp;
}
cout << mini << '\n';
return false;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
void solve() {
ll n, k;
cin >> n >> k;
if (k % n != 0) {
ll q = (n + k - 1) / k;
n = abs(n - k * q);
}
cout << n;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
void solve() {
ll n, k;
cin >> n >> k;
n %= k;
cout << min(n, k - n);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| replace | 11 | 16 | 11 | 13 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
int main() {
ll n, k;
cin >> n >> k;
if (k == 1) {
cout << "0" << endl;
return 0;
}
while (1) {
if (n - k > 0) {
n -= k;
} else {
break;
}
}
if (n > abs(n - k)) {
cout << abs(n - k) << endl;
} else {
cout << n << endl;
}
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
int main() {
ll n, k;
cin >> n >> k;
if (n > k * 2) {
n = n % k;
}
while (1) {
if (n - k > 0) {
n -= k;
} else {
break;
}
}
if (n > abs(n - k)) {
cout << abs(n - k) << endl;
} else {
cout << n << endl;
}
return 0;
} | replace | 14 | 17 | 14 | 16 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
while (abs(n - k) < n)
n = abs(n - k);
cout << n;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
n = n - k * (n / k);
while (abs(n - k) < n)
n = abs(n - k);
cout << n;
return 0;
} | insert | 13 | 13 | 13 | 14 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
ll a = n % k;
ll x = min(a, k - a);
cout << x << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, k;
cin >> n >> k;
ll a = n % k;
ll x = min(a, k - a);
cout << x << endl;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;
const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
ll n, m, t, a[mxN];
vi v;
void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
int main() {
fast();
cin >> n >> m;
bool ok = true;
if (n % m == 0)
cout << 0, ok = false;
if (ok) {
if (abs(n - m) > n)
cout << n;
else {
while (abs(n - m) < n) {
n = abs(n - m);
}
cout << n;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;
const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
ll n, m, t, a[mxN];
vi v;
void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
int main() {
fast();
cin >> n >> m;
bool ok = true;
if (n % m == 0)
cout << 0, ok = false;
if (ok) {
if (abs(n - m) > n)
cout << n;
else {
cout << abs((n % m) - m);
}
}
return 0;
}
| replace | 45 | 49 | 45 | 46 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define IN(type, a) \
type a; \
cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n) \
cout << fixed << setprecision(n) << (x) << endl // 小数をn桁で出力
int main() {
IN(int, n);
IN(int, k);
n %= k;
COUT(min(n, abs(k - n)));
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define IN(type, a) \
type a; \
cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n) \
cout << fixed << setprecision(n) << (x) << endl // 小数をn桁で出力
int main() {
IN(ll, n);
IN(ll, k);
n %= k;
COUT(min(n, abs(k - n)));
}
| replace | 27 | 29 | 27 | 29 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (n % m == 0) {
cout << 0 << endl;
return 0;
}
long long fff = n % m;
long long ans = n;
for (int i = 0; i < n % m; i++) {
fff = fff - m;
if (fff < 0)
fff = fff * -1;
ans = min(ans, fff);
}
cout << ans << endl;
}
| #include <iostream>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long k = n % m;
long long j = m - k;
if (k < 0)
k = k * -1;
if (j < 0)
j = j + -1;
cout << min(k, j) << endl;
}
| replace | 6 | 19 | 6 | 13 | TLE | |
p02719 | C++ | Runtime Error | #include <cmath>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int N, K;
cin >> N >> K;
if (N % K == 0) {
cout << 0 << endl;
} else {
cout << min(N % K, K - N % K) << endl;
}
return 0;
} | #include <cmath>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
long long N, K;
cin >> N >> K;
if (N % K == 0) {
cout << 0 << endl;
} else {
cout << min(N % K, K - N % K) << endl;
}
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int abs(int a, int b) {
if (a < b) {
return b - a;
} else {
return a - b;
}
}
int main() {
long long n, k;
cin >> n >> k;
set<int> S;
long long f;
if (k == 1) {
cout << 0 << endl;
return 0;
}
while (k < n) {
n = n - k;
}
long long mini = min(n, k - n);
cout << mini << endl;
} | #include <bits/stdc++.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int abs(int a, int b) {
if (a < b) {
return b - a;
} else {
return a - b;
}
}
int main() {
long long n, k;
cin >> n >> k;
set<int> S;
long long f;
if (k == 1) {
cout << 0 << endl;
return 0;
}
n %= k;
long long mini = min(n, k - n);
cout << mini << endl;
} | replace | 23 | 26 | 23 | 24 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
ll n, k;
cin >> n >> k;
set<ll> S;
if (n % k == 0)
cout << 0 << "\n";
else {
int mi = n;
while (1) {
n = min(n, abs(n - k));
if (S.count(n)) {
cout << n << "\n";
break;
}
S.insert(n);
}
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
ll n, k;
cin >> n >> k;
set<ll> S;
if (n > k) {
if (n % k == 0) {
cout << 0 << "\n";
return 0;
}
n = n % k;
cout << k - n << "\n";
} else {
while (1) {
n = min(n, abs(n - k));
if (S.count(n)) {
cout << n << "\n";
break;
}
S.insert(n);
}
}
return 0;
} | replace | 12 | 16 | 12 | 21 | TLE | |
p02719 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
long long int n, k;
cin >> n >> k;
n = n % k;
if (abs(n - k) >= n) {
cout << n << endl;
} else {
cout << abs(n - k) << endl;
}
} | #include <algorithm>
#include <array>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
n = n % k;
if (abs(n - k) >= n) {
cout << n << endl;
} else {
cout << abs(n - k) << endl;
}
} | delete | 12 | 16 | 12 | 12 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (n == m || n % m == 0) {
cout << '0';
} else {
n = n % m;
vector<long long> v;
for (long long i = 0; i < n; i++) {
n = abs(n - m);
v.push_back(n);
}
sort(v.begin(), v.end());
cout << v[0];
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (n == m || n % m == 0) {
cout << '0';
} else {
n = n % m;
vector<long long> v;
for (long long i = 0; i < 2; i++) {
n = abs(n - m);
v.push_back(n);
}
sort(v.begin(), v.end());
cout << v[0];
}
return 0;
} | replace | 10 | 11 | 10 | 11 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
long long a, b;
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;
}
| replace | 4 | 6 | 4 | 5 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, N_2, K;
cin >> N >> K;
if (N % K == 0) {
cout << 0 << endl;
return 0;
}
while (true) {
N_2 = abs(N - K);
if (N < N_2) {
cout << N << endl;
break;
} else {
N = N_2;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, N_2, K;
cin >> N >> K;
N_2 = N % K;
long long K_2 = K - N_2;
cout << min(N_2, K_2) << endl;
} | replace | 6 | 19 | 6 | 9 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意!
#define mod 1000000007
#define rep(i, n) \
for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意!
int main() {
ll N, K;
cin >> N >> K;
ll d = abs(N - K);
while (d <= N) {
N = d;
d = abs(N - K);
}
cout << N << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意!
#define mod 1000000007
#define rep(i, n) \
for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意!
int main() {
ll N, K;
cin >> N >> K;
cout << min(N % K, K - N % K) << endl;
}
| replace | 12 | 18 | 12 | 13 | TLE | |
p02719 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, m, x, y, z, q;
cin >> n >> m;
if (n == m || n % m == 0)
cout << n % m;
else if (n > m) {
while (n > m)
n -= m;
x = abs(n - m), y = abs(x - m), z = abs(y - m);
cout << min(min(x, y), z);
} else {
x = abs(n - m), y = abs(x - m), z = abs(y - m);
cout << min(min(x, y), z);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, m, x, y, z, q;
cin >> n >> m;
if (n == m || n % m == 0)
cout << n % m;
else if (n > m) {
n %= m;
x = abs(n - m), y = abs(x - m), z = abs(y - m);
cout << min(min(x, y), z);
} else {
x = abs(n - m), y = abs(x - m), z = abs(y - m);
cout << min(min(x, y), z);
}
return 0;
} | replace | 11 | 13 | 11 | 12 | TLE | |
p02719 | C++ | Runtime Error | #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;
if (n % k == 0)
cout << 0;
else if (abs(n % k - k) <= abs(n % k))
cout << abs(n % k - k);
else
cout << (abs(n % k));
}
| #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long int n, k;
cin >> n >> k;
if (n % k == 0)
cout << 0;
else if (abs(n % k - k) <= abs(n % k))
cout << abs(n % k - k);
else
cout << (abs(n % k));
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
long long n, k;
cin >> n >> k;
long long min = n;
long long tmp = 0;
while (true) {
tmp = abs(min - k);
if (min > tmp)
min = tmp;
else
break;
}
cout << min << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
long long n, k;
cin >> n >> k;
long long min = n % k;
long long tmp = 0;
while (true) {
tmp = abs(min - k);
if (min > tmp)
min = tmp;
else
break;
}
cout << min << endl;
}
| replace | 9 | 10 | 9 | 10 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll m, n;
cin >> n >> m;
ll t = n;
// cout << n%m;
n = n % m;
m = m % t;
set<ll> st;
while (max(n, m)) {
if (st.find(n) != st.end())
break;
st.insert(n);
n = abs(n - m);
}
ll min = 1000000000000000000;
for (auto it : st)
if (it < min)
min = it;
cout << min;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll m, n;
cin >> n >> m;
ll a = n / m;
ll b = a + 1;
cout << min(abs(n - (a * m)), abs(n - (b * m)));
} | replace | 7 | 23 | 7 | 10 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
if (N % K == 0)
N = 0;
while (N > abs(N - K)) {
N = abs(N - K);
}
cout << N << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
N %= K;
while (N > abs(N - K)) {
N = abs(N - K);
}
cout << N << endl;
} | replace | 6 | 8 | 6 | 7 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
n -= (n / k) * k;
cout << min(n, k - n) << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
n -= (n / k) * k;
cout << min(n, k - n) << '\n';
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int main() {
long long int N;
long long int K;
cin >> N >> K;
long long int res = 1000000000000000001;
while (N < res) {
res = N;
N = labs(N - K);
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int main() {
long long int N;
long long int K;
cin >> N >> K;
long long int res = 1000000000000000001;
if (N > K)
N = N % K + K;
while (N < res) {
res = N;
N = labs(N - K);
}
cout << res << endl;
} | insert | 10 | 10 | 10 | 12 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;
int main() {
ll N, K;
cin >> N >> K;
ll x = min(K, abs(N - K));
ll y = max(K, abs(N - K));
cout << y % x << endl;
}
| #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;
int main() {
ll N, K;
cin >> N >> K;
ll x = N % K;
ll y = K - x;
cout << min(x, y) << endl;
}
| replace | 10 | 13 | 10 | 13 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
long long n, k, m, temp;
int cnt = 3;
cin >> n >> k;
m = n;
if (m > 0) {
while (1) {
temp = n - k;
if (temp < 0) {
--cnt;
if (cnt < 0) {
break;
}
m = min(m, abs(temp));
}
}
}
cout << m << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
long long n, k, m, temp;
int cnt = 3;
cin >> n >> k;
m = n;
if (m > 0) {
if (n > k) {
n = n % k;
m = min(m, n);
}
for (int i = 0; i < 2; ++i) {
n = abs(n - k);
m = min(m, n);
}
}
cout << m << endl;
return 0;
}
| replace | 12 | 21 | 12 | 19 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K, n, k, ans;
cin >> N >> K;
n = N % K;
k = K - n;
ans = min(n, k);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, K, n, k, ans;
cin >> N >> K;
n = N % K;
k = K - n;
ans = min(n, k);
cout << ans << endl;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main(void) {
long n, k;
long b, a, temp = 0;
cin >> n >> k;
b = n;
while (1) {
a = b - k;
// cout<<a<< " " << b << endl;
if (a < 0) {
break;
}
b = a;
}
// cout << a << " "<< b<<endl;
a = a * -1;
temp = min(a, b);
cout << temp << "\n";
return 0;
} | #include <iostream>
using namespace std;
int main(void) {
long n, k;
long b, a, temp = 0;
cin >> n >> k;
temp = n / k;
b = n - k * temp;
a = b - k;
// cout << a << " "<< b<<endl;
a = a * -1;
temp = min(a, b);
cout << temp << "\n";
return 0;
} | replace | 7 | 16 | 7 | 10 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
// 素数判定
bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
int main() {
ll n, k;
cin >> n >> k;
if (k == 1) {
cout << "0" << endl;
return 0;
}
ll ans = n;
bool flag = false; // 処理終了フラグ
for (;;) {
ll tmp = abs(ans - k);
if (ans < tmp)
break;
ans = tmp;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
// 素数判定
bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
int main() {
ll n, k;
cin >> n >> k;
n = n % k;
ll ans = n;
bool flag = false; // 処理終了フラグ
for (;;) {
ll tmp = abs(ans - k);
if (ans < tmp)
break;
ans = tmp;
}
cout << ans << endl;
} | replace | 27 | 32 | 27 | 28 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long m, n, y, x;
int main() {
scanf("%lld%lld", &m, &n);
x %= y;
printf("%lld", min(y - x, x));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long m, n, y, x;
int main() {
scanf("%lld%lld", &x, &y);
if (y == 0)
printf("%lld", x);
else {
x %= y;
printf("%lld", min(y - x, x));
}
return 0;
} | replace | 6 | 9 | 6 | 15 | -8 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
}
int main() {
ll n, k;
cin >> n >> k;
ll min = n;
ll diff = abs(n - k);
if (diff > min) {
cout << min << endl;
} else {
min = diff;
bool flag = true;
while (flag) {
diff = abs(diff - k);
if (diff > min) {
cout << min << endl;
break;
} else {
min = diff;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
void printVec(std::vector<int> &vec) {
std::cout << "";
for (auto it = vec.begin(); it != vec.end(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
}
int main() {
ll n, k;
cin >> n >> k;
ll min = n;
ll diff = abs(n - k);
if (diff > min) {
cout << min << endl;
} else {
min = diff;
bool flag = true;
ll div = n / k;
// cout << "diff = " << diff << endl;
// cout << "div = " << div << endl;
diff = abs(n - (div * k));
if (diff > abs(diff - k)) {
cout << abs(diff - k) << endl;
} else {
cout << diff << endl;
}
}
return 0;
}
| replace | 24 | 32 | 24 | 32 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
int n, k, x, y;
cin >> n >> k;
if (n >= k) {
x = n % k;
y = min(x, k - x);
} else {
x = k - n;
y = min(x, n);
}
cout << y << 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;
int main() {
ll n, k, x, y;
cin >> n >> k;
if (n >= k) {
x = n % k;
y = min(x, k - x);
} else {
x = k - n;
y = min(x, n);
}
cout << y << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a, b;
cin >> n >> k;
a = n % k;
b = k - a;
if (b < a) {
cout << b;
} else {
cout << a;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, a, b;
cin >> n >> k;
a = n % k;
b = k - a;
if (b < a) {
cout << b;
} else {
cout << a;
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long
int main() {
fastio;
ll n, k;
cin >> n >> k;
if (n % k == 0)
cout << 0;
else {
set<int> s;
s.insert(abs(n - k));
n = abs(n - k);
while (1) {
n = abs(n - k);
if (s.find(n) != s.end()) {
cout << min(n, abs(n - k));
break;
} else
s.insert(n);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long
int main() {
fastio;
ll n, k;
cin >> n >> k;
cout << min(n % k, abs(n % k - k));
return 0;
} | replace | 13 | 28 | 13 | 15 | TLE | |
p02719 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define endl '\n'
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, k;
cin >> n >> k;
cout << n % (abs(n - k)) << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define endl '\n'
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, k;
cin >> n >> k;
cout << min(n % k, k - (n % k)) << endl;
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02719 | C++ | Time Limit Exceeded | /******************************************
* Author : sinon.su96@gmail.com
* Or : ahafid96@gmail.com
* Username : SINON
* Date : April 2020
* Civil and Structural engineering student
* at Ecole des Ponts ParisTech
* ***************************************/
// Import usefull library :
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// usefull abreviation
#define fi first
#define se second
#define pb push_back
#define sqr(x) (x) * (x)
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
int main() {
long long n, k;
long long x;
cin >> n >> k;
x = n;
while (abs(x - k) < x) {
x = abs(x - k);
}
cout << x << "\n";
return 0;
}
| /******************************************
* Author : sinon.su96@gmail.com
* Or : ahafid96@gmail.com
* Username : SINON
* Date : April 2020
* Civil and Structural engineering student
* at Ecole des Ponts ParisTech
* ***************************************/
// Import usefull library :
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// usefull abreviation
#define fi first
#define se second
#define pb push_back
#define sqr(x) (x) * (x)
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
int main() {
long long n, k;
long long x;
cin >> n >> k;
x = n % k;
while (abs(x - k) < x) {
x = abs(x - k);
}
cout << x << "\n";
return 0;
}
| replace | 48 | 49 | 48 | 49 | TLE | |
p02719 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, k;
cin >> n >> k;
long last_n;
do {
last_n = n;
n = abs(n - k);
} while (n < last_n);
cout << last_n << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, k;
cin >> n >> k;
long option1, option2;
option1 = n - n / k * k;
option2 = abs(option1 - k);
if (option1 > option2)
cout << option2 << endl;
else
cout << option1 << endl;
return 0;
}
| replace | 8 | 14 | 8 | 16 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef complex<int> ci;
typedef complex<double> cd;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define ins insert
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR((a), 0, (b))
#define R0F(a, b) ROF((a), (b), -1)
#define FORI(a, b) for (auto(a) = (b).begin(); (a) != (b).end(); ++(a))
#define ROFI(a, b) for (auto(a) = (b).rbegin(); (a) != (b).rend(); ++(a))
#define CEIL(a, b) ((a) + (b)-1) / (b)
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t> bool ckmin(t &a, const t &b) {
return a > b ? a = b, true : false;
}
template <typename t> bool ckmax(t &a, const t &b) {
return a < b ? a = b, true : false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> sols;
sols.pb(n);
if (n > k) {
n -= (n - k) / k * k;
sols.pb(n);
n -= k;
}
assert(n < k);
sols.pb(n);
sols.pb(k - n);
cout << *min_element(ALL(sols)) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef complex<int> ci;
typedef complex<double> cd;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define ins insert
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR((a), 0, (b))
#define R0F(a, b) ROF((a), (b), -1)
#define FORI(a, b) for (auto(a) = (b).begin(); (a) != (b).end(); ++(a))
#define ROFI(a, b) for (auto(a) = (b).rbegin(); (a) != (b).rend(); ++(a))
#define CEIL(a, b) ((a) + (b)-1) / (b)
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t> bool ckmin(t &a, const t &b) {
return a > b ? a = b, true : false;
}
template <typename t> bool ckmax(t &a, const t &b) {
return a < b ? a = b, true : false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> sols;
sols.pb(n);
if (n >= k) {
n -= (n - k) / k * k;
sols.pb(n);
n -= k;
}
assert(n < k);
sols.pb(n);
sols.pb(k - n);
cout << *min_element(ALL(sols)) << endl;
return 0;
}
| replace | 49 | 50 | 49 | 50 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define N 200005
#define mod 1000000007
#define fo(n) for (int i = 1; i <= n; i++)
typedef pair<int, int> pii;
typedef long long int ll;
typedef long int li;
int mod1 = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
n = n % k;
cout << min(n, k - n);
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define N 200005
#define mod 1000000007
#define fo(n) for (int i = 1; i <= n; i++)
typedef pair<int, int> pii;
typedef long long int ll;
typedef long int li;
int mod1 = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
n = n % k;
cout << min(n, k - n);
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
if (N % K == K - (N % K)) {
cout << N % K << endl;
}
if (N % K > K - (N % K)) {
cout << K - (N % K) << endl;
}
if (N % K < K - (N % K)) {
cout << N % K << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
if (N % K == K - (N % K)) {
cout << N % K << endl;
}
if (N % K > K - (N % K)) {
cout << K - (N % K) << endl;
}
if (N % K < K - (N % K)) {
cout << N % K << endl;
}
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
typedef long long ll;
using namespace std;
int main(void) {
ll N, K;
cin >> N >> K;
if (N % K == 0) {
cout << 0 << endl;
return 0;
}
while (true) {
ll N_tmp = abs(N - K);
if (N_tmp > N) {
cout << N << endl;
return 0;
}
N = N_tmp;
}
return 0;
} | #include <cmath>
#include <iostream>
typedef long long ll;
using namespace std;
int main(void) {
ll N, K;
cin >> N >> K;
if (N >= K) {
N = N % K;
}
while (true) {
ll N_tmp = abs(N - K);
if (N_tmp > N) {
cout << N << endl;
return 0;
}
N = N_tmp;
}
return 0;
} | replace | 8 | 11 | 8 | 10 | TLE | |
p02719 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define REP(i, s, n) for (ll i = s; i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int main() {
ll N, K;
cin >> N >> K;
ll ans = N % (abs(N - K));
while (true) {
if (abs(ans - K) < ans) {
ans = abs(ans - K);
} else {
break;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define REP(i, s, n) for (ll i = s; i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int main() {
ll N, K;
cin >> N >> K;
ll ans = N % (K);
while (true) {
if (abs(ans - K) < ans) {
ans = abs(ans - K);
} else {
break;
}
}
cout << ans << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p02719 | Python | Time Limit Exceeded | N, K = map(int, input().split())
while abs(N - K) < N:
N = abs(N - K)
print(N)
| N, K = map(int, input().split())
N %= K
while abs(N - K) < N:
N = abs(N - K)
print(N)
| insert | 1 | 1 | 1 | 3 | TLE | |
p02719 | Python | Runtime Error | import sys
# 未解決(最後だけREになる)
def get():
return list(map(int, input().split()))
a = get()
b = a[0]
c = a[1]
if b < c:
if abs(b - c) < b:
print(abs(b - a))
sys.exit(0)
else:
print(b)
sys.exit(0)
else:
if a[0] % a[1] == a[1] or a[0] % a[1] == 0:
print(0)
sys.exit(0)
else:
if abs((a[0] % a[1]) - a[1]) < abs(((a[0] % a[1]) - a[1]) % a[1]):
if abs(a[0] % a[1]) < abs((a[0] % a[1]) - a[1]):
print(abs(a[0] % a[1]))
sys.exit(0)
else:
print(abs((a[0] % a[1]) - a[1]))
sys.exit(0)
else:
if abs(a[0] % a[1]) < abs(((a[0] % a[1]) - a[1]) % a[1]):
print(abs(a[0] % a[1]))
sys.exit(0)
else:
print(abs(((a[0] % a[1]) - a[1]) % a[1]))
sys.exit(0)
| import sys
# 未解決(最後だけREになる)
def get():
return list(map(int, input().split()))
a = get()
b = a[0]
c = a[1]
if b < c:
if abs(b - c) < b:
print(abs(b - c))
sys.exit(0)
else:
print(b)
sys.exit(0)
else:
if a[0] % a[1] == a[1] or a[0] % a[1] == 0:
print(0)
sys.exit(0)
else:
if abs((a[0] % a[1]) - a[1]) < abs(((a[0] % a[1]) - a[1]) % a[1]):
if abs(a[0] % a[1]) < abs((a[0] % a[1]) - a[1]):
print(abs(a[0] % a[1]))
sys.exit(0)
else:
print(abs((a[0] % a[1]) - a[1]))
sys.exit(0)
else:
if abs(a[0] % a[1]) < abs(((a[0] % a[1]) - a[1]) % a[1]):
print(abs(a[0] % a[1]))
sys.exit(0)
else:
print(abs(((a[0] % a[1]) - a[1]) % a[1]))
sys.exit(0)
| replace | 14 | 15 | 14 | 15 | 0 | |
p02719 | Python | Time Limit Exceeded | n, k = map(int, input().split())
r = []
if n % k == 0:
print(0)
exit()
while True:
n = abs(n - k)
r.append(n)
if r.count(n) >= 2:
break
print(min(r))
| n, k = map(int, input().split())
r = []
n = n % k
if n == 0:
print(0)
exit()
while True:
n = abs(n - k)
r.append(n)
if r.count(n) >= 2:
break
print(min(r))
| replace | 3 | 4 | 3 | 5 | TLE | |
p02719 | Python | Runtime Error | 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))))
| replace | 2 | 3 | 2 | 3 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02719/Python/s891781735.py", line 3, in <module>
print(min(n % k), (k - (n % k)))
TypeError: 'int' object is not iterable
|
p02719 | Python | Time Limit Exceeded | def resolve():
N, K = list(map(int, input().split()))
if K == 1:
print(0)
return
if N % K == 0:
print(0)
return
x = N
memo = [N]
while True:
x = min(abs(x - K), x)
if x in memo:
print(min(memo))
return
memo.append(x)
return
resolve()
| def resolve():
N, K = list(map(int, input().split()))
print(min(N % K, K - (N % K)))
return
resolve()
| replace | 2 | 16 | 2 | 3 | TLE | |
p02719 | Python | Time Limit Exceeded | list_input = [int(n) for n in input().split()]
N = list_input[0]
K = list_input[1]
while N > abs(N - K):
N = abs(N - K)
print(N)
| list_input = [int(n) for n in input().split()]
N = list_input[0]
K = list_input[1]
while N > abs(N - K):
if N >= K:
N = N % K
else:
N = K - N
print(N)
| replace | 6 | 8 | 6 | 10 | TLE | |
p02719 | Python | Time Limit Exceeded | import sys
a = [int(i) for i in input().split()]
N = a[0]
K = a[1]
if K == 1:
print(0)
sys.exit()
def resZ(i, K):
return abs(i - K)
while True:
ab = resZ(N, K)
# print(ab)
if N < ab:
print(N)
# print('end')
sys.exit()
N = ab
# def
| import sys
a = [int(i) for i in input().split()]
N = a[0]
K = a[1]
if K == 1:
print(0)
sys.exit()
def resZ(i, K):
return abs(i - K)
ab = resZ(N, K)
# print(ab)
if N < ab:
print(N)
# print('end')
sys.exit()
N = N % K
while True:
ab = resZ(N, K)
# print(ab)
if N < ab:
print(N)
# print('end')
sys.exit()
N = ab
# def
| insert | 15 | 15 | 15 | 23 | TLE | |
p02719 | Python | Time Limit Exceeded | n, k = list(map(int, input().split()))
n_prev = n
while True:
n = abs(n - k)
if n > n_prev:
print(n_prev)
exit()
else:
n_prev = n
| n, k = list(map(int, input().split()))
print(min(n % k, abs(k - n % k)))
| replace | 2 | 11 | 2 | 3 | TLE | |
p02719 | Python | Time Limit Exceeded | N, K = map(int, input().split())
tmp1 = abs(N - K)
while True:
if K == 1:
print(0)
break
tmp2 = abs(tmp1 - K)
if tmp1 < tmp2:
print(tmp1)
break
else:
tmp1 = tmp2
| N, K = map(int, input().split())
print(min(N % K, K - (N % K)))
| replace | 1 | 14 | 1 | 2 | TLE | |
p02719 | Python | Time Limit Exceeded | N, K = map(int, input().split())
Nj = N
while True:
Ni = Nj
Nj = abs(Ni - K)
if Ni > N:
print(N)
break
elif Nj > Ni:
print(Ni)
break
elif K == 1 or Nj == K:
print(0)
break
else:
continue
| n, k = map(int, input().split())
if n % k == 0:
print(0)
else:
l = [n]
p = n // k
c = n - (p * k)
half = k // 2
while c > half:
c = abs(c - k)
l.append(c)
print(min(l))
| replace | 0 | 16 | 0 | 12 | TLE | |
p02719 | Python | Time Limit Exceeded | #!python3
# input
N, K = list(map(int, input().split()))
def main():
x = N
while True:
y = max(x - K, K - x)
if y < x:
x = y
else:
break
print(x)
if __name__ == "__main__":
main()
| #!python3
# input
N, K = list(map(int, input().split()))
def main():
s = N % K
ans = min(s, K - s)
print(ans)
if __name__ == "__main__":
main()
| replace | 7 | 15 | 7 | 10 | TLE | |
p02719 | Python | Runtime Error | N, K = list(map(int, input().split()))
if N >= K:
print(N % K)
else:
print(K % N)
| N, K = list(map(int, input().split()))
print(min(N % K, K - (N % K)))
| replace | 2 | 6 | 2 | 3 | 0 | |
p02719 | Python | Time Limit Exceeded | import sys
N, K = map(int, input().split())
first = N
list_a = []
if N % K == 0:
print(0)
sys.exit()
else:
while N > 0:
N = N - K
second = N + K
N = abs(N)
list_a.append(N)
list_a.append(second)
list_a.append(first)
list_a = sorted(list_a)
print(list_a[0])
| import sys
N, K = map(int, input().split())
first = N
list_a = []
if N % K == 0:
print(0)
sys.exit()
else:
X = N // K
N = N - (K * (X + 1))
second = N + K
N = abs(N)
list_a.append(N)
list_a.append(second)
list_a.append(first)
list_a = sorted(list_a)
print(list_a[0])
| replace | 10 | 12 | 10 | 12 | TLE | |
p02719 | Python | Time Limit Exceeded | import sys
N, K = map(int, input().split())
if K == 1:
print(0)
sys.exit()
current = N
while True:
prev = current
current = abs(current - K)
next = abs(current - K)
if prev == next:
print(min(current, next))
break
| import sys
N, K = map(int, input().split())
if K == 1:
print(0)
sys.exit()
a = abs(N - K * (N // K + 1))
print(min(a, abs(a - K)))
| replace | 8 | 17 | 8 | 10 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
int main() {
ull n, k;
cin >> n >> k;
if (n % k == 0)
cout << 0 << endl;
else {
while (abs((ll)(n - k)) <= n && n != 0) {
n = abs((ll)(n - k));
}
cout << n << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
int main() {
ull n, k;
cin >> n >> k;
if (n % k == 0)
cout << 0 << endl;
else {
n = n - ((n / k) * k);
while (abs((ll)(n - k)) <= n && n != 0) {
n = abs((ll)(n - k));
}
cout << n << endl;
}
} | insert | 10 | 10 | 10 | 11 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int n, k;
cin >> n >> k;
bool check = 0;
if (n % k == 0) {
check = 1;
cout << "0";
}
if (check == 0) {
set<long long int> s;
s.insert(n);
long long int tmp = n;
bool in = 0;
while (1) {
long long int a = abs(tmp - k);
auto it = s.find(a);
if (it != s.end())
break;
else if (in == 1) {
s.insert(a);
break;
}
if (a < k) {
// cout<<"hi"<<endl;
in = 1;
}
s.insert(a);
tmp = a;
}
long long int min = *min_element(s.begin(), s.end());
cout << min;
}
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int n, k;
cin >> n >> k;
bool check = 0;
if (n % k == 0) {
check = 1;
cout << "0";
}
if (check == 0) {
long long int a = n / k;
long long int tmp = n - a * k;
cout << min(abs(tmp - k), tmp);
}
return 0;
}
| replace | 25 | 48 | 25 | 28 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
long long n, k;
cin >> n >> k;
long long res = n;
while (res > 0) {
long long front = res;
res = min(res, abs(res - k));
if (front == res)
break;
}
cout << res << endl;
} | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
long long n, k;
cin >> n >> k;
long long res = n;
long long a = n / k;
res = n - a * k;
while (res > 0) {
long long front = res;
res = min(res, abs(res - k));
if (front == res)
break;
}
cout << res << endl;
} | insert | 23 | 23 | 23 | 25 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
long long int n, i = 0;
long long int a, b, c = 0, k = 0;
cin >> n >> k;
if (k == 1 || k == n) {
cout << 0 << endl;
return 0;
}
if (n / k > 10000000000) {
while (n >= 1000000000) {
n -= k * 10000000;
}
while (1) {
i++;
a = n - k;
// cout << "a"<<a << endl;
if (a < 0) {
a = a * -2 + a;
// cout <<"a2"<<a<< endl;
}
b = a - k;
// cout <<"b"<< b << endl;
if (b < 0) {
b = b * -2 + b;
// cout <<"b2"<< b << endl;
}
if (b < a && n != b) {
n = b;
} else {
if (i == 1 && a < n)
n = a;
cout << k - n << endl;
return 0;
}
}
}
// cout << n << endl;
while (1) {
i++;
a = n - k;
// cout << "a"<<a << endl;
if (a < 0) {
a = a * -2 + a;
// cout <<"a2"<<a<< endl;
}
b = a - k;
// cout <<"b"<< b << endl;
if (b < 0) {
b = b * -2 + b;
// cout <<"b2"<< b << endl;
}
if (b < a && n != b) {
n = b;
} else {
if (i == 1 && a < n)
n = a;
if (n - k)
cout << n << endl;
break;
}
}
return 0;
} | #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
long long int n, i = 0;
long long int a, b, c = 0, k = 0;
cin >> n >> k;
if (k == 1 || k == n) {
cout << 0 << endl;
return 0;
}
if (n / k > 10000000000) {
if (k / 10 > 1) {
while (n >= 1000000000) {
n -= k * 10000000;
}
} else {
n -= k * 100000000000000000;
while (n >= 100000000) {
n -= k * 10000000;
}
}
while (1) {
i++;
a = n - k;
// cout << "a"<<a << endl;
if (a < 0) {
a = a * -2 + a;
// cout <<"a2"<<a<< endl;
}
b = a - k;
// cout <<"b"<< b << endl;
if (b < 0) {
b = b * -2 + b;
// cout <<"b2"<< b << endl;
}
if (b < a && n != b) {
n = b;
} else {
if (i == 1 && a < n)
n = a;
cout << k - n << endl;
return 0;
}
}
}
// cout << n << endl;
while (1) {
i++;
a = n - k;
// cout << "a"<<a << endl;
if (a < 0) {
a = a * -2 + a;
// cout <<"a2"<<a<< endl;
}
b = a - k;
// cout <<"b"<< b << endl;
if (b < 0) {
b = b * -2 + b;
// cout <<"b2"<< b << endl;
}
if (b < a && n != b) {
n = b;
} else {
if (i == 1 && a < n)
n = a;
if (n - k)
cout << n << endl;
break;
}
}
return 0;
} | replace | 19 | 21 | 19 | 28 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
if (k == 1 || n == k) {
cout << 0 << endl;
return 0;
}
long long tmp = abs(n - k);
do {
n = tmp;
tmp = abs(n - k);
} while (n > tmp);
cout << n << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
if (k == 1 || n == k) {
cout << 0 << endl;
return 0;
}
long long tmp = abs(n - k);
if (n % k == 0) {
cout << 0 << endl;
} else {
long long dev = n % k;
if (dev < abs(dev - k)) {
cout << dev << endl;
} else {
cout << abs(dev - k) << endl;
}
}
return 0;
}
| replace | 17 | 23 | 17 | 27 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (int i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a) memset(a, 0, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
ll n, k;
cin >> n >> k;
map<ll, ll> mp;
ll mn = n;
while (mp[n] != 1) {
mp[n] = 1;
n = abs(n - k);
mn = min(mn, n);
}
cout << mn << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (int i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a) memset(a, 0, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
ll n, k;
cin >> n >> k;
ll res = n % k;
if (res > k / 2)
res = k - res;
cout << res << endl;
}
| replace | 17 | 25 | 17 | 21 | TLE | |
p02719 | C++ | Time Limit Exceeded | /// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int maxn = 2e5 + 100;
const ll inf = 1e18;
ll ans(ll a, ll b) {
if (a <= b)
return min(a, abs(a - b));
else
return ans(abs(a - b), b);
}
int main() {
fast;
ll n, k;
cin >> n >> k;
if (k == 1) {
cout << 0 << endl;
} else
cout << ans(n, k) << endl;
return 0;
}
/*
*/
| /// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int maxn = 2e5 + 100;
const ll inf = 1e18;
ll ans(ll a, ll b) {
if (a <= b)
return min(a, abs(a - b));
else
return ans(a % b, b);
}
int main() {
fast;
ll n, k;
cin >> n >> k;
if (k == 1) {
cout << 0 << endl;
} else
cout << ans(n, k) << endl;
return 0;
}
/*
*/
| replace | 18 | 19 | 18 | 19 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int64_t> N;
int64_t K;
cin >> N.at(0) >> K;
int64_t i = 0;
while (true) {
N.at(i + 1) = N.at(i) - K;
if (N.at(i + 1) < 0) {
N.at(i + 1) *= (-1);
if (N.at(i + 1) < N.at(i)) {
cout << N.at(i + 1) << endl;
} else {
cout << N.at(i) << endl;
}
break;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
int64_t m = min(N % K, abs(N % K - K));
cout << m << endl;
}
| replace | 4 | 23 | 4 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
ll mod = 1e9 + 7;
int main() {
fast
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n, k;
cin >> n >> k;
ll ans = n % k;
ans = min(ans, abs(ans - k));
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
ll mod = 1e9 + 7;
int main() {
fast
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
ll n,
k;
cin >> n >> k;
ll ans = n % k;
ans = min(ans, abs(ans - k));
cout << ans;
return 0;
} | replace | 13 | 18 | 13 | 19 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; // 10^9
int main(void) {
int N, K;
cin >> N >> K;
ll a = N % K;
ll b = abs(K - a);
cout << min(a, b) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; // 10^9
int main(void) {
ll N, K;
cin >> N >> K;
ll a = N % K;
ll b = abs(K - a);
cout << min(a, b) << endl;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll n, k;
cin >> n >> k;
ll n1;
if (n - k < 0)
n1 = -(n - k);
else
n1 = (n - k);
int flag = 0;
while (!flag) {
if (n < n1)
flag = 1;
else {
n = n1;
if (n - k < 0)
n1 = -(n - k);
else
n1 = (n - k);
}
}
cout << n;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll n, k;
cin >> n >> k;
ll p = n / k;
ll q = n - (k * p);
n = q;
ll n1;
if (n - k < 0)
n1 = -(n - k);
else
n1 = (n - k);
int flag = 0;
while (!flag) {
if (n < n1)
flag = 1;
else {
n = n1;
if (n - k < 0)
n1 = -(n - k);
else
n1 = (n - k);
}
}
cout << n;
return 0;
} | insert | 6 | 6 | 6 | 9 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <string>
using namespace std;
int main() {
int N, K, W;
cin >> N >> K;
W = N % K;
if (W < K - W) {
cout << W;
} else {
cout << K - W;
}
return 0;
}
| #include <bits/stdc++.h>
#include <string>
using namespace std;
int main() {
long long N, K, W;
cin >> N >> K;
W = N % K;
if (W < K - W) {
cout << W;
} else {
cout << K - W;
}
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b;
c = a % b;
if (c > b / 2) {
cout << b - c << endl;
} else {
cout << c << endl;
}
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
long long int a, b, c;
cin >> a >> b;
c = a % b;
if (c > b / 2) {
cout << b - c << endl;
} else {
cout << c << endl;
}
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02719 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
long long a, b;
long long out;
int main() {
cin >> a >> b;
out = labs(a - b);
while (out > labs(out - b))
out = labs(out - b);
cout << out;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
long long a, b;
long long out;
int main() {
cin >> a >> b;
long long x = 0;
if (a >= b) {
if (a % b)
x = min(a % b, llabs(a % b - b));
else
x = 0;
} else
x = min(a, llabs(a - b));
cout << x << endl;
}
| replace | 8 | 12 | 8 | 17 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
// const ll INF = 1e18L + 5;
// const int INF = 1e9 + 5;
// const double pi = 3.14159265358979323846;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
while (true) {
if (n % k == 0) {
cout << 0 << endl;
return 0;
} else if (abs(n - k) < (n % k)) {
cout << min(n, abs(n - k)) << endl;
return 0;
} else {
n = abs(n - k);
}
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
// const ll INF = 1e18L + 5;
// const int INF = 1e9 + 5;
// const double pi = 3.14159265358979323846;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
while (true) {
if (n % k == 0) {
cout << 0 << endl;
return 0;
} else if (abs(n - k) < (n % k)) {
cout << min(n, abs(n - k)) << endl;
return 0;
} else if ((n % k) < abs(n - k)) {
cout << min(n % k, abs((n % k) - k)) << endl;
return 0;
} else {
n = abs(n - k);
}
}
}
| insert | 29 | 29 | 29 | 32 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
if (n % k == 0) {
cout << 0 << endl;
return 0;
}
while (1) {
if (n < k) {
if (n < abs(n - k)) {
cout << n << endl;
} else {
cout << abs(n - k) << endl;
}
return 0;
}
n = abs(n - k);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
if (n % k == 0) {
cout << 0 << endl;
return 0;
}
while (1) {
if (n < k) {
if (n < abs(n - k)) {
cout << n << endl;
} else {
cout << abs(n - k) << endl;
}
return 0;
}
n = abs(n - (k * (n / k)));
}
return 0;
} | replace | 53 | 54 | 53 | 54 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main() {
ll n, k;
cin >> n >> k;
if (k == 1 || k == 0) {
cout << 0 << endl;
exit(0);
}
while (1) {
ll x = n;
n = abs(n - k);
if (n > x) {
cout << x << endl;
exit(0);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main() {
ll n, k;
cin >> n >> k;
if (n > k) {
n %= k;
}
if (k == 1 || k == 0) {
cout << 0 << endl;
exit(0);
}
while (1) {
ll x = n;
n = abs(n - k);
if (n > x) {
cout << x << endl;
exit(0);
}
}
return 0;
} | insert | 13 | 13 | 13 | 17 | TLE | |
p02719 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
ll n, k;
cin >> n >> k;
ll temp = abs(n - k);
while (temp > 0) {
temp = temp - k;
}
ll ans = min(temp + k, abs(temp));
cout << ans << 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;
int main() {
ll n, k;
cin >> n >> k;
// ll temp = abs(n - k);
// while(temp > 0) {
// temp = temp - k;
// }
ll temp = n % k;
// for(int i = 0; i < n; i++){
// temp = temp - k;
// if(temp < 0)break;
// }
ll ans = min(temp, abs(temp - k));
cout << ans << endl;
return 0;
} | replace | 9 | 14 | 9 | 20 | TLE | |
p02719 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt", "r", stdin);
#define write freopen("vorta.txt", "w", stdout);
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(NULL);
#define PI 2 * acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl
const int MAX = 2e6 + 5, MOD = 1e9 + 7, MAXLG = log2(MAX) + 1;
const ll inf = 1e18 + 5;
int arr[MAX];
int main() {
fastio;
ll n, k;
cin >> n >> k;
cout << min(n % k, k % (abs(n - k))) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt", "r", stdin);
#define write freopen("vorta.txt", "w", stdout);
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(NULL);
#define PI 2 * acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl
const int MAX = 2e6 + 5, MOD = 1e9 + 7, MAXLG = log2(MAX) + 1;
const ll inf = 1e18 + 5;
int arr[MAX];
int main() {
fastio;
ll n, k;
cin >> n >> k;
if (n == k || !n)
cout << 0 << "\n";
else {
if (n > k)
n %= k;
cout << min(n, abs(n - k)) << "\n";
}
}
| replace | 30 | 31 | 30 | 37 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.