alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define repo(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

ll aaa(ll n, ll k) {
  ll a = n - k;
  if (a == 0) {
    return 0;
  }
  if (a < 0) {
    a *= -1;
    return min(a, n);
  }

  return aaa(a, k);
}

int main() {
  ll N, K;
  cin >> N >> K;
  //     if(K == 1){
  //         cout << 0 << endl;
  //         return 0;
  //     }
  ll yo = N / K;
  ll ama = N % K;
  if (ama == 0) {
    cout << 0 << endl;
    return 0;
  }

  if (yo > 0) {
    ll yyy = N - (yo * K);
    cout << min(yyy, -1 * (yyy - K));
    return 0;
  }

  cout << min(N, -1 * (N - K)) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define repo(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

ll aaa(ll n, ll k) {
  ll a = n - k;
  if (a == 0) {
    return 0;
  }
  if (a < 0) {
    a *= -1;
    return min(a, n);
  }

  return aaa(a, k);
}

int main() {
  ll N, K;
  cin >> N >> K;
  if (K == 1) {
    cout << 0 << endl;
    return 0;
  }
  //     ll min_val = min(N,K);
  //
  //     min_val = min(min_val,N/K);
  //     cout << min_val << endl;

  cout << aaa(N, K) << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: 0

Fixed submission:

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

int main() {
  int n, k, x;
  cin >> n >> k;
  x = n % k;
  if (2 * x > k) {
    n = k - x;
  }
  cout << n << endl;
  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 x = n % k;
  while (1) {
    if (x > abs(x - k)) {
      x = abs(x - k);
    } else {
      break;
    }
  }

  cout << x << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long int n, k;

  cin >> n >> k;
  while (1) {

    if (k == 1 || n == 0) {
      cout << "0" << endl;
      break;
    }

    if (n > abs(n - k)) {
      n = abs(n - k);

    } else {
      cout << n << endl;
      break;
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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


Error: 0

Fixed submission:

//============================================================================
// Name        : a.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <bits/stdc++.h>

using namespace std;

int main() {
  long long n, k, m;
  cin >> n >> k;
  while (true) {
    if (k == 1) {
      n = 0;
      break;
    }
    if (k == 2) {
      n = n % k;
      break;
    }
    if (k % n == 0) {
      break;
    }
    m = abs(n - k);
    if (m < n) {
      n = m;
    } else {
      break;
    }
  }
  cout << n << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define inf 1000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define fastread                                                               \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL)
#define rng_23                                                                 \\
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vii;
typedef set<ll> si;
typedef multiset<ll> msi;
typedef map<ll, ll> mii;
int main() {
  ll n, k;
  cin >> n >> k;
  if (n < k)
    cout << min(n, k - n);
  else
    cout << min(k - n % k, n % k);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define inf 1000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define fastread                                                               \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL)
#define rng_23                                                                 \\
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int, int> mii;
int main() {
  int n, k;
  cin >> n >> k;
  if (n < k)
    cout << min(n, k - n);
  else
    cout << min(k - n % k, n % k);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  long long int n, k;
  cin >> n >> k;
  long long int x = n % k;
  if (abs(x - k) < x) {
    cout << abs(x - k) << endl;
  } else {
    cout << x << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  long long int n, k;
  cin >> n >> k;

  long long int mi = min(n, k);
  long long int ma = max(n, k);
  if (ma % mi != 0) {
    while (ma % mi != 0) {
      long long int old_y = mi;
      mi = ma % mi;
      ma = old_y;
    }
    cout << mi << endl;
  } else {
    cout << mi << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: 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);
  }
  n = n % k;
  while (1) {
    n = labs(n - k);
    if (n > nn)
      break;
    nn = n;
  }

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

Error: TLE

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);
  }
  while (1) {
    n = labs(n - k);
    if (n > nn)
      break;
    nn = n;
  }

  cout << min(kk, nn) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  if (n < k) {
    int ans = min(n, k - n);
    cout << ans << endl;
  } else if (n == k) {
    cout << 0 << endl;
  } else if (n > k) {
    if (n % k == 0) {
      cout << 0 << endl;
    } else {
      int ans = min(n % k, k - n % k);
      cout << ans << 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;

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

Error: TLE

Fixed submission:

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

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

  bool judge = true;
  int ans;
  if (K == 1)
    cout << 0 << endl;
  else {
    while (judge) {
      N = abs(N - K);
      int N_next;
      N_next = abs(N - K);
      if (N < N_next) {
        judge = false;
        ans = N;
      }
    }
    cout << ans << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: 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;
  ll r = n % k;
  ll ans = min(r, k - r);
  cout << ans << endl;
}


Error: TLE

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;
  while (n >= k) {
    n -= k;
  }
  ll ans = min(n, k - n);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

  long int sp;

  if (N >= K) {
    sp = N / K;
    N = N - K * sp;
  }

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

Error: 0

Fixed submission:

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

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

  long int sp;
  if (N >= K) {
    sp = N / K;
    N = N - K * sp;
  } else if (K >= N) {
    sp = K / N;
    N = K - N * sp;
  }

  for (;;) {
    if (N >= K) {
      N_work = N - K;
      if (N_work >= N) {
        cout << N << endl;
        return 0;
      } else {
        N = N_work;
      }
    } else if (K > N) {
      N_work = K - N;
      if (N_work >= N) {
        cout << N << endl;
        return 0;
      } else {
        N = N_work;
      }
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
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##_len = (n); i < i##_len; ++i)
typedef long long ll;
#define pb push_back

void solve() {
  ll n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    exit(0);
  }

  n = n % k;

  while (true) {
    ll tmp = abs(k - n);
    if (tmp < n)
      n = tmp;
    else
      break;
  }

  cout << n << endl;
}

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

Error: TLE

Fixed submission:

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

void solve() {
  ll n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    exit(0);
  }
  while (true) {
    ll tmp = abs(k - n);
    if (tmp < n)
      n = tmp;
    else
      break;
  }
  cout << n << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using namespace std;
int main() {
  long long int N, K;
  cin >> N >> K;
  long long int tmp;
  if (N >= K) {
    tmp = N % K;
  } else {
    tmp = N;
  }
  // cout << tmp << endl;
  cout << min(tmp, abs(tmp - K)) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using namespace std;
int main() {
  long long int N, K;
  cin >> N >> K;
  long long int ans = -1;
  long long int tmp = abs(K - N);
  while (true) {
    N = abs(K - N);
    // cout << "N" << N << endl;
    if (K == 1 || K == 0) {
      break;
    } else {
      if (tmp < N) {
        break;
      } else {
        tmp = N;
      }
    }
  }
  if (K == 1) {
    cout << 0 << endl;
  } else if (K == 0) {
    cout << N << endl;
  } else {
    cout << tmp << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  cout << min(n % m, m - (n % m)) << '\\n';
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << min(n % m, m - (n % m)) << '\\n';
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  if (n < k) {
    n = min(n, k - n);
    cout << n << endl;
    return 0;
  } else {
    n = n % k;
  }

  ll minimum = n;
  while (true) {
    n = abs(n - k);
    if (minimum == n)
      break;
    minimum = min(minimum, n);
  }

  cout << minimum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

  ll minimum = n;

  while (true) {
    n = abs(n - k);
    if (minimum == n)
      break;
    minimum = min(minimum, n);
  }

  cout << minimum << endl;

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

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  long long n, k, x, y;
  cin >> n >> k;
  x = n % k;
  y = k - x;
  cout << min(x, y) << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = n;
  if (n % k == 0) {
    ans = 0;
  } else {
    while (n > abs(n - k)) {
      n = abs(n - k);
      ans = n;
    }
  }
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <iostream>
#include <stdlib.h>
using namespace std;
void a(int n, int k);
int main() {
  int n, k;
  cin >> n >> k;
  a(n, k);
  return 0;
}
void a(int n, int k) {
  int x = 0, y = 0;
  while (1) {
    x = n;
    y = n - k;
    n = abs(y);
    if (n >= x)
      cout << x;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  long long signed int N, K, a;
  cin >> N >> K;
  if (K == 0) {
    cout << N;
  }
  a = N % K;
  if (abs(a - K) <= a)
    cout << abs(a - K);
  else
    cout << a;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long signed int N, K, t = 0, a;
  cin >> N >> K;
  if (K > N) {
    if (K > 2 * N)
      cout << N;
    else
      cout << abs(N - K);
  } else if (N % K == 0)
    cout << "0";
  else if (N % K == 1)
    cout << "1";
  else {
    while (t < 10 ^ 9) {
      a = abs(N - K);
      if (a < N)
        N = a;
      else
        break;
    }
    cout << N;
  }

  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, ans = 0;
  cin >> n >> k;
  if (n % k == 0)
    cout << 0;
  else {
    if (n < k) {
      ans = min(n, abs(n - k));
    } else {
      ll tmp = n / k;
      n = n - (tmp * k);
      ans = min(n, abs(n - k));
    }
    cout << ans;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  ll n, k;
  cin >> n >> k;
  ll mini = LLONG_MAX;
  mini = min(mini, n);
  ll prev_mini = LLONG_MAX;
  if (n % k == 0) {
    cout << 0;
  } else {
    while (mini != prev_mini) {
      prev_mini = mini;
      mini = min(n, abs(n - k));
      n = abs(n - k);
    }
    cout << mini;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
  ll n, k;
  cin >> n >> k;
  ll m = n % k;

  if (abs(m - k) < m)
    cout << abs(m - k) << endl;
  else
    cout << m << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
  ll n, k;
  cin >> n >> k;
  int m = n % k;
  if (m == 0)
    cout << 0 << endl;
  else {
    vector<ll> vec(m + 1);
    vec.at(0) = n;
    vec.at(1) = abs(n - k);
    for (int i = 2; i <= m; i++) {
      vec.at(i) = abs(vec.at(i - 1) - k);
    }
    sort(vec.begin(), vec.end());
    cout << vec.at(0) << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int, int>;
using psi = pair<string, int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++)
#define repdown(i, n) for (in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() { cout << "Yes"; }

void no() { cout << "No"; }

int main() {
  kyun;
  in6 n, k;
  cin >> n >> k;
  in6 ans = n % k;
  cout << min(ans, abs(ans - k));
  hinata;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int, int>;
using psi = pair<string, int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++)
#define repdown(i, n) for (in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() { cout << "Yes"; }

void no() { cout << "No"; }

int main() {
  kyun;
  in6 n, k;
  cin >> n >> k;
  in6 ans = n;
  while (1) {
    in6 now = abs(ans - k);
    if (now < ans)
      ans = now;
    else
      break;
  }
  cout << ans;
  hinata;
}
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 N = n;
  long long mn = 1000000000000000000;
  while (n >= 0) {
    mn = min(n, mn);
    if (n < k) {
      n = k - n;
    } else {
      n = n % k;
    }
    if (n == mn) {
      mn = min(n, mn);
      break;
    }
  }
  cout << mn;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long long n, k;
  cin >> n >> k;
  long long N = n;
  long long mn = 1000000000000000000;
  while (n >= 0) {
    if (k == 1) {
      mn = 0;
      break;
    }
    if ((n % 2 == 0 && k == 2) || (n % 3 == 0 && k == 3) ||
        (n % 4 == 0 && k == 4) || (n % 5 == 0 && k == 5) ||
        (n % 10 == 0 && k % 10 == 0)) {
      mn = 0;
      break;
    }
    mn = min(n, mn);
    if (n < k) {
      n = k - n;
    } else {
      n = n - k;
    }
    if (n == mn) {
      mn = min(n, mn);
      break;
    }
  }
  cout << mn;

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


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  long long a;
  cin >> n >> k;
  if (n % k == 0)
    cout << '0';
  else {
    a = min(n % k, k - n % k);
    cout << a;
  }
}


Error: WA

Fixed submission:


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  int a;
  cin >> n >> k;
  if (n % k == 0)
    cout << '0';
  else {
    a = min(n % k, k - n % k);
    cout << a;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long sup = n % k;
  cout << min(sup, k - sup) << endl;
  return (0);
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int sup = n % k;
  cout << min(sup, k - sup) << endl;
  return (0);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x)                                                                \\
  static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x))   \\
      .str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll mod = n % k;
  cout << min(mod, k - mod) << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x)                                                                \\
  static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x))   \\
      .str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

int main() {
#ifndef ONLINE_JUDGE
  freopen("test.in", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll mod = n % k;
  cout << min(mod, k - mod) << endl;

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

#include <algorithm>
#include <iostream>
using namespace std;

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


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  int res = min(n % k, abs(n % k - k));
  cout << res << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

// Replacing Integer

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

int main() {
  ll N, K, a, b;
  cin >> N >> K;
  a = N % K;
  b = abs(a - K);
  if (a >= b) {
    cout << b << endl;
  } else {
    cout << a << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

// Replacing Integer

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

int mabs(ll num) {
  if (num > 0)
    return num;
  else
    return -num;
}

int main() {
  ll N, K, Ans;
  cin >> N >> K;
  do {
    Ans = labs(N - K);
    if (Ans >= N) {
      break;
    }
    N = Ans;
  } while (true);

  cout << N << endl;
  return 0;
}