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

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define F0R(i, a) for (int i = 0; i < a; i++)
#define R0F(i, a) for (int i = a - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define ins insert
#define ft front()
#define bk back()
#define f first
#define s second
#define trav(a, x) for (auto &a : x)
#define ALL(x) (x).begin(), (x).end()

const int MOD = 1000000007;
const int MX = 2e5 + 2;
const ll INF = 1000000000000000000;
const ld PI = 4 * atan((ld)1);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

bool tkmin(int a, int b) { return b < a ? a = b, true : false; }
bool tkmax(int a, int b) { return b > a ? a = b, true : false; }
int rudiv(int a, int b) { return a / b + !(a % b == 0); }

// Output
void op(int ok) { cout << ok << endl; }
void op(string ok) { cout << ok << endl; }
void op(ll ok) { cout << ok << endl; }
void op(char ok) { cout << ok << endl; }
void op(db ok) { cout << fixed << setprecision(7) << ok << endl; }
void op(ld ok) { cout << fixed << setprecision(7) << ok << endl; }
void op(pi ok) { cout << ok.f << " " << ok.s << endl; }
void op(pl ok) { cout << ok.f << " " << ok.s << endl; }
void op(pd ok) { cout << ok.f << " " << ok.s << endl; }

// -----------

ll n, k;

int main() {
  IOS;
  cin >> n >> k;
  op(min(n % k, abs(k - n % k)));
  return 0;
  // You should actually read the notes to self.
}

/* NOTES TO SELF:
    Int overflow? Array bounds?
    Edge cases? (n = 1, n = 0)
    Don't be dumbosity please pace yourself.
*/

Error: 0

Fixed submission:

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define F0R(i, a) for (int i = 0; i < a; i++)
#define R0F(i, a) for (int i = a - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define ins insert
#define ft front()
#define bk back()
#define f first
#define s second
#define trav(a, x) for (auto &a : x)
#define ALL(x) (x).begin(), (x).end()

const int MOD = 1000000007;
const int MX = 2e5 + 2;
const ll INF = 1000000000000000000;
const ld PI = 4 * atan((ld)1);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

bool tkmin(int a, int b) { return b < a ? a = b, true : false; }
bool tkmax(int a, int b) { return b > a ? a = b, true : false; }
int rudiv(int a, int b) { return a / b + !(a % b == 0); }

// Output
void op(int ok) { cout << ok << endl; }
void op(string ok) { cout << ok << endl; }
void op(ll ok) { cout << ok << endl; }
void op(char ok) { cout << ok << endl; }
void op(db ok) { cout << fixed << setprecision(7) << ok << endl; }
void op(ld ok) { cout << fixed << setprecision(7) << ok << endl; }
void op(pi ok) { cout << ok.f << " " << ok.s << endl; }
void op(pl ok) { cout << ok.f << " " << ok.s << endl; }
void op(pd ok) { cout << ok.f << " " << ok.s << endl; }

// -----------

int n, k;

int main() {
  IOS;
  cin >> n >> k;
  op(min(n % k, abs(k - n % k)));
  return 0;
  // You should actually read the notes to self.
}

/* NOTES TO SELF:
    Int overflow? Array bounds?
    Edge cases? (n = 1, n = 0)
    Don't be dumbosity please pace yourself.
*/