prithivMLmods/Coder-Stat huggingface dataset:
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define sortAl(v) sort(v.begin(), v.end())
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)
#define dout(n) cout << #n << " = " << n << endl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  while (n > abs(n - k))
    n = abs(n - k);
  cout << n << endl;
}

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define sortAl(v) sort(v.begin(), v.end())
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)
#define dout(n) cout << #n << " = " << n << endl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  n = n % k;
  while (n > abs(n - k))
    n = abs(n - k);
  cout << n << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = n;
  while (1) {
    n = abs(k - n);
    if (n < ans)
      ans = n;
    else
      break;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, k;
  cin >> n >> k;
  ll t = n % k;
  ll ans = min(t, k - t);
  cout << ans << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  long long N, K;
  long long cnt;
  bool update = true;

  cin >> N >> K;

  long long minimum;

  while (update) {
    update = false;
    minimum = N;
    N = min(N, abs(N - K));
    if (minimum > N) {
      update = true;
    }
  }

  cout << N;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  long long N, K;
  long long cnt;
  bool update = true;

  cin >> N >> K;

  long long minimum;

  N = N % K;

  while (update) {
    update = false;
    minimum = N;
    N = min(N, abs(N - K));
    if (minimum > N) {
      update = true;
    }
  }

  cout << N;

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: 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 {
    while (1) {
      a = n;
      n = abs(n - k);
      if (n > a) {
        cout << a << endl;
        break;
      }
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, flag, sum = 0, sum1 = 0, cnt = 0, ans, lo, mo, n, m;
  vector<long long int> vec;
  list<long long int> mylist;
  vector<long long int>::iterator it1;
  list<long long int>::iterator it2;
  cin >> n >> m;

  cout << min(n % m, abs(n % m - m)) << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  long long n, k, ans;
  int flag = 0;
  scanf("%lld %lld", &n, &k);
  ans = abs(n - k);
  while (flag < 100) {
    if (n >= k && n % k == 0) {
      printf("0\n");
      return 0;
    }
    n = abs(n - k);
    if (n < ans) {
      ans = n;
      flag = 0;
    }
    flag++;
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  long long n, k, ans;
  int flag = 0;
  scanf("%lld %lld", &n, &k);
  if (n >= k)
    n = n % k;
  ans = n;
  if (k - n < ans)
    ans = k - n;
  printf("%lld\n", ans);
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <math.h>
#include <stdio.h>

int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  while (abs(n - k) < n) {
    n = abs(n - k);
  }
  printf("%lld\n", n);

  return 0;
}

Fixed submission:
#include <math.h>
#include <stdio.h>

int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  n = n % k;
  while (abs(n - k) < n) {
    n = abs(n - k);
  }
  printf("%lld\n", n);

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  ll output = n % abs(n - k);
  cout << output << endl;
}


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

using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  ll remainder = n % k;
  ll output = min(remainder, abs(k - remainder));
  cout << output << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n = 0;
  long long k = 0;
  cin >> n >> k;

  long long checker = 1000000000000000000;

  while (1) {
    checker = n;
    n = abs(n - k);
    if (n >= checker) {
      break;
    }
  }

  cout << checker << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n = 0;
  long long k = 0;
  cin >> n >> k;

  cout << min(n % k, k - n % k) << "\n";
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for (ll i = l; i < (ll)r; i++)
#define per(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define per3(i, l, r) for (ll i = (ll)r - 1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template <class T, class U> inline void cmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> inline void cmin(T &a, U b) {
  if (a > b)
    a = b;
}

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v)
    is >> in;
  return is;
}
#line 2 "c.cpp"

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

  ll d = n - k;
  cout << k % d << el;
}


