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

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  long long N, K;
  cin >> N >> K;

  while (true) {
    N = N % K - K;
    if (N <= 0) {
      if (0 - N < N + K) {
        cout << 0 - N << endl;
        break;
      } else {
        cout << N + K << endl;
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  long long N, K;
  cin >> N >> K;

  while (true) {
    N = N - K;
    if (N <= 0) {
      if (0 - N < N + K) {
        cout << 0 - N << endl;
        break;
      } else {
        cout << N + K << endl;
        break;
      }
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  // your code goes here
  ll n, m;
  cin >> n >> m;
  n %= m;
  cout << min(n, m - n);
}


Error: WA

Fixed submission:

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

int main() {
  // your code goes here
  int n, m;
  cin >> n >> m;
  cout << (n % m);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ill long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;

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

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define ill long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;

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

/*-----------Author: Araz Jabrayilov---------*/
/*------------@araz17----(~~)#5371-----------*/

#include <bits/stdc++.h>

#define ll long long
#define endl '\\n'

using namespace std;

// int a[105];

int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  ll n;
  ll m;

  cin >> n >> m;
  n = n % m;

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

  return 0;
}


Error: 0

Fixed submission:

/*-----------Author: Araz Jabrayilov---------*/
/*------------@araz17----(~~)#5371-----------*/

#include <bits/stdc++.h>

#define ll long long
#define endl '\\n'

using namespace std;

// int a[105];

int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n = 0;
  int k = 0;
  int dif = 0;
  cin >> n >> k;
  n = n % k;

  int res = 0;

  res = min(n, abs(n - k));

  cout << res << endl;

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

#pragma region
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

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

  c = N / K;

  if (c >= 1) {
    N = abs(N - K * c);
  }

  cout << min(abs(N - K), N) << endl;
}

Error: 0

Fixed submission:

#pragma region
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

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

  c = N / K;

  if (c >= 1) {
    N = abs(N - K * c);
  }

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

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

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

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


Error: 0

Fixed submission:

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

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

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

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

int main() {
  long long int n, k, t;
  cin >> n >> k;
  t = n % k;
  cout << min(t, abs(t - k)) << endl;
  return 0;
}

Error: 0

Fixed submission:

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

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  long long a = N % K;
  long long ans = min(a, K - a);
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  int a = N % K;
  int ans = min(a, K - a);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fo(i, n) for (i = 0; i < n; i++)
#define fok(i, k, n) for (i = k; i < n; i++)
#define ci(x) cin >> x;
#define ci2(x, y) cin >> x >> y;
#define co(x) cout << x << "\\n";
#define co2(x, y) cout << x << " " << y << "\\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int mod = 1000000007;

int main() {
  ll n, k;
  ci2(n, k);
  cout << min(n % k, abs(n % k - k)) << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fo(i, n) for (i = 0; i < n; i++)
#define fok(i, k, n) for (i = k; i < n; i++)
#define ci(x) cin >> x;
#define ci2(x, y) cin >> x >> y;
#define co(x) cout << x << "\\n";
#define co2(x, y) cout << x << " " << y << "\\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int mod = 1000000007;

int main() {
  ll n, k;
  ci2(n, k);
  if (abs(n - k) > n) {
    co(n);
  } else {
    ll x = n % abs(n - k);
    x = min(x, k - x);
    co(x);
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

  int64_t answer = N;

  // Kは1以上

  int64_t a = 0;
  int64_t b = 0;

  if (N >= K) {
    a = N % K;
    b = K - (N % K);
    answer = min(a, b);
    cout << answer << endl;
  }

  else {
    if (N == 0) {
      answer = 0;
      cout << answer << endl;
    } else if (N < (K - N)) {
      answer = N;
      cout << answer << endl;
    } else {
      answer = (K - N);
      cout << answer << endl;
    }
  }
}


Error: 0

Fixed submission:

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

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

  int64_t answer = N;

  // Kは1以上

  int64_t a = 0;
  int64_t b = 0;

  if (N >= K) {
    a = N % K;
    b = K - (N % K);
    answer = min(a, b);
    cout << answer << endl;
  }

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

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define fi first
#define si second
#define mp make_pair
#define f(n) for (ll i = 0; i < n; i++)
#define ff(m) for (ll j = 0; j < m; j++)
#define fr(i, p, n) for (ll i = p; i < n; i++)
#define in insert
ll exp(ll a, ll b, ll m);
#define vl vector<ll>
#define pll pair<ll, ll>

void solve() {

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

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

  int t = 1;
  // cin>>t;
  while (t--)
    solve();

  return 0;
}

ll exp(ll a, ll b, ll m) {
  if (b == 0) {
    return 1;
  }
  ll temp = exp(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b & 1) {
    return (temp * (a % m)) % m;
  }
  return temp;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define fi first
#define si second
#define mp make_pair
#define f(n) for (ll i = 0; i < n; i++)
#define ff(m) for (ll j = 0; j < m; j++)
#define fr(i, p, n) for (ll i = p; i < n; i++)
#define in insert
ll exp(ll a, ll b, ll m);
#define vl vector<ll>
#define pll pair<ll, ll>

void solve() {

  int n, k;
  cin >> n >> k;
  cout << n % k;
}

int main() {

  int t = 1;
  // cin>>t;
  while (t--)
    solve();

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  long long X, K;
  cin >> X >> K;
  if (X == K || K == 1)
    cout << 0;
  else {
    X %= K;
    long long temp = X;
    X = abs(X - K);
    while (X < temp) {
      temp = X;
      X = abs(X - K);
    }
    cout << temp;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  long long X, K;
  cin >> X >> K;
  if (X == K || K == 1)
    cout << 0;
  else {
    long long temp = X;
    X = abs(X - K);
    while (X < temp) {
      temp = X;
      X = abs(X - K);
    }
    cout << temp;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: 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);
  if (n >= k)
    n = n % k;
  ans = n;
  if (k - n < ans)
    ans = k - n;
  printf("%lld\\n", ans);
  return 0;
}


Error: TLE

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);
  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;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

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

  n = n % k;
  while (abs(n - k) < n) {
    n = abs(n - k);
  }
  cout << n << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll m = n;
  while (1) {
    n = abs(n - k);
    if (m <= n)
      break;
    else
      m = n;
  }
  cout << m << "\\n";

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

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

int main() {
  ll i, n, k;
  scanf("%lld", &n);
  scanf("%lld", &k);

  ll p = n % k;
  ll pp = -1 * (p - k);
  if (p > pp)
    printf("%lld", pp);
  else
    printf("%lld", p);
  return 0;
}

Error: TLE

Fixed submission:

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

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


Error: TLE

Fixed submission:

#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;
      }
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: 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;

  N = N % K;

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

  cout << N;

  return 0;
}

Error: TLE

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;

  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, verdict: Runtime Error

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

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

  long long t = N % K;
  cout << min(t, K - t) << endl;
}

Error: 0

Fixed submission:

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

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

  int t = N % K;
  cout << min(t, K - t) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a, b, k1;
  cin >> a >> b;
  k1 = a % b;
  cout << min(k1, b - k1) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a, b;
  cin >> a >> b;
  int64_t k = abs(a - b);
  int64_t k1 = a % k;
  if (b != 1)
    cout << k1 << endl;
  else
    cout << 0 << endl;
}
Problem p02719 (C++) — buggy submission, verdict: 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 t = n % k;
  ll ans = min(t, k - t);
  cout << ans << endl;
}

Error: TLE

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 ans = n;
  while (1) {
    n = abs(k - n);
    if (n < ans)
      ans = n;
    else
      break;
  }
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: 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;
  n = n % k;
  while (n > abs(n - k))
    n = abs(n - k);
  cout << n << endl;
}

