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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

struct Mobil {
  int p, q, r, b;
  Mobil() {}
  Mobil(int p, int q, int r, int b) : p(p), q(q), r(r), b(b) {}
};

typedef long long ll;

int N;
int in[128];
Mobil mb[128];

ll rec(int v) {
  ll res = 0, r = 0, b = 0, rw = 1, bw = 1;
  Mobil m = mb[v];
  if (m.r) {
    rw = rec(m.r);
    r = m.p * rw;
  } else
    r = m.p;
  if (m.b) {
    bw = rec(m.b);
    b = m.q * bw;
  } else
    b = m.q;
  ll lcm = r * b / __gcd(r, b);
  //  printf("%d\\n", v);
  ///  printf("%lld\\n", lcm);
  //  printf("%lld %lld %lld %lld\\n", rw, r, bw, b);
  res += rw * lcm / r;
  res += bw * lcm / b;
  return res;
}

int main() {
  while (scanf("%d", &N) && N) {
    memset(in, 0, sizeof in);
    for (int i = 1; i <= N; i++) {
      int p, q, r, b;
      scanf("%d%d%d%d", &p, &q, &r, &b);
      mb[i] = Mobil(p, q, r, b);
      in[r] = in[b] = 1;
    }

    int s = -1;
    for (int i = 1; i <= N; i++)
      if (!in[i])
        s = i;
    printf("%d\\n", rec(s));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

struct Mobil {
  int p, q, r, b;
  Mobil() {}
  Mobil(int p, int q, int r, int b) : p(p), q(q), r(r), b(b) {}
};

typedef long long ll;

int N;
int in[128];
Mobil mb[128];

ll rec(int v) {
  ll res = 0, r = 0, b = 0, rw = 1, bw = 1;
  Mobil m = mb[v];
  if (m.r) {
    rw = rec(m.r);
    r = m.p * rw;
  } else
    r = m.p;
  if (m.b) {
    bw = rec(m.b);
    b = m.q * bw;
  } else
    b = m.q;
  ll lcm = r * b / __gcd(r, b);
  //  printf("%lld\\n", lcm);
  //  printf("%lld %lld %lld %lld\\n", rw, r, bw, b);
  res += rw * lcm / r;
  res += bw * lcm / b;
  return res;
}

int main() {
  while (scanf("%d", &N) && N) {
    for (int i = 1; i <= N; i++) {
      int p, q, r, b;
      scanf("%d%d%d%d", &p, &q, &r, &b);
      mb[i] = Mobil(p, q, r, b);
      in[r] = in[b] = 1;
    }

    int s = -1;
    for (int i = 1; i <= N; i++)
      if (!in[i])
        s = i;
    printf("%d\\n", rec(s));
  }
  return 0;
}
Problem p00443 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
long long b[100], c[100], d[100], e[100], f[100];
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    long long t = a;
    a = b;
    b = t;
  }
  return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long dfs(long long a) {
  if (a == -1)
    return 1;
  long long L = dfs(d[a] - 1);
  long long R = dfs(e[a] - 1);
  long long s = gcd(c[a], b[a]);
  c[a] /= s;
  b[a] /= s;
  // printf("%lld,%lld\\n",L*c[a],R*b[a]);
  long long u = lcm(L * b[a], R * c[a]);
  return u / c[a] + u / b[a];
}
int main() {
  long long a;
  while (scanf("%lld", &a), a) {
    for (long long i = 0; i < a; i++)
      scanf("%lld%lld%lld%lld", b + i, c + i, d + i, e + i);
    for (long long i = 0; i < a; i++)
      f[i] = -1;
    for (long long i = 0; i < a; i++) {
      if (d[i] > 0)
        f[d[i] - 1] = i;
      if (e[i] > 0)
        f[e[i] - 1] = i;
    }
    long long parent = 0;
    for (long long i = 0; i < a; i++)
      if (f[i] == -1)
        parent = i;
    printf("%lld\\n", dfs(parent));
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
int lenL[100];
int lenR[100];
int L[100];
int R[100];
long long int c[100];
long long int d[100];
long long wL[100];
long long wR[100];
int parent[100];
bool visited[100];
long long int gcd(long long int a, long long int b) {
  while (b) {
    a %= b;
    long long int val = b;
    b = a;
    a = val;
  }
  return a;
}
int main() {
  int a;
  while (scanf("%d", &a), a) {
    for (int i = 0; i < a; i++) {
      scanf("%d%d%d%d", lenL + i, lenR + i, L + i, R + i);
    }
    long long total = 1;
    for (int i = 0; i < a; i++) {
      c[i] = lenL[i] / gcd(lenL[i], lenR[i]);
      d[i] = lenR[i] / gcd(lenR[i], lenL[i]);
      total *= (c[i] + d[i]);
    }
    for (int i = 0; i < a; i++)
      parent[i] = -1;
    for (int i = 0; i < a; i++) {
      if (L[i])
        parent[L[i] - 1] = i;
      if (R[i])
        parent[R[i] - 1] = i;
    }
    for (int i = 0; i < a; i++)
      visited[i] = false;
    for (int j = 0; j < a; j++) {
      for (int i = 0; i < a; i++) {
        if (parent[i] == -1 && visited[i] == false) {
          wL[i] = total / (c[i] + d[i]) * d[i];
          wR[i] = total / (c[i] + d[i]) * c[i];
          visited[i] = true;
        } else if (parent[i] != -1 && visited[i] == false &&
                   visited[parent[i]] == true) {
          visited[i] = true;
          wL[i] = (L[parent[i]] == i + 1 ? wL[parent[i]] : wR[parent[i]]) /
                  (c[i] + d[i]) * d[i];
          wR[i] = (L[parent[i]] == i + 1 ? wL[parent[i]] : wR[parent[i]]) /
                  (c[i] + d[i]) * c[i];
        }
      }
    }
    while (1) {
      long long val = total;
      for (int i = 0; i < a; i++) {
        val = gcd(val, gcd(wL[i], wR[i]));
      }
      if (val == 1)
        break;
      total /= val;
      for (int i = 0; i < a; i++) {
        wL[i] /= val;
        wR[i] /= val;
      }
    }
    printf("%lld\\n", total);
  }
}
Problem p00443 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

long long gcd(long long a, long long b) { // Ååöñ
  if (a == 0 || b == 0)
    return 0;
  if (b > a)
    swap(a, b);
  long long tmp;
  while ((tmp = a % b) != 0) {
    a = b;
    b = tmp;
  }
  return b;
}

long long lcm(long long a, long long b) { // Å¬ö{
  return a / gcd(a, b) * b;
}

long long solve(vector<vector<int>> &stick, int i) {
  if (i == 0)
    return 1;

  long long p = stick[i][0];
  long long q = stick[i][1];

  long long a = solve(stick, stick[i][2]);
  long long b = solve(stick, stick[i][3]);
  long long tmp = lcm(p * a, q * b);
  a = tmp / p;
  b = tmp / q;

  return a + b;
}

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    vector<vector<int>> stick(n + 1, vector<int>(4));
    vector<bool> check(n + 1, false);
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < 4; ++j) {
        cin >> stick[i][j];
      }
      check[stick[i][2]] = check[stick[i][3]] = true;
    }

    long long ret = 0;
    for (int i = 1; i <= n; ++i) {
      if (!check[i])
        ret += solve(stick, i);
    }
    cout << ret << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

long long gcd(long long a, long long b) { // Ååöñ
  if (a == 0 || b == 0)
    return 0;
  if (b > a)
    swap(a, b);
  long long tmp;
  while ((tmp = a % b) != 0) {
    a = b;
    b = tmp;
  }
  return b;
}

long long lcm(long long a, long long b) { // Å¬ö{
  return a / gcd(a, b) * b;
}

long long solve(vector<vector<int>> &stick, int i) {
  if (i == 0)
    return 1;

  long long p = stick[i][0];
  long long q = stick[i][1];
  long long tmp = gcd(p, q);
  p /= tmp;
  q /= tmp;

  long long a = solve(stick, stick[i][2]);
  long long b = solve(stick, stick[i][3]);
  tmp = lcm(q * a, p * b);
  long long x = tmp / (q * a);
  long long y = tmp / (p * b);

  return a * x + b * y;
}

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    vector<vector<int>> stick(n + 1, vector<int>(4));
    vector<bool> check(n + 1, false);
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < 4; ++j) {
        cin >> stick[i][j];
      }
      check[stick[i][2]] = check[stick[i][3]] = true;
    }

    long long ret = 0;
    for (int i = 1; i <= n; ++i) {
      if (!check[i])
        ret += solve(stick, i);
    }
    cout << ret << endl;
  }
}
Problem p00443 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
LL n;
LL p[111];
LL q[111];
LL r[111];
LL b[111];
LL m[111];

