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, k;
  cin >> n >> k;
  long long d1 = n / k;
  long long d2 = d1 + 1;
  long long a1 = abs(n - (d1 * k));
  long long a2 = abs(n - (d2 * k));
  cout << min(a1, a2);
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
long int N, K;
int main() {
  cin >> N >> K;
  if (N < K) {
    cout << min(N, K - N) << endl;
  } else {
    long int r = N % K;
    if (r != 0) {
      cout << min(r, K - r) << endl;
    } else {
      cout << r << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int N, K;
int main() {
  cin >> N >> K;
  if (N < K) {
    cout << min(N, K - N) << endl;
  } else {
    int r = N % K;
    if (r != 0) {
      cout << min(K - r, r) << endl;
    } else {
      cout << r << endl;
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n, k;
  cin >> n >> k;
  long long c = n, x;
  x = n / k;
  c = n - k * x;
  while (c > k / 2) {
    if (c > k) {
      c = c - k;
    } else {
      c = k - c;
    }
  }
  cout << c << endl;
}

/*　答えはkの半分以下のいずれか。*/

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int c = n;
  while (c > k / 2) {
    if (c > k) {
      c = c - k;
      continue;
    } else {
      c = k - c;
    }
  }
  cout << c << endl;
}

/*　答えはkの半分以下のいずれか。*/
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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


Error: TLE

Fixed submission:

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

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

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

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

int main() {
  int x, k, save_p, flag;
  flag = 0;
  cin >> save_p >> k;

  if (k == 1) {
    cout << 0;
  } else {
    while (flag == 0) {
      x = abs(save_p - k);
      if (save_p < x || save_p == 0) {
        cout << save_p;
        flag = 1;
      } else {
        save_p = x;
      }
    }
  }

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

#include <bits/stdc++.h>
#define ll long long int
#define vll vector<ll>
#define uset unordered_set<string>
using namespace std;

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

  ll n, k, ans = 0, diff;
  cin >> n >> k;

  diff = n - k;
  ans = abs(diff) % k;
  ll temp = abs(ans - k);
  if (temp < ans) {
    ans = abs(ans - k);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define vll vector<ll>
#define uset unordered_set<string>
using namespace std;

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

  ll n, k, ans = 0;
  cin >> n >> k;
  ll a, b;

  a = max(n, k);
  b = min(n, k);

  if (a % b == 0) {
    ans = 0;
  } else {
    ll temp = a;
    a /= b;
    b *= a;

    ans = temp - b;
    // cout << ans << " " << temp << " " << a << " " << b << endl;
    if (abs(ans - k) >= 0) {
      ans = abs(ans - k);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

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

  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  long long int n, k, m;
  cin >> n >> k;
  long long int time = n / k;
  if (k * time != n) {
    time += 1;
  }
  m = 0;
  if (n % k == 0) {
    cout << 0;
    return 0;
  }
  for (long long int i = 0; i < time; ++i) {
    if (n - k < 0) {
      m = k - n;
    } else {
      m = n - k;
    }
    if (i < time - 1) {
      n = m;
    }
  }
  if (n > m) {
    cout << m;
  } else {
    cout << n;
  }

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

#include <fstream>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;

int main() {

  // long long min = numeric_limits<long long>::max();

  long long n, k;

  cin >> n >> k;

  long long t = n % k;

  long long e;

  if (abs(t - k) < n % k) {
    cout << abs(t - k) << endl;
  } else {
    cout << n % k << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <fstream>
#include <iostream>
#include <limits>
#include <vector>
using namespace std;

int main() {

  long long min = numeric_limits<long long>::max();

  long long n, k;

  cin >> n >> k;

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

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

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

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

  cout << min(K - t, t) << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, K, t;
  cin >> N >> K;
  t = N % K;
  int C = K - t;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> //strcmp、strncmp関数を使うために必要

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

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> //strcmp、strncmp関数を使うために必要

int main() {
  int N, K;
  // bool j = true;
  // vector<int> vec(N);
  cin >> N >> K;
  // int n = N;
  int t = 0;

  /*if(N==0 || K==1 || N==K){
      cout << 0 << endl;
      j = false;
  }*/

  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() {
  long long n, k;
  cin >> n >> k;
  cout << min(n % k, k - n % k);
}

Error: WA

Fixed submission:

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

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  long long n = 0, k = 0;
  cin >> n >> k;
  long long a = llabs(n - k);
  n = llabs(a - k);
  while (n < a) {
    a = n;
    n = llabs(n - k);
  }
  cout << a << 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;
  if (n % k == 0)
    cout << n % k;
  else if (n < k) {
    if (abs(n - k) < n)
      cout << abs(n - k);
    else
      cout << n % k;
  } else
    cout << k - n % 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 == 0)
    cout << n % k;
  else if (n < k)
    cout << n;
  else
    cout << k - 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 a, b;
  a = N % K;
  b = K - a;

  if (a < b)
    cout << a;
  else
    cout << b;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, K;

  cin >> N >> K;

  int a, b;
  a = N % K;
  b = K - a;

  if (a < b)
    cout << a;
  else
    cout << b;

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

#include <bits/stdc++.h>
#define f(i, j, k) for (int i = j; i < k; i++)
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  if (a > b) {
    a = a % b;
  }
  cout << min(a, b - a) << endl;
  ;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define f(i, j, k) for (int i = j; i < k; i++)
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  while (a > abs(a - b)) {
    a = abs(a - b);
  }
  cout << a << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

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

#include <iostream>
using namespace std;

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

  long long int a, b;
  a = N % K;
  b = abs(a - K);

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

  int a, b;
  a = N % K;
  b = abs(a - K);

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

#include <bits/stdc++.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
double node[maxn];

int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n % k;
  ll b = k - a;
  cout << min(a, b) << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
double node[maxn];

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

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
int main() {
  ll N, K;
  cin >> N >> K;
  ll tmp = N % K;
  ll Tmp = K - tmp;
  if (tmp < Tmp) {
    cout << tmp << endl;
  } else {
    cout << Tmp << endl;
  }
}

Error: TLE

Fixed submission:

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
int main() {
  ll N, K;
  cin >> N >> K;
  ll tmp = N % K;
  vector<ll> ans = {tmp};
  for (ll i = 0; i < tmp; i++) {
    ll Tmp = K - ans.at(i);
    Tmp = Tmp % K;
    ans.push_back(Tmp);
  }
  sort(ans.begin(), ans.end());
  cout << ans.at(0) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  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;

int main() {
  long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << "0" << endl;
  } else {
    long x = 0, y = 0;
    for (int i = 0; i < n; i++) {
      n = abs(n - k);
      if (n == x || n == y) {
        break;
      }
      y = x;
      x = n;
    }
    cout << min(x, y) << 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;
  cout << min(n % k, k - n % 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: Runtime Error

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

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


Error: 0

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf = 1000001000;
ll INF = 100000000000000000;
ll MOD = 1000000007;
// g++ code.cpp   ./a.out

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf = 1000001000;
ll INF = 100000000000000000;
ll MOD = 1000000007;
// g++ code.cpp   ./a.out

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

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
long k;
long calc(long n) {
  long result = abs(n - k);
  if (n < result)
    return n;
  return calc(result);
}

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

  while (n > k) {
    n = n % k;
  }
  cout << calc(n) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
long k;
long calc(long n) {
  long result = abs(n - k);
  if (n < result)
    return n;
  return calc(result);
}

int main() {
  long n;
  cin >> n >> k;
  if (k == 1)
    cout << 0 << endl;
  else
    cout << calc(n) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdarg.h>
#include <string>
#include <vector>
using ll = long long;

using namespace std;

int main() { /*7日目*/
             // 少数も使いたい割り算はしない方がいい
  //  数値の大きさ
  // for文で0代入する場所はforの一文下
  // オーバーフローする一手手前を分解して作る・ 割り算で減らしていく
  // for文いつも間違える/ i<nなら最後はa[n-1]
  ll n, k;
  cin >> n >> k;
  ll am = n % k;
  ll ma = am - k;
  if (am > -ma)
    cout << -ma;
  else
    cout << am;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdarg.h>
#include <string>
#include <vector>
using ll = long long;

using namespace std;

int main() { /*7日目*/
             // 少数も使いたい割り算はしない方がいい
  //  数値の大きさ
  // for文で0代入する場所はforの一文下
  // オーバーフローする一手手前を分解して作る・ 割り算で減らしていく
  // for文いつも間違える/ i<nなら最後はa[n-1]
  ll n, k;
  cin >> n >> k;
  ll k2;
  if (k == 1) {
    cout << "0";
    return 0;
  }
  k2 = k / 2;

  bool con = true;
  while (con) {
    if (n < k2 and n >= 0) {
      cout << n;
      break;
    } else if (n < 0) {
      cout << -n;
      break;
    }
    n -= k;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>

using namespace std;
typedef long long ll;

int main(void) {
  ll n, k;
  cin >> n >> k;
  ll r = n % k;
  ll ans = min(r, llabs(k - r));
  cout << ans;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>

using namespace std;
typedef long long ll;

int main(void) {
  ll n, k;
  cin >> n >> k;
  if (n > k) {
    ll ans = min(n % k, llabs(n - (n % k)));
    cout << ans;
  }

  else {
    ll ans = min(k % n, llabs(k - (k % n)));
    cout << ans;
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

Error: WA

Fixed submission:

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

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

int n, k;

signed main() {
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int n, k;

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

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

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

  int64_t ans = n % k;
  if (k - ans < ans) {
    cout << k - ans;
  } else {
    cout << ans;
  }
}

Error: 0

Fixed submission:

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

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

  float y = n / k;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int N, K;
  cin >> N;
  cin >> K;
  long int d = N % K;
  if (d <= K / 2) {
    cout << d << endl;
  } else {
    cout << K - d << endl;
  }
}

Error: 0

Fixed submission:

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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) REP(i, 1, n + 1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x, y) make_pair(x, y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 510000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

ll n, k;

int main() {

  cin >> n >> k;

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

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) REP(i, 1, n + 1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x, y) make_pair(x, y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 510000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

int n, k;

int main() {

  cin >> n >> k;

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

  return 0;
}