alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  ll a, b;
  cin >> a >> b;
  cout << min(a % b, b % a);
  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 diff = abs(N - K);
          long long prev_diff = N;

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

          bool flag = true;
          while(flag) {
                  if(diff >= prev_diff)
                          flag = false;
                  else {
                          prev_diff = diff;
                          diff = abs(diff - K);
                  }
          }
  */
  N %= K;
  if (N >= abs(N - K))
    cout << abs(N - K) << endl;
  else
    cout << N << endl;
}

Error: TLE

Fixed submission:

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

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

  long long diff = abs(N - K);
  long long prev_diff = N;

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

  bool flag = true;
  while (flag) {
    if (diff >= prev_diff)
      flag = false;
    else {
      prev_diff = diff;
      diff = abs(diff - K);
    }
  }

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

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


Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
long long n, k;

int main(void) {
  long long ans, t;
  scanf("%lld%lld", &n, &k);
  if (n % k == 0) {
    cout << "0";
    return 0;
  }
  if (n > k)
    n %= k;
  n = min(n, abs(n - k));
  cout << n;
  return 0;
}

Error: TLE

Fixed submission:

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

ll f(ll a) {
  if (a < 0)
    return -a;
  else
    return a;
}

int main() {
  ll a, b, c;
  cin >> a >> b;
  c = a - b;
  f(c);
  if (b == 1) {
    cout << "0" << endl;
  } else {
    while (f(a - b) < a) {
      a = f(a - b);
    }
    cout << a << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

// Do not get frustrated over WA. Check for edge cases and runtime errors :)
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k;
  cin >> n >> k;
  if (abs(n - k) > n)
    cout << n;
  else if (k == 1 || n == k)
    cout << 0;
  else {
    cout << min(n % k, abs(n % k - k));
  }
  return 0;
}


Error: WA

Fixed submission:

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

// Do not get frustrated over WA. Check for edge cases and runtime errors :)
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k;
  cin >> n >> k;
  if (abs(n - k) > n)
    cout << n;
  else if (k == 1)
    cout << 0;
  else {
    cout << n % abs(n - k);
  }
  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;
  long long J = N / K;
  long long ans;
  long long ichi, ni;
  ichi = N - K * J;
  ni = K * (J + 1) - N;
  ans = min(ichi, ni);
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int J;
  int ans;
  if (K == 0) {
    ans = N;
  }

  if (N > K) {
    J = N % K;
    K -= J;
    ans = K;
  } else {
    ans = 100000000;
    for (int i = 0; i < 111; i++) {
      ans = min(N, ans);
      if (N > K)
        N -= K;
      else
        N = K - N;
      ans = min(N, ans);
    }
  }

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

#include <bits/stdc++.h>

using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;
#define PI 3.14159265359
bool dp[100100];

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;
#define PI 3.14159265359
bool dp[100100];

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

  while (N > K / 2) {
    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;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define ALL(x) (x).begin(), (x).end()
#define IN(type, a)                                                            \\
  type a;                                                                      \\
  cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n)                                                            \\
  cout << fixed << setprecision(n) << (x) << endl // 小数をn桁で出力

int main() {
  IN(ll, n);
  IN(ll, k);
  n %= k;
  COUT(min(n, abs(k - n)));
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define ALL(x) (x).begin(), (x).end()
#define IN(type, a)                                                            \\
  type a;                                                                      \\
  cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n)                                                            \\
  cout << fixed << setprecision(n) << (x) << endl // 小数をn桁で出力

int main() {
  IN(int, n);
  IN(int, k);
  n %= k;
  COUT(min(n, abs(k - n)));
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  if (n % m == 0) {
    cout << 0 << endl;
    return 0;
  }
  long long fff = n % m;
  long long ans = n;
  for (int i = 0; i < n % m; i++) {
    fff = fff - m;
    if (fff < 0)
      fff = fff * -1;
    ans = min(ans, fff);
  }
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
  long long N, K;
  cin >> N >> K;

  if (N % K == 0) {
    cout << 0 << endl;
  } else {
    cout << min(N % K, K - N % K) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
  int N, K;
  cin >> N >> K;

  if (N % K == 0) {
    cout << 0 << endl;
  } else {
    cout << min(N % K, K - N % K) << endl;
  }

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

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

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ll long long

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

  cout << min(n % k, abs(n % k - k));

  return 0;
}

Error: TLE

Fixed submission:

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

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ll long long

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

  if (n % k == 0)
    cout << 0;
  else {
    set<int> s;
    s.insert(abs(n - k));
    n = abs(n - k);
    while (1) {
      n = abs(n - k);
      if (s.find(n) != s.end()) {
        cout << min(n, abs(n - k));
        break;
      } else
        s.insert(n);
    }
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define endl '\\n'

using namespace std;

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

  long long n, k;

  cin >> n >> k;

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define endl '\\n'

using namespace std;

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

  long long n, k;

  cin >> n >> k;

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

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

/******************************************
 * Author : sinon.su96@gmail.com
 * Or : ahafid96@gmail.com
 * Username : SINON
 * Date : April 2020
 * Civil and Structural engineering student
 * at Ecole des Ponts ParisTech
 * ***************************************/

// Import usefull library :
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

// usefull abreviation
#define fi first
#define se second
#define pb push_back
#define sqr(x) (x) * (x)
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;

int main() {
  long long n, k;
  long long x;
  cin >> n >> k;
  x = n % k;
  while (abs(x - k) < x) {
    x = abs(x - k);
  }
  cout << x << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

/******************************************
 * Author : sinon.su96@gmail.com
 * Or : ahafid96@gmail.com
 * Username : SINON
 * Date : April 2020
 * Civil and Structural engineering student
 * at Ecole des Ponts ParisTech
 * ***************************************/

// Import usefull library :
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

// usefull abreviation
#define fi first
#define se second
#define pb push_back
#define sqr(x) (x) * (x)
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;

int main() {
  long long n, k;
  long long x;
  cin >> n >> k;
  x = n;
  while (abs(x - k) < x) {
    x = abs(x - k);
  }
  cout << x << "\\n";
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>

using namespace std;

int main() {
  long n, k;
  cin >> n >> k;
  long option1, option2;
  option1 = n - n / k * k;
  option2 = abs(option1 - k);
  if (option1 > option2)
    cout << option2 << endl;
  else
    cout << option1 << endl;

  return 0;
}


Error: TLE

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

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

// c++ -std=c++14 atcoder.cpp
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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


Error: 0

Fixed submission:

// c++ -std=c++14 atcoder.cpp
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int64_t n, k;
  cin >> n >> k;
  int16_t ans;
  if (n >= k) {
    ans = n % k;
    if (ans > k - ans) {
      ans = k - ans;
    }
  } else {
    ans = k % n;
    if (ans > n - ans) {
      ans = n - ans;
    }
  }

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

#include <iostream>
// #include <math.h>

using namespace std;

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

  x = N % K;

  if (x < abs(x - K))
    cout << x << endl;
  else
    cout << abs(x - K) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>

using namespace std;

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

  x = N % K;

  if (x < abs(x - K))
    cout << x << endl;
  else
    cout << abs(x - K) << endl;

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

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

int main() {

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

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

  long long tmp = abs(n - k);

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

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

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

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

  long long tmp = abs(n - k);

  do {
    n = tmp;
    tmp = abs(n - k);
  } while (n > tmp);

  cout << n << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (int i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a) memset(a, 0, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repA(i, a, b) for (int i = a; i <= b; i++)
#define repD(i, b, a) for (int i = b; i >= a; i--)
#define fill(a) memset(a, 0, sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  ll n, k;
  cin >> n >> k;
  map<ll, ll> mp;
  ll mn = n;
  while (mp[n] != 1) {
    mp[n] = 1;
    n = abs(n - k);
    mn = min(mn, n);
  }
  cout << mn << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define mx 1000002
#define fastio                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
int32_t main() {
  ll n, m;
  cin >> n >> m;
  cout << min(abs(m - n % m), n % m) << "\\n";
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define mx 1000002
#define fastio                                                                 \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
int32_t main() {
  int n, m;
  cin >> n >> m;
  cout << min(n, n % m) << "\\n";
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

ll n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n >> m;
  bool ok = true;
  if (n % m == 0)
    cout << 0, ok = false;
  if (ok) {
    if (abs(n - m) > n)
      cout << n;
    else {
      cout << abs((n % m) - m);
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

ll n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n >> m;
  bool ok = true;
  if (n % m == 0)
    cout << 0, ok = false;
  if (ok) {
    if (abs(n - m) > n)
      cout << n;
    else {
      while (abs(n - m) < n) {
        n = abs(n - m);
      }
      cout << n;
    }
  }

  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;
  long long a;
  a = n % k;
  long long ans;
  ans = min(a, k - a);
  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 temp;
  while (n != 0) {
    if (n % k == 0) {
      n = 0;
    } else if (n >= k) {
      temp = n - k;
    } else {
      temp = k - n;
    }

    if (temp <= n) {
      n = temp;
    } else {
      break;
    }
  }
  cout << n << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define ll long long int

int main(void) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;

  n %= m;
  n = (n < abs(n - m)) ? n : abs(n - m);

  cout << n << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define ll long long int

int main(void) {

  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m;
  cin >> n >> m;
  while (true) {
    if (n < abs(n - m))
      break;
    n = abs(n - m);
  }

  cout << n << endl;
  return 0;
}