alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: 0

Fixed submission:

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

int main() {
  long long N, K, tmp;
  cin >> N >> K;
  if (N == 1 || K == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (N > K) {
    tmp = K - (N % K);
  } else {
    tmp = N - (K % N);
  }

  cout << tmp << 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;
  cout << min(n % k, k - n % k);
}


Error: 1

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i, n) for (ll i = 0; i < n; i++)
#define of(i, p, n) for (ll i = n - 1; i >= p; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define mem(x, p) memset(x, p, sizeof(x))
#define trav(it, a) for (auto it = a.begin(); it != a.end(); ++it)
#define kk "\\n"
const ll mod = 1e9 + 7;
int main() {
  IOS ll n, k;
  cin >> n >> k;
  if (n == k || k == 1 || n == 0 || (n % k == 0))
    cout << 0;
  else {
    ll p = abs(n - k);
    if (n < k) {
      if (p < n)
        cout << p;
      else
        cout << n;
    } else {
      ll q = n / k;
      q = n - (q * k);
      ll r = abs(q - k);
      cout << min(r, q);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i, n) for (ll i = 0; i < n; i++)
#define of(i, p, n) for (ll i = n - 1; i >= p; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define mem(x, p) memset(x, p, sizeof(x))
#define trav(it, a) for (auto it = a.begin(); it != a.end(); ++it)
#define kk "\\n"
const ll mod = 1e9 + 7;
int main() {
  IOS ll n, k;
  cin >> n >> k;
  if (n == k || k == 1 || n == 0)
    cout << 0;
  else {
    ll p = abs(n - k);
    while (1) {
      ll q = abs(p - k);
      if (q >= p) {
        cout << p;
        break;
      }
      p = q;
    }
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;

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

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;

int main() {
  int N, K, tmp;
  cin >> N >> K;
  tmp = N % K;
  if (tmp < abs(tmp - K)) {
    cout << tmp << endl;
    return 0;
  } else {
    cout << abs(tmp - K) << 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;
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }
  long long ans = n % k;
  ans = min(abs(ans - k), ans);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long a = n, b = n / k + 1;
  vector<long long> ans;
  ans.push_back(n);
  for (int i = 0; i < b; i++) {
    n = abs(n - k);
    ans.push_back(n);
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: 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;
  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;
}

Error: TLE

Fixed submission:

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  while (1) {
    N = N - K;
    if (N < 0) {
      break;
    }
  }

  int N1 = abs(N);
  int N2 = abs(N1 - K);
  cout << min(N1, N2) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error



#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll N, K;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;

  ll d = N % K;
  ll d_abs = d - K < 0 ? K - d : d - K;
  ll ans = min(d, d_abs);
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  long long int d = n % k;
  long long int d1 = (d - k) < 0 ? k - d : d - k;
  long long int ans = min(d1, d);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long int N, K;
  cin >> N >> K;
  if (K != 0) {
    long long int d = N / K;
    long long int e = (N - d * K);
    long long int f = (d + 1) * K - N;
    if (e <= f) {
      N = e;
      cout << N;
    } else {
      N = f;
      cout << N;
    }

  } else {
    cout << N;
  }
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int d = n / k;
  int e = n - d * k;
  int f = (d + 1) * k - n;
  if (f >= e) {
    n = e;
  } else {
    n = f;
  }
  cout << n;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n % k;
  ll b = k - (n % k);
  ll ans;
  ans = min(a, b);
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main() {
  int n, k;
  cin >> n >> k;
  int a = n % k;
  int b = k - (n % k);
  int ans;
  ans = min(a, b);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  ll N, K;
  cin >> N >> K;
  ll a = min(abs(N - N / K * K), abs(N - N / K * K - K));
  cout << min(a, abs(N - N / K * K + K)) << endl;
}


Error: -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)


Fixed submission:

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

int main() {
  int N;
  int K;
  cin >> N >> K;
  if (N % K == 0) {
    cout << "0" << endl;
    abort();
  }
  vector<int> vec;
  int f;
  if (N - K < 0) {
    f = 0 - N + K;
  } else {
    f = N - K;
  }
  for (int i = 0; i < 100000; i++) {
    if (f - K < 0) {
      f = 0 - f + K;
    } else {
      f = f - K;
    }
    vec.at(i) = f;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int64_t N, K;
  cin >> N >> K;
  int64_t a;

  if (N >= K) {
    a = N % K;
    a = min(a, K - a);
  } else {
    a = min(N, K - N);
  }
  cout << a << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;
  int64_t a;

  if (N >= K) {
    a = N % K;
    a = min(a, K - a);
  } else {
    a = K % N;
    a = min(a, K - a);
  }
  cout << a << endl;

  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  while (n > abs(n - k)) {
    if (n > k) {
      n = n - max(1LL, (n - k) / k) * k;
    } else {
      n = k - n;
    }
  }
  cout << n << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
  } else {
    while (n > abs(n - k)) {
      n = abs(n - k);
    }
    cout << n << 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 rem = n % k;
  long long x = k - rem;
  long long ans = min(rem, x);
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int rem = n % k;
  int ans = min(rem, k - rem);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: 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 {
    n = n - ((n / k) * k);
    while (abs((ll)(n - k)) <= n && n != 0) {
      n = abs((ll)(n - k));
    }
    cout << n << endl;
  }
}

Error: TLE

Fixed submission:

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


Error: 0

Fixed submission:

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

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST                                                                   \\
  int inox, t;                                                                 \\
  cin >> t;                                                                    \\
  for (inox = 1; inox <= t; inox++)
#define rep(i, n) for (i = 0; i < n; i++)
#define repr(i, n) for (i = n - 1; i >= 0; i--)
#define FAST                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
using namespace std;
#define modd 998244353

int main() {

  ll n, m;
  cin >> n >> m;
  cout << min(abs(n % m), abs(m - abs(n % m)));
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST                                                                   \\
  int inox, t;                                                                 \\
  cin >> t;                                                                    \\
  for (inox = 1; inox <= t; inox++)
#define rep(i, n) for (i = 0; i < n; i++)
#define repr(i, n) for (i = n - 1; i >= 0; i--)
#define FAST                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
using namespace std;
#define modd 998244353

int main() {

  int n, m;
  cin >> n >> m;
  cout << abs(n % m);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  unsigned long long N, K;
  cin >> N >> K;
  if (N > K) {
    N = N % K;
  }
  unsigned long long v = N < K - N ? N : K - N;
  cout << v << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  if (N > K) {
    N = N % K;
  }
  int v = N < K - N ? N : K - N;
  cout << v << endl;

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main() {
  ll N, K;
  cin >> N >> K;
  ll m;
  ll M;
  ll ans;

  m = N / K;
  M = m + 1;
  ans = min(N - K * m, K * M - N);

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main() {
  int N, K;
  cin >> N >> K;
  int m;
  int M;
  int ans;

  m = N / K;
  M = m + 1;
  ans = min(N - K * m, K * M - N);

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

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


Error: WA

Fixed submission:

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

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

Error: 0

Fixed submission:

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

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

int main() {
  int64_t N;
  int64_t K;
  cin >> N >> K;

  int64_t min = N % K;
  if (K == 1)
    min = 0;
  else if (min >= K / 2) {
    min = K - min;
  }

  cout << min << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int64_t N;
  int64_t K;
  cin >> N >> K;

  int64_t min = N;

  if (K == 1)
    min = 0;
  else {
    while (true) {
      if (N <= K / 2) {
        min = N;
        break;
      } else {
        if (N >= K)
          N -= K;
        else
          N = K - N;
      }
    }
  }
  cout << min << endl;
}