alexjercan/bugnet huggingface dataset:
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 % k == 0) {
    cout << "0" << endl;
  } else {
    a = n % k;
    n = abs(k - a);
    if (a > n) {
      cout << n << endl;
    } else if (n >= a) {
      cout << a << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, a;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    while (1) {
      a = n;
      n = abs(n - k);
      if (n % k == 0) {
        cout << 0 << endl;
        break;
      } else if (n > a) {
        cout << a << endl;
        break;
      }
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

int main() {
  long long int n, k;
  cin >> n >> k;
  if (n < k) {
    if (n > k / 2)
      cout << abs(n - k) << endl;
    else
      cout << n << endl;
  } else {
    if (n % k == 0)
      cout << 0 << endl;
    else {
      if (n % k < k / 2)
        cout << n % k << endl;
      else
        cout << k - n % k << endl;
    }
  }
  return 0;
}


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 (k % n == 0)
      cout << n << endl;
    else
      cout << 1 << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  if (n % k < (k - n % k))
    cout << n % k << endl;
  else
    cout << k - n % k << endl;
  return 0;
}
/*
39-14=25
25-14=11
11-14=3
3-14=11

3-7=4
4-7=3

*/

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (n == 0) {
    cout << 0 << endl;
  } else {
    if (n > k) {
      if (n % k != 0)
        cout << 1 << endl;
      else
        cout << 0 << endl;
    } else {
      cout << n << endl;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  long long int x, k, x3 = 0, x4 = 0;
  cin >> x >> k;
  cout << min(x % k, abs((x % k) - k)) << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  long long int a, k, q = -1;
  for (long long int i = 1; i <= 1000000000000000000; i++) {
    a = abs(a - k);
    q = min(q, a);
  }
  cout << q << endl;
}
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 amari = N % K;

  long long ans = min(amari, K - amari);
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  while (true) {
    long long oldN = N;
    N = min(N, abs(N - K));
    if (oldN == N) {
      break;
    }
  }
  cout << N;
}
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 == 0) {
    cout << 0 << endl;
  } else if (a % b <= b - a % b) {
    cout << a % b << endl;
  } else
    cout << b - a % b << endl;
}

Error: 0

Fixed submission:

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

#include <iostream>
#include <stdio.h>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

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

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

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

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

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

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long n, k;
  vector<long long> v;
  cin >> n >> k;
  long long m = n;
  v.push_back(n);
  bool flag = 1;
  while (1) {
    if (n > k)
      n = n % k;
    else
      n = abs(n - k);
    m = min(n, m);
    for (int i = 0; i < v.size(); i++) {
      if (n == v[i])
        flag = 0;
    }
    if (flag == 0)
      break;
    else
      v.push_back(n);
  }
  cout << m << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long n, k;
  vector<long long> v;
  cin >> n >> k;
  long long m = n;
  v.push_back(n);
  bool flag = 1;
  while (1) {
    n = abs(n - k);
    m = min(n, m);
    for (int i = 0; i < v.size(); i++) {
      if (n == v[i])
        flag = 0;
    }
    if (flag == 0)
      break;
    else
      v.push_back(n);
  }
  cout << m << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

#define MOD (1000000007)
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
  ll maxv = max(a, b);
  ll minv = min(a, b);

  if (maxv % minv == 0)
    return minv;
  else
    return gcd(maxv - minv, minv);
}

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

  cout << min(N % K, K - (N % K)) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

#define MOD (1000000007)
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
  ll maxv = max(a, b);
  ll minv = min(a, b);

  if (maxv % minv == 0)
    return minv;
  else
    return gcd(maxv - minv, minv);
}

