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

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

int main() {
  long long N, N_2, K;
  cin >> N >> K;
  N_2 = N % K;
  long long K_2 = K - N_2;
  cout << min(N_2, K_2) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long N, N_2, K;
  cin >> N >> K;
  if (N % K == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (true) {
    N_2 = abs(N - K);
    if (N < N_2) {
      cout << N << endl;
      break;
    } else {
      N = N_2;
    }
  }
}
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 a = n / k;
  int64_t ans;
  if (n % k == 0) {
    cout << "0" << endl;
  } else {
    ans = min(n - a * k, (a + 1) * k - n);
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int cnt = n / k;
  int ans;
  if (n < k) {
    cout << n << endl;
  } else if (n % k == 0) {
    cout << "0" << endl;
  } else {
    ans = min(abs(n - cnt * k), abs(n - (cnt + 1) * k));
    cout << ans << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
void minabs(long long int, long long int);

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

  return 0;
}
void minabs(long long int n, long long int k) {

  n = (n % k);

  while (n >= abs(n - k)) {
    n = abs(n - k);
  }
  cout << n << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  if (n < k) {
    cout << n << endl;
  } else {

    int x = n;
    int mini = INT_MAX;

    for (int i = 0; i < n - k + 1; i++) {
      x = abs(x - k);
      mini = min(mini, x);
    }
    cout << mini << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n - 1);
  return ans * n;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
bool is_prime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1)
    res = res * x % mod;
  return res;
}

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n - 1);
  return ans * n;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
bool is_prime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1)
    res = res * x % mod;
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll tmp1 = n % k;
  ll tmp2 = k % tmp1;
  if (tmp2)
    cout << min(tmp1, tmp2) << endl;
  else
    cout << tmp1 << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int r;
  r = N % K;
  if (r < K - r) {
    cout << r << endl;
  } else {
    cout << K - r << 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, a = 0;
  cin >> N >> K;
  a = N % K;
  cout << min(a, K - a) << endl;
}

Error: 0

Fixed submission:

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

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

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

int main(void) {
  long long n, k;
  cin >> n >> k;
  long long min = n % k;
  long long tmp = 0;
  while (true) {
    tmp = abs(min - k);
    if (min > tmp)
      min = tmp;
    else
      break;
  }
  cout << min << endl;
}


Error: TLE

Fixed submission:

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

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

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

int main() {
  ll m, n;
  cin >> n >> m;
  ll a = n / m;
  ll b = a + 1;
  cout << min(abs(n - (a * m)), abs(n - (b * m)));
}

Error: WA

Fixed submission:

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

int main() {
  ll m, n;
  cin >> n >> m;
  ll t = n;
  // cout << n%m;
  n = n % m;
  m = m % t;
  set<ll> st;
  while (max(n, m)) {
    if (st.find(n) != st.end())
      break;
    st.insert(n);
    n = abs(n - m);
  }
  ll min = 1000000000000000000;
  for (auto it : st)
    if (it < min)
      min = it;
  cout << min;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <set>
#include <vector>

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  long long p = N % K;
  long long ans = 0;
  do {
    ans = p;
    p = abs(ans - K);
  } while (ans > p);

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <set>
#include <vector>

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>

using namespace std;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  int p = N % K;
  int ans = 0;
  do {
    ans = p;
    p = abs(ans - K);
  } while (ans > p);

  cout << ans << endl;
  return 0;
}
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;
  N %= K;
  while (N > abs(N - K)) {
    N = abs(N - K);
  }
  cout << N << endl;
}

Error: TLE

Fixed submission:

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

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

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

Error: 0

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>

using namespace std;

