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

#include <iostream>
#include <list>
#include <string>
using namespace std;

int N, M;
list<int> players;

bool check(int n, string s) {
  if (n % 5 == 0 && n % 3 == 0)
    return s == "FizzBuzz";
  if (n % 5 == 0)
    return s == "Buzz";
  if (n % 3 == 0)
    return s == "Fizz";
  return s == to_string(n);
}

int main() {
loop:
  cin >> M >> N;
  if (!N)
    return 0;

  players.clear();
  for (int i = 0; i < M; i++)
    players.push_back(i + 1);
  auto p = players.begin();
  for (int i = 1; i <= N; i++) {
    string s;
    cin >> s;
    if (players.front() == players.back())
      continue;
    if (!check(i, s))
      p = players.erase(p);
    else
      ++p;
    if (p == players.end())
      p = players.begin();
  }
  for (auto v : players) {
    cout << v;
    if (v != players.back())
      cout << " ";
  }
  cout << endl;
  goto loop;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int N, M, t, p;
bool players[1000];

bool check(int n, string s) {
  if (n % 5 == 0 && n % 3 == 0)
    return s == "FizzBuzz";
  if (n % 5 == 0)
    return s == "Buzz";
  if (n % 3 == 0)
    return s == "Fizz";
  return s == to_string(n);
}

void next() {
  do
    t = (t + 1) % M;
  while (!players[t]);
}

void print() {
  for (int i = 0; i < M; i++) {
    if (players[i]) {
      cout << i + 1;
      if (p-- > 0)
        cout << " ";
    }
  }
  cout << endl;
}

int main() {
loop:
  cin >> M >> N;
  if (!N)
    return 0;

  t = 0;
  p = N;
  for (int i = 0; i < M; i++)
    players[i] = true;
  for (int i = 1; i <= N; i++) {
    string s;
    cin >> s;
    if (!check(i, s)) {
      players[t] = false;
      p--;
    }
    next();
  }
  print();
  goto loop;
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)

using namespace std;

int main() {
  int m, n;
  char s[9];
  while (scanf("%d%d", &m, &n) && m && n) {
    vector<bool> mem(m);
    rep(i, m) mem[i] = false;
    int p = 0, c = 1;
    FOR(i, 1, n + 1) {
      scanf("%s", s);
      if (c < m) {
        int f = 0;
        if (i % 15 == 0) {
          if (strcmp(s, "FizzBuzz"))
            f = 1;
        } else if (i % 5 == 0) {
          if (strcmp(s, "Buzz"))
            f = 1;
        } else if (i % 3 == 0) {
          if (strcmp(s, "Fizz"))
            f = 1;
        } else {
          if (i != atoi(s))
            f = 1;
        }

        if (f)
          mem[p] = 1, ++c;
        do {
          p = (p + 1) % m;
        } while (mem[p]);
      }
    }
    int f = 0;
    rep(i, m) {
      if (!mem[i]) {
        printf(f ? " %d" : "%d", i + 1);
        f = 1;
      }
    }
    puts("");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)

using namespace std;

int main() {
  int m, n;
  char s[9];
  while (scanf("%d%d", &m, &n) && m && n) {
    vector<bool> mem(m);
    rep(i, m) mem[i] = true;
    int p = 0;
    FOR(i, 1, n + 1) {
      scanf("%s", s);
      if (i % 15 == 0) {
        if (strcmp(s, "FizzBuzz"))
          mem[p] = false;
      } else if (i % 5 == 0) {
        if (strcmp(s, "Buzz"))
          mem[p] = false;
      } else if (i % 3 == 0) {
        if (strcmp(s, "Fizz"))
          mem[p] = false;
      } else {
        if (i != s[0] - '0')
          mem[p] = false;
      }

      do {
        p++;
        if (p >= m)
          p = 0;
      } while (!mem[p]);
    }
    int f = 0;
    rep(i, m) {
      if (mem[i]) {
        printf(f ? " %d" : "%d", i + 1);
        f = 1;
      }
    }
    puts("");
  }
  return 0;
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

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

string i_to_s(int n) {
  string s;
  do {
    s.push_back((n % 10) + '0');
    n /= 10;
  } while (n != 0);
  reverse(s.begin(), s.end());
  return s;
}

string FizzBuzz(int i) {
  return i % 3 ? i % 5 ? i_to_s(i) : "Buzz" : i % 5 ? "Fizz" : "FizzBuzz";
}

int main() {
  int m, n;
  int p[1001];

  while (cin >> m >> n, m | n) {
    int num = m;
    bool flag = true;
    for (int i = 0; i < 1001; ++i)
      p[i] = 1;

    for (int i = 0, j = 0; i < n; ++i, ++j, j %= m) {

      while (p[j] == 0 && flag) {
        j++;
        j %= m;
      }
      string s;
      cin >> s;

      if (!(s == FizzBuzz(i + 1)) && flag) {
        p[j] = 0;
        num--;
      }
      if (num == 1) {
        flag = false;
      }
    }
    vector<int> vc;
    for (int i = 0; i < m; ++i) {

      if (p[i])
        vc.push_back(i + 1);
    }
    for (int i = 0; i < (int)vc.size(); ++i) {
      cout << vc[i];
      (i == vc.size() - 1) ? cout << endl : cout << " ";
    }
  }
}

Error: TLE

Fixed submission:

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

string i_to_s(int n) {
  string s;
  do {
    s.push_back((n % 10) + '0');
    n /= 10;
  } while (n != 0);
  reverse(s.begin(), s.end());
  return s;
}

string FizzBuzz(int i) {
  return i % 3 ? i % 5 ? i_to_s(i) : "Buzz" : i % 5 ? "Fizz" : "FizzBuzz";
}

int main() {
  int m, n;
  int p[1001];

  while (cin >> m >> n, m | n) {
    int num = m;
    for (int i = 0; i < 1001; ++i)
      p[i] = 1;

    for (int i = 0, j = 0; i < n; ++i, ++j, j %= m) {

      while (p[j] == 0) {
        j++;
        j %= m;
      }
      string s;
      cin >> s;
      if (s == FizzBuzz(i + 1)) {
      } else {
        // cout << "delete : " << j << endl;
        p[j] = 0;
        num--;
      }
      if (num == 1)
        break;
    }
    vector<int> vc;
    for (int i = 0; i < m; ++i) {

      if (p[i])
        vc.push_back(i + 1);
    }
    for (int i = 0; i < (int)vc.size(); ++i) {
      cout << vc[i];
      (i == vc.size() - 1) ? cout << endl : cout << " ";
    }
  }
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <string>
using namespace std;

bool isMissing(string word, int number) {
  if (number % 15 == 0)
    return word != "FizzBuzz";
  if (number % 3 == 0)
    return word != "Fizz";
  if (number % 5 == 0)
    return word != "Buzz";
  return word != to_string(number);
}

int main() {
  int m, n;
  while (cin >> m >> n, m + n) {
    string words[10001];
    list<int> member;

    for (int i = 1; i <= n; i++)
      cin >> words[i];
    for (int i = 1; i <= m; i++)
      member.push_back(i);

    auto nowPlayer = member.begin();
    for (int i = 1; i <= n; i++) {

      if (isMissing(words[i], i))
        nowPlayer = member.erase(nowPlayer);
      else
        nowPlayer++;
      if (nowPlayer == member.end())
        nowPlayer = member.begin();

      if (member.size() == 1)
        break;
    }

    auto i = member.begin();
    cout << *i;
    for (i++; i != member.end(); i++) {
      cout << ' ' << *i;
    }
    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <string>
using namespace std;

bool isMissing(string word, int number) {
  if (number % 15 == 0)
    return word != "FizzBuzz";
  if (number % 3 == 0)
    return word != "Fizz";
  if (number % 5 == 0)
    return word != "Buzz";
  return word != to_string(number);
}

int main() {
  int m, n;
  while (cin >> m >> n, m + n) {
    list<int> member;
    for (int i = 1; i <= m; i++)
      member.push_back(i);

    auto nowPlayer = member.begin();
    for (int i = 1; i <= n; i++) {
      string word;
      cin >> word;

      if (isMissing(word, i))
        nowPlayer = member.erase(nowPlayer);
      else
        nowPlayer++;
      if (nowPlayer == member.end())
        nowPlayer = member.begin();

      if (member.size() == 1)
        break;
    }

    auto i = member.begin();
    cout << *i;
    for (i++; i != member.end(); i++) {
      cout << ' ' << *i;
    }
    cout << endl;
  }

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

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int m, n;
  string s;
  bool flag;
  int cur;
  while (cin >> m >> n && m && n) {
    vector<int> p(m);
    cur = 0;
    for (int i = 1; i <= m; ++i)
      p[i - 1] = i;
    for (int i = 1; i <= n; ++i) {
      cin >> s;
      flag = false;
      if (i % 15 == 0)
        flag = s != "FizzBuzz";
      else if (i % 5 == 0)
        flag = s != "Buzz";
      else if (i % 3 == 0)
        flag = s != "Fizz";
      else
        flag = i != atoi(s.c_str());
      if (p.size() > 1 && flag) {
        p.erase(p.begin() + cur);
        cur = cur % p.size();
      } else
        cur = (cur + 1) % p.size();
    }
    for (int i = 0; i < p.size(); ++i)
      cout << p[i] << ((i == p.size() - 1) ? "\\n" : " ");
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int m, n;
  string s;
  bool flag;
  int cur;
  while (cin >> m >> n && m && n) {
    vector<int> p(m);
    cur = 0;
    for (int i = 1; i <= m; ++i)
      p[i - 1] = i;
    for (int i = 1; i <= n; ++i) {
      cin >> s;
      flag = false;
      if (i % 15 == 0)
        flag = s != "FizzBuzz";
      else if (i % 5 == 0)
        flag = s != "Buzz";
      else if (i % 3 == 0)
        flag = s != "Fizz";
      else if (i != atoi(s.c_str()))
        flag = true;
      if (p.size() > 1 && flag)
        p.erase(p.begin() + cur);
      else
        cur = (cur + 1) % p.size();
    }
    for (int i = 0; i < p.size(); ++i)
      cout << p[i] << ((i == p.size() - 1) ? "\\n" : " ");
  }
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdlib>
#include <iostream>
#include <string>
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
using namespace std;
bool check(string s, int n) {
  if (n % 15 == 0) {
    if (s == "FizzBuzz")
      return true;
    else
      return false;
  } else if (n % 5 == 0) {
    if (s == "Buzz")
      return true;
    else
      return false;
  } else if (n % 3 == 0) {
    if (s == "Fizz")
      return true;
    else
      return false;
  } else {
    if (atoi(s.c_str()) == n)
      return true;
    else
      return false;
  }
}
int main() {
  int m, n;
  string s;
  while (cin >> m >> n, (m || n)) {
    bool f[1010] = {};
    string s[10010];
    int cur = 0;
    rep(i, n) { cin >> s[i]; }
    int p = m;
    rep(i, n) {
      if (!check(s[i], i + 1)) {
        f[cur % m] = true;
        p--;
      }
      if (p <= 1)
        break;
      while (f[++cur % m]) {
      }
    }
    bool b = 1;
    rep(i, m) {
      if (!b && !f[i]) {
        cout << " " << i + 1;
      }
      if (b && !f[i]) {
        cout << i + 1;
        b = 0;
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <string>
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
using namespace std;
bool check(string s, int n) {
  if (n % 15 == 0) {
    if (s == "FizzBuzz")
      return true;
    else
      return false;
  } else if (n % 5 == 0) {
    if (s == "Buzz")
      return true;
    else
      return false;
  } else if (n % 3 == 0) {
    if (s == "Fizz")
      return true;
    else
      return false;
  } else {
    if (atoi(s.c_str()) == n)
      return true;
    else
      return false;
  }
}
int main() {
  int m, n;
  string s;
  while (cin >> m >> n, (m || n)) {
    bool f[1010] = {};
    int cur = 0;
    rep2(i, 1, n + 1) {
      cin >> s;
      if (!check(s, i))
        f[cur % m] = true;
      while (f[++cur % m]) {
      }
    }
    bool b = 1;
    rep(i, m) {
      if (!b && !f[i]) {
        cout << " " << i + 1;
      }
      if (b && !f[i]) {
        cout << i + 1;
        b = 0;
      }
    }
    cout << endl;
  }
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

set<int> S;
int m, n;
string func(int a) {
  if (a % 15 == 0) {
    return "FizzBuzz";
  }
  if (a % 3 == 0) {
    return "Fizz";
  }
  if (a % 5 == 0) {
    return "Buzz";
  }
  stringstream ss;
  ss << a;
  return ss.str();
}
int next(int a) {
  set<int>::iterator it = S.find(a);
  it++;
  if (it == S.end())
    it = S.begin();
  return *it;
}
void solve() {
  int now = 0;
  S.clear();
  rep(i, m) S.insert(i);
  rep(i, n) {
    string s;
    cin >> s;
    if (S.size() == 1)
      continue;
    int n = next(now);
    if (s != func(i + 1)) {
      S.erase(now);
    }
    now = n;
  }
  bool flag = false;
  for (auto &e : S) {
    if (flag) {
      cout << " ";
    }
    cout << e + 1;
    flag = true;
  }
  cout << endl;
}
int main() {
  while (cin >> m >> n) {
    if (m + n == 0)
      break;
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

set<int> S;
int m, n;
string func(int a) {
  string res = "";
  if (a % 3 == 0) {
    res += "Fizz";
  } else if (a % 5 == 0) {
    res += "Buzz";
  } else if (a % 15 == 0) {
    res += "FizzBuzz";
  } else {
    stringstream ss;
    ss << a;
    res = ss.str();
  }

  return res;
}
int next(int a) {
  set<int>::iterator it = S.find(a);
  it++;
  if (it == S.end())
    it = S.begin();
  return *it;
}
void solve() {
  int now = 0;
  S.clear();
  rep(i, m) S.insert(i);
  rep(i, n) {
    string s;
    cin >> s;
    if (s != func(i + 1)) {
      S.erase(now);
    }
    now = next(now);
  }
  bool flag = false;
  for (auto &e : S) {
    if (flag) {
      cout << " ";
    }
    cout << e + 1;
    flag = true;
  }
  cout << endl;
}
int main() {
  while (cin >> m >> n) {
    if (m + n == 0)
      break;
    solve();
  }

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

#include <iostream>
#include <vector>
using namespace std;
int m, n;
string s;
vector<int> r;
int main() {
  while (~scanf("%d%d", &m, &n)) {
    if (m == 0 && n == 0)
      break;
    int pos = 0;
    r.clear();
    for (int i = 1; i <= m; i++)
      r.push_back(i);
    for (int i = 1; i <= n; i++) {
      cin >> s;
      if (i % 15 == 0) {
        if (s != "FizzBuzz" && r.size() != 1)
          r.erase(r.begin() + pos);
        else
          pos++;
      } else if (i % 3 == 0) {
        if (s != "Fizz" && r.size() != 1)
          r.erase(r.begin() + pos);
        else
          pos++;
      } else if (i % 5 == 0) {
        if (s != "Buzz" && r.size() != 1)
          r.erase(r.begin() + pos);
        else
          pos++;
      } else {
        if (s != to_string(i) && r.size() != 1)
          r.erase(r.begin() + pos);
        else
          pos++;
      }
      pos %= r.size();
    }
    for (int i = 0; i < r.size(); i++) {
      if (i)
        printf(" ");
      printf("%d", r[i]);
    }
    printf("\\n");
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int m, n;
string s;
vector<int> r;
int main() {
  while (~scanf("%d%d", &m, &n)) {
    if (m == 0 && n == 0)
      break;
    int pos = 0;
    for (int i = 1; i <= n; i++) {
      cin >> s;
      if (i % 15 == 0) {
        if (s != "FizzBuzz" && r.size() != 1)
          r.erase(r.begin() + pos);
      } else if (i % 3 == 0) {
        if (s != "Fizz" && r.size() != 1)
          r.erase(r.begin() + pos);
      } else if (i % 5 == 0) {
        if (s != "Buzz" && r.size() != 1)
          r.erase(r.begin() + pos);
      } else {
        if (s != to_string(i) && r.size() != 1)
          r.erase(r.begin() + pos);
      }
      pos = (pos + 1) % r.size();
    }
    for (int i = 0; i < r.size(); i++) {
      if (i)
        printf(" ");
      printf("%d", r[i]);
    }
    printf("\\n");
  }
  return 0;
}
Problem p00221 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int p[2000];

int main() {
  int n, m;
  string s;
  while (cin >> n >> m, n | m) {
    memset(p, -1, sizeof(p));
    for (int i = 1; i <= n; ++i)
      p[i - 1] = i;
    int now = 0;
    for (int i = 0; i < m; ++i) {
      // cout<<"now "<<now<<endl;
      cin >> s;
      if ((i + 1) % 3 == 0 && (i + 1) % 5 == 0) {
        if (s != "FizzBuzz")
          p[now] = -1;
      } else if ((i + 1) % 3 == 0) {
        if (s != "Fizz")
          p[now] = -1;
      } else if ((i + 1) % 5 == 0) {
        if (s != "Buzz")
          p[now] = -1;
      } else {
        if (atoi(s.c_str()) != i + 1)
          p[now] = -1;
      }

      for (int i = 1; i <= n; ++i) {
        if (p[(now + i + n) % n] > 0) {
          now = (now + i + n) % n;
          break;
        }
        if (i == n) {
          p[now] = now + 1;
          break;
        }
      }
    }

    bool first = true;
    for (int i = 0; i < n; ++i) {
      if (p[i] > 0) {
        if (!first)
          printf(" ");
        printf("%d", p[i]);
        first = false;
      }
    }
    puts("");
  }
}

Error: 0

Fixed submission:

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int p[2000];

int main() {
  int n, m;
  string s;
  while (cin >> n >> m, n | m) {
    memset(p, -1, sizeof(p));
    for (int i = 1; i <= n; ++i)
      p[i - 1] = i;
    int now = 0;
    for (int i = 0; i < m; ++i) {
      // cout<<"now "<<now<<endl;
      cin >> s;
      if ((i + 1) % 3 == 0 && (i + 1) % 5 == 0) {
        if (s != "FizzBuzz")
          p[now] = -1;
      } else if ((i + 1) % 3 == 0) {
        if (s != "Fizz")
          p[now] = -1;
      } else if ((i + 1) % 5 == 0) {
        if (s != "Buzz")
          p[now] = -1;
      } else {
        if (atoi(s.c_str()) != i + 1)
          p[now] = -1;
      }

      for (int i = 1; i <= n; ++i) {
        if (p[(now + i + n) % n] > 0) {
          now = (now + i + n) % n;
          break;
        }
      }
    }

    vector<int> ans;
    for (int i = 0; i < n; ++i)
      if (p[i] > 0)
        ans.push_back(p[i]);
    for (int i = 0; i < ans.size() - 1; ++i)
      cout << ans[i] << " ";
    if (ans.size() >= 1)
      cout << ans[ans.size() - 1] << endl;
  }
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool fizzBuzzCheck(int n, string s) {
  if (n % 15 == 0)
    return (s == "FizzBuzz");
  if (n % 3 == 0)
    return (s == "Fizz");
  if (n % 5 == 0)
    return (s == "Buzz");

  for (int i = 0; i < s.length(); i++)
    if (s[i] < '0' || s[i] > '9')
      return false;

  return (atoi(s.c_str()) == n);
}

int main() {
  int n, m;
  string s;

  while (scanf("%d %d\\n", &m, &n), m) {

    vector<int> rem(m);
    for (int i = 0; i < m; i++) {
      rem[i] = i + 1;
    }
    int c = 0;
    for (int i = 1; i <= n; i++) {
      getline(cin, s);
      if (rem.size() == 1)
        continue;
      if (!fizzBuzzCheck(i, s)) {
        rem.erase(remove(rem.begin(), rem.end(), rem[c]), rem.end());
      } else {
        c++;
      }
      c %= rem.size();
    }
    for (int i = 0; i < rem.size(); i++) {
      cout << (i ? " " : "") << rem[i];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

bool FizzBuzz(int a, string s) {
  if (a % 15 == 0)
    return (s == "FizzBuzz");
  if (a % 3 == 0)
    return (s == "Fizz");
  if (a % 5 == 0)
    return (s == "Buzz");
  for (int i = 0; i < s.length(); i++)
    if (s[i] < '0' || s[i] > '9')
      return false;
  return (atoi(s.c_str()) == a);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m, n;
  string t;
  while (scanf("%d%d\\n", &m, &n), m) {
    vector<int> al(m);
    REP(i, m) al[i] = i + 1;
    int now = 0;
    REP(i, n) {
      getline(cin, t);
      if (al.size() == 1)
        continue;
      if (!FizzBuzz(i + 1, t)) {
        al.erase(remove(al.begin(), al.end(), al[now]), al.end());
      } else {
        now++;
      }
      now %= al.size();
    }
    REP(i, al.size()) { cout << (i == 0 ? "" : " ") << al[i]; }
    cout << endl;
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, j) FOR(i, 0, j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1},
          dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;

bool isPrime[10000001];
std::vector<int> P, PQ;

int main() {
  std::fill(isPrime, isPrime + 10000001, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 4; i <= 10000000; i += 2) {
    isPrime[i] = false;
  }

  P.push_back(2);
  for (int i = 3; i <= 10000000; i += 2) {
    if (isPrime[i]) {
      P.push_back(i);
      for (int j = i * 2; j <= 10000000; j += i) {
        isPrime[j] = false;
      }
    }
  }

  for (int i = 0; i + 4 <= P.size(); i++) {
    if (P[i] + 2 == P[i + 1] && P[i + 1] + 4 == P[i + 2] &&
        P[i + 2] + 2 == P[i + 3]) {
      // std::cout << P[i+3] << std::endl;
      PQ.push_back(P[i + 3]);
    }
  }

  int n;
  while (std::cin >> n, n) {
    int lb = 0, ub = PQ.size();
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      if (PQ[mid] > n) {
        ub = mid;
      } else {
        lb = mid;
      }
    }
    std::cout << PQ[lb] << std::endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>

const int MAX_N = 10000000;
int is_prime[MAX_N + 1];

int main() {
  std::vector<int> quad;

  for (int i = 0; i <= MAX_N; i++) {
    is_prime[i] = 1;
  }

  is_prime[1] = 0;

  for (int i = 2; i <= 10000000; i++) {
    if (is_prime[i]) {
      if (i - 8 >= 2 && is_prime[i - 8] && is_prime[i - 6] &&
          is_prime[i - 2]) { // 4つ子素数か
        quad.push_back(i);
      }

      for (int j = i * 2; j <= MAX_N; j += i) {
        is_prime[j] = 0;
      }
    }
  }

  int n;
  while (std::cin >> n, n) {
    for (int i = quad.size() - 1; i >= 0; i--) {
      if (quad[i] <= n) {
        std::cout << quad[i] << std::endl;
        break;
      }
    }
  }
}