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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define test()                                                                 \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (int i = start; i < end; i++)
#define N 100001
#define all(v) v.begin(), v.end()
#define oa(a, n)                                                               \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << a[i] << " ";                                                       \\
  nl
#define ov(a)                                                                  \\
  for (int i = 0; i < a.size(); i++)                                           \\
    cout << a[i] << " ";                                                       \\
  nl
#define vinn(n, v)                                                             \\
  int n;                                                                       \\
  cin >> n;                                                                    \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define vinm(n, m, v)                                                          \\
  int n, m;                                                                    \\
  cin >> n >> m;                                                               \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define debug(x) cerr << #x << " : " << x << endl;
mt19937 rd(time(0)); // i = rd%n
int gcd(int a, int b) {
  if (b == 0)
    return a;
  a %= b;
  return gcd(b, a);
}
signed main() {
  fastio();
  int n, k;
  cin >> n >> k;
  cout << min(n % k, ((-n) % k + k) % k);

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define test()                                                                 \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (int i = start; i < end; i++)
#define N 100001
#define all(v) v.begin(), v.end()
#define oa(a, n)                                                               \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << a[i] << " ";                                                       \\
  nl
#define ov(a)                                                                  \\
  for (int i = 0; i < a.size(); i++)                                           \\
    cout << a[i] << " ";                                                       \\
  nl
#define vinn(n, v)                                                             \\
  int n;                                                                       \\
  cin >> n;                                                                    \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define vinm(n, m, v)                                                          \\
  int n, m;                                                                    \\
  cin >> n >> m;                                                               \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define debug(x) cerr << #x << " : " << x << endl;
mt19937 rd(time(0)); // i = rd%n
int gcd(int a, int b) {
  if (b == 0)
    return a;
  a %= b;
  return gcd(b, a);
}
signed main() {
  fastio();

  int n, k;
  cin >> n >> k;
  cout << min(n % k, min(gcd(n, k), k % n));

  return 0;
}