Fixed submission:
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for (ll i = l; i < (ll)r; i++)
#define per(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define per3(i, l, r) for (ll i = (ll)r - 1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template <class T, class U> inline void cmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> inline void cmin(T &a, U b) {
  if (a > b)
    a = b;
}

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v)
    is >> in;
  return is;
}
#line 2 "c.cpp"

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

  if (n > k)
    n %= k;
  ll ans = n;
  ll d = abs(n - k);
  cmin(ans, d);
  cmin(ans, abs(k - d));
  if (k == 1)
    ans = 0;
  cout << ans << el;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  long long Z;
  if (N > K)
    Z = N - K;
  else
    Z = K - N;
  for (long long i = 0; N > Z; i++) {
    if (N > K)
      Z = N - K;
    else
      Z = K - N;
    if (N > Z) {
      N = Z;
      if (K > N)
        Z = K - N;
      else
        Z = N - K;
    } else
      break;
  }
  cout << N;

  return 0;
}

Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  long long z = N % K;
  long long ans = min(z, K - z);
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0;
    return 0;
  }
  while (n >= k) {
    int p = n / k;
    n = n - p * k;
  }
  if (abs(n - k) > n)
    cout << n;
  else
    cout << abs(n - k);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0;
    return 0;
  }
  while (n >= k) {
    n %= k;
  }
  if (abs(n - k) > n)
    cout << n;
  else
    cout << abs(n - k);
}
Problem p02719 (C++)

Buggy submission (status: 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;
  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;
}

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;
  n = abs(n % k);
  ans = min(ans, n);
  n = k - n;
  ans = min(ans, n);
  cout << ans;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << min(abs(n - m * (n / m)), abs(n - m * (n / m + 1)));
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  cout << min(abs(n - m * (n / m)), abs(n - m * (n / m + 1)));
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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


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

int main() {
  long long int n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    if (n > k) {
      n = n % k;
    }
    cout << min(n, k - n) << endl;
  }
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <sstream>
#include <stdio.h>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
vector<int> Data;

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

  n = n % k;

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

  if (n >= (k / 2)) {
    n = k - n;
  }

  cout << n << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <sstream>
#include <stdio.h>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
vector<int> Data;

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

  n = n % k;

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

  if (n >= (k / 2)) {
    n = k - n;
  }

  cout << n << endl;

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;
  while (N > abs(K - N)) {
    N = abs(N - K);
  }
  cout << N << endl;
}

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

