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

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(n) (n).begin(), (n).end()
#define ll long long

void solve() {
  int n, m;
  cin >> n >> m;
  int a[101];

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll sum = 0;

  for (int i = 0; i < n; i++) {
    sum += a[i];
  }

  int cnt = 0;

  for (int i = 0; i < n; i++) {
    if (a[i] >= (sum / (m * 4.0))) {
      cnt++;
      if (cnt == m) {
        cout << "Yes" << '\\n';
        return;
      }
    }
  }

  cout << "No" << '\\n';
}

int main() {

  solve();

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(n) (n).begin(), (n).end()
#define ll long long

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  // Write from here.
  int n, m;
  cin >> n >> m;

  std::vector<int> v(n);
  int sum_votes = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum_votes += v[i];
  }
  int popular_no = (int)((1.0 / (4.0 * m)) * sum_votes);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] >= popular_no) {
      cnt++;
    }
  }
  if (cnt == m) {
    cout << "Yes\\n";
  } else
    cout << "No\\n";

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

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int, int>;
using psi = pair<string, int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++)
#define repdown(i, n) for (in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647

int main() {
  kyun;
  int n, m;
  cin >> n >> m;
  vi data(n);
  rep(i, n) cin >> data[i];
  double sum = 0;
  cout << fixed << setprecision(10);
  rep(i, n) sum += data[i];
  sort(all(data));
  reverse(all(data));
  bool ans = 1;
  double check = sum / (4 * m);
  if (check > data[m - 1])
    ans = 0;
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int, int>;
using psi = pair<string, int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++)
#define repdown(i, n) for (in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647

