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

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

// #define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

int main() {

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

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


Error: TLE

Fixed submission:

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

// #define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

int main() {

  int N, K;
  cin >> N >> K;
  int min = N;
  while (true) {
    N = abs(N - K);
    if (N <= K / 2) {
      break;
    }
  }

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

#include <iostream>
using namespace std;

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

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

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

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

int main() {
  ll N, K;
  cin >> N >> K;
  ll x = N % K;
  ll y = K - x;
  cout << min(x, y) << endl;
}


Error: 0

Fixed submission:

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

int main() {
  ll N, K;
  cin >> N >> K;
  ll x = min(K, abs(N - K));
  ll y = max(K, abs(N - K));
  cout << y % x << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

  if (N % K < (K + 1) / 2)
    cout << N % K << endl;
  else
    cout << K - N % K << endl;
}

Error: 0

Fixed submission:

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

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

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
  ll int n, k;
  cin >> n >> k;

  ll int a = n % k;
  if (a == 0) {
    cout << "0\\n";
    return 0;
  }
  ll int b = a - k;
  b = b * (-1);
  if (a < b) {
    cout << a << "\\n";
    return 0;
  }
  cout << b << "\\n";
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;

ll int saiki(ll int n, ll int k) {
  ll int a = n - k;
  if (a < 0) {
    a = a * (-1);
  }
  if (n < a) {
    return n;
  } else {
    n = a;
    return saiki(n, k);
  }
}

int main() {
  ll int n, k;
  cin >> n >> k;
  if (n == k) {
    cout << "0\\n";
    return 0;
  }
  if (n == 0) {
    cout << "0\\n";
    return 0;
  }
  if (k == 1) {
    cout << "0\\n";
    return 0;
  }

  cout << saiki(n, k) << "\\n";
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
long long int MOD(long long int a) {
  if (a > 0)
    return a;
  else
    return (-1) * a;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int rem = n % m;
  if (n == 0 || m == 0)
    cout << n;
  else
    cout << min(rem, MOD(m - rem));
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int MOD(int a) {
  if (a > 0)
    return a;
  else
    return (-1) * a;
}
int main() {
  int n, m;
  cin >> n >> m;
  int rem = n % m;
  cout << min(rem, MOD(m - rem));
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long substract(long long a, long long b) { // 差の絶対値　3項演算
  long long num = (a - b);
  return (num > 0) ? num : -num;
}
int main() {
  long long N, K, m = 0;
  cin >> N >> K;
  m = N % K;
  if (m < substract(m, K)) {
    cout << m;
    return 0;
  } else {
    m = substract(m, K);
    cout << m;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int substract(int a, int b) { // 差の絶対値　3項演算
  int num = (a - b);
  return (num > 0) ? num : -num;
}
int main() {
  int N, K, m;
  cin >> N >> K;
  m = N;
  if (N % K == 0) {
    cout << 0;
    return 0;
  }
  while (1) {
    if (m < substract(m, K)) {
      cout << m;
      return 0;
    } else {
      m = substract(m, K);
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long int x, y;
  cin >> x >> y;
  long long int r = x % y, ans = min(y - r, r);

  cout << ans;
}


Error: WA

Fixed submission:

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

int main() {
  long int x, y;
  cin >> x >> y;
  long int ans = x, r = y % x;
  ans = min(r, x - r);
  cout << ans;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, K;
  cin >> N >> K;
  if (N == K)
    cout << 0 << endl;
  else if (N < K) {
    if (N * 2 > K)
      cout << K - N << endl;
    else
      cout << N << endl;
  } else {
    ll a;
    if (N % K == 0)
      cout << 0 << endl;
    else {
      ll a = (N / K) + 1;
      cout << abs(N - K * a) << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, K;
  cin >> N >> K;
  if (N == K)
    cout << 0 << endl;
  else if (N < K) {
    if (N * 2 > K)
      cout << K - N << endl;
    else
      cout << N << endl;
  } else {
    ll a;
    if (N % K == 0)
      cout << 0 << endl;
    else {
      ll a = (N / K) + 1;
      ll answer = 100000000000000100;
      for (ll i = 1; i <= a; i++) {
        answer = min(answer, abs(N - K * a));
      }
      cout << answer << endl;
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long int monmo(long long int n, long long int k, int keta) {
  if (n == 0) {
    return 0;
  } else if (keta < 0) {
    return n;
  } else {
    long long int tmpk;
    tmpk = k;
    for (int i = 0; i < keta; i++) {
      tmpk *= 10;
    }
    while (n >= tmpk) {
      n -= tmpk;
    }
    return monmo(n, k, keta - 1);
  }
}

int main(void) {
  long long int n, k, a, b, na, ka;
  int cn = 0, ck = 0;
  cin >> n >> k;
  na = n;
  ka = k;
  while (na > 9) {
    na /= 10;
    cn++;
  }
  while (ka > 9) {
    ka /= 10;
    ck++;
  }
  a = monmo(n, k, cn - ck);
  b = a - k;
  b *= -1;
  if (a > b)
    cout << b;
  else
    cout << a;
}

Error: TLE

Fixed submission:

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

long long int monmo(long long int n, long long int k, int keta) {
  if (n == 0) {
    return 0;
  } else if (keta == -1) {
    return n;
  } else {
    long long int tmpk;
    tmpk = k;
    for (int i = 0; i < keta; i++) {
      tmpk *= 10;
    }
    while (n >= tmpk) {
      n -= tmpk;
    }
    return monmo(n, k, keta - 1);
  }
}

int main(void) {
  long long int n, k, a, b, na, ka;
  int cn = 0, ck = 0;
  cin >> n >> k;
  na = n;
  ka = k;
  while (na > 9) {
    na /= 10;
    cn++;
  }
  while (ka > 9) {
    ka /= 10;
    ck++;
  }
  a = monmo(n, k, cn - ck);
  b = a - k;
  b *= -1;
  if (a > b)
    cout << b;
  else
    cout << a;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long int
#define MOD 1000000007

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

  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long int
#define MOD 1000000007

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

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

#include <iostream>
using namespace std;

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

  long long t = n % k;
  long long result = min(t, k - t);

  cout << result << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

// long long abs(long long num){
//     if(num<0){
//         return -1*num;
//     }
//     else{
//         return num;
//     }
// }

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

  long sub = n;
  long prev_sub;
  while (true) {
    prev_sub = sub;
    sub = abs(sub - k);
    if (sub > prev_sub) {
      break;
    }
  }

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

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

Error: TLE

Fixed submission:

#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;
  while (N > abs(N - K)) {
    N = abs(N - K);
  }
  cout << N;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool cmp(int a, int b) { return a > b; }

int main() {

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

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

  bool check = 0;
  if (n % k == 0) {
    check = 1;
    cout << "0";
  }

  if (check == 0) {
    long long int a = n / k;
    long long int tmp = n - a * k;
    cout << min(abs(tmp - k), tmp);
  }

  return 0;
}


Error: TLE

Fixed submission:

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

bool cmp(int a, int b) { return a > b; }

int main() {

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

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

  bool check = 0;
  if (n % k == 0) {
    check = 1;
    cout << "0";
  }

  if (check == 0) {
    set<long long int> s;
    s.insert(n);
    long long int tmp = n;
    bool in = 0;
    while (1) {
      long long int a = abs(tmp - k);
      auto it = s.find(a);

      if (it != s.end())
        break;
      else if (in == 1) {
        s.insert(a);
        break;
      }
      if (a < k) {
        // cout<<"hi"<<endl;
        in = 1;
      }
      s.insert(a);
      tmp = a;
    }
    long long int min = *min_element(s.begin(), s.end());
    cout << min;
  }

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

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

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


Error: 0

Fixed submission:

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

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

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

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

  long long int minimum = min(x, K - x);
  cout << minimum << endl;
}

Error: TLE

Fixed submission:

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

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

  int minimum = x;

  for (int i = 0; i < K; i++) {
    x = K - x;
    minimum = min(minimum, x);
  }

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

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

Error: -8

Fixed submission:

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

#include <cstdlib>
#include <iostream> // 백준 12840
using namespace std;

typedef long long int ll;

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

  ll n, k;
  cin >> n >> k;
  n = n % k;
  while (abs(n - k) < n)
    n = abs(n - k);
  cout << n;

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream> // 백준 12840
using namespace std;

typedef long long int ll;

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

  ll n, k;
  cin >> n >> k;
  while (abs(n - k) < n)
    n = abs(n - k);
  cout << 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 data = n % k;
  long long ans = min(data, k - data);

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  long long n, k;
  cin >> n >> k;
  long long data = 0;
  long long ans;
  if (k == 1) {
    ans = 0;
  } else {
    if (n > k) {
      data = n % k;
      ans = k - data;
    } else if (n == k) {
      ans = 0;
    } else {
      if (n == 1) {
        ans = 0;
      } else {
        if (k % n == 0) {
          ans = n;
        } else {
          data = k % n;
          ans = n - data;
        }
      }
    }
  }

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

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

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


Error: 0

Fixed submission:

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

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

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

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

Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#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: Time Limit Exceeded

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

int main() {
  long long n, k;
  cin >> n >> k;
  long long min = n;
  if (n > k) {
    n = n % k;
  }
  if (n % k == 0) {
    cout << 0;
    return 0;
  }
  while (1) {
    n = abs(n - k);
    if (n < min && n != 0) {
      min = n;
    } else {
      cout << min;
      return 0;
    }
  }
  if (n != 0) {
    cout << min;
  } else {
    cout << 0;
  }
}

Error: TLE

Fixed submission:

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

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  long long n, k;
  cin >> n >> k;
  set<long long> st;
  long long n_min = n;
  while (st.count(n) == 0) {
    st.insert(n);
    n = abs(n - k);
    n_min = min(n, n_min);
  }
  cout << n_min << 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);

  return 0;
}

Error: 0

Fixed submission:

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

int main() {

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

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

  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++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

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;
#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 A = abs(N - K);

  ll D = min(K, A);

  cout << N % D << endl;
}
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;
  cout << min(N % K, K - (N % K)) << 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) {
    long long amari;
    amari = n % k;

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

Error: 0

Fixed submission:

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

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

  if (n >= k) {
    int amari;
    amari = n % k;

    if (abs(amari - k) < amari)
      cout << abs(amari - k) << endl;
    else
      cout << amari << endl;
  } else {
    if (k - n < n)
      cout << k - n << endl;
    else
      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) {
    if (n % k > k - n % k)
      cout << k - n % k << endl;
    else
      cout << n % k << endl;
  } else if (n == k)
    cout << 0 << endl;
  else {
    if (k - n < n)
      cout << k - n << endl;
    else
      cout << n << endl;
  }
}

Error: 0

Fixed submission:

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

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

  if (n > k) {
    if (n % k > k - n % k)
      cout << k - n % k << endl;
    else
      cout << n % k << endl;
  } else if (n == k)
    cout << n << endl;
  else {
    if (k - n < n)
      cout << k - n << endl;
    else
      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;

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


Error: 0

Fixed submission:

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

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

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1001001001;
const long long INFL = (1LL << 60);
const double eps = (1e-9);

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

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

  if (n == k || n == 0) {
    puts("0");
    return 0;
  }

  ll ans = n;

  if (n > k) {
    n -= (n / k) * k;
  }

  chmin(ans, n);

  for (int i = 0; i < 100; i++) {
    n = abs(n - k);
    chmin(ans, n);
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1001001001;
const long long INFL = (1LL << 60);
const double eps = (1e-9);

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

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

  if (n == k) {
    puts("0");
    return 0;
  }

  ll ans = n;

  if (n > k) {
    n -= (n / k) * k;
  } else {
    n -= k - (k / n) * n;
  }

  chmin(ans, n);

  for (int i = 0; i < 100; i++) {
    n = abs(n - k);
    chmin(ans, n);
  }

  cout << ans << endl;

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

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  if (N < abs(N - K)) {
    cout << N;
  }
  if (N % K == 0) {
    cout << '0';
  }
  if (N % K == 1) {
    cout << '1';
  }
}
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 N, K;
  cin >> N >> K;
  long x = N % K;
  long y = K - x;
  cout << min(x, y) << 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 x = N % K;
  int y = K - x;
  cout << min(x, y) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  long long t = N % K;
  long long u = min(t, K - t);
  cout << u << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int t = N % K;
  int u = min(t, K - t);
  cout << u << endl;
}