int main() {
  long long N, K;
  cin >> N >> K;
  long long ans = min(N % K, K - N % K);
  cout << ans << endl;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
long long gcd(long long a, long long b) {
  ll gcdmax = max(a, b);
  ll gcdmin = min(a, b);
  while (true) {
    if (gcdmax % gcdmin == 0)
      break;
    else
      gcdmax %= gcdmin;
    swap(gcdmin, gcdmax);
  }
  return gcdmin;
}
ll powerup(ll N, ll P, ll M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    ll t = powerup(N, P / 2, M);
    return t * t % M;
  } else
    return N * powerup(N, P - 1, M) % M;
}
int main() {
  ll N, M;
  cin >> N >> M;
  ll G;
  G = gcd(N, M);
  if (N % M == 0)
    cout << 0 << endl;
  else
    cout << G << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
long long gcd(long long a, long long b) {
  ll gcdmax = max(a, b);
  ll gcdmin = min(a, b);
  while (true) {
    if (gcdmax % gcdmin == 0)
      break;
    else
      gcdmax %= gcdmin;
    swap(gcdmin, gcdmax);
  }
  return gcdmin;
}
ll powerup(ll N, ll P, ll M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    ll t = powerup(N, P / 2, M);
    return t * t % M;
  } else
    return N * powerup(N, P - 1, M) % M;
}
int main() {
  ll N, M;
  cin >> N >> M;
  cout << min(N % M, M - N % M) << endl;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <exception>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
  /*freopen("output.txt", "w", stdout);
  freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
  fast();
  // File();
  ll a, b;
  cin >> a >> b;
  ll diff = abs(a - b);
  cout << a % min(diff, b) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <exception>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
  /*freopen("output.txt", "w", stdout);
  freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
  fast();
  // File();
  ll a, b;
  cin >> a >> b;
  if (a <= b)
    cout << min(a, abs(a - b));
  else {
    if (a % b == 0)
      cout << 0 << endl;
    else {
      a %= b;
      cout << min(a, abs(a - b));
    }
  }
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  cout << min(N % K, abs(N % K - K));
  return 0;
}

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

int main() {
  long long N, K;
  cin >> N >> K;
  cout << min(N % K, abs(N % K - K));
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int sum = 0, cnt = 0;
  rep(i, 0, n) {
    cin >> a[i];
    sum += a[i];
  }
  rep(i, 0, n) {
    if ((double)a[i] > (double)(sum / (4 * m)))
      cnt++;
  }
  if (cnt >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  lli n, k;
  cin >> n >> k;
  n %= k;
  lli temp = abs(n - k);
  cout << min(n, temp) << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  cout << min(n % k, abs((n % k) - k)) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  cout << min(n % k, abs((n % k) - k)) << endl;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (n % k < k - n % k)
    cout << n % k;
  else
    cout << k - n % k;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  if (n % k < k - n % k)
    cout << n % k;
  else
    cout << k - n % k;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  long long int n, k;

  cin >> n >> k;
  if (k == 1) {
    cout << "0";
  } else if (k == 0) {
    cout << n;
  } else {
    while (abs(n - k) <= n) {
      n = abs(n - k);
    }
    cout << n;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  long long int n, k;

  cin >> n >> k;
  long long int mn;

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

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, x, y;
  cin >> N >> K;
  x = N % K;
  y = K - x;
  if (x > y)
    cout << y << endl;
  else
    cout << x << endl;
}


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

int main() {
  int64_t N, K, x, y;
  cin >> N >> K;
  x = N % K;
  y = K - x;
  if (x > y)
    cout << y << endl;
  else
    cout << x << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <stdlib.h>
int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  if (k == 1) {
    printf("%d\n", 0);
    return 0;
  }
  long long tmp = 0;
  while (1) {
    tmp = n;
    n = llabs(n - k);
    if (tmp <= n) {
      printf("%lld\n", tmp);
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <stdlib.h>
int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  if (k == 1) {
    printf("%d\n", 0);
    return 0;
  }
  long long tmp = 0;
  n = n % k;
  while (1) {
    tmp = n;
    n = llabs(n - k);
    if (tmp <= n) {
      printf("%lld\n", tmp);
      return 0;
    }
  }
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;
  set<int64_t> x;
  for (; !x.count(N);) {
    x.insert(N);
    if (N > K)
      N -= K;
    else
      N = K - N;
  }
  cout << *begin(x) << endl;
}

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

int main() {
  int64_t N, K;
  cin >> N >> K;
  set<int64_t> x;
  for (; !x.count(N);) {
    x.insert(N);
    if (N > K)
      N %= K;
    else
      N = K - N;
  }
  cout << *begin(x) << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if (a < b)
    return euclidean_gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template <class T> inline bool changeMinimum(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template <class T> inline bool changeMaximum(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template <typename T> T output(T answer) {
  cout << answer << endl;
  return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

  ll N, K;
  cin >> N >> K;

  ll n = N;

  while (1) {
    //        n = abs( - K);
    if (abs(n - K) < n) {
      //            continue;
      n = abs(n - K);
      //            cout << n;
    } else {
      cout << n << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if (a < b)
    return euclidean_gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template <class T> inline bool changeMinimum(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template <class T> inline bool changeMaximum(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template <typename T> T output(T answer) {
  cout << answer << endl;
  return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

  ll N, K;
  cin >> N >> K;

  ll n = N;

  n = N % K;
  while (1) {
    //        n = abs( - K);
    if (abs(n - K) < n) {
      //            continue;
      n = abs(n - K);
      //            cout << n;
    } else {
      cout << n << endl;
      return 0;
    }
  }
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll a, b;
  cin >> a >> b;
  cout << min(a % b, b % a);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll a, b;
  cin >> a >> b;
  if (a == 0) {
    cout << 0;
    return 0;
  }
  cout << min(a % b, b - (a % b));
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02719 (C++)

Buggy submission (status: 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;
  while (ans > K / 2) {
    ans = abs(ans - K);
  }
  cout << ans << endl;
  return 0;
}


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 % K;
  while (ans > K / 2) {
    ans = abs(ans - K);
  }
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
#define MAX 1000003
#define pii pair<ll, ll>
#define VP vector<pii>
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (ll(i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(), (v).end()
#define S(x) scanf("%d", &(x))
#define S2(x, y) scanf("%d%d", &(x), &(y))
#define SL(x) scanf("%lld", &(x))
#define SL2(x) scanf("%lld%lld", &(x), &(y))
#define P(x) printf("%d\n", (x))
#define FF first
#define SS second
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  ll ans = n;
  map<ll, ll> m;
  while (m[n] == 0) {
    ll prev = n;
    n = abs(n - k);
    m[prev]++;
    ans = min(ans, n);
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define MAX 1000003
#define pii pair<ll, ll>
#define VP vector<pii>
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (ll(i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(), (v).end()
#define S(x) scanf("%d", &(x))
#define S2(x, y) scanf("%d%d", &(x), &(y))
#define SL(x) scanf("%lld", &(x))
#define SL2(x) scanf("%lld%lld", &(x), &(y))
#define P(x) printf("%d\n", (x))
#define FF first
#define SS second
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  ll ans = n;
  n = n % k;
  map<ll, ll> m;
  while (m[n] == 0) {
    ll prev = n;
    n = abs(n - k);
    m[prev]++;
    ans = min(ans, n);
  }
  cout << ans;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define vi(v) vector<int> v;
#define all(v) v.begin(), v.end()

using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  while (true) {
    if (n % k == 0) {
      cout << "0";
      break;
    }
    if (n <= k) {
      cout << min(n, k - n);
      break;
    } else
      n = abs(n - k);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define vi(v) vector<int> v;
#define all(v) v.begin(), v.end()

using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;

  cout << min(k - (n % k), n % k) << '\n';
  // else if(n%k!=0&&n<k)
  //    cout<<min(n%k, n);
  // else
  //    cout<<"0";

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define X first
#define Y second
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
const int maxn = 1e4 + 10;
int a[maxn];

ll ABS(ll a, ll b) {
  if (a > b) {
    return a - b;
  } else
    return b - a;
}

int main() {
  ll n, k;
  cin >> n >> k;
  if (n < k / 2) {
    cout << n << endl;
    return 0;
  }
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll num = ABS(n, k);
  while (num < n) {
    n = num;

    num = ABS(n, k);
  }
  cout << n << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define X first
#define Y second
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
const int maxn = 1e4 + 10;
int a[maxn];

ll ABS(ll a, ll b) {
  if (a > b) {
    return a - b;
  } else
    return b - a;
}

int main() {
  ll n, k;
  cin >> n >> k;
  if (n < k / 2) {
    cout << n << endl;
    return 0;
  }
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << min(n % k, ABS(n % k, k)) << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  long long min = n;
  while (true) {
    if (k == 1) {
      min = 0;
      break;
    }
    long long a = n - k;
    if (a < 0)
      a = -a;
    if (a < min) {
      min = a;
      n = a;
    } else
      break;
  }
  cout << min << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  long long min = n;
  long long a = n % k;
  long long ans = std::min(a, k - a);
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, K, M;
  cin >> N >> K;
  M = min(N % K, K - N % K);
  cout << M << endl;
  return 0;
}

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

int main() {
  ll N, K, M;
  cin >> N >> K;
  M = min(N % K, K - N % K);
  cout << M << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  if (N > K) {
    N = N % K;
  }
  N = min(N, K - N);
  cout << N << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  if (N > K) {
    N = N % K;
  }
  N = min(N, K - N);
  cout << N << endl;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int a, b;
  cin >> a >> b;
  if (a % b == 0)
    cout << 0;
  else if (a < b)
    cout << min(b - a, a);
  else
    cout << min(abs(b - (a % b)), a % b);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long a, b;
  cin >> a >> b;
  if (a % b == 0)
    cout << 0;
  else if (a < b)
    cout << min(b - a, a);
  else
    cout << min(abs(b - (a % b)), a % b);

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/04/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  return 0;
}


Fixed submission:
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/04/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll n, k;
  cin >> n >> k;
  cout << min(n % k, k - n % k) << endl;

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

  ull ans = 0;
  if (n % k == 0) {
    ans = 0;
    cout << ans << endl;
    return 0;
  }
  if (n <= abs(n - k)) {
    ans = n;
    cout << ans << endl;
    return 0;
  }

  ull bef_n = 1000000000000000001;
  while (n < bef_n) {
    bef_n = n;
    n = (ull)abs(n - k);
    // cout << n << " " << bef_n << endl;
  }
  cout << bef_n << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

  ull ans = 0;
  if (n % k == 0) {
    ans = 0;
    cout << ans << endl;
    return 0;
  }
  if (n <= abs(n - k)) {
    ans = n;
    cout << ans << endl;
    return 0;
  }

  n = (n % k > k / 2) ? k - (n % k) : n % k;
  cout << n << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a;
  long long int x;
  x = n;
  for (int i = 0; i < n + 1; ++i) {
    if (x > abs(x - k)) {
      x = abs(x - k);
    } else {
      cout << x << endl;
      break;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int r;
  long long int s;
  r = n % k;
  s = abs(n % k - k);
  long long int ans;
  ans = min(r, s);
  cout << ans << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << "0" << endl;
  } else {
    long x = 0, y = 0;
    for (int i = 0; i < n; i++) {
      n = abs(n - k);
      if (n == x || n == y) {
        break;
      }
      y = x;
      x = n;
    }
    cout << min(x, y) << endl;
  }
}

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

int main() {
  long n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << endl;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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


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

int main() {
  long long n, k;
  cin >> n >> k;
  if (k - (n % k) <= n % k) {
    cout << k - (n % k) << endl;
  } else {
    cout << n % k << endl;
  }
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf = 1000001000;
ll INF = 100000000000000000;
ll MOD = 1000000007;
// g++ code.cpp   ./a.out

int main() {
  ll n, k;
  cin >> n >> k;
  while (abs(n - k) < n) {
    n = abs(n - k);
  }
  cout << n << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf = 1000001000;
ll INF = 100000000000000000;
ll MOD = 1000000007;
// g++ code.cpp   ./a.out

int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n % k;
  n = min(a, abs(a - k));
  cout << n << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdarg.h>
#include <string>
#include <vector>
using ll = long long;

using namespace std;

int main() { /*7日目*/
             // 少数も使いたい割り算はしない方がいい
  //  数値の大きさ
  // for文で0代入する場所はforの一文下
  // オーバーフローする一手手前を分解して作る・ 割り算で減らしていく
  // for文いつも間違える/ i<nなら最後はa[n-1]
  ll n, k;
  cin >> n >> k;
  ll k2;
  if (k == 1) {
    cout << "0";
    return 0;
  }
  k2 = k / 2;

  bool con = true;
  while (con) {
    if (n < k2 and n >= 0) {
      cout << n;
      break;
    } else if (n < 0) {
      cout << -n;
      break;
    }
    n -= k;
  }
}

