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

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main() {
  fast;
  ll n, k;
  cin >> n >> k;
  cout << min(n % k, k - n % k) << '\\n';
  return 0;
}
ll strtoint(string str) {
  ll x = 0;
  stringstream ss;
  ss << str;
  ss >> x;
  return x;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main() {
  fast;
  ll n, k;
  cin >> n >> k;
  while (true) {
    n = abs(n - k);
    if (k == 1)
      break;
    if (abs(n - k) <= n)
      continue;
    else
      break;
  }
  (k == 1) ? cout << 0 << '\\n' : cout << n << '\\n';
  return 0;
}
ll strtoint(string str) {
  ll x = 0;
  stringstream ss;
  ss << str;
  ss >> x;
  return x;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, k;
  cin >> n >> k;
  cout << min({n % k, (n + k - 1) / k * k - n, n}) << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  cout << min({n % k, (n + k - 1) / k * k - n, n}) << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll N, K;
  cin >> N >> K;
  N = N > K ? N % K : K - N;
  while (1) {
    if (N == 0)
      break;
    ll absdif = (N > K ? N % K : K - N);
    if (N > absdif) {
      N = absdif;
    } else {
      break;
    }
  }
  cout << N << endl;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  ll N, K;
  cin >> N >> K;
  N = (N % K > K % N ? N % K : K % N);
  while (1) {
    if (N == 0)
      break;
    ll absdif = ((N % K > K % N) ? N % K : K % N);
    if (N > absdif) {
      N = absdif;
    } else {
      break;
    }
  }
  cout << N << endl;

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

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x;
  cin >> n >> k;
  x = min(n % k, k - n % k);
  cout << x << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  cin >> n >> k;

  cout << min(k - n % k, n % k) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n, k;

  cin >> n >> k;

  cout << min(k - n % k, n % k) << endl;
}
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 hel = min(n % k, k - (n % k));
  cout << hel << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, k;
  cin >> n >> k;
  n = n - (n / k) * k;
  long long int hell = INT_MAX;
  while (1) {
    n = abs(n - k);
    if (n == hell) {
      break;
    }
    hell = n;
  }

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

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

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

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

Error: 0

Fixed submission:

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

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

  if (n < k)
    x = k % n;
  else
    x = n % k;
  if (n != k)
    cout << min(x, k - x) << endl;
  else
    cout << 0 << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  using namespace std;
  long int N, K;
  cin >> N >> K;

  if (K == 1) {
    printf("0\\n");
  } else if (N > K) {
    long int tmp = N % K;
    printf("%ld", abs(tmp - K));
  } else {
    while (true) {
      if (N < abs(N - K)) {
        printf("%ld\\n", N);
        break;
      } else {
        N = abs(N - K);
      }
    }
  }
}

Error: TLE

Fixed submission:

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

