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

#include <iostream>
using namespace std;
/*
bool sw[1000001];
int i;

void sws(int k){
        if(k==1){
                sw[i]=true;
                return;
        }
        if(k%2==0) sws(k/2);
        else if(k%3==0) sws(k/3);
        else if(k%5==0) sws(k/5);
        return;
}
*/
// korenisuru
int dp[1000001];
int f(int n) {
  if (~dp[n])
    return dp[n];
  int ans = 0;
  if (n % 2 == 0)
    ans |= f(n / 2);
  else if (n % 3 == 0)
    ans |= f(n / 3);
  else if (n % 5 == 0)
    ans |= f(n / 5);
  return dp[n] = ans;
}

int main() {
  int m, n;
  for (int i = 0; i <= 1000000; i++)
    dp[i] = -1;
  dp[1] = 1;
  for (int i = 1000000; i >= 1; i--)
    f(i);
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      ans += dp[i];
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
/*
bool sw[1000001];
int i;

void sws(int k){
        if(k==1){
                sw[i]=true;
                return;
        }
        if(k%2==0) sws(k/2);
        else if(k%3==0) sws(k/3);
        else if(k%5==0) sws(k/5);
        return;
}
*/
// korenisuru
int dp[1000001];
int f(int n) {
  if (~dp[n])
    return dp[n];
  int ans = 0;
  if (n % 2 == 0)
    ans |= f(n / 2);
  else if (n % 3 == 0)
    ans |= f(n / 3);
  else if (n % 5 == 0)
    ans |= f(n / 5);
  return dp[n] = ans;
}

int main() {
  int m, n;
  for (int i = 0; i <= 1000000; i++)
    dp[i] = -1;
  dp[1] = 1;
  for (int i = 1000000; i >= 1; i++)
    f(i);
  while (cin >> m && m) {
    cin >> n;
    int ans = 0;
    for (int i = m; i <= n; i++)
      ans += dp[i];
    cout << ans << endl;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int dp[1000001] = {0};
int main() {
  int a = 1, n, m;
  for (int i = 0; a <= 1000000; i++) {
    int b = 1;
    for (int j = 0; a * b <= 1000000; j++) {
      int c = 1;
      for (int k = 0; a * b * c <= 1000000; k++) {
        dp[a * b * c] = true;
        c *= 5;
      }
      b *= 3;
    }
    a *= 2;
  }
  for (int i = 1; i <= 1000000; i++) {
    dp[i] += dp[i - 1];
  }
  while (cin >> m && m) {
    cin >> n;
    cout << dp[n] - dp[m - 1] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int dp[1000001] = {0};
int main() {
  int k, m, n;
  dp[1] = 1;
  for (int i = 1; i <= 500000; i++) {
    dp[i * 2] |= 1;
    dp[i * 3] |= 1;
    dp[i * 5] |= 1;
  }
  for (int i = 1; i <= 1000000; i++) {
    dp[i] += dp[i - 1];
  }
  while (cin >> m && m) {
    cin >> n;
    cout << dp[n] - dp[m - 1] << endl;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> PL;

ll n, m;
ll a[1000100];

int main() {
  for (int i = 1; i <= 1000000; i *= 2) {
    for (int j = 1; j * i <= 1000000; j *= 3) {
      for (int k = 1; k * j * i <= 1000000; k *= 5) {
        a[i * j * k] = 1;
      }
    }
  }
  while (cin >> m) {
    if (m == 0)
      break;
    cin >> n;
    ll c = 0;
    FOR(i, m, n + 1) {
      if (a[i]) {
        c++;
      }
    }
    cout << c << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> PL;

ll n, m;

int main() {
  while (cin >> m) {
    if (m == 0)
      break;
    cin >> n;
    ll c = 0;
    FOR(i, m, n + 1) {
      FOR(j, 1, 11) {
        ll x = pow(60.0, (double)j);
        if (x % i == 0) {
          c++;
          break;
        }
      }
    }
    cout << c << endl;
  }
}
Problem p00162 (C++) — buggy submission, verdict: Runtime Error

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

const int HAMMING_MAX = 1000001;

int main() {
  bool hamming[HAMMING_MAX];
  memset(hamming, 0, sizeof(hamming));

  for (int x = 1; x < HAMMING_MAX; x *= 2) {
    for (int y = 1; x * y < HAMMING_MAX; y *= 3) {
      for (int z = 1; x * y * z < HAMMING_MAX; z *= 5) {
        int h = x * y * z;
        hamming[h] = true;
      }
    }
  }

  int n, m;
  while (cin >> n && n) {
    cin >> m;
    int count = 0;
    for (int i = n; i <= m; ++i) {
      if (hamming[i]) {
        ++count;
      }
    }
    cout << count << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

const int HAMMING_MAX = 100001;

int main() {
  bool hamming[HAMMING_MAX];
  memset(hamming, 0, sizeof(hamming));

  for (int x = 1; x < HAMMING_MAX; x *= 2) {
    for (int y = 1; x * y < HAMMING_MAX; y *= 3) {
      for (int z = 1; x * y * z < HAMMING_MAX; z *= 5) {
        int h = x * y * z;
        hamming[h] = true;
      }
    }
  }

  int n, m;
  while (cin >> n && n) {
    cin >> m;
    int count = 0;
    for (int i = n; i <= m; ++i) {
      if (hamming[i]) {
        ++count;
      }
    }
    cout << count << endl;
  }

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

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

using namespace std;

bool f[10000002];

int main() {

  f[1] = true;
  f[3] = true;
  f[5] = true;

  for (int i = 2; i < 10000001; i *= 2) {
    f[i] = true;
  }
  // cout<<"#";
  for (int i = 3; i < 10000001; i *= 3) {
    f[i] = true;
  }
  for (int i = 5; i < 10000001; i *= 5) {
    f[i] = true;
  }
  for (int i = 2; i < 10000001; i++) {
    if (f[i] == true) {
      for (int j = i; j < 10000001; j *= 5)
        f[j] = true;
      for (int j = i; j < 10000001; j *= 3)
        f[j] = true;
      for (int j = i; j < 10000001; j *= 2)
        f[j] = true;
    }
  }

  int a, b;

  while (1) {
    int ans = 0;
    cin >> a;
    if (a == 0)
      break;
    cin >> b;

    for (int i = a; i <= b; i++)
      if (f[i] == true) {
        ans++;
      } // cout<<i<<endl;}

    cout << ans << endl;
  }

  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  long long int A, B;
  int n[101][101][3] = {};
  while (1) {
    cin >> A >> B;
    if (A == 0 && B == 0)
      break;
    long long int g = 60;
    int c = 0;
    for (long long int i = A; i <= B; i++) {
      g = 60;
      for (long long int j = 1; j < 20; j++) {
        if (g % i == 0) { // cout<<g<<endl;
          c++;
          break;
        } else {
          g *= 60;
        }
      }
    }
    cout << c << endl;
  }
  return 0;
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {

  int m, n;

  while (1) {

    cin >> m;

    if (m == 0)
      break;

    cin >> n;

    int count = 0;

    for (int i = m; i <= n; ++i) {

      int result = i;

      while (1) {

        if (result % 2 == 0)
          result = result / 2;
        else if (result % 3 == 0)
          result = result / 3;
        else if (result % 5 == 0)
          result = result / 5;
        else
          break;
      }

      if (result == 1)
        count++;
    }

    cout << count << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int m, n;

  while (cin >> m >> n, m || n) {

    int count = 0;

    for (int i = m; i <= n; ++i) {

      int result = i;

      while (1) {

        if (result % 2 == 0)
          result = result / 2;
        else if (result % 3 == 0)
          result = result / 3;
        else if (result % 5 == 0)
          result = result / 5;
        else
          break;
      }

      if (result == 1)
        count++;
    }

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

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 1000001
using namespace std;

int main() {
  bool hamming[N] = {false};
  hamming[1] = true;
  for (int j = 2; j < N; j++) {
    int i = j;
    while (i % 2 == 0)
      i /= 2;
    while (i % 3 == 0)
      i /= 3;
    while (i % 5 == 0)
      i /= 5;
    if (i == 1)
      hamming[j] = true;
  }

  int m, n;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;

    int count = 0;
    for (int i = m; i <= n; i++)
      if (hamming[i])
        count++;

    cout << count << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 10000000
using namespace std;
int main() {
  bool hamming[N] = {false};
  hamming[1] = true;
  for (int j = 2; j < N; j++) {
    int i = j;
    while (i % 2 == 0)
      i /= 2;
    while (i % 3 == 0)
      i /= 3;
    while (i % 5 == 0)
      i /= 5;
    if (i == 1)
      hamming[j] = true;
  }

  int m, n;
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    cin >> n;

    int count = 0;
    for (int i = m; i <= n; i++)
      if (hamming[i])
        count++;

    cout << count << endl;
  }

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

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

int x[2000000];
long long p;
int a, b, sum;

int main() {
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 13; j++) {
      for (int k = 0; k < 9; k++) {
        p = (long long)pow(2, i) * (long long)pow(3, j) * (long long)pow(5, k);
        if (p < 2000000) {
          x[p] = 1;
        }
      }
    }
  }
  while (true) {
    sum = 0;
    cin >> a;
    if (a == 0) {
      break;
    }
    cin >> b;
    for (int i = a; i <= b; i++) {
      sum += x[i];
    }
    cout << sum << endl;
  }
}

Error: -11

Fixed submission:

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

int x[2000000];
long long p;
int a, b, sum;

int main() {
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 13; j++) {
      for (int k = 0; k < 9; k++) {
        p = (int)pow(2, i) * (int)pow(3, j) * (int)pow(5, k);
        if (p < 2000000) {
          x[p] = 1;
        }
      }
    }
  }
  while (true) {
    sum = 0;
    cin >> a;
    if (a == 0) {
      break;
    }
    cin >> b;
    for (int i = a; i <= b; i++) {
      sum += x[i];
    }
    cout << sum << endl;
  }
}
Problem p00162 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

unsigned long long power(int a, int b) {
  if (b == 0) {
    return 1LL;
  }

  return power(a, b - 1) * a;
}

int main() {
  vector<bool> s(1000001, false);

  for (int i = 0; i < 22; i++) {
    for (int j = 0; j < 14; j++) {
      for (int k = 0; k < 10; k++) {
        unsigned long long sum = power(2, i) * power(3, j) * power(5, k);

        if (sum <= 1000000ULL) {
          s[sum] = true;
        }
      }
    }
  }

  int m, n;

  while (cin >> m >> n) {
    int sum = 0;

    for (int i = m; i <= n; i++) {
      sum += (s[i] ? 1 : 0);
    }

    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

long long power(int a, int b) {
  if (b == 0) {
    return 1LL;
  }

  return power(a, b - 1) * a;
}

int main() {
  vector<bool> s(1000001, false);

  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 12; j++) {
      for (int k = 0; k < 8; k++) {
        long long sum = power(2, i) * power(3, j) * power(5, k);

        if (sum <= 1000000LL) {
          s[sum] = true;
        }
      }
    }
  }

  int m, n;

  while (true) {
    cin >> m >> n;

    if (m == 0 && n == 0) {
      break;
    }

    int sum = 0;

    for (int i = m; i <= n; i++) {
      sum += (s[i] ? 1 : 0);
    }

    cout << sum << endl;
  }

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

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

vector<vector<int>> money{
    {0, 300, 500, 600, 700, 1350, 1650},
    {0, 0, 350, 450, 600, 1150, 1500},
    {0, 0, 0, 250, 400, 1000, 1350},
    {0, 0, 0, 0, 250, 850, 1300},
    {0, 0, 0, 0, 0, 600, 1150},
    {0, 0, 0, 0, 0, 0, 500},
    {0, 0, 0, 0, 0, 0, 0},

};
vector<int> dis{6, 7, 5, 5, 20, 15};

int main() {
  while (1) {
    int d;
    cin >> d;
    if (!d)
      break;
    int start, goal;
    {

      int h, m;
      cin >> h >> m;
      start = h * 60 + m;
    }
    int a;
    cin >> a;
    {

      int h, m;
      cin >> h >> m;
      goal = h * 60 + m;
    }
    d--;
    a--;
    if (d < a)
      swap(d, a);
    int cost = money[a][d];
    cost /= 50;
    int distance = 0;
    for (int i = a; i < d; ++i) {
      distance += dis[i];
    }
    bool flag = false;
    if ((start <= 1170 || 1050 <= goal) && !(start < 1050 && 1170 < goal))
      flag = true;
    if (distance <= 40 && flag)
      cost = (cost + 1) / 2;
    cost *= 50;
    cout << cost << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

vector<vector<int>> money{
    {0, 300, 500, 600, 700, 1350, 1650},
    {0, 0, 350, 450, 600, 1150, 1500},
    {0, 0, 0, 250, 400, 1000, 1350},
    {0, 0, 0, 0, 250, 850, 1300},
    {0, 0, 0, 0, 0, 600, 1150},
    {0, 0, 0, 0, 0, 0, 500},
    {0, 0, 0, 0, 0, 0, 0},

};
vector<int> dis{6, 7, 5, 5, 20, 15};

int main() {
  while (1) {
    int d;
    cin >> d;
    int start, goal;
    {

      int h, m;
      cin >> h >> m;
      start = h * 60 + m;
    }
    int a;
    cin >> a;
    {

      int h, m;
      cin >> h >> m;
      goal = h * 60 + m;
    }
    d--;
    a--;
    if (d < a)
      swap(d, a);
    int cost = money[a][d];
    cost /= 50;
    int distance = 0;
    for (int i = a; i < d; ++i) {
      distance += dis[i];
    }
    bool flag = false;
    if ((start <= 1170 || 1050 <= goal) && !(start < 1050 && 1170 < goal))
      flag = true;
    if (distance <= 40 && flag)
      cost = (cost + 1) / 2;
    cost *= 50;
    cout << cost << endl;
  }
  return 0;
}
Problem p00163 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int sic, sh, sm, eic, eh, em, st, et, S, E, flag, ans;
  int d[8][8];
  bool c[8][8];
  d[1][2] = d[2][1] = 300;
  d[1][3] = d[3][1] = 500;
  d[1][4] = d[4][1] = 600;
  d[1][5] = d[5][1] = 700;
  d[1][6] = d[6][1] = 1350;
  d[1][7] = d[7][1] = 1650;
  d[2][3] = d[3][2] = 350;
  d[2][4] = d[4][2] = 450;
  d[2][5] = d[5][2] = 600;
  d[2][6] = d[6][2] = 1150;
  d[2][7] = d[7][2] = 1500;
  d[3][4] = d[4][3] = 250;
  d[3][5] = d[5][3] = 400;
  d[3][6] = d[6][3] = 1000;
  d[3][7] = d[7][3] = 1350;
  d[4][5] = d[5][4] = 250;
  d[4][6] = d[6][4] = 850;
  d[4][7] = d[7][4] = 1300;
  d[5][6] = d[6][5] = 600;
  d[5][7] = d[7][5] = 1150;
  d[6][7] = d[7][6] = 500;
  S = 17 * 3600 + 30 * 60;
  E = 19 * 3600 + 30 * 60;
  for (int i = 1; i < 8; i++)
    for (int j = 1; j < 8; j++)
      c[i][j] = true;
  c[1][6] = c[6][1] = false;
  c[3][7] = c[7][3] = false;
  c[2][7] = c[7][2] = false;
  c[1][7] = c[7][1] = false;
  while (1) {
    cin >> sic >> sh >> sm >> eic >> eh >> em;
    if (!sic)
      break;
    st = sh * 3600 + sm * 60;
    et = eh * 3600 + em * 60;
    flag = 0;
    if ((S <= st && st <= E) || (S <= et && et <= E))
      flag = 1;
    ans = d[sic][eic];
    if (flag && c[sic][eic]) {
      int cal;
      ans /= 2;
      cal = ans % 100;
      if (cal % 50) {
        ans /= 100;
        ans *= 100;
        if (cal < 50)
          ans += 50;
        else
          ans += 100;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int sic, sh, sm, eic, eh, em, st, et, S, E, flag, ans;
  int d[8][8];
  d[1][2] = d[2][1] = 300;
  d[1][3] = d[3][1] = 500;
  d[1][4] = d[4][1] = 600;
  d[1][5] = d[5][1] = 700;
  d[1][6] = d[6][1] = 1350;
  d[1][7] = d[7][1] = 1650;
  d[2][3] = d[3][2] = 350;
  d[2][4] = d[4][2] = 450;
  d[2][5] = d[5][2] = 600;
  d[2][6] = d[6][2] = 1150;
  d[2][7] = d[7][2] = 1500;
  d[3][4] = d[4][3] = 250;
  d[3][5] = d[5][3] = 400;
  d[3][6] = d[6][3] = 1000;
  d[3][7] = d[7][3] = 1350;
  d[4][5] = d[5][4] = 250;
  d[4][6] = d[6][4] = 850;
  d[4][7] = d[7][4] = 1300;
  d[5][6] = d[6][5] = 600;
  d[5][7] = d[7][5] = 1150;
  d[6][7] = d[7][6] = 500;
  S = 17 * 3600 + 30 * 60;
  E = 19 * 3600 + 30 * 60;
  while (1) {
    /*cin>>sic>>sh>>sm>>eic>>eh>>em;
    if(!sic) break;
    st=sh*3600+sm*60;
    et=eh*3600+em*60;
    flag=0;
    if((S<=st&&st<=E)||(S<=et&&et<=E)) flag=1;
    ans=d[sic][eic];*/
    // if(flag){
    int c;
    cin >> c;
    ans = c;
    int cal;
    ans /= 2;
    cal = ans % 100;
    if (cal % 50) {
      ans /= 100;
      ans *= 100;
      if (cal < 50)
        ans += 50;
      else
        ans += 100;
    }
    //    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00164 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int n, a[26], s, t, p;

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    s = 32;
    p = 0;
    while (s > 0) {
      t = (s - 1) % 5;
      s -= t;
      cout << s << endl;

      s -= a[p % n];
      p++;
      if (s < 0) {
        s = 0;
      }
      cout << s << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, a[4], s, t, p;

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    s = 32;
    p = 0;
    while (s > 0) {
      t = (s - 1) % 5;
      s -= t;
      cout << s << endl;

      s -= a[p % n];
      p++;
      if (s < 0) {
        s = 0;
      }
      cout << s << endl;
    }
  }

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

#include <iostream>
using namespace std;

int main() {

  int n, v[26];
  int w[7] = {31, 26, 21, 16, 11, 6, 1};

  while (cin >> n) {
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }

    cout << 31 << endl;
    for (int i = 0; i < 6; i++) {
      cout << w[i] - v[i % n] << endl;
      cout << w[i + 1] << endl;
    }
    cout << 0 << endl;
  }

  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int n, v[26];
  int w[7] = {31, 26, 21, 16, 11, 6, 1};

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

    cout << 31 << endl;
    for (int i = 0; i < 6; i++) {
      cout << w[i] - v[i % n] << endl;
      cout << w[i + 1] << endl;
    }
    cout << 0 << endl;
  }

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

// AOJ 0164
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int n;
  while (cin >> n, n) {
    vector<int> kotori(n);
    int kotori_cnt = 0, honoka = 32;
    for (int i = 0; i < n; i++) {
      cin >> kotori[i];
    }
    while (honoka > 0) {
      honoka -= ((honoka - 1) % 5);
      cout << honoka << endl;
      // kotori
      honoka -= (kotori[kotori_cnt % n]);
      // cout << "*** DEBUG " << kotori_cnt << endl;
      kotori_cnt++;
      if (honoka <= 0)
        break;
      cout << honoka << endl;
    }
    cout << 0 << endl;
  }

  return 0;
}

Error: -8

Fixed submission:

// AOJ 0164
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    vector<int> kotori(n);
    int kotori_cnt = 0, honoka = 32;
    for (int i = 0; i < n; i++) {
      cin >> kotori[i];
    }
    while (honoka > 0) {
      honoka = honoka - ((honoka - 1) % 5);
      cout << honoka << endl;
      // kotori
      honoka -= (kotori[kotori_cnt % n]);
      // cout << "*** DEBUG " << kotori_cnt << endl;
      kotori_cnt++;
      if (honoka <= 0)
        break;
      cout << honoka << endl;
    }
    cout << 0 << endl;
  }

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

#include <stdio.h>

int main() {

  int n[30] = {};
  int N;
  int r = 0;
  while (1) {
    scanf("%d", &N);
    if (N == 0)
      break;

    for (int i = 0; i < N; i++)
      scanf("%d", &n[i]);

    int P = 32;
    int j = 0;
    while (1) {
      if (P <= 0)
        break;
      P -= (P - 1) % 5;
      printf("%d\\n", P);
      if (P == 1)
        break;
      P -= n[j];
      printf("%d\\n", P);
      j++;
      j = j % N;
    }
    P = 0;
    printf("%d\\n", P);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {

  int n[5] = {};
  int N;
  int r = 0;
  while (1) {
    scanf("%d", &N);
    if (N == 0)
      break;

    for (int i = 0; i < N; i++)
      scanf("%d", &n[i]);

    int P = 32;
    int j = 0;
    while (1) {
      if (P <= 0)
        break;
      P -= (P - 1) % 5;
      printf("%d\\n", P);
      if (P == 1)
        break;
      P -= n[j];
      printf("%d\\n", P);
      j++;
      j = j % N;
    }
    P = 0;
    printf("%d\\n", P);
  }
  return 0;
}
Problem p00164 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n, a[10000], cnt, turn;
int main() {
  while (true) {
    turn = 0;
    cnt = 31;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << "31" << endl;
    while (cnt >= a[turn % n]) {
      cnt -= a[turn % n];
      turn++;
      if (cnt == 0) {
        break;
      }
      cout << cnt << endl;
      cnt -= (cnt + 4) % 5;
      cout << cnt << endl;
    }
    cout << "0" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n, a[10000], cnt, turn;
int main() {
  while (true) {
    turn = 0;
    cnt = 31;
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << "31" << endl;
    while (cnt >= a[turn % n]) {
      cnt -= a[turn % n];
      turn++;
      cout << cnt << endl;
      cnt -= (cnt - 1) % 5;
      cout << cnt << endl;
    }
    cout << "0" << endl;
  }
  return 0;
}
Problem p00164 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

void loop(int remain, int *jiro_rule, int rule_size, int cur) {
  remain -= (remain - 1) % 5;
  cout << remain << endl;
  if (remain == 0)
    return;
  if (remain <= *(jiro_rule + cur)) {
    cout << 0 << endl;
    return;
  }
  remain -= *(jiro_rule + cur);
  cout << remain << endl;
  cur++;
  if (cur == rule_size)
    cur = 0;
  loop(remain, jiro_rule, rule_size, cur);
}

int main() {
  int i;
  while (cin >> i) {
    if (i == 0)
      break;
    int a[i];
    for (int p = 0; p < i; p++) {
      cin >> a[p];
    }
    loop(32, a, i, 0);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void loop(int remain, int *jiro_rule, int rule_size, int cur) {
  remain -= (remain - 1) % 5;
  cout << remain << endl;
  if (remain == 0)
    return;
  if (remain < *(jiro_rule + cur)) {
    cout << 0 << endl;
    return;
  }
  remain -= *(jiro_rule + cur);
  cout << remain << endl;
  cur++;
  if (cur == rule_size)
    cur = 0;
  loop(remain, jiro_rule, rule_size, cur);
}

int main() {
  int i;
  while (cin >> i) {
    if (i == 0)
      break;
    int a[i];
    for (int p = 0; p < i; p++) {
      cin >> a[p];
    }
    loop(32, a, i, 0);
  }
  return 0;
}