Fixed submission:
#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdarg.h>
#include <string>
#include <vector>
using ll = long long;

using namespace std;

int main() { /*7日目*/
             // 少数も使いたい割り算はしない方がいい
  //  数値の大きさ
  // for文で0代入する場所はforの一文下
  // オーバーフローする一手手前を分解して作る・ 割り算で減らしていく
  // for文いつも間違える/ i<nなら最後はa[n-1]
  ll n, k;
  cin >> n >> k;
  ll am = n % k;
  ll ma = am - k;
  if (am > -ma)
    cout << -ma;
  else
    cout << am;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>

using namespace std;
typedef long long ll;

int main(void) {
  ll n, k;
  cin >> n >> k;
  if (n > k) {
    ll ans = min(n % k, llabs(n - (n % k)));
    cout << ans;
  }

  else {
    ll ans = min(k % n, llabs(k - (k % n)));
    cout << ans;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>

using namespace std;
typedef long long ll;

int main(void) {
  ll n, k;
  cin >> n >> k;
  ll r = n % k;
  ll ans = min(r, llabs(k - r));
  cout << ans;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
// typedef long long int lli;

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

  if (n % k == 0)
    cout << 0 << endl;
  else {
    while (1) {
      if (abs(n - k) < n)
        n = abs(n - k);
      else
        break;
    }

    cout << n << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
// typedef long long int lli;

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

  if (n % k == 0)
    cout << 0 << endl;
  else {
    long d = fabs((n % k) - k);
    if (d < n)
      cout << d << endl;
    else
      cout << n << endl;
  }
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long int n, k, m;
  cin >> n >> k;
  long long int time = n / k;
  if (k * time != n) {
    time += 1;
  }
  m = 0;
  if (n % k == 0) {
    cout << 0;
    return 0;
  }
  for (long long int i = 0; i < time; ++i) {
    if (n - k < 0) {
      m = k - n;
    } else {
      m = n - k;
    }
    if (i < time - 1) {
      n = m;
    }
  }
  if (n > m) {
    cout << m;
  } else {
    cout << n;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  long long n = 0, k = 0;
  cin >> n >> k;
  long long a = llabs(n - k);
  n = llabs(a - k);
  while (n < a) {
    a = n;
    n = llabs(n - k);
  }
  cout << a << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  long long n = 0, k = 0;
  cin >> n >> k;
  n = n % k;
  if (n > k - n)
    cout << k - n << endl;
  else
    cout << n << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
  ll n, k;
  cin >> n >> k;
  n = min(n % k, n);
  while (true) {
    int pre = n;
    n = min(abs(n - k), n);
    if (n == pre)
      break;
  }
  cout << n << endl;
  return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  n = min(n % k, n);
  while (true) {
    ll pre = n;
    n = min(abs(n - k), n);
    if (n == pre)
      break;
  }
  cout << n << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  long long n, k;
  cin >> n >> k;
  if (k == n % abs(n - k))
    cout << "0";
  else
    cout << n % abs(n - k);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  long long n, k;
  cin >> n >> k;
  n %= k;
  cout << min(n, abs(n - k));
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
int main() {
  ll n, k;
  cin >> n >> k;
  while (n >= k) {
    n -= k;
  }
  ll ans = min(n, k - n);
  cout << ans << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
int main() {
  ll n, k;
  cin >> n >> k;
  ll r = n % k;
  ll ans = min(r, k - r);
  cout << ans << endl;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  N = N % K;
  cout << min(N, K - N) << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  unsigned long long N, K;
  cin >> N >> K;
  N = N % K;
  cout << min(N, K - N) << endl;
  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, k;
  cin >> n >> k;
  long long kk;
  kk = k;
  long long nn = 1000000000000000000;
  if (n % k == 0) {
    cout << 0 << endl;
    return (0);
  }
  while (1) {
    n = labs(n - k);
    if (n > nn)
      break;
    nn = n;
  }

  cout << min(kk, nn) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, k;
  cin >> n >> k;
  long long kk;
  kk = k;
  long long nn = 1000000000000000000;
  if (n % k == 0) {
    cout << 0 << endl;
    return (0);
  }
  n = n % k;
  while (1) {
    n = labs(n - k);
    if (n > nn)
      break;
    nn = n;
  }

  cout << min(kk, nn) << endl;
}
Problem p02719 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (ll i = 0; i < 1e17; ++i) {
    if ((abs(n - k)) < n) {
      n = abs(n - k);
    } else {
      break;
    }
  }
  cout << abs(n) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll flag = n / k;
  n -= flag * k;
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (ll i = 0; i < 1e17; ++i) {
    if ((abs(n - k)) < n) {
      n = abs(n - k);
    } else {
      break;
    }
  }
  cout << abs(n) << endl;

  return 0;
}
Problem p02719 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int n, k;

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

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

long long n, k;

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