LL GCD(LL x, LL y) {
  if (x < y)
    x ^= y ^= x ^= y;
  LL r = x % y;
  if (r)
    return GCD(y, r);
  else
    return y;
}

LL solve(int k) {
  if (k == 0)
    return 1;
  if (m[k])
    return m[k];
  LL rm = solve(r[k]) * p[k];
  LL bm = solve(b[k]) * q[k];
  LL l = rm * bm / GCD(rm, bm);
  // cout << "k = " << k << " : " << l/p[k] << " + " << l/q[k] << endl;
  return m[k] = l / p[k] + l / q[k];
}

int main(void) {
  while (cin >> n && n) {
    memset(p, 0, sizeof(p));
    memset(q, 0, sizeof(q));
    memset(r, 0, sizeof(r));
    memset(b, 0, sizeof(b));
    memset(m, 0, sizeof(m));
    for (int i = 1; i <= n; i++) {
      cin >> p[i] >> q[i] >> r[i] >> b[i];
      LL g = GCD(p[i], q[i]);
      p[i] /= g;
      q[i] /= g;
    }
    LL res = 0;
    for (int i = 1; i <= n; i++) {
      res = max(res, solve(i));
    }
    cout << res << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n;
int p[111];
int q[111];
int r[111];
int b[111];
int m[111];

int GCD(int x, int y) {
  if (x < y)
    x ^= y ^= x ^= y;
  int r = x % y;
  if (r)
    return GCD(y, r);
  else
    return y;
}

int solve(int k) {
  if (k == 0)
    return 1;
  if (m[k])
    return m[k];
  int rm = solve(r[k]) * p[k];
  int bm = solve(b[k]) * q[k];
  int l = rm * bm / GCD(rm, bm);
  // cout << "k = " << k << " : " << l/p[k] << " + " << l/q[k] << endl;
  return m[k] = l / p[k] + l / q[k];
}

int main(void) {
  while (cin >> n && n) {
    memset(p, 0, sizeof(p));
    memset(q, 0, sizeof(q));
    memset(r, 0, sizeof(r));
    memset(b, 0, sizeof(b));
    memset(m, 0, sizeof(m));
    for (int i = 1; i <= n; i++) {
      cin >> p[i] >> q[i] >> r[i] >> b[i];
      int g = GCD(p[i], q[i]);
      p[i] /= g;
      q[i] /= g;
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
      res = max(res, solve(i));
    }
    cout << res << endl;
  }
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
  int temp = 0;
  int cost_input[10];
  int cost_return = 0;
  int num[10];
  int j = 0;

  for (int i = 0; i < 10; ++i) {
    CI temp;
    if (temp == 0) {
      j = i;
      break;
    }
    cost_input[i] = temp;

    cost_return = 1000 - cost_input[i];
    num[i] = 0;

    if (cost_return < 5) {
      num[i] = cost_return;
      continue;
    } else {
      if (cost_return < 10) {
        num[i] = 1 + cost_return - 5;
        continue;
      }
    }

    if (cost_return >= 500) {
      ++num[i];
      cost_return -= 500;
    }
    while (1) {
      if (cost_return >= 100) {
        ++num[i];
        cost_return -= 100;
      }
      if (cost_return < 100)
        break;
    }
    if (cost_return >= 50) {
      ++num[i];
      cost_return -= 50;
    }
    while (1) {
      if (cost_return >= 10) {
        ++num[i];
        cost_return -= 10;
        if (cost_return < 10)
          break;
      }
    }

    if (cost_return >= 5) {
      ++num[i];
      cost_return -= 5;
    }
    while (1) {
      if (cost_return >= 1) {
        ++num[i];
        cost_return -= 1;
      }
      if (cost_return < 1)
        break;
    }
  }

  for (int i = 0; i < j; ++i) {
    CO num[i] E
  }
}

Error: TLE

Fixed submission:

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

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
  int temp = 0;
  int cost_input[10];
  int cost_return = 0;
  int num_answer = 0;
  int j = 0;

  for (int i = 0; i < 10; ++i) {
    CI temp;
    if (temp == 0) {
      j = i;
      break;
    }
    cost_input[i] = temp;

    cost_return = 1000 - cost_input[i];
    num_answer = 0;

    if (cost_return >= 500) {
      ++num_answer;
      cost_return -= 500;
    }
    while (1) {
      if (cost_return >= 100) {
        ++num_answer;
        cost_return -= 100;
      }
      if (cost_return < 100)
        break;
    }
    if (cost_return >= 50) {
      ++num_answer;
      cost_return -= 50;
    }
    while (1) {
      if (cost_return >= 10) {
        ++num_answer;
        cost_return -= 10;
        if (cost_return < 10)
          break;
      }
    }

    if (cost_return >= 5) {
      ++num_answer;
      cost_return -= 5;
    }
    while (1) {
      if (cost_return >= 1) {
        ++num_answer;
        cost_return -= 1;
      }
      if (cost_return < 1)
        break;
    }
  }

  for (int i = 0; i < j; ++i) {
    CO num_answer E
  }
}
Problem p00444 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    n = 1000 - n;
    int ans = 0, i;
    int w[6] = {500, 100, 50, 10, 5, 1};
    for (i = 0; i <= 5; i++) {
      ans = ans + n / w[i];
      n = n - n / w[i] * w[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    n = 1000 - n;
    int ans = 0, i;
    int w[6] = {500, 100, 50, 10, 5, 1};
    for (i = 0; i <= 6; i++) {
      ans = ans + n / w[i];
      n = n - n / w[i] * w[i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
#define INF (1 << 30)

int dp[1001], tmp[] = {500, 100, 50, 10, 5, 1}, n;
int main() {
  fill_n(dp, 1001, INF);
  dp[0] = 0;
  for (int i = 0; i < 1001; i++) {
    for (int j = 0; j < 6; j++) {
      if (i - tmp[j] >= 0)
        dp[i] = min(dp[i], dp[i - tmp[j]] + 1);
    }
  }
  while (cin >> n, n)
    cout << dp[1000 - n] << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  for (int i = 1; i < 1000; i++) {
    for (int j = 1; j < 1000; j++) {
      cin >> n;
      cout << n << endl;
    }
  }
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

//============================================================================
// Name        : 0521.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
  int x;
  int c[6] = {500, 100, 50, 10, 5, 1};
  while (1) {
    int ans = 0;
    cin >> x;
    x = 1000 - x;
    if (x == 1000) {
      break;
    }
    for (int i = 0; i < 6; i++) {
      ans = x / c[i] + ans;
      x = x % c[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

//============================================================================
// Name        : 0521.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
  int x;
  int c[6] = {500, 100, 50, 10, 5, 1};
  while (1) {
    int ans = 0;
    cin >> x;
    x = 1000 - x;
    if (x == 0) {
      break;
    }
    for (int i = 0; i < 6; i++) {
      ans = x / c[i] + ans;
      x = x % c[i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

int kane;
int oturi[6] = {500, 100, 50, 10, 5, 1};
int mai;

int main() {
  while (1) {
    mai = 0;
    cin >> kane;
    if (kane == 0)
      break;
    kane = 1000 - kane;
    for (int i = 0; i < 6; i++) {
      mai += (kane / oturi[i]);
      kane %= oturi[i];
    }
    cout << mai << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

int kane;
int oturi[6] = {500, 100, 50, 10, 5, 1};
int mai;

int main() {
  while (1) {
    mai = 0;
    cin >> kane;
    kane = 1000 - kane;
    if (kane == 0)
      break;
    for (int i = 0; i < 6; i++) {
      mai += (kane / oturi[i]);
      kane %= oturi[i];
    }
    cout << mai << endl;
  }

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

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  while (1) {

    int N;
    cin >> N;
    if (!N)
      break;
    N = 1000 - N;
    int ans = 0;
    vector<int> s;
    s = {500, 100, 50, 10, 5, 1};
    for (auto m : s) {
      ans += N / m;
      N %= m;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  while (1) {

    int N;
    cin >> N;
    N = 1000 - N;
    int ans = 0;
    set<int> s;
    s = {500, 100, 50, 10, 5, 1};
    for (auto m : s) {
      ans += N / m;
      N /= m;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int total;
  int change;
  int count = 0;
  while (true) {
    cin >> total;
    if (total == 0) {
      break;
    }
    change = 1000 - total;
    while (true) {
      if (change >= 500) {
        change -= 500;
        count++;
      } else if (change >= 100) {
        change -= 100;
        count++;
      } else if (change >= 50) {
        change -= 50;
        count++;
      } else if (change >= 10) {
        change -= 10;
        count++;
      } else if (change >= 5) {
        change -= 5;
        count++;
      } else {
        change--;
        count++;
      }
      if (change == 0) {
        break;
      }
    }
    cout << count << "\\n";
    count = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int total;
  int change;
  int count = 0;
  while (true) {
    cin >> total;
    if (total == 0) {
      break;
    }
    change = 1000 - total;
    while (true) {
      if (change >= 500) {
        change -= 500;
        count++;
      } else if (change >= 100) {
        change -= 100;
        count++;
      } else if (change >= 50) {
        change -= 50;
        count++;
      } else if (change >= 10) {
        change -= 10;
        count++;
      } else if (change >= 5) {
        change -= 5;
        count++;
      } else {
        change--;
        count++;
      }
    }
    cout << count << "\\n";
    count = 0;
  }
  return 0;
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, e, f, g;
  while (1) {
    cin >> a;
    if (a == 0)
      break;
    b = (1000 - a) / 500;
    c = (1000 - (a + 500 * b)) / 100;
    d = (1000 - (a + 500 * b + 100 * c)) / 50;
    e = (1000 - (a + 500 * b + 100 * c + 50 * d)) / 10;
    f = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e)) / 5;
    g = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e + 5 * f)) / 1;
    cout << b + c + d + e + f + g << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, e, f, g;
  while (1) {
    cin >> a;
    if (a = 0)
      break;
    b = (1000 - a) / 500;
    c = (1000 - (a + 500 * b)) / 100;
    d = (1000 - (a + 500 * b + 100 * c)) / 50;
    e = (1000 - (a + 500 * b + 100 * c + 50 * d)) / 10;
    f = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e)) / 5;
    g = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e + 5 * f)) / 1;
    cout << b + c + d + e + f + g << endl;
  }
  return 0;
}
Problem p00444 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int money, count = 0, oturi[1000] = {};
  int money2[6] = {500, 100, 50, 10, 5, 1};

  for (int i = 0; i >= 0; i++) {
    cin >> money;
    count++;
    if (money == 0)
      break;
    oturi[i] = 1000 - money;
  }

  for (int j = 0; j < count; j++) {
    int maisu = 0;
    for (int i = 0; i < 6; i++) {
      maisu += oturi[j] / money2[i];
      oturi[j] %= money2[i];
    }
    if (maisu > 0)
      cout << maisu << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int money, oturi, maisu = 0;

  cin >> money;
  oturi = 1000 - money;
  for (int i = 1000; oturi > 0; i /= 10) {
    oturi %= i;
    if (oturi >= i / 10) {
      (oturi / (i / 10) >= 5) ? (maisu += oturi / (i / 10) - 4)
                              : (maisu += oturi / (i / 10));
    }
  }
  cout << maisu << endl;

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

#include <stdio.h>

int main() {
  int n, c;
  while (1) {

    scanf("%d", &n);
    if (n == 0)
      break;
    c = 0;
    n = 1000 - n;
    do {
      if (n >= 500) {
        n = n - 500;
        c++;
      } else if (n >= 100) {
        n = n - 100;
        c++;
      } else if (n >= 50) {
        n = n - 50;
        c++;
      } else if (n >= 10) {
        n = n - 10;
        c++;
      } else if (n >= 5) {
        n = n - 5;
        c++;
      } else if (n >= 1) {
        n = n - 1;
        c++;
      }
    } while (n != 0);
    printf("%d\\n", c);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int n, c;
  while (1) {

    scanf("%d", &n);
    if (n == 0)
      break;
    c = 0;
    n = 1000 - n;
    do {
      if (n >= 500) {
        n - 500;
        c++;
      } else if (n >= 100) {
        n - 100;
        c++;
      } else if (n >= 50) {
        n - 50;
        c++;
      } else if (n >= 10) {
        n - 10;
        c++;
      } else if (n >= 5) {
        n - 5;
        c++;
      } else if (n >= 1) {
        n - 1;
        c++;
      }
    } while (n != 0);
    printf("%d\\n", c);
  }
  return 0;
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  // your code goes here
  int n;
  while (cin >> n && n != 0) {
    n = 1000 - n;
    int sum = 0;
    int coin[] = {500, 100, 50, 10, 5, 1};
    for (int i = 0; i < 6; i++)
      while (n >= coin[i]) {
        sum++;
        n -= coin[i];
      }
    cout << sum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, ans = 0;
  int coin[6] = {500, 100, 50, 10, 5, 1};

  while (cin >> n) {
    n = 1000 - n;
    for (int i = 0; 1 < 6; i++) {
      ans += n / coin[i];
      n %= coin[i];
    }
  }
  return 0;
}
Problem p00444 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, b;
  while (true) {
    cin >> b;
    n = 1000 - b;
    ;
    if (b == 0) {
      break;
    }
    cout << n / 500 + (n / 100) % 5 + (n / 50) % 2 + (n / 10) % 5 +
                (n / 5) % 2 + n % 5
         << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, b;
  while (true) {
    cin >> b;
    n = 1000 - b;
    ;
    if (n == 0) {
      break;
    }
    cout << n / 500 + (n / 100) % 5 + (n / 50) % 2 + (n / 10) % 5 +
                (n / 5) % 2 + n % 5
         << endl;
  }
}