int main() {
  // code

  long long i, j, k, n, m, p = 0;
  cin >> n >> k;
  cout << min(n % k, abs((n % k) - k)) << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>

using namespace std;

int main() {
  // code
  int tc;
  int i, j, k, n, m, p = 0;
  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;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7

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

  cout << (abs(n % k) < abs(k - (n % k)) ? abs(n % k) : abs(k - (n % k)))
       << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7

int main() {
  LL n, k;
  cin >> n >> k;
  LL n2 = n;

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

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

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <map>
#include <math.h>
#include <set>
#include <string>

#define INF 1000000000000
#define MOD 1000000007 // 10^9+7:合同式の法
#define JUUHATI 1000000000000000000
#define JUUHATIPLUS 1000000000000000001

using namespace std;
typedef long long ll;

// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

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

  if (N % K == 0 or N == K)
    ans1 = 0;
  else {
    ans1 = N % K;
    ans2 = ans1;
    if (K - ans1 < ans2)
      ans1 = K - ans2;
  }
  cout << ans1 << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <map>
#include <math.h>
#include <set>
#include <string>

#define INF 1000000000000
#define MOD 1000000007 // 10^9+7:合同式の法
#define JUUHATI 1000000000000000000
#define JUUHATIPLUS 1000000000000000001

using namespace std;
typedef long long ll;

// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

int main() {
  ll N, K, minx = JUUHATIPLUS, modK, ans;
  cin >> N >> K;

  if (K == 1)
    ans = 0;
  else {
    modK = abs(N - K);
    ans = N % modK;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define scd(x) scanf("%lf", &x)
#define l0(i, n) for (ll i = 0; i < n; i++)

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // CODE TONOY
  ll n, k;
  cin >> n >> k;
  cout << (ll)min(n % k, k - (n % k));
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define scd(x) scanf("%lf", &x)
#define l0(i, n) for (ll i = 0; i < n; i++)

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // CODE TONOY
  int n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k));
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

int main() {
  long long int N;
  long long int K;
  cin >> N >> K;
  long long int res = 1000000000000000001;
  if (N > K)
    N = N % K + K;
  while (N < res) {
    res = N;
    N = labs(N - K);
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

int main() {
  long long int N;
  long long int K;
  cin >> N >> K;
  long long int res = 1000000000000000001;
  while (N < res) {
    res = N;
    N = labs(N - K);
  }
  cout << res << 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;

  if (n % k == 0) {
    cout << "0" << endl;
  } else {
    cout << min(abs(n - (n / k) * k), abs(n - (n / k + 1) * k)) << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

long long gcd(long long N, long long K) {
  if (N > K)
    return gcd(K, N);
  if (K % N == 0)
    return N;
  else
    return gcd(K % N, N);
}

int main() {
  long long N;
  long long K;
  cin >> N >> K;
  cout << gcd(N, K) << endl;
  ;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

  ll a = N % K;

  ll b = fabs(a - K);

  if (a <= b) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

  int a = N % K;

  int b = fabs(a - K);

  if (a <= b) {
    cout << a << endl;
  } else {
    cout << b << endl;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  long long int n, k, m, p, x;
  cin >> n >> k;
  m = n % k;
  p = k - n % k;
  x = min(m, p);
  cout << x;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define f(i, a, b) for (int i = a; i <= b; i++)
inline ll read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
#define d read()
ll n, k;
ll ans;
int main() {
  scanf("%lld %lld", &n, &k);
  printf("%lld", min(n - n / k * k, -(n - n / k * k - k)));
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  if (N < K)
    cout << N;
  if (N % K == 0)
    cout << "0";
  if (N > K and N % K != 0)
    cout << abs(N - (N / K + 1) * K);
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, p, q;
  cin >> n >> k;
  if (n >= k) {
    p = n % k;
    q = abs(p - k);
    cout << min(p, q) << "\\n";
  } else {

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


Error: WA

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

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

  ll d = abs(N - K);
  while (d <= N) {
    N = d;
    d = abs(N - K);
  }
  cout << N << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
const int maxn = 100000 + 100;
using namespace std;
ll n, k, t;

int main() {
  cin >> n >> k;
  if (k == 0) {
    cout << n;
    return 0;
  }
  if (k > n) {
    cout << min(k - n, n);
    return 0;
  }
  t = n % k;
  cout << min(t, k - t);
  /*
std::ios::sync_with_stdio(false);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
const int maxn = 100000 + 100;
using namespace std;
long long int n, k, t;

int main() {
  cin >> n >> k;
  if (k == 0) {
    cout << n;
    return 0;
  }
  if (n < k) {
    swap(n, k);
  }
  t = n % k;
  cout << min(t, k - t);
  /*
std::ios::sync_with_stdio(false);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/

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

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <string>
#include <vector>

using namespace std;

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

  long long res = N % K;
  N = res;
  if (res == 0) {
    cout << "0" << endl;
    return 0;
  }

  while (res > abs(N - K)) {
    N = abs(N - K);
    res = N;
  }

  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <string>
#include <vector>

using namespace std;

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

  int res = N % K;
  N = res;
  if (res == 0) {
    cout << "0" << endl;
    return 0;
  }

  while (res > abs(N - K)) {
    N = abs(N - K);
    res = N;
  }

  cout << res << endl;
  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, m, x, y, z, q;
  cin >> n >> m;
  if (n == m || n % m == 0)
    cout << n % m;
  else if (n > m) {
    n %= m;
    x = abs(n - m), y = abs(x - m), z = abs(y - m);
    cout << min(min(x, y), z);
  } else {
    x = abs(n - m), y = abs(x - m), z = abs(y - m);
    cout << min(min(x, y), z);
  }
  return 0;
}

Error: TLE

Fixed submission:


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

int main() {
  ll n, m, x, y, z, q;
  cin >> n >> m;
  if (n == m || n % m == 0)
    cout << n % m;
  else if (n > m) {
    while (n > m)
      n -= m;
    x = abs(n - m), y = abs(x - m), z = abs(y - m);
    cout << min(min(x, y), z);
  } else {
    x = abs(n - m), y = abs(x - m), z = abs(y - m);
    cout << min(min(x, y), z);
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  if (n == 0)
    cout << 0 << endl;
  else if (k == 0)
    cout << n << endl;
  else if (n >= k) {

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (n == 0)
    cout << 0 << endl;
  else {
    if (n >= k)
      cout << n % k << endl;
  }
  if (n < k)
    cout << 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;
  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() {
  int N, K;
  cin >> N >> K;
  if (N >= K) {
    if (K == 1) {
      cout << "0" << endl;
      return 0;
    }

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

#include <bits/stdc++.h>
using namespace std;
// C - Traveling Salesman around Lake

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

  long long bn, n;
  bn = N + 1;
  n = N;

  long long rrr = N % K;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// C - Traveling Salesman around Lake

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

  long long bn, n;
  bn = N + 1;
  n = N;

  while (bn > n) {
    bn = n;
    n = abs(n - K);
  }

  cout << bn << endl;
}