alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define MAX 1000003
#define pii pair<ll, ll>
#define VP vector<pii>
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (ll(i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(), (v).end()
#define S(x) scanf("%d", &(x))
#define S2(x, y) scanf("%d%d", &(x), &(y))
#define SL(x) scanf("%lld", &(x))
#define SL2(x) scanf("%lld%lld", &(x), &(y))
#define P(x) printf("%d\\n", (x))
#define FF first
#define SS second
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  ll ans = n;
  n = n % k;
  map<ll, ll> m;
  while (m[n] == 0) {
    ll prev = n;
    n = abs(n - k);
    m[prev]++;
    ans = min(ans, n);
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define MAX 1000003
#define pii pair<ll, ll>
#define VP vector<pii>
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (ll(i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(), (v).end()
#define S(x) scanf("%d", &(x))
#define S2(x, y) scanf("%d%d", &(x), &(y))
#define SL(x) scanf("%lld", &(x))
#define SL2(x) scanf("%lld%lld", &(x), &(y))
#define P(x) printf("%d\\n", (x))
#define FF first
#define SS second
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  ll ans = n;
  map<ll, ll> m;
  while (m[n] == 0) {
    ll prev = n;
    n = abs(n - k);
    m[prev]++;
    ans = min(ans, n);
  }
  cout << ans;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const int mod = 1'000'000'007;

ll factor(ll n, ll k) {
  ll x = abs(n - k);
  if (x > n) {
    return n;
  }
  return factor(x, k);
}

int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll x = n % k;
  ll y = abs(x - k);
  ll z = min(x, y);
  cout << z << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const int mod = 1'000'000'007;

ll factor(ll n, ll k) {
  ll x = abs(n - k);
  if (x > n) {
    return n;
  }
  return factor(x, k);
}

int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = factor(n, k);
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;
  long long ans = min(N % K, K - N % K);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;
  while (N > abs(K - N)) {
    N = abs(N - K);
  }
  cout << N << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long mod(string num, long long a) {
  // Initialize result
  long long res = 0;

  // One by one process all digits of 'num'
  for (long long i = 0; i < num.length(); i++)
    res = (res * 10 + (int)num[i] - '0') % a;

  return res;
}

int main() {
  long long k, diff, last;
  string n;
  cin >> n >> k;
  long long s = mod(n, k);
  if (abs(s - k) < s)
    s = mod(to_string(k), s);
  cout << s;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long n, k, diff, last;
  cin >> n >> k;
  last = n;
  while (true) {
    diff = abs(n - k);
    n = diff;
    if (diff >= last)
      break;
    last = diff;
  }
  cout << last;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  cout << min(n % k, k - n % k) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int a = n % k;
  cout << min(a, abs(k - a)) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ll N, K, a;
  cin >> N >> K;
  a = N % K;
  if (N % K == 0) {
    cout << "0" << endl;
  } else {
    if (K / 2 > N) {
      cout << N << endl;
    } else {
      if (a < K) {
        cout << K - a << endl;
      } else {
        cout << N % K << endl;
      }
    }
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  ll sum = 0;
  ll count = 0;
  vector<ll> v(N);
  for (ll i = 0; i < N; i++) {
    cin >> v[i];
  }
  for (ll i = 0; i < N; i++) {
    sum += v[i];
  }
  for (ll i = 0; i < N; i++) {
    if (floor(sum / 4 / M) < v[i]) {
      count += 1;
    }
  }
  if (count >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <stdlib.h>
int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  if (k == 1) {
    printf("%d\\n", 0);
    return 0;
  }
  long long tmp = 0;
  n = n % k;
  while (1) {
    tmp = n;
    n = llabs(n - k);
    if (tmp <= n) {
      printf("%lld\\n", tmp);
      return 0;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  if (k == 1) {
    printf("%d\\n", 0);
    return 0;
  }
  long long tmp = 0;
  while (1) {
    tmp = n;
    n = llabs(n - k);
    if (tmp <= n) {
      printf("%lld\\n", tmp);
      return 0;
    }
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, K, x, y;
  cin >> N >> K;
  x = N % K;
  y = K - x;
  if (x > y)
    cout << y << endl;
  else
    cout << x << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, x, y;
  cin >> N >> K;
  x = N % K;
  y = K - x;
  if (x > y)
    cout << y << endl;
  else
    cout << x << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x1, x2, n, k, i;
int main() {
  cin >> n >> k;
  n %= k;
  cout << (n > k / 2 ? abs(n - k) : n) << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x, k, i, n;
int main() {
  cin >> n >> k;
  x = n;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  k %= n;
  cout << k << endl;
  while (n >= k) {
    n = abs(n - k);
  }
  cout << (n < x ? n : x) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  long long int n, k;

  cin >> n >> k;
  long long int mn;

  n = n % k;
  mn = min(n, k - n);
  cout << mn;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long long int n, k;

  cin >> n >> k;
  if (k == 1) {
    cout << "0";
  } else if (k == 0) {
    cout << n;
  } else {
    while (abs(n - k) <= n) {
      n = abs(n - k);
    }
    cout << n;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#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;
  else
    cout << k - n % k;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (n % k < k - n % k)
    cout << n % k;
  else
    cout << k - n % k;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll euclidean_gcd(ll a, ll b) {
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll p = 0;
  ll d = n;

  if ((n % k == 0) && (n >= k)) {
    cout << "0";
  } else if (n < k) {
    cout << min(abs(n - k), n);
  } else {
    cout << min(n % k, (abs(n % k - k)));
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll euclidean_gcd(ll a, ll b) {
  if (a < b)
    return euclidean_gcd(b, a);
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll p = 0;
  ll d = n;
  bool f = 0;

  if ((n % k == 0) && (n >= k)) {
    cout << "0";
    return 0;
  }
  /*
  while(!f){
      p = d;
      d = d%k;
      if (d>p) f=1;
    }
    cout<<p;*/
  cout << euclidean_gcd(n, k);
}
Problem p02719 (C++) — buggy submission, verdict: 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;
using P = pair<int, int>;
const int INF = 100000000;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = min(n % k, abs(n % k - k));
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#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>;
const int INF = 100000000;

ll func(ll n, ll k) {
  ll mini = min(n, abs(n - k));
  if (mini == n) {
    return n;
  } else {
    return func(mini, k);
  }
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = func(n, k);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

#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;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#define lp(i, n) for (int i = 0; i < n; i++)
#define pau system("pause")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, k, ans;
  cin >> n >> k;
  ans = min(abs(n % k), abs((n % k) - k));
  cout << ans << endl;
}


Error: 0

Fixed submission:

#define lp(i, n) for (int i = 0; i < n; i++)
#define pau system("pause")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  if (k >= n)
    if (k % n == 0)
      cout << 0 << endl;
    else
      cout << min(k - n, n) << endl;
  else if (k == 1)
    cout << 0 << endl;
  else {
    if ((n % 2 == 0 && k % 2 == 0) || (n % k == 0))
      cout << 0 << endl;
    else
      cout << 1 << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: WA

Fixed submission:

#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;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

#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() {
  int N, K, diff;
  cin >> N >> K;

  if (N == K) {
    cout << 0 << endl;
  } else if (N < K) {
    cout << N << endl;
  } else {
    diff = N % K;
    if (diff > abs(diff - K)) {
      cout << abs(diff - K) << endl;
    } else {
      cout << diff << endl;
    }
  }

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <exception>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
  /*freopen("output.txt", "w", stdout);
  freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
  fast();
  // File();
  ll a, b;
  cin >> a >> b;
  if (a <= b)
    cout << min(a, abs(a - b));
  else {
    if (a % b == 0)
      cout << 0 << endl;
    else {
      a %= b;
      cout << min(a, abs(a - b));
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <exception>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
  /*freopen("output.txt", "w", stdout);
  freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
  fast();
  // File();
  ll a, b;
  cin >> a >> b;
  ll diff = abs(a - b);
  cout << a % min(diff, b) << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  cout << min(n % k, abs((n % k) - k)) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  ll n, k;
  std::cin >> n >> k;

  // 様子見。
  //  ll temp=n;
  //  ll mi=100100100100100101;
  //
  //  ll sa;
  //  rep(i,10){
  //    std::cout << "temp" <<temp<<'\\n';
  //    if(abs(temp-k)==mi)break;
  //    sa =temp-abs(temp-k);
  //    std::cout << "sa" << sa<<'\\n';
  //    if(sa<0)break;
  //    temp=abs(temp-k);
  //    if(mi==-1)mi=n;
  //    else  mi =min(mi,temp);
  //
  //    std::cout << temp <<":"<<sa<<'\\n';
  //  }
  //
  //  std::cout << min(temp,n) << '\\n';

  // それっぽいもの
  //  if(n-k!=0)std::cout << min(n%min(abs(n-k),k),n) << '\\n';
  //  else std::cout << 0 << '\\n';

  // 真面目に考察

  std::cout << min(n - n / k * k, abs(n - n / k * k - k)) << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  ll n, k;
  std::cin >> n >> k;

  //
  // ll temp=n;
  // ll mi=100100100100100101;
  //
  // ll sa;
  // rep(i,10){
  //   std::cout << "temp" <<temp<<'\\n';
  //   if(abs(temp-k)==mi)break;
  //   sa =temp-abs(temp-k);
  //   std::cout << "sa" << sa<<'\\n';
  //   if(sa<0)break;
  //   temp=abs(temp-k);
  //   if(mi==-1)mi=n;
  //   else  mi =min(mi,temp);
  //
  //   std::cout << temp <<":"<<sa<<'\\n';
  // }
  //
  // std::cout << min(temp,n) << '\\n';
  std::cout << n % min(abs(n - k), k) << '\\n';

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;
  cout << min(N % K, K - (N % K)) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int x = N % K;
  int y = K % N;
  if (N > K) {
    cout << min(x, K - x) << endl;
  } else
    cout << min(y, N - y) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n]
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  FIO;
  // c_p_c();
  int n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n]
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  // FIO;
  c_p_c();
  int n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;
  long long t = N / K;
  long long ans = N - t * K;
  long long an = K - ans;
  if (an < ans) {
    ans = an;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int t = N / K;
  int ans = N - t * K;
  int an = K - ans;
  if (an < ans) {
    ans = an;
  }
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;
  if (N % K > abs(N % K - K)) {
    cout << abs(N % K - K) << endl;
  } else {
    cout << N % K << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  cout << abs(N % K) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  cout << min(N % K, K - N % K) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  cout << min(N % K, K - N % K) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;
  int64_t t = N % K;
  if (t < (K - t))
    cout << t << endl;
  else {
    int64_t ans = K - t;
    cout << ans << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int t = N % K;
  if (t < (K - t))
    cout << t << endl;
  else {
    int ans = K - t;
    cout << ans << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}