Error: TLE

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

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i, k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {

  ll K, N;
  cin >> N >> K;
  ll mae = N;
  while (1) {

    ll ab;
    if (N > K) {
      if (N % K == 0) {
        N = 0;
        break;
      }
      ab = N % K;
    } else {
      ab = abs(N - K);
    }

    if (ab < mae) {
      N = ab;
    } else {
      break;
    }
    mae = N;
  }

  cout << N << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i, k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long ll;

using namespace std;

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

  ll K, N;
  cin >> N >> K;
  ll mae = N;
  while (1) {

    ll ab;
    if (N > K) {
      if (N % K == 0) {
        N = 0;
        break;
      }
      ab = N % K;
    } else {
      if (K % N == 0) {
        break;
      }
      ab = abs(N - K);
    }

    if (ab < mae) {
      N = ab;
    } else {
      break;
    }
    mae = N;
  }

  cout << N << endl;

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

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

  ll ans = 0;
  ll tmp = n % k, tmp_prev = tmp;
  for (;;) {
    tmp = abs(tmp - k);
    if (tmp > tmp_prev) {
      ans = tmp_prev;
      break;
    }
    tmp_prev = tmp;
    // cout << tmp << " " << tmp_prev<< endl;
  }
  // tmp = n;
  // rep(i,n){
  //   tmp = abs(tmp - k);
  //   cout << tmp << " " << tmp_prev<< endl;
  // }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

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

  ll ans = 0;
  ll tmp = n, tmp_prev = n;
  for (;;) {
    tmp = abs(tmp - k);
    if (tmp > tmp_prev) {
      ans = tmp_prev;
      break;
    }
    tmp_prev = tmp;
    // cout << tmp << " " << tmp_prev<< endl;
  }
  // tmp = n;
  // rep(i,n){
  //   tmp = abs(tmp - k);
  //   cout << tmp << " " << tmp_prev<< endl;
  // }
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int main() {
  long N, K, X;
  std::cin >> N >> K;
  X = N % K;
  if (labs(X) > labs(X - K)) {
    std::cout << labs(X - K);
  } else {
    std::cout << labs(X);
  }
}

Error: WA

Fixed submission:

#include <iostream>

int main() {
  int N, K, X;
  std::cin >> N >> K;
  X = N % K;
  if (abs(X) > abs(X - K)) {
    std::cout << abs(X - K);
  } else {
    std::cout << abs(X);
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  ll x = n % k;
  ll y = abs(n % k - k);
  if (x > y)
    cout << y << endl;
  else
    cout << x << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  rep(i, n) cin >> a[i];
  int sum = 0;
  rep(i, n) sum += a[i];
  int cnt = 0;
  rep(i, n) {
    if (a[i] >= sum / 4 / m)
      cnt++;
  }
  if (cnt >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main() {
  ll n, k, ans = 0;

  cin >> n >> k;
  /// TLE
  //    for(int i=0;i<n;i++)
  //    {
  //
  //        ans=min(n,abs(n-k));
  //        n=ans;
  //    }
  //
  //     cout<<ans;

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main() {
  ll n, k, ans = 0;

  cin >> n >> k;

  for (int i = 0; i < n; i++) {

    ans = min(n, abs(n - k));
    n = ans;
  }

  cout << ans;

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

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

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

  ll a = min(n % m, m - (n % m));
  cout << a << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  long long a = min(n % m, m - (n % m));
  cout << a << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n, k, m, temp;
  int cnt = 3;
  cin >> n >> k;
  m = n;
  if (m > 0) {
    if (n > k) {
      n = n % k;
      m = min(m, n);
    }
    for (int i = 0; i < 2; ++i) {
      n = abs(n - k);
      m = min(m, n);
    }
  }
  cout << m << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long long n, k, m, temp;
  int cnt = 3;
  cin >> n >> k;
  m = n;
  if (m > 0) {
    while (1) {
      temp = n - k;
      if (temp < 0) {
        --cnt;
        if (cnt < 0) {
          break;
        }
        m = min(m, abs(temp));
      }
    }
  }
  cout << m << endl;
  return 0;
}