int main() {
  kyun;
  int n, m, sum;
  cin >> n >> m;
  vi data(n);
  rep(i, n) cin >> data[i];
  sum = 0;
  rep(i, n) sum += data[i];
  sort(all(data));
  reverse(all(data));
  m--;
  bool ans = 1;
  int check = sum / (4 * m);
  if (check >= data[m])
    ans = 0;
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  string s;
  cin >> n >> m;
  vector<int> v(n);
  int sum = 0;
  rep(i, n) {
    cin >> v[i];
    sum += v[i];
  }
  int can = 0;
  rep(i, n) {
    if (v[i] >= (sum + 4 * m - 1) / (4 * m)) {
      can++;
      // cout << v[i] << endl;
    }
  }
  if (can >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  string s;
  vector<int> v(n);
  cin >> n >> m;
  int sum = 0;
  int ans = 0;
  rep(i, n) {
    cin >> v[i];
    sum += v[i];
  }
  rep(i, n) {
    if ((sum / 4 * m) < v[i])
      ans++;
  }
  if (ans >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

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

#include <stdio.h>

int main(void) {
  int n, m, sum = 0, c = 0;
  int a[100] = {};

  scanf("%d %d", &n, &m);

  for (int i = 0; i < n; i++) {
    scanf("%d ", &a[i]);
    sum += a[i];
  }

  for (int j = 0; j < n; j++) {
    if (a[j] >= 0.25 * sum / m)
      c++;
  }

  if (c >= m)
    printf("Yes\\n");
  else
    printf("No\\n");

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int n, m, sum = 0, c = 0;
  int a[100];

  scanf("%d %d", &n, &m);

  for (int i = 0; i < n; i++) {
    scanf("%d ", a[i]);
    sum += a[i];
  }

  for (int j = 0; j < n; j++) {
    if (a[j] >= 0.25 * sum / m)
      c++;
  }

  if (c >= m)
    printf("Yes\\n");
  else
    printf("No\\n");

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);

  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  double sum = accumulate(vec.begin(), vec.end(), 0);

  if (vec.at(n - m) >= sum / (4 * m)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);

  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int sum = accumulate(vec.begin(), vec.end(), 0);

  if (vec.at(n - m + 1) >= sum / (4 * m)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  float Q = 0;
  cin >> N >> M;

  vector<int> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Q += A[i];
  }

  sort(A.rbegin(), A.rend());

  if (A.at(M - 1) >= Q / (4 * M)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, M, Q = 0;
  cin >> N >> M;

  vector<int> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Q += A[i];
  }

  if (A.at(M) > Q / (4 * M)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m, i, sumt;
  double mm;
  int k;

  sumt = 0;
  k = 0;
  cin >> n >> m;
  int a[n];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sumt += a[i];
  }
  mm = sumt / (4.0 * m);

  for (i = 1; i <= n; i++) {
    if (a[i] >= mm)
      k++;
  }

  if (k >= m) {
    wcout << "Yes" << endl;
  } else {
    wcout << "No" << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, i, sumt;
  double mm;
  int k;

  sumt = 0;
  k = 0;
  cin >> n >> m;
  int a[n];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sumt += a[i];
  }
  mm = sumt / (4.0 * m);
  for (i = 1; i <= n; i++) {
    if (a[n] >= mm)
      k++;
  }

  if (k >= m) {
    wcout << "Yes" << endl;
  } else {
    wcout << "NO" << endl;
  }

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

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)

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

int main() {

  fastio;

  ll t;
  t = 1;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    ld a[n];
    ld sum = 0;
    rep(i, n) {
      cin >> a[i];
      sum += a[i];
    }
    sort(a, a + n);
    if (m > n)
      cout << "No";
    else {
      if (a[n - m] >= (double)(sum / (double)(4 * m)))
        cout << "Yes";
      else
        cout << "No";
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  ll t;
  t = 1;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    ld a[n];
    ld sum = 0;
    rep(i, n) {
      cin >> a[i];
      sum += a[i];
    }
    sort(a, a + n);
    if (m > n)
      cout << "No";
    else {
      if (a[n - m] >= (double)(sum / (double)(4 * m)))
        cout << "Yes";
      else
        cout << "No";
    }
  }
  return 0;
}
Problem p02718 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int a[100];
  int N, M;
  int f = 1;
  int p;

  cin >> N >> M;

  for (int i = 1; i <= N; i++) {
    cin >> a[i - 1];
  }

  while (f) {
    for (int i = 1; i <= N; i++) {
      if (a[i - 1] < a[i] && i != N) {
        p = a[i - 1];
        a[i - 1] = a[i];
        a[i] = p;
        break;
      }
      if (i == N)
        f = 0;
    }
  }

  int sum = 0;
  for (int i = 1; i <= N; i++) {
    sum += a[i - 1];
  }

  if (a[M - 1] * 4 * M >= sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N, 0);

  for (int i = 1; i <= N; i++) {
    cin >> a.at(i - 1);
  }

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int sum = 0;
  for (int i = 1; i <= N; i++) {
    sum += a.at(i - 1);
  }

  if (a.at(M) * 4 * M >= sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

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

#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int sum = 0;
  REP(i, N) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  int count = 0;
  REP(i, N) {
    if (A.at(i) * 4 * M >= sum) {
      ++count;
    }
  }

  if (count >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int sum = 0;
  REP(i, N) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(), A.end());

  for (int i = N - 1; i >= (N - 1 - M); --i) {
    if (A.at(i) < sum / (4 * M)) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n); i >= 0; --i)
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} fast_ios_;

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

  int sum = 0;
  vector<int> a(N);
  rep(i, N) {
    cin >> a[i];
    sum += a[i];
  }

  double m4 = sum / 4.0 / M;
  int mm = M;
  rep(i, N) {
    if (a[i] >= m4) {
      --mm;
    }
    if (mm == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n); i >= 0; --i)
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} fast_ios_;

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

  int sum = 0;
  vector<int> a(M);
  rep(i, N) {
    cin >> a[i];
    sum += a[i];
  }

  int m4 = sum / 4.0 / M;
  int mm = M;
  rep(i, N) {
    if (a[i] >= m4) {
      --mm;
    }
    if (mm == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define endl "\\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define endl "\\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  int sum = 0, cnt = 0;
  rep(i, 0, n) {
    cin >> a[i];
    sum += a[i];
  }
  rep(i, 0, n) {
    if ((double)a[i] > (double)(sum / (4 * m)))
      cnt++;
  }
  if (cnt >= m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  long n, k, t;
  cin >> n >> k;
  t = n % k;
  cout << min(t, k - t) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, k;

  cin >> n >> k;
  int t;
  int m = 1;
  if (k == 1) {
    cout << 0 << endl;
    m = 0;
  }
  while (m) {
    t = n - k;
    if (t < 0) {
      t = -t;
    }
    if (t == n || t == 0) {
      cout << t << endl;
      m = 0;
    } else
      n = t;
  }

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

  return 0;
}

Error: WA

Fixed submission:

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

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

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

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

int main() {
  int64_t x, y;
  cin >> x >> y;
  int64_t a, b;
  a = x % y;
  b = y - a;
  cout << min(a, b) << 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 x, y;
  cin >> x >> y;
  int a = 10000000, b = 10000000;
  a = x % y;
  if (a != 0)
    b = x % a;
  cout << min(a, b) << endl;
}
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;
  cout << min(n % k, k - n % k) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int zet(int a, int b) {
  if (a - b > 0) {
    return a - b;
  } else {
    return b - a;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  int ans = N;
  set<int> s;
  while (!s.count(ans)) {
    s.insert(ans);
    int d;
    d = zet(ans, K);
    ans = min(ans, d);
  }
  cout << ans << 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;
  int64_t number, number_before;

  N = N % K;
  number_before = N;
  number = N - K;
  if (number < 0) {
    number *= -1LL;
  }
  N = number;

  while (1) {
    number = N - K;
    if (number < 0) {
      number *= -1LL;
    }
    if (number == number_before) {
      cout << min(number, N) << endl;
      break;
    }
    number_before = N;
    N = number;
  }
}

Error: 0

Fixed submission:

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

int main() {

  int N, K;
  cin >> N >> K;
  int number, number_before;

  N = N % K;
  number_before = N;
  number = max(N, K) - min(N, K);
  N = number;

  while (1) {
    number = max(N, K) - min(N, K);
    if (number == number_before) {
      cout << min(number, N) << endl;
      break;
    }
    number_before = N;
    N = number;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int N, K, min1, tmp1, tmp2, tmp3;
  min1 = 1000000000000000001;
  cin >> N >> K;

  tmp1 = N / K;
  tmp2 = N - tmp1 * K;
  tmp3 = -1 * (N - (tmp1 + 1) * K);
  min1 = min(tmp2, tmp3);

  cout << min1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long long int N, K, tmp, min1;
  min1 = 1000000000000000001;
  cin >> N >> K;

  while (true) {

    if (K == 1) {
      min1 = 0;
      break;
    }

    if (N > K) {
      tmp = N - K;
    } else {
      tmp = K - N;
    }

    if (tmp > N) {
      min1 = N;
      break;
    }

    if (min1 < tmp) {
      break;
    }

    min1 = tmp;
    N = tmp;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define 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: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

int main() {
  long long int a, n, k;
  cin >> n >> k;
  bool check = true;
  while (check) {
    a = n;
    n = abs(n - k);
    if (a <= n)
      break;
  }
  cout << a << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  if (n == m || n % m == 0) {
    cout << '0';
  } else {
    n = n % m;
    vector<long long> v;
    for (long long i = 0; i < 2; i++) {
      n = abs(n - m);
      v.push_back(n);
    }
    sort(v.begin(), v.end());
    cout << v[0];
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  if (n == m || n % m == 0) {
    cout << '0';
  } else {
    n = n % m;
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      n = abs(n - m);
      v.push_back(n);
    }
    sort(v.begin(), v.end());
    cout << v[0];
  }
  return 0;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

template <typename T>

inline T read() {
  T x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -f;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c - 48);
    c = getchar();
  }
  return x * f;
}

#define lint long long int
#define ulint unsigned lint

const lint inf = 1e18 + 1e7;
const int MAXN = 1e5 + 1e1;

map<lint, bool> m;

lint n, k, minn = inf;

int main(void) {

  // freopen("testdata.in","r",stdin);
  // freopen("testdata.out","w",stdout);

  scanf("%lld%lld", &n, &k);

  n -= (n / k) * k;

  while (!m[n]) {
    m[n] = true;
    n -= k;
    if (n < 0)
      n = -n;
    minn = min(minn, n);
  }

  printf("%lld\\n", minn);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

template <typename T>

inline T read() {
  T x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -f;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c - 48);
    c = getchar();
  }
  return x * f;
}

#define lint long long int
#define ulint unsigned lint

const lint inf = 1e18 + 1e7;
const int MAXN = 1e5 + 1e1;

bool t[MAXN];

lint n, k, minn = inf;

int main(void) {

  // freopen("testdata.in","r",stdin);
  // freopen("testdata.out","w",stdout);

  scanf("%lld%lld", &n, &k);

  n -= (n / k) * k;

  while (!t[n]) {
    t[n] = true;
    n -= k;
    if (n < 0)
      n = -n;
    minn = min(minn, n);
  }

  printf("%lld\\n", minn);

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

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

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

  ll n, k;
  cin >> n >> k;
  set<ll> S;

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

  } else {
    while (1) {
      n = min(n, abs(n - k));
      if (S.count(n)) {
        cout << n << "\\n";
        break;
      }
      S.insert(n);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

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

  ll n, k;
  cin >> n >> k;
  set<ll> S;

  if (n % k == 0)
    cout << 0 << "\\n";
  else {
    int mi = n;
    while (1) {
      n = min(n, abs(n - k));
      if (S.count(n)) {
        cout << n << "\\n";
        break;
      }
      S.insert(n);
    }
  }

  return 0;
}