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

#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(), s.end()
#define FIN                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

const int MAXN = 200010;
vector<ll> v[MAXN], v2[MAXN];

int main() {
  FIN;
  int t;
  cin >> t;
  while (t--) {
    ll n, ans = 0;
    cin >> n;
    fore(i, 0, n + 1) v[i].clear(), v2[i].clear();
    fore(i, 0, n) {
      int k, l, r;
      cin >> k >> l >> r;
      if (l - r > 0)
        ans += r, v[k - 1].pb(l - r);
      else
        ans += l, v2[k].pb(r - l);
    }
    multiset<ll> did;
    fore(i, 0, n) {
      for (auto x : v[i]) {
        if (SZ(did) < i + 1)
          did.insert(x);
        else if (*did.begin() < x)
          did.erase(did.begin()), did.insert(x);
      }
    }
    for (auto x : did)
      ans += x;

    did.clear();
    for (int i = n - 1; i >= 0; i--) {
      for (auto x : v2[i]) {
        if (SZ(did) < (n - i))
          did.insert(x);
        else if (*did.begin() < x)
          did.erase(did.begin()), did.insert(x);
      }
    }
    for (auto x : did)
      ans += x;

    cout << ans << "\\n";
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(), s.end()
#define FIN                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

const int MAXN = 200010;
vector<ii> v[MAXN];

int main() {
  FIN;
  int t;
  cin >> t;
  while (t--) {
    ll n, ans = 0;
    cin >> n;
    fore(i, 0, n) v[i].clear();
    fore(i, 0, n) {
      int k, l, r;
      cin >> k >> l >> r;
      ans += r;
      v[k - 1].pb({l - r, k - 1});
    }
    multiset<ii> did;
    fore(i, 0, n) {
      for (auto x : v[i]) {
        if (SZ(did) < i + 1)
          did.insert(x);
        else if (did.begin()->fst < x.fst)
          did.erase(did.begin()), did.insert(x);
      }
    }
    vector<ii> h;
    for (auto x : did)
      h.pb(x);
    sort(ALL(h));
    reverse(ALL(h));
    fore(i, 0, n) {
      if (h[i].snd >= i)
        ans += h[i].fst;
      else if (h[i].fst >= 0)
        ans += h[i].fst;
    }
    cout << ans << "\\n";
  }
}
Problem p02610 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define endl '\\n'

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (; t; t--) {
    int n;
    cin >> n;
    vector<int> k(n), l(n), r(n);
    vector<pair<int, int>> vl(n);
    for (int i = 0; i < n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      k[i]--;
      vl[i] = {(l[i] - r[i]), i};
    }
    sort(vl.rbegin(), vl.rend());
    int ans = 0;
    set<int> q;
    for (int i = 0; i < n; i++)
      q.insert(i);
    for (int i = 0; i < n; i++) {
      if (vl[i].first <= 0)
        break;
      int id = vl[i].second;
      auto t = q.upper_bound(k[id]);
      if (t == q.begin()) {
        ans += r[id];
      } else {
        ans += l[id];
        t--;
        q.erase(t);
      }
    }
    for (int i = 0; i < n; i++)
      q.insert(i);
    for (int i = n - 1; i >= 0; i--) {
      if (vl[i].first > 0)
        break;
      int id = vl[i].second;
      auto t = q.upper_bound(k[id]);
      if (t == q.end())
        ans += l[id];
      else {
        ans += r[id];
        q.erase(t);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define endl '\\n'

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (; t; t--) {
    int n;
    cin >> n;
    vector<int> k(n), l(n), r(n);
    vector<pair<int, int>> vl(n);
    for (int i = 0; i < n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      k[i]--;
      vl[i] = {(l[i] - r[i]), i};
    }
    sort(vl.rbegin(), vl.rend());
    int ans = 0;
    set<int> q;
    for (int i = 0; i < n; i++)
      q.insert(i);
    for (int i = 0; i < n; i++) {
      if (vl[i].first <= 0)
        break;
      int id = vl[i].second;
      auto t = upper_bound(q.begin(), q.end(), k[id]);
      if (t == q.begin()) {
        ans += r[id];
        // cout << id << " r" << endl;
      } else {
        ans += l[id];
        t--;
        q.erase(t);
        // cout << id << " l" << endl;
      }
    }
    for (int i = 0; i < n; i++)
      q.insert(i);
    for (int i = n - 1; i >= 0; i--) {
      if (vl[i].first > 0)
        break;
      // cout << vl[i].first << " " << vl[i].second << endl;
      int id = vl[i].second;
      auto t = upper_bound(q.begin(), q.end(), k[id]);
      if (t == q.end())
        ans += l[id];
      else {
        ans += r[id];
        q.erase(t);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02610 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

void solve() {
  int N;
  cin >> N;

  vector<int> diff1[N + 1], diff2[N + 2];
  ll ans = 0;
  REP(i, N) {
    int K, L, R;
    cin >> K >> L >> R;
    if (L >= R)
      diff1[K].push_back(L - R);
    else
      diff2[K + 1].push_back(R - L);
    ans += min(L, R);
  }

  priority_queue<int, vector<int>, greater<int>> que;
  FOR(i, 1, N + 1) {
    for (int d : diff1[i])
      que.push(d);
    while (que.size() > i)
      que.pop();
  }
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  FOR(i, 1, N + 1) {
    for (int d : diff2[N + 1 - i])
      que.push(d);
    while (que.size() > i)
      que.pop();
  }
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;
}

int main() {
  int T;
  cin >> T;
  REP(i, T) solve();
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

vector<int> diff1[200001], diff2[200002];

void solve() {
  REP(i, 200001) diff1[i].clear();
  REP(i, 200002) diff2[i].clear();
  int N;
  cin >> N;

  ll ans = 0;
  REP(i, N) {
    int K, L, R;
    cin >> K >> L >> R;
    if (L >= R)
      diff1[K].push_back(L - R);
    else
      diff2[K + 1].push_back(R - L);
    ans += min(L, R);
  }

  priority_queue<int, vector<int>, greater<int>> que;
  FOR(i, 1, N + 1) {
    for (int d : diff1[i])
      que.push(d);
    while (que.size() > i)
      que.pop();
  }
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  FOR(i, 1, N + 1) {
    for (int d : diff2[N + 1 - i])
      que.push(d);
    while (que.size() > i)
      que.pop();
  }
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;
}

int main() {
  int T;
  cin >> T;
  REP(i, T) solve();
  return 0;
}
Problem p02611 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long expo(long long base, long long exponent, long long mod) {
  long long ans = 1;
  while (exponent != 0) {
    if (exponent & 1)
      ans = (1LL * ans * base) % mod;
    base = (1LL * base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}
long long inv[10004];
long long C(long long n, long long r) {
  long long res = 1, cur = 1;
  for (long long i = n; i > r; i--) {
    res = res * i % 1000000007;
    res = res * inv[cur] % 1000000007;
    cur++;
  }
  return res;
}
void solve() {
  long long n, ans = 0;
  cin >> n;
  if (n < 5) {
    cout << 0 << endl;
    return;
  }
  n -= 5;
  for (long long i = 0; i < 12; i++) {
    long long r = n - i;
    if (r < 0)
      break;
    if (r % 2)
      continue;
    r /= 2;
    ans = (ans + C(11, i) * C(15 + r, r) % 1000000007) % 1000000007;
  }
  cout << ans << endl;
}

int main() {
  for (long long i = 1; i < 102; i++) {
    inv[i] = expo(i, 1000000005, 1000000007);
  }
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, s1, s2, n1, n2, u1, u2, k1, k2, e1, e2;
long long a[100000000];
long long ddd(int x) {
  long long ans = 0;
  for (s1 = 0; s1 <= x; s1++) {
    for (s2 = s1 + 1; s2 <= x; s2++) {
      for (n1 = 0; n1 <= x; n1++) {
        for (n2 = n1 + 1; n2 <= x; n2++) {
          for (u1 = 0; u1 <= x; u1++) {
            for (u2 = u1 + 1; u2 <= x; u2++) {
              for (k1 = 0; k1 <= x; k1++) {
                for (k2 = k1 + 1; k2 <= x; k2++) {
                  for (e1 = 0; e1 <= x; e1++) {
                    for (e2 = e1 + 1; e2 <= x; e2++) {
                      if ((s1 + s2 + n1 + n2 + u1 + u2 + k1 + k2 + e1 + e2) <=
                          x) {
                        ans += (s2 - s1) * (n2 - n1) * (u2 - u1) * (k2 - k1) *
                               (e2 - e1);
                        ans %= 1000000007;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return ans;
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    cout << ddd(a[i]);
  }
  return 0;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 1000 == 0)
    cout << 0 << endl;
  else
    cout << ((n / 1000) + 1) * 1000 - n << endl;
  return 0;
}


Error: 100

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 1000 == 0)
    return 0;
  else
    return ((n / 1000) + 1) * 1000 - n;
  return 0;
}
Problem p02612 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int ans = 0;

  if (n < 1000) {
    ans = 1000 - n;
    cout << ans << endl;
    return 0;
  } else if (n % 1000 == 0) {
    cout << ans << endl;
    return 0;
  } else {
    while (n > 1000) {
      n -= 1000;
      ans = 1000 - n;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

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

  int ans = 0;
  while (n <= 10000 || n > 1000) {
    if (n % 1000 == 0)
      break;
    n = n - 1000;
    ans = 1000 - n;
  }

  cout << ans << endl;

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


#include <iostream>

using namespace std;

int main() {

  int N;
  cin >> N;

  if (N % 1000) {
    cout << (1000 - N % 1000) << std::endl;
  } else {
    cout << N % 1000 << endl;
  }

  return 0;
}

Error: 1

Fixed submission:


#include <iostream>

using namespace std;

int main() {

  int N;
  cin >> N;

  if (N % 1000) {
    cout << (1000 - N % 1000) << std::endl;
  } else {
    cout << N % 1000 << endl;
  }

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

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

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

  if (n % 1000 != 0)
    cout << 1000 - n % 1000 << endl;
  else
    cout << 0 << endl;
}


Error: TLE

Fixed submission:

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

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

  for (int i; i = 1; i++) {
    if (i * 1000 >= n) {
      cout << i * 1000 - n << endl;
      break;
    }
  }
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;

int main() {
  int ans;
  int n;
  scanf("%d", &n);
  if (n % 1000 == 0) {
    ans = 0;
  } else {
    ans = 1000 - n % 1000;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: 100

Fixed submission:

#include <iostream>
int main() {
  int ans;
  int n;
  std::cin >> n;
  ans = 1000 - n % 1000;
  return ans;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  n = n % 1000;
  n = 1000 - n;
  if (n == 1000)
    cout << 0 << endl;
  else
    cout << n << endl;
}


Error: 100

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  n = n % 1000;
  n = 1000 - n;
  if (n == 1000)
    return 0;
  return n;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long
#define ll long long
#define pb push_back

#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, a, b) for (int i = (a); i > (b); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

const int mod = 1e9 + 7;
const ll inf = 2e18 + 5;

void solve() {
  int n, k;
  cin >> n;
  int m = n % 1000;
  m = 1000 - m;
  if (m == 1000)
    cout << 0 << endl;
  else
    cout << m << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("fin.txt", "r", stdin);
  freopen("fout.txt", "w", stdout);
#endif
  int cases = 1;
  // cin>>cases;

  for (int iter = 0; iter < cases; iter++) {
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

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

#define int long long
#define ll long long
#define pb push_back

#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, a, b) for (int i = (a); i > (b); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

const int mod = 1e9 + 7;
const ll inf = 2e18 + 5;

void solve() {
  int n, k;
  cin >> n;
  int m = n % m;
  m = n - m;
  if (m == n)
    cout << 0 << endl;
  else
    cout << m << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("fin.txt", "r", stdin);
  freopen("fout.txt", "w", stdout);
#endif
  int cases = 1;
  // cin>>cases;

  for (int iter = 0; iter < cases; iter++) {
    solve();
  }
  return 0;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int tmp = 0;
  while (tmp < n) {
    tmp += 1000;
  }
  cout << tmp - n;
}

Error: 132

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int cask;
  cin >> cask;
  cout << cask % 1000;
  if (cask % 1000 != 0) {
    return (cask % 1000);
  }
  return 0;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 1000 == 0)
    cout << 0;
  else
    cout << 1000 - n % 1000;
  return 0;
}


Error: 100

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << 1000 - n % 1000;
  return 1000 - n % 1000;
}
Problem p02612 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;

  cin >> a;
  if (a % 1000 == 0) {
    cout << 0;
  } else
    cout << 1000 - (a % 1000);

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  while (true) {

    cin >> a;
    if (a % 1000 == 0) {
      cout << 0;
    } else
      cout << 1000 - (a % 1000);
  }

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

#include <iostream>
using namespace std;
int main() {
  int bill;

  cin >> bill;
  if (bill % 1000 == 0) {

    cout << "0" << endl;
  } else {
    int return_bill = 1000 - (bill % 1000);
    cout << return_bill << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int bill;
  while (1) {
    cin >> bill;
    int return_bill = 1000 - (bill % 1000);
    cout << return_bill << endl;
  }
  return 0;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

/// You just can't beat the person who never gives up

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n;
bool Never_give_up() {
  cin >> n;
  cout << (n + 999) / 1000 * 1000 - n << endl;
  return 0;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // scanf("%d",&t);
  while (t--)
    Never_give_up();
  return 0;
}

Error: WA

Fixed submission:

/// You just can't beat the person who never gives up

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n;
bool Never_give_up() {
  cin >> n;
  cout << (n + 999) / 1000 * 1000 - n << endl;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // scanf("%d",&t);
  while (t--)
    Never_give_up();
  return 0;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 1000 == 0) {
    cout << "0\\n";
  } else {
    cout << 1000 - (n % 1000) << endl;
  }
  return 0;
}


Error: 1

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 1000 == 0) {
    cout << "0";
  } else {
    cout << 1000 - (n % 1000);
  }
  return 1;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP,
Ruby, C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS Code,
Compile, Run and Debug online from anywhere in world.

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

int main() {
  int n;
  cin >> n;
  while (n > 1000) {
    n = n % 1000;
  }
  if (n != 0)
    cout << 1000 - n << "\\n";
  else
    cout << 0 << "\\n";

  return 0;
}


Error: 0

Fixed submission:

/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP,
Ruby, C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS Code,
Compile, Run and Debug online from anywhere in world.

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

int main() {
  int n;
  cin >> n;
  string s = to_string(n);
  int l = s.length();
  string c;
  for (int i = 0; i < l - 3; i++) {
    c += s[i];
  }

  int p = stoi(c);
  p = (p + 1) * 1000;
  cout << abs(n - p) << "\\n";

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

#include <iostream>
using namespace std;

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


Error: 100

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, rem = 0;
  cin >> n;
  rem = n % 1000;
  if ((rem) == 0)
    return rem;
  else
    return 1000 - rem;
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define MIN -10000000
#define MAX 10000000
#define debug printf("%d", __LINE__)
using namespace std;
int main() {
  // freopen("sb.out", "w", stdout);
  // for(int n = 1; n<=10000; n++)
  //{
  int n;
  cin >> n;
  if (n <= 1000) {
    if (n == 0)
      cout << 0 << endl;
    else
      cout << 1000 - n << endl;
  } else if (n % 1000 == 0)
    cout << 0 << endl;
  else if (n % 1000 != 0) {
    int shengXiaLaiDe;
    shengXiaLaiDe = n % 1000;
    cout << 1000 - shengXiaLaiDe << endl;
    //}
  }
}


Error: WA

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define MIN -10000000
#define MAX 10000000
#define debug printf("%d", __LINE__)
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  if (n <= 1000)
    return printf("%d", 1000 - n);
  if (n % 1000 == 0)
    return printf("%d", 0), 0;
  if (n % 1000 != 0) {
    int shengXiaLaiDe;
    shengXiaLaiDe = n % 1000;
    if (shengXiaLaiDe <= 500)
      printf("%d", shengXiaLaiDe);
    else
      printf("%d", 1000 - shengXiaLaiDe);
  }
}
Problem p02612 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int t = n % 1000;
  if (t == 0)
    cout << "0";
  else
    cout << 1000 - t;
}

Error: 100

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int t = n % 1000;
  return 1000 - t;
}
Problem p02612 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 1000 == 0)
    cout << 0 << endl;
  else {
    while (n % 1000 > 1000) {
      n = n % 1000;
    }
    cout << 1000 - (n % 1000) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i = 2;
  ;
  cin >> n;
  while ((n % 1000) < 1000) {
    n = n * i;
    i++;
  }
  cout << n % 1000 << endl;
  return 0;
}
Problem p02612 (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() {
  int N;
  cin >> N;

  int S = N % 1000;

  if (S == 0) {
    cout << 0 << endl;
  } else {
    cout << 1000 - S << endl;
  }
}


Error: WA

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;
  cin >> N;

  int S = N / 1000;
  int T = S * 1000;
  cout << N % T << endl;
}