int main() {
  int N, K;
  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(void) {

  int64_t n;
  int64_t k;
  cin >> n >> k;

  int64_t ans0;
  int64_t ans1;
  int64_t div;
  int64_t i;

  div = n / k;

  ans0 = n - k * div;
  ans1 = abs(n - k * (div + 1));

  cout << min(ans0, ans1) << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {

  int64_t n;
  int64_t k;
  cin >> n >> k;

  int64_t ans0;
  int64_t ans1;
  int64_t temp;
  int64_t i;

  i = 0;

  while (n > (k * i)) {
    i++;
    temp = k * i;
  }

  ans0 = abs(n - k * (i));
  ans1 = abs(n - k * (i - 1));

  cout << min(ans0, ans1) << endl;

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

#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;

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

  long long int n, k, min;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0;
  } else {
    n %= k;
    do {
      min = n;
      n = abs(n - k);
    } while (n < min);
    cout << min;
  }

  // system("pause");
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;

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

  long long int n, k, min;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0;
  } else {
    do {
      min = n;
      n = abs(n - k);
    } while (n < min);
    cout << min;
  }

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

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

void Main() {
  long long N, K;
  cin >> N >> K;

  cout << min(N % K, abs(K - N % K)) << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Error: TLE

Fixed submission:

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

void Main() {
  long long N, K;
  cin >> N >> K;
  long long x = N;
  long long tmp = abs(N - K);
  bool isExist = (x > tmp);
  while (isExist) {
    x = tmp;
    tmp = abs(tmp - K);
    if (x <= tmp) {
      break;
    }
  }
  cout << x << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

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

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

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

  cout << min(n % k, k - n % k);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

  ll a, b;
  a = n % k;
  b = k - a;
  if (a < b) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

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

  cout << n % k << endl;

  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 < (int)(n); i++)

int main() {
  const long long INF = 1e18 + 10;
  long long N, K;
  cin >> N >> K;
  int chk = 0;
  long long min = INF;
  N = N - K * (N / K);

  while (chk == 0) {
    N = abs(N - K);
    if (N == min)
      chk++;
    if (N < min)
      min = N;
  }
  cout << min << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  const int INF = 1e9 + 10;
  long long N, K;
  cin >> N >> K;
  int chk = 0;
  long long min = INF;
  N = N - K * (N / K);

  while (chk == 0) {
    N = abs(N - K);
    if (N == min)
      chk++;
    if (N < min)
      min = N;
  }
  cout << min << endl;
}
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;
  N %= K;
  while (N > abs(N - K)) {
    N = abs(N - K);
  }
  cout << N << endl;
}

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int64_t N, K;
  cin >> N >> K;
  int64_t min = N;

  if (K == 1) {
    cout << 0 << endl;
    return 0;
  } else {
    N %= K;
    while (1) {
      N = abs(N - K);
      if (min < N)
        break;

      min = N;
    }
  }
  cout << min << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int64_t N, K;
  cin >> N >> K;
  int64_t min = N;

  if (K == 1) {
    cout << 0 << endl;
    return 0;
  } else {
    while (1) {
      N = abs(N - K);
      if (min <= N)
        break;

      min = N;
    }
  }
  cout << min << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <math.h>
using namespace std;

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


Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <math.h>
using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  map<long long, bool> mp;
  long long ans = n;
  while (!mp[abs(n - k)]) {
    mp[abs(n - k)] = 1;
    ans = min(ans, abs(n - k));
    n = abs(n - k);
  }
  cout << ans;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

#define FastIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define nl "\\n"
#define sp " "
#define int long long

int32_t main() {
  FastIO;
  int n, k;
  cin >> n >> k;
  int x = n / k;
  int y = x + 1;
  x *= k;
  y *= k;
  int ans = min(abs(x - n), abs(y - n));
  cout << ans << nl;
  return 0;
}


Error: 0

Fixed submission:

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

#define FastIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define nl "\\n"
#define sp " "
#define int long long

int32_t main() {
  FastIO;
  int n, k;
  cin >> n >> k;
  if (k > n / 2)
    k = abs(n - k);
  cout << n % k << nl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int N, K;
  cin >> N >> K;
  long long int MIN, tmp;
  long long int ref = 2000000000000000000;
  while (true) {
    tmp = N - K;
    if (tmp < 0)
      tmp *= -1;
    if (tmp < ref) {
      ref = tmp;
      N = tmp;
    } else {
      break;
    }
  }
  cout << ref << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long N, K;
  cin >> N >> K;
  long a = N % K;

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

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int a = N % K;
  if (K != 1) {
    cout << min(a, K - a) << endl;
  } else
    cout << 0 << endl;

  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++)
using namespace std;
typedef long long ll;

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

  ll n, k;
  cin >> n >> k;
  ll mod = n % k;
  ll modEdit = k - mod;
  cout << min(mod, modEdit) << endl;
  return 0;
}

Error: 0

Fixed submission:

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

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

  ll n, k;
  cin >> n >> k;
  ll diff = abs(n - k);
  ll mod = n % diff;
  if (mod == k) {
    cout << 0 << endl;
  } else {
    cout << mod << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const ll maxn = 1005;
const ll mod = 1e9 + 7;
const ll inf = 1 << 30;
int main() {
  ll n, k;
  scanf("%lld%lld", &n, &k);
  ll x = n % k;
  printf("%lld", min(x, abs(x - k)));
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const ll maxn = 1005;
const ll mod = 1e9 + 7;
const ll inf = 1 << 30;
int main() {
  int n, k;
  cin >> n >> k;
  int x = n % k;
  printf("%d", min(x, abs(x - k)));
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(void) {
  long int n, k, a, de;
  long int ans = 1000000000000000001;
  vector<int> acc;

  cin >> n >> k;

  acc.push_back(n);

  while (!(ans == 0)) {
    if (n >= k) {
      de = n / k;
      a = abs(n - (k * de));
      // a = abs(n-k);
      ans = min(ans, a);
      acc.push_back(a);
      n = a;
      // cout << "flag1" << endl;
    } else {
      a = abs(n - k);
      if (ans < a) {
        goto OUT;
      }
      ans = min(ans, a);
      // cout << "n=" << n << endl;
      // cout << "k=" << k << endl;
      // cout << "a=" << a << endl;
      // cout << "ans=" << ans << endl;
      // for(int i = 0; i < acc.size(); i++){
      //     //cout << "acc[" << i << "]=" << acc[i] << endl;
      //     if(acc[i] == a){
      //         goto OUT;
      //     }
      // }
      // a = abs(n - k);
      acc.push_back(a);
      // ans = min(ans, a);
      n = a;

      // cout << "hoge" << endl;
    }
  }
OUT:

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(void) {
  long int n, k, a, de, mul;
  long int ans = 1000000000000000001;
  vector<int> acc;

  cin >> n >> k;

  acc.push_back(n);

  while (!(ans == 0)) {
    if (n >= k) {
      de = n / k;
      mul = k * de;
      a = abs(n - mul);
      // a = abs(n-k);
      ans = min(ans, a);
      acc.push_back(a);
      n = a;
      // cout << "flag1" << endl;
    } else {
      a = abs(n - k);
      ans = min(ans, a);
      // cout << "n=" << n << endl;
      // cout << "k=" << k << endl;
      // cout << "a=" << a << endl;
      // cout << "ans=" << ans << endl;
      for (int i = 0; i < acc.size(); i++) {
        // cout << "acc[" << i << "]=" << acc[i] << endl;
        if (acc[i] == a) {
          goto OUT;
        }
      }
      // a = abs(n - k);
      acc.push_back(a);
      // ans = min(ans, a);
      n = a;

      // cout << "hoge" << endl;
    }
  }
OUT:

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

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

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

Error: TLE

Fixed submission:

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

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

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long ans;
long long olddif = pow(10, 18);
int d(long long x, long long y) {
  // cout<<old;
  int dif = abs(x - y);
  if (dif <= olddif) {
    ans = dif;
    olddif = dif;
    d(dif, y);
  }
  return ans;
}

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

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


Error: 0

Fixed submission:

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define all(v) (v).begin(), (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
#ifndef ONLINE_JUDGE
#endif
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << "\\n";
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define all(v) (v).begin(), (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << "0\\n";
  } else
    cout << __gcd(n, k) << "\\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;
  cout << min(n % k, k - n % k);
}


Error: WA

Fixed submission:

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

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