int main(void) {
  using namespace std;
  long int N, K;
  cin >> N >> K;

  while (true) {
    if (K == 1) {
      printf("0\\n");
      break;
    }
    if (N < abs(N - K)) {
      printf("%ld\\n", N);
      break;
    } else {
      N = abs(N - K);
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  if (N > K) {
    N = N % K;
  }

  while ((2 * N) > K) {
    N = abs(N - K);
  }
  cout << N << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

  while ((2 * N) > K) {
    N = abs(N - K);
  }
  cout << N << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define REP(i, a, n) for (int i = a; i < n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;

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

  n = n % k;

  cout << min(n, k - n) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define REP(i, a, n) for (int i = a; i < n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;

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

  if (k == 1)
    cout << 0 << endl;
  else {
    set<ll> abc;
    while (true) {
      n = abs(n - k);
      if (abc.find(n) != abc.end())
        break;
      else
        abc.insert(n);
    }
    cout << *(abc.begin()) << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x, y;
ll abs2(ll f) {
  if (f < 0)
    return -f;
  return f;
}
ll min2(ll a, ll b) {
  if (a < b)
    return a;
  return b;
}
int main() {
  cin >> x >> y;
  if (x > y) {
    x = x - (x / y) * y;
  }
  cout << min2(abs2(x - y), abs2(x));
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x, y;
ll abs2(ll f) {
  if (f < 0)
    return -f;
  return f;
}
ll min2(ll a, ll b) {
  if (a < b)
    return a;
  return b;
}
int main() {
  cin >> x >> y;
  while (x > y) {
    x = x - y;
  }
  cout << min2(abs2(x - y), abs2(x));
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int64_t a = 0;
  int64_t b = 0;
  a = n % k;

  b = a - k;
  if (b < 0)
    b = b * (-1);

  cout << min(a, b) << endl;
}

Error: TLE

Fixed submission:

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

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

  int64_t a = 0;

  while (1) {
    a = n - k;
    if (a < 0)
      a = a * (-1);

    if (a < n)
      n = a;
    else
      break;
  }

  cout << n << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  long N, K, cnt = 0;
  cin >> N >> K;
  while (N - K > 0) {
    N -= K;
  }
  if (abs(N - K) < N) {
    N = abs(N - K);
  }
  cout << N;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  unsigned long long int n, k, n1;
  cin >> n >> k;
  n1 = n;
  while (n >= 0) {
    n = n - k;
  }
  n = llabs(n);
  if (n > n1) {
    cout << n1;
  } else
    cout << n;

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

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <type_traits>
#include <vector>

typedef long long ll;

using namespace std;

// 素因数分解
void factoring(ll n, map<ll, ll> &mp) {
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1)
    mp[n]++;
}

// 絶対値
template <class T, class U = std::make_unsigned_t<T>> U SafeAbs(T x) {
  return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

int main() {

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

  ll min = n;

  if (n % k == 0) {
    min = 0;
  } else {
    min = n % k;
    while (true) {
      if (SafeAbs(k - min) < min) {
        min = SafeAbs(min - k);
      } else {
        break;
      }
    }
  }

  cout << min << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <type_traits>
#include <vector>

typedef long long ll;

using namespace std;

// 素因数分解
void factoring(ll n, map<ll, ll> &mp) {
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1)
    mp[n]++;
}

// 絶対値
template <class T, class U = std::make_unsigned_t<T>> U SafeAbs(T x) {
  return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

int main() {

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

  ll min = n;

  while (true) {
    if (SafeAbs(min - k) < min) {
      min = SafeAbs(min - k);

    } else {
      break;
    }
  }

  cout << min << endl;

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

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

int run_test() {
  ll n, k;
  cin >> n >> k;
  ll t = n / k;
  n -= k * t;
  if (abs(n - k) < n) {
    n = abs(n - k);
  }
  cout << n;
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  while (t--) {
    run_test();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x, d) cout << fixed << setprecision(d) << x
#define fill(a, b) memset((a), (b), sizeof((a)))
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);                   \\
  srand(time(NULL));
ll power(ll x, ll y, ll m) {
  ll r = 1;
  for (; y; y >>= 1) {
    if (y & 1)
      r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

int run_test() {
  ll n, k;
  cin >> n >> k;
  while (abs(n - k) < n) {
    n = abs(n - k);
  }
  cout << n;
  return 0;
}

int main() {
  FAST;
  ll t;
  t = 1;

  while (t--) {
    run_test();
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;

int main() {
  int64_t i, K, N;
  cin >> N >> K;
  int64_t diff;
  diff = N % K;
  int64_t mi;
  mi = min(K - diff, diff);
  cout << mi;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;

int main() {
  int i, K, N;
  cin >> N >> K;
  int diff;
  diff = N % K;
  int mi;
  mi = min(K - diff, diff);
  cout << mi;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long long int p, q;
  p = n % k;
  q = k - n % k;
  if (p < q)
    cout << p << endl;
  else
    cout << q << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

  while (1) {
    if (n <= 1000 * k)
      break;
    n -= 1000 * k;
  }

  long long int x = n;
  while (1) {
    if (abs(x - k) < x) {
      x = abs(x - k);
      // cout << x << endl;
    } else
      break;
  }
  cout << x << endl;

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  long n, k;
  cin >> n >> k;
  double d;
  long a;
  if (k == 0) {
    a = 0;
  } else {
    a = n / k;
  }
  long ans = min(abs(n - a * k), abs(n - ((a + 1) * k)));
  // d=(double)n/k;
  // if(d>((int)(n/k))+0.5){a=(int)d+1;}
  // else{a=(int)d;}
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  double d;
  int a;
  a = n / k;
  int ans = min(abs(n - a * k), abs(n - ((a + 1) * k)));
  // d=(double)n/k;
  // if(d>((int)(n/k))+0.5){a=(int)d+1;}
  // else{a=(int)d;}
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout << setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
#define lint long long
#define FOR(i, a, b) for (lint i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

lint euclidean_gcd(lint a, lint b) {
  lint r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lint n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout << setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
#define lint long long
#define FOR(i, a, b) for (lint i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  if (n % k != 0)
    cout << gcd(n, k) << endl;
  else
    cout << 0 << endl;
  return 0;
}
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 ans = n % k;

  if (ans > k / 2) {
    ans = k - ans;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  while (n >= k / 2) {
    if (n >= k) {
      n -= k;
    } else {
      n = k - n;
    }
  }
  cout << n << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <string.h>
#define pb push_back
#define all(v) v.begin(), v.end()
#define see(x) cout << #x << " : " << (x) << endl;
#define ya cout << "yes" << endl;
#define no cout << "no" << endl;
#define ff first
#define sc second
typedef long long ll;
using namespace std;
const ll N = 1e5 + 7;
ll n, k, i, j, ans;
int main() {
  //    ios::sync_with_stdio(false);
  //    cin.tie(NULL),cout.tie(NULL);
  cin >> n >> k;
  if ((n == k) || k == 1 || n == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (n < k) {
    k = n - k;
    if (k < 0)
      k = -k;
    cout << (ll)min(n, k) << endl;
  } else {
    ll p = n % k;
    k = k - p;
    if (k < 0)
      k = -k;
    cout << (ll)min(n, k) << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <cstring>
#include <string.h>
#define pb push_back
#define FAST                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(), cout.tie();
typedef long long ll;
// const long double pi = acos(-1.0);
// const int mod = 1e9+7;
using namespace std;
int main() {
  // FAST
  ll n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << "0\\n";
  } else if (k % n == 0) {
    cout << n << endl;
    ;
    return 0;
  }
  cout << k % n << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

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

int main() {
  long int X, K;
  cin >> X >> K;

  if (X > K) {
    X = X % K + K;
  }

  while (true) {
    if (X >= K) {
      X = max(X - K, K - X);
    } else if (X <= K / 2) {
      break;
    } else {
      X = K - X;
      break;
    }
  }

  cout << X << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long int X, K;
  cin >> X >> K;

  if (X > K) {
    X = X % K + K;
  }

  while (true) {
    if (X >= K) {
      X = max(X - K, K - X);
    } else if (X < K / 2) {
      break;
    } else {
      X = K - X;
    }
  }

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

#include <stdio.h>
int main() {
  long int a, b, c;
  scanf("%ld %ld", &a, &b);
  long int d = a % b;
  if (b % 2 == 1) {
    if (d <= (b - 1) / 2) {
      printf("%ld", d);
    } else {
      c = b - d;
      printf("%ld", c);
    }
  } else {
    if (d < b / 2) {
      printf("%ld", d);
    } else {
      c = b - d;
      printf("%ld", c);
    }
  }
}


Error: WA

Fixed submission:

#include <stdio.h>
int main() {
  unsigned int a, b, c;
  scanf("%d, %d", &a, &b);
  unsigned int d = b - a % b;
  if (b % 2 == 1) {
    if (d <= (b - 1) / 2) {
      printf("%d", d);
    } else {
      c = b - d;
      printf("%d", c);
    }
  } else {
    if (d < b / 2) {
      printf("%d", d);
    } else {
      c = b - d;
      printf("%d", c);
    }
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846

#define REP(i, s, n) for (ll i = s; i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;

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

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846

#define REP(i, s, n) for (ll i = s; i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = N % (abs(N - K));
  while (true) {
    if (abs(ans - K) < ans) {
      ans = abs(ans - K);
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
  ll N, K;
  cin >> N >> K;
  if (N >= K) {
    N = N % K;
  }
  while (true) {
    ll N_tmp = abs(N - K);
    if (N_tmp > N) {
      cout << N << endl;
      return 0;
    }
    N = N_tmp;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
  ll N, K;
  cin >> N >> K;
  if (N % K == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (true) {
    ll N_tmp = abs(N - K);
    if (N_tmp > N) {
      cout << N << endl;
      return 0;
    }
    N = N_tmp;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

  if (N % K > K - (N % K)) {
    cout << K - (N % K) << endl;
  }

  if (N % K < K - (N % K)) {
    cout << N % K << endl;
  }
}

Error: 0

Fixed submission:

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

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

  if (N % K == K - (N % K)) {
    cout << N % K << endl;
  }

  if (N % K > K - (N % K)) {
    cout << K - (N % K) << endl;
  }

  if (N % K < K - (N % K)) {
    cout << N % K << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
#define ff first
#define ss second
#define N 200005
#define mod 1000000007
#define fo(n) for (int i = 1; i <= n; i++)
typedef pair<int, int> pii;
typedef long long int ll;
typedef long int li;
int mod1 = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

Error: WA

Fixed submission:

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

#define pb push_back
#define ff first
#define ss second
#define N 200005
#define mod 1000000007
#define fo(n) for (int i = 1; i <= n; i++)
typedef pair<int, int> pii;
typedef long long int ll;
typedef long int li;
int mod1 = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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