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

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


Error: WA

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int N, K, a, t;
  cin >> N >> K;
  a = N % K;
  t = abs(a - K);
  cout << min(t, a) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int N, K, ans;
  cin >> N >> K;
  ans = N;
  while (true) {
    ans = N;
    N = abs(N - K);
    if (ans <= N)
      break;
  }

  cout << ans << endl;
  return 0;
}
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 endl "\\n"

int32_t main() {

  unsigned long long n, k, mn;
  cin >> n >> k;

  if (n >= k)
    mn = n % k;

  else
    mn = n;

  mn = min(mn, k - mn);

  cout << mn;
  return 0;
}

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 endl "\\n"

int32_t main() {

  unsigned long long n, k, mn;
  cin >> n >> k;
  if (n >= k && n % k == 0) {
    cout << '0';
    return 0;
  } else if (k > n && k % n == 0) {
    cout << n;
    return 0;
  }
  n = n >= k ? n - k : k - n;
  mn = n;

  while (true) {
    n = n >= k ? n - k : k - n;
    if (n >= mn)
      break;
    else
      mn = n;
  }

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(k, a, b) for (int k = (a); k < (b); k++)
#define FORE(k, a, b) for (int k = (a); k <= (b); k++)
#define REP(k, a) for (int k = 0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main(void) {
  ll n, k;
  cin >> n >> k;
  ll m = n % k;
  ll res = min(m, abs(m - k));

  cout << res << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(k, a, b) for (int k = (a); k < (b); k++)
#define FORE(k, a, b) for (int k = (a); k <= (b); k++)
#define REP(k, a) for (int k = 0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main(void) {
  int n, k;
  cin >> n >> k;
  int m = n % k;
  int res = min(m, abs(m - k));

  cout << res << endl;

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

/*
 * Project: AtCoder Beginners Contest 161 C - Replacing Integer
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/04/04
 * Copyright (c) 2020 toms74209200
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

long n, k;

void solve() {

  long diff = 0;
  diff = n % k;

  while (1) {
    if (diff > n) {
      cout << n << endl;
      return;
    } else {
      n = diff;
    }
    diff = abs(n - k);
  }
}

int main() {

  cin >> n >> k;

  solve();
}


Error: TLE

Fixed submission:

/*
 * Project: AtCoder Beginners Contest 161 C - Replacing Integer
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/04/04
 * Copyright (c) 2020 toms74209200
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

long n, k;

void solve() {

  long diff = 0;

  if (k == 1) {
    cout << 0 << endl;
    return;
  }

  while (1) {
    diff = abs(n - k);
    if (diff > n) {
      cout << n << endl;
      return;
    } else {
      n = diff;
    }
  }
}

int main() {

  cin >> n >> k;

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

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

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

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  ll n, k;
  ll rem = n % k;
  ll p = abs(k - n);
  ll res = min(p, rem);
  cout << res << endl;

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000
#define MAXN 100001

long long N, M;
int A[MAXN];

int main() {
  cin >> N >> M;
  printf("%lld\\n", min(N % M, abs(N % M - M)));
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000
#define MAXN 100001

int N, M;
int A[MAXN];

int main() {
  cin >> N >> M;
  printf("%d\\n", min(N % M, abs(N % M - M)));
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n, k, ans;
  cin >> n >> k;
  if (n == k)
    ans = 0;
  else if (n > k)
    ans = min(n % k, k - n % k);
  else
    ans = min(n, k - n);
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  int n, k, ans;
  cin >> n >> k;
  if (n == k)
    ans = 0;
  else if (n > k)
    ans = min(n % k, k - n % k);
  else
    ans = min(n, k - 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++)
using namespace std;
using ll = long long;

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


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;

int main() {
  ll n, k;
  cin >> n >> k;
  if (k == 1)
    cout << 0 << endl;
  else if (n < k) {
    if (2 * n < k)
      cout << n << endl;
    else
      cout << k - n << endl;
  } else if (n >= k) {
    ll curMin = 1e18;
    for (int i = 1;; i++) {
      ll x = n - k * i;
      curMin = min(curMin, abs(x));
      if (x < 0)
        break;
    }
    cout << curMin << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: 0

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

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i, a, n) for (int i = (a); i < (n); i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define rrepa(i, a, n) for (int i = n; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pi;

int main() {

  ll n, k;
  cin >> n >> k;

  if (k == 1) {
    cout << 0 << "\\n";
    return 0;
  }

  if (n > k)
    n = n - ((ll)(n / k)) * k;

  cout << min(n, k - n) << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i, a, n) for (int i = (a); i < (n); i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define rrepa(i, a, n) for (int i = n; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pi;

int main() {

  ll n, k;
  cin >> n >> k;

  if (k == 1) {
    cout << 0 << "\\n";
    return 0;
  }

  if (k > n)
    swap(n, k);
  n = n - ((ll)(n / k)) * k;

  cout << k - n << "\\n";

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

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

int64_t zettaichi(int64_t x) {
  if (x >= 0) {
    return x;
  } else {
    x = -x;
    return x;
  }
}

int main() {
  int64_t n, k;
  cin >> n >> k;
  int64_t min = 0;

  int64_t a, b, c;
  a = n % k;
  c = a - k;
  b = zettaichi(c);
  if (a > b) {
    min = b;
  } else {
    min = a;
  }
  cout << min << endl;
}


Error: 0

Fixed submission:

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

int zettaichi(int x) {
  if (x >= 0) {
    return x;
  } else {
    x *= -1;
    return x;
  }
}

int main() {
  int64_t n, k;
  cin >> n >> k;
  int min = 0;

  if (n < k) {
    int a, b;
    a = k % n;
    b = zettaichi(a - k);

    if (a >= b) {
      min = b;
    } else {
      min = a;
    }

  } else if (n == k) {
    min = 0;
  } else if (n > k) {
    int c, d;
    c = n % k;
    d = zettaichi(c - k);

    if (c >= d) {
      min = d;
    } else {
      min = c;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {

  long long num[2];
  long long tmp;

  cin >> num[0] >> num[1];

  tmp = num[0] % num[1];

  cout << min(tmp, num[1] - tmp);

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  std::string str[2];
  long long num[2];
  long long tmp;

  std::cin >> str[0] >> str[1];
  for (int i = 0; i < 2; i++) {
    num[i] = stoi(str[i]);
  }

  tmp = num[0] % num[1];

  cout << std::min(tmp, num[0] - tmp);

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

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

int main(int argc, char const *argv[]) {
  unsigned long N, K;
  cin >> N >> K;

  const auto mod = N % K;

  cout << min(mod, K - mod) << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

template <typename T> T mkabs(T i, T j) {
  T diff = i > j ? i - j : j - i;

  // cout << "mkabs : " << i << ", " << j << ", " << diff << endl;
  if (diff < 0)
    return -diff;
  return diff;
}

int main(int argc, char const *argv[]) {
  unsigned long N, K;
  cin >> N >> K;

  unsigned long ans = N;
  while (true) {
    unsigned long abs = mkabs(ans, K);
    // cout << "abs: " << abs << endl;

    if (abs < ans) {
      ans = abs;
    } else {
      cout << ans << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, flag, sum = 0, sum1 = 0, cnt = 0, ans, lo, mo, n, m;
  vector<long long int> vec;
  list<long long int> mylist;
  vector<long long int>::iterator it1;
  list<long long int>::iterator it2;
  cin >> n >> m;

  cout << min(n % m, abs(n % m - m)) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, flag, sum = 0, sum1 = 0, cnt = 0, ans, lo, mo;
  string n, m;
  vector<long long int> vec;
  list<long long int> mylist;
  vector<long long int>::iterator it1;
  list<long long int>::iterator it2;
  cin >> n >> m;
  stringstream geek(n);
  geek >> lo;
  stringstream geek1(m);
  geek1 >> mo;
  if (mo == 1) {
    cout << 0 << endl;
    return 0;
  }

  while (1) {

    flag = abs(lo - mo);
    if (flag <= abs(flag - mo)) {
      ans = flag;
      break;
    }
    lo = flag;
  }
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

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

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(), (x).end()
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"
#define pb push_back
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define mp make_pair
#define print(v)                                                               \\
  ;                                                                            \\
  for (auto x : v)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl;
typedef long long int ll;
int main() {
  fast;
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    ll ans = n - ((n / k) * k);
    if (abs(ans - k) < ans) {
      ans = abs(ans - k);
    }
    cout << ans << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(), (x).end()
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"
#define pb push_back
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define mp make_pair
#define print(v)                                                               \\
  ;                                                                            \\
  for (auto x : v)                                                             \\
    cout << x << " ";                                                          \\
  cout << endl;
typedef long long int ll;
int main() {
  fast;
  ll n, m;
  cin >> n >> m;
  ll sum = 0;
  ll arr[n + 1];
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  ll big = ceil(sum / (4 * m));
  ll count = 0;
  for (ll i = 0; i < n; i++) {
    if (arr[i] >= big) {
      count++;
    }
  }
  if (count >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
long long gcd(long long a, long long b) {
  ll gcdmax = max(a, b);
  ll gcdmin = min(a, b);
  while (true) {
    if (gcdmax % gcdmin == 0)
      break;
    else
      gcdmax %= gcdmin;
    swap(gcdmin, gcdmax);
  }
  return gcdmin;
}
ll powerup(ll N, ll P, ll M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    ll t = powerup(N, P / 2, M);
    return t * t % M;
  } else
    return N * powerup(N, P - 1, M) % M;
}
int main() {
  ll N, M;
  cin >> N >> M;
  cout << min(N % M, M - N % M) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
long long gcd(long long a, long long b) {
  ll gcdmax = max(a, b);
  ll gcdmin = min(a, b);
  while (true) {
    if (gcdmax % gcdmin == 0)
      break;
    else
      gcdmax %= gcdmin;
    swap(gcdmin, gcdmax);
  }
  return gcdmin;
}
ll powerup(ll N, ll P, ll M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    ll t = powerup(N, P / 2, M);
    return t * t % M;
  } else
    return N * powerup(N, P - 1, M) % M;
}
int main() {
  ll N, M;
  cin >> N >> M;
  ll G;
  G = gcd(N, M);
  if (N % M == 0)
    cout << 0 << endl;
  else
    cout << G << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
// #include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++)
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  ll mod = N % K;
  if (mod > K - mod) {
    mod = K - mod;
  }
  cout << mod << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
// #include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++)
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  int mod = N % K;
  if (mod > K / 2) {
    mod = K - mod;
  }
  cout << mod << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <sstream>
#include <stdio.h>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
vector<int> Data;

int main(void) {
  long n, k;
  cin >> n >> k;

  n = n % k;

  if (n == 0) {
    cout << n << endl;
    return 0;
  }

  if (n >= (k / 2)) {
    n = k - n;
  }

  cout << n << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <sstream>
#include <stdio.h>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
vector<int> Data;

int main(void) {
  int n, k;
  cin >> n >> k;

  n = n % k;

  if (n == 0) {
    cout << n << endl;
    return 0;
  }

  if (n >= (k / 2)) {
    n = k - n;
  }

  cout << n << endl;

  return 0;
}
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;
  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    if (n > k) {
      n = n % k;
    }
    cout << min(n, k - n) << endl;
  }
}


Error: 0

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  cout << min(abs(n - m * (n / m)), abs(n - m * (n / m + 1)));
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << min(abs(n - m * (n / m)), abs(n - m * (n / m + 1)));
}