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

/*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
        DON'T ADJUST THE GOALS,
        ADJUST THE ACTION STEPS.

--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU
UNCOMFORTABLE.

--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  IO();
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

const int MOD = 1e9 + 7;

ll power(ll a, ll b) {
  ll ans = 1;

  while (b > 0) {
    if (b & 1)
      ans *= a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}

ll powm(ll a, ll b) {
  a %= MOD;
  ll ans = 1;

  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return ans;
}

void IO() {
#ifndef ONLINE_JUDGE
  freopen("Input.txt", "r", stdin);
  freopen("Output.txt", "w", stdout);
#endif
}

//================================

int main() {
  // FAST;

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

  cout << min(n % k, abs(n % k - k)) << "\\n";
  return 0;
}

Error: WA

Fixed submission:

/*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
        DON'T ADJUST THE GOALS,
        ADJUST THE ACTION STEPS.

--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU
UNCOMFORTABLE.

--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  IO();
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

const int MOD = 1e9 + 7;

ll power(ll a, ll b) {
  ll ans = 1;

  while (b > 0) {
    if (b & 1)
      ans *= a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}

ll powm(ll a, ll b) {
  a %= MOD;
  ll ans = 1;

  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return ans;
}

void IO() {
#ifndef ONLINE_JUDGE
  freopen("Input.txt", "r", stdin);
  freopen("Output.txt", "w", stdout);
#endif
}

//================================

int main() {
  FAST;

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

  cout << min(n % k, abs(n % k - k)) << "\\n";
  return 0;
}