alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: 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;
}

Error: WA

Fixed submission:

#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;
}
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 A = N % K;
  if (A < abs(A - K)) {
    cout << A << endl;
  } else {
    cout << abs(A - 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;
  if (A < abs(A - K)) {
    cout << A << endl;
  } else {
    cout << abs(A - K) << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: 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);

  ll n, k;
  cin >> n >> k;
  ll rem = n % k;
  cout << min(rem, abs(rem - k));
}

Error: WA

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n % k;
  ll b = abs(k - a);

  cout << min(a, b);

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll m = abs(n - k);

  if (k == 1)
    cout << 0;
  else
    cout << n % m;

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin()                                                         \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
typedef unsigned long long int ullint;

#define M_DEBUG if (1)

/******************************************************************************
        Main
******************************************************************************/
int main() {
  lint n = 0, k = 0;
  cin >> n >> k;
  assert(n >= 0 && n <= pow(10, 18));
  assert(k >= 1 && n <= pow(10, 18));

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

  lint x = (n > k) ? n % k : k - n;
  while (x < n) {
    n = x;
    x = (n - k > 0) ? n - k : -(n - k);
  }
  cout << n << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin()                                                         \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
typedef unsigned long long int ullint;

#define M_DEBUG if (1)

/******************************************************************************
        Main
******************************************************************************/
int main() {
  lint n = 0, k = 0;
  cin >> n >> k;
  assert(n >= 0 && n <= pow(10, 18));
  assert(k >= 1 && n <= pow(10, 18));

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

  lint x = (n - k > 0) ? n - k : -(n - k);
  while (x < n) {
    n = x;
    x = (n - k > 0) ? n - k : -(n - k);
  }
  cout << n << endl;

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

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

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


Error: 0

Fixed submission:

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

int main() {
  int n, k;
  int ans;
  cin >> n >> k;
  ans = n % k;
  if (ans > k - n % k)
    ans = k - n % k;
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: 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;
  }
  n %= k;
  long long mini = min(n, k - n);
  cout << mini << endl;
}

Error: TLE

Fixed submission:

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


#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, k, a;
  cin >> n >> k;
  if (n == 0 || n == k)
    cout << "0" << endl;
  else if (n > k)
    cout << min(n % k, abs(k - (n % k))) << endl;
  else
    cout << min(n, abs(n - k)) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  long long int a, b;
  while (1) {
    cin >> a >> b;
    if (2 * a <= b) {
      cout << a << endl;
    } else if (a < b && b < 2 * a) {
      cout << (b - a) << endl;
    } else {
      cout << a % b << endl;
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, i, d, temp;
  cin >> a >> b;
  d = a;

  if (b == 1) {
    d = 0;
  }

  else {
    while (1) {

      temp = abs(d - b);
      if (temp > d)
        break;
      else if (temp < d)
        d = temp;
    }
  }
  cout << d;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int N = 1e5;
#define min(x, y) (x < y) ? x : y
ll n, k, m, res;
int main() {
  cin >> n >> k;
  if (n == 0)
    res = 0;
  else if (n >= k) {
    res = n % k;
    res = min(res, fabs(res - k));
  } else
    res = min(n, k - n);
  cout << res << endl;
}


Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int N = 1e5;
ll n, k, m, res;
int main() {
  cin >> n >> k;
  if (n > k)
    res = n % k;
  else if (n == k)
    res = 0;
  else
    res = k % n;
  cout << res << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
  ll n, k;
  cin >> n >> k;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (n == k) {
    cout << 0 << endl;
    return 0;
  }
  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    set<ll> used;
    used.insert(n);
    ll ans = n;
    while (true) {
      ll nxt = abs(n - k);
      ans = min(ans, nxt);
      if (used.find(nxt) != used.end()) {
        break;
      } else {
        used.insert(nxt);
      }
      n = nxt;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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


Error: 0

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main() {
  long N, K;
  cin >> N >> K;

  long ans = N % K;

  if (abs(ans - K) < ans)
    cout << abs(ans - K) << endl;
  else
    cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main() {
  long N, K;
  cin >> N >> K;

  long ans = N;
  while (ans >= 0) {
    ans -= K;
  }

  if (abs(ans) < ans + K)
    cout << abs(ans) << endl;
  else
    cout << ans + K << endl;
  return 0;
}
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 m = min(N % K, abs(N % K - K));
  cout << m << 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() {

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

Error: WA

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, i, j, l, d, p;
  cin >> n >> k;
  // p=n;

  vector<long long int> v, v1, v2;

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, i, j, l, d;
  cin >> n >> k;
  vector<long long int> v, v1, v2;
  for (i = 0; i < n; i++) {
    l = abs(n - k);
    v.push_back(l);
    d = abs(l - k);
    v.push_back(d);
  }
  sort(v.begin(), v.end());
  for (j = 0; j != v.size(); j++) {
    if (v[j] == v[j + 1]) {
      cout << v[j] << endl;
      break;
    }
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define endl "\\n"
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;
  //  ll ans;
  //  if(n < k) {
  //    ans = n;
  //  } else if(n == k) {
  //    ans = 0;
  //  } else {
  //    ll ama = n % k;
  //    ans = min(ama, abs(k-ama));
  //  }
  ll ans = min(n % k, abs(k - (n % k)));

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define endl "\\n"
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;
  ll nk = abs(n - k);
  ll ans = n % nk;
  if (nk == 1)
    ans = 1;

  if (k == 1)
    ans = 0;
  cout << ans << endl;

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

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

int main() {
  long long N, K, A, B;
  cin >> N >> K;

  A = K;
  B = N;

  if (N > K) {
    A = (B / K);
    A = A * K;
    B = B - A;
    B = min(B, -1 * (B - K));
    cout << B << endl;
  } else if (N == K)
    cout << 0 << endl;
  else {
    N = min(N, -1 * (N - K));
    cout << N << endl;
  }

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int a, b, c, i, d;

  cin >> a >> b;

  /*  if(b == 0)
      c= a;
    else if(a<b){
      c = a;}
    else if(a==b){
      c = 0;}
    else if(a==0){
      c = 0;}
   else if(a > b){*/
  d = a % b;
  c = min(abs(b - d), d);

  //  for(i=1;;i++){
  // if((abs(a - b*i)) > (abs(a - b*(i+1)))){
  // c = abs(a - b*(i+1));
  // else{
  //   break;}
  //  }
  //  }
  //  else{
  //   c = a;

  // }

  cout << c;

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



*/


Error: TLE

Fixed submission:

/// 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;
}
/*



*/
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  ll N, K;
  cin >> N >> K;
  ll ans = N % K;
  while (ans > K / 2) {
    ans = abs(ans - K);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

  ll N, K;
  cin >> N >> K;
  ll ans = N;
  while (ans > K / 2) {
    ans = abs(ans - K);
  }
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {

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

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

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

Error: WA

Fixed submission:

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

ll diff(ll N, ll K) {
  if (N < abs(N - K))
    return N;
  else {
    N = abs(N - K);
    diff(N, K);
  }
}

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

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


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N;
  cin >> K;
  N %= K;
  if (N > K - N)
    cout << K - N;
  else
    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;
  long long cnt = N / K + 1;
  cout << min(abs(N - (K * cnt)), abs(N - (K * (cnt - 1)))) << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int cnt = N / K + 1;
  cout << min(abs(N - (K * cnt)), abs(N - (K * (cnt - 1)))) << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long a, b;
  cin >> a >> b;

  if (a > b) {
    a %= b;
  }

  if (a > b / 2) {
    a = b - a;
  }

  cout << a;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int a, b;
  cin >> a >> b;

  if (a > b) {
    a %= b;
  }

  if (a > b / 2) {
    a = b - a;
  }

  cout << a;

  return 0;
}