prithivMLmods/Coder-Stat huggingface dataset:
Problem p00217 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
struct k {
  int bangou;
  int score;
};
int main() {
  int n;
  int d1, d2, b;
  k id[1000];
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> b >> d1 >> d2;
      id[i].bangou = b;
      id[i].score = (d1 + d2);
    }
    int max = 0;
    int ans_b;
    for (int i = 0; i < n; i++) {
      if (id[i].score > max) {
        max = id[i].score;
        ans_b = id[i].bangou;
      }
    }
    cout << ans_b << " " << max << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
struct k {
  int bangou;
  int score;
};
int main() {
  int n;
  int d1, d2, b;
  k id[10001];
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> b >> d1 >> d2;
      id[i].bangou = b;
      id[i].score = (d1 + d2);
    }
    int max = 0;
    int ans_b;
    for (int i = 0; i < n; i++) {
      if (id[i].score > max) {
        max = id[i].score;
        ans_b = id[i].bangou;
      }
    }
    cout << ans_b << " " << max << endl;
  }
  return 0;
}
Problem p00218 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  vector<vector<int>> p(10000, vector<int>(3));
  vector<char> ans(10000);
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> p[i][0] >> p[i][1] >> p[i][2];
      if (p[i][0] == 100 || p[i][1] == 100 || p[i][2] == 100)
        ans[i] = 'A';
      else if (90 * 2 <= p[i][0] + p[i][1])
        ans[i] = 'A';
      else if (80 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'A';
      else if (70 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'B';
      else if (50 * 3 <= p[i][0] + p[i][1] + p[i][2] &&
               (80 <= p[i][0] || 80 <= p[i][1]))
        ans[i] = 'B';
      else
        ans[i] = 'C';
    }
    for (int i = 0; i < n; i++)
      cout << ans[i] << endl;
    p.clear();
    ans.clear();
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  vector<vector<int>> p(10000, vector<int>(3));
  vector<char> ans(10000);
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> p[i][0] >> p[i][1] >> p[i][2];
      if (p[i][0] == 100 || p[i][1] == 100 || p[i][2] == 100)
        ans[i] = 'A';
      else if (90 * 2 <= p[i][0] + p[i][1])
        ans[i] = 'A';
      else if (80 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'A';
      else if (70 * 3 <= p[i][0] + p[i][1] + p[i][2])
        ans[i] = 'B';
      else if (50 * 3 <= p[i][0] + p[i][1] + p[i][2] &&
               (80 <= p[i][0] || 80 <= p[i][1]))
        ans[i] = 'B';
      else
        ans[i] = 'C';
    }
    for (int i = 0; i < n; i++)
      cout << ans[i] << endl;
  }
  return 0;
}
Problem p00218 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main(void) {
  int number, pm, pe, pj, temp;
  while (1) {
    scanf("%d", &number);
    for (int i = number; i > 0; i--) {
      scanf("%d %d %d", &pm, &pe, &pj);
      if (pm == 100 || pe == 100 || pj == 100 || (pe + pm) / 2 >= 90 ||
          (pe + pm + pj) / 3 >= 80) {
        printf("A\n");
      } else if ((pe + pm + pj) / 3 >= 70 ||
                 ((pe + pm + pj) / 3 >= 50 && (pe >= 80 || pm >= 80))) {
        printf("B\n");
      } else {
        printf("C\n");
      }
    }
  }
  return 0;
}


Fixed submission:
#include <stdio.h>

int main(void) {
  int number, pm, pe, pj, temp;
  while (1) {
    scanf("%d", &number);
    if (number == 0) {
      break;
    }
    for (int i = number; i > 0; i--) {
      scanf("%d %d %d", &pm, &pe, &pj);
      if (pm == 100 || pe == 100 || pj == 100 || (pe + pm) / 2 >= 90 ||
          (pe + pm + pj) / 3 >= 80) {
        printf("A\n");
      } else if ((pe + pm + pj) / 3 >= 70 ||
                 ((pe + pm + pj) / 3 >= 50 && (pe >= 80 || pm >= 80))) {
        printf("B\n");
      } else {
        printf("C\n");
      }
    }
  }
  return 0;
}
Problem p00219 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  while (cin >> n, n) {
    int c[10];
    fill(c, c + 10, 0);
    for (int i = 0; i < n; i++)
      cin >> t, c[t]++;
    for (int i = 0; i < n; i++) {
      if (!c[i])
        cout << '-';
      else
        for (int j = 0; j < c[i]; j++)
          cout << '*';
      cout << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  while (cin >> n, n) {
    int c[10];
    fill(c, c + 10, 0);
    for (int i = 0; i < n; i++)
      cin >> t, c[t]++;
    for (int i = 0; i < 10; i++) {
      if (!c[i])
        cout << '-';
      else
        for (int j = 0; j < c[i]; j++)
          cout << '*';
      cout << endl;
    }
  }
}
Problem p00219 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;
  int buy;
  int ice[10];

  while (scanf("%d", &n), n != 0) {
    for (int i = 0; i < 10; i++) {
      ice[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      scanf("%d", &buy);
      ice[buy]++;
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < ice[i]; j++) {
        if (ice[i] == 0) {
          cout << "-" << endl;
          break;
        } else {
          cout << "*";
        }
      }
      cout << endl;
    }
  }

  return (0);
}

Fixed submission:
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;
  int buy;
  int ice[10];

  while (scanf("%d", &n), n != 0) {
    for (int i = 0; i < 10; i++) {
      ice[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      scanf("%d", &buy);
      ice[buy]++;
    }

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < ice[i]; j++) {
        if (ice[i] == 0) {
          cout << "-" << endl;
          break;
        } else {
          cout << "*";
        }
      }
      cout << endl;
    }
  }

  return (0);
}
Problem p00219 (C++)

Buggy submission (status: 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;
    vector<int> nums(10000);
    for (int i = 0; i < N; ++i) {
      int a;
      cin >> a;
      nums[a]++;
    }
    for (int i = 0; i < 10; ++i) {
      if (nums[i]) {
        for (int j = 0; j < nums[i]; ++j) {
          cout << '*';
        }
      } else {
        cout << '-';
      }
      cout << endl;
    }
  }
  return 0;
}

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;
    if (!N)
      break;
    vector<int> nums(10000);
    for (int i = 0; i < N; ++i) {
      int a;
      cin >> a;
      nums[a]++;
    }
    for (int i = 0; i < 10; ++i) {
      if (nums[i]) {
        for (int j = 0; j < nums[i]; ++j) {
          cout << '*';
        }
      } else {
        cout << '-';
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00219 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int menu[10];
    fill_n(menu, n, 0);
    rep(i, n) {
      int a;
      cin >> a;
      menu[a]++;
    }
    rep(i, 10) {
      if (menu[i] == 0) {
        cout << "-" << endl;
      } else {
        rep(j, menu[i]) { cout << "*"; }
        cout << endl;
      }
    }
  }

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int menu[15];
    fill_n(menu, 15, 0);
    rep(i, n) {
      int a;
      cin >> a;
      menu[a]++;
    }
    rep(i, 10) {
      if (menu[i] == 0) {
        cout << "-" << endl;
      } else {
        rep(j, menu[i]) { cout << "*"; }
        cout << endl;
      }
    }
  }

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
Problem p00219 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int a, n;
  while (1) {
    map<int, string> str;
    cin >> n;
    for (a = 0; a < n; a++) {
      int b;
      cin >> b;
      str[b].push_back('*');
    }
    for (a = 0; a <= 9; a++) {
      if (str.size() > 0)
        cout << str[a] << endl;
      else
        cout << "-" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int a, n;
  while (1) {
    map<int, string> str;
    cin >> n;
    if (n == 0)
      break;
    for (a = 0; a < n; a++) {
      int b;
      cin >> b;
      str[b].push_back('*');
    }
    for (a = 0; a <= 9; a++) {
      if (str.size() > 0)
        cout << str[a] << endl;
      else
        cout << "-" << endl;
    }
  }
  return 0;
}
Problem p00219 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, a;
  cin >> n;
  int b[10] = {};
  while (cin >> a) {
    b[a] += 1;
  }
  for (int i = 0; i < 10; i++) {
    if (b[i] > 0) {
      string s(b[i], '*');
      cout << s << endl;
    } else {
      cout << '-' << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, a;
  while (cin >> n, n) {
    int b[10] = {};
    for (int i = 0; i < n; i++) {
      cin >> a;
      b[a] += 1;
    }
    for (int i = 0; i < 10; i++) {
      if (b[i] > 0) {
        string s(b[i], '*');
        cout << s << endl;
      } else if (b[i] <= 0) {
        cout << '-' << endl;
      }
    }
  }
  return 0;
}
Problem p00220 (C++)

Buggy submission (status: Runtime Error):
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

int main() {
  char c;
  while (1) {
    string str;
    long long a, b;
    getline(cin, str);
    if (str[0] == '-') {
      break;
    }
    a = b = 0;
    int i = 0;
    while (str[i] != '.') {
      a *= 10;
      a += str[i] - '0';
      i++;
    }
    i++;
    int d = 1000;
    while (i < str.size()) {
      b += d * (str[i] - '0');
      d /= 10;
      i++;
    }

    a *= 16;
    b *= 16;
    a += b / 10000;

    if ((~(0xfff) & a) || (b % 10000))
      cout << "NA" << endl;
    else {
      for (int i = 0; i < 12; i++) {
        if (i == 8)
          cout << ".";
        cout << !!(a & (0x1 << (11 - i)));
      }
      cout << endl;
    }
  }
}

Fixed submission:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

int main() {
  char c;
  while (1) {
    string str;
    long long a, b;
    getline(cin, str);
    if (str[0] == '-') {
      break;
    }
    a = b = 0;
    int i = 0;
    while (str[i] != '.' && i < str.size()) {
      a *= 10;
      a += str[i] - '0';
      i++;
    }
    i++;
    int d = 1000;
    while (i < str.size()) {
      b += d * (str[i] - '0');
      d /= 10;
      i++;
    }

    a *= 16;
    b *= 16;
    a += b / 10000;

    if ((~(0xfff) & a) || (b % 10000))
      cout << "NA" << endl;
    else {
      for (int i = 0; i < 12; i++) {
        if (i == 8)
          cout << ".";
        cout << !!(a & (0x1 << (11 - i)));
      }
      cout << endl;
    }
  }
}
Problem p00221 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int M, N;

  while (cin >> M >> N, M != 0 && N != 0) {
    bool flag[1005] = {};
    int jb = 0;
    int cnt = 1;
    int d = 0;
    bool lock = false;
    while (cnt <= N) {
      string S;
      cin >> S;
      while (!lock) {
        if (S == "FizzBuzz") {
          if (cnt % 15 != 0) {
            flag[jb] = true;
            d++;
          }
        } else if (S == "Fizz") {
          if (cnt % 3 != 0 || cnt % 15 == 0) {
            flag[jb] = true;
            d++;
          }
        } else if (S == "Buzz") {
          if (cnt % 5 != 0 || cnt % 15 == 0) {
            flag[jb] = true;
            d++;
          }
        } else {
          int val = atoi(S.c_str());
          if (val != cnt || cnt % 3 == 0 || cnt % 5 == 0) {
            flag[jb] = true;
            d++;
          }
        }
        if (d == M - 1) {
          lock = true;
        }
        (jb += 1) %= M;
        while (flag[jb]) {
          (jb += 1) %= M;
        }
      }
      cnt++;
    }
    vector<int> ans;
    for (int i = 0; i < M; i++) {
      if (!flag[i]) {
        ans.push_back(i + 1);
      }
    }
    cout << ans[0];
    for (int i = 1; i < ans.size(); i++) {
      cout << " " << ans[i];
    }
    cout << endl;
  }
  return (0);
}


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

int main() {
  int M, N;

  while (cin >> M >> N, M != 0 && N != 0) {
    bool flag[1005] = {};
    int jb = 0;
    int cnt = 1;
    int d = 0;
    bool lock = false;
    while (cnt <= N) {
      string S;
      cin >> S;
      if (!lock) {
        if (S == "FizzBuzz") {
          if (cnt % 15 != 0) {
            flag[jb] = true;
            d++;
          }
        } else if (S == "Fizz") {
          if (cnt % 3 != 0 || cnt % 15 == 0) {
            flag[jb] = true;
            d++;
          }
        } else if (S == "Buzz") {
          if (cnt % 5 != 0 || cnt % 15 == 0) {
            flag[jb] = true;
            d++;
          }
        } else {
          int val = atoi(S.c_str());
          if (val != cnt || cnt % 3 == 0 || cnt % 5 == 0) {
            flag[jb] = true;
            d++;
          }
        }
        if (d == M - 1) {
          lock = true;
        }
        (jb += 1) %= M;
        while (flag[jb]) {
          (jb += 1) %= M;
        }
      }
      cnt++;
    }
    vector<int> ans;
    for (int i = 0; i < M; i++) {
      if (!flag[i]) {
        ans.push_back(i + 1);
      }
    }
    cout << ans[0];
    for (int i = 1; i < ans.size(); i++) {
      cout << " " << ans[i];
    }
    cout << endl;
  }
  return (0);
}
Problem p00221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

int main() {
  int m, n;
  while (cin >> m >> n, m | n) {
    vector<int> player(m);
    rep(i, m) player[i] = i;

    int p = 0;
    FOR(i, 1, n + 1) {
      string s;
      cin >> s;
      if (player.size() == 1)
        continue;

      if (!check(s, i))
        player.erase(player.begin() + p);
      else
        p = (p + 1) % player.size();
    }
    rep(i, player.size()) { cout << (i ? " " : "") << player[i] + 1; }
    cout << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

int main() {
  int m, n;
  while (cin >> m >> n, m | n) {
    vector<int> player(m);
    rep(i, m) player[i] = i;

    int p = 0;
    FOR(i, 1, n + 1) {
      string s;
      cin >> s;
      if (player.size() == 1)
        continue;

      if (!check(s, i))
        player.erase(player.begin() + p);
      else
        p++;
      p %= player.size();
    }
    rep(i, player.size()) { cout << (i ? " " : "") << player[i] + 1; }
    cout << endl;
  }

  return 0;
}
Problem p00221 (C++)

Buggy submission (status: Runtime Error):
#include <list>
#include <stdio.h>
#include <string.h>

int main() {
  using namespace std;
  int i, n, m, ps;
  char opn[10], ans[10];
  bool ff, bf;
  list<int> player;
  list<int>::iterator it;
  do {
    scanf("%d %d", &m, &n);
    if (!m && !n)
      break;
    for (i = 0; i < m; i++)
      player.push_back(i + 1);
    for (i = 0, it = player.begin(), ps = m; i < n; i++) {
      scanf("%s", opn);
      if (ps < 2)
        continue;
      ff = (i + 1) % 3 == 0, bf = (i + 1) % 5 == 0;
      if (ff || bf) {
        sprintf(ans, "%s%s", ff ? "Fizz" : "", bf ? "Buzz" : "");
      } else {
        sprintf(ans, "%d", i + 1);
      }
      if (strcmp(ans, opn)) {
        it = player.erase(it);
        ps--;
      } else {
        it++;
      }
      if (it == player.end())
        it = player.begin();
    }
    it = player.begin();
    while (it != player.end()) {
      printf("%d", *it);
      it++;
      if (it != player.end())
        printf(" ");
    }
    printf("\n");
    player.clear();
  } while (1);
  return 0;
}

Fixed submission:
#include <list>
#include <stdio.h>
#include <string.h>

int main() {
  using namespace std;
  int i, n, m, ps;
  char opn[20], ans[20];
  bool ff, bf;
  list<int> player;
  list<int>::iterator it;
  do {
    scanf("%d %d", &m, &n);
    if (!m && !n)
      break;
    for (i = 0; i < m; i++)
      player.push_back(i + 1);
    for (i = 0, it = player.begin(), ps = m; i < n; i++) {
      scanf("%s", opn);
      if (ps < 2)
        continue;
      ff = (i + 1) % 3 == 0, bf = (i + 1) % 5 == 0;
      if (ff || bf) {
        sprintf(ans, "%s%s", ff ? "Fizz" : "", bf ? "Buzz" : "");
      } else {
        sprintf(ans, "%d", i + 1);
      }
      if (strcmp(ans, opn)) {
        it = player.erase(it);
        ps--;
      } else {
        it++;
      }
      if (it == player.end())
        it = player.begin();
    }
    it = player.begin();
    while (it != player.end()) {
      printf("%d", *it);
      it++;
      if (it != player.end())
        printf(" ");
    }
    printf("\n");
    player.clear();
  } while (1);
  return 0;
}
Problem p00221 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

string to_s(int n) {
  string s;
  while (n) {
    s += n % 10 + '0';
    n /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
string FizzBuzz(int n) {
  if (n % 3 == 0 && n % 5 == 0)
    return "FizzBuzz";
  if (n % 3 == 0)
    return "Fizz";
  if (n % 5 == 0)
    return "Buzz";
  return to_s(n);
}

int main() {
  int m, n;
  bool f[1000];
  while (cin >> m >> n, m | n) {
    fill_n(f, m, true);
    string s;
    int rest = m;
    int num = 1, a = 0;
    for (int i = 0; i < n; i++) {
      cin >> s;
      if (rest == 1)
        break;
      while (!f[a]) {
        a = (a + 1) % m;
      }
      if (s != FizzBuzz(num)) {
        f[a] = false;
        rest--;
      }
      a = (a + 1) % m;
      num++;
    }
    bool first = true;
    for (int i = 0; i < m; i++) {
      if (!f[i])
        continue;
      if (!first)
        cout << ' ';
      first = false;
      cout << i + 1;
    }
    cout << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

string to_s(int n) {
  string s;
  while (n) {
    s += n % 10 + '0';
    n /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
string FizzBuzz(int n) {
  if (n % 3 == 0 && n % 5 == 0)
    return "FizzBuzz";
  if (n % 3 == 0)
    return "Fizz";
  if (n % 5 == 0)
    return "Buzz";
  return to_s(n);
}

int main() {
  int m, n;
  bool f[1000];
  while (cin >> m >> n, m | n) {
    fill_n(f, m, true);
    string s;
    int rest = m;
    int num = 1, a = 0;
    for (int i = 0; i < n; i++) {
      cin >> s;
      if (rest == 1)
        continue;
      while (!f[a]) {
        a = (a + 1) % m;
      }
      if (s != FizzBuzz(num)) {
        f[a] = false;
        rest--;
      }
      a = (a + 1) % m;
      num++;
    }
    bool first = true;
    for (int i = 0; i < m; i++) {
      if (!f[i])
        continue;
      if (!first)
        cout << ' ';
      first = false;
      cout << i + 1;
    }
    cout << endl;
  }
  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

const int nmax = 10000000;
char nums[nmax];

int main() {
  int n;
  for (int i = 2; i < nmax; i++) {
    nums[i] = '1';
  }
  for (int i = 2; i * i < nmax; i++) {
    for (int k = 2; k * i < nmax; k++) {
      nums[i * k] = '0';
    }
  }
  while (cin >> n) {
    if (n == 0)
      break;
    int i = n;
    while (nums[i] == '0' || nums[i - 2] == '0' || nums[i - 6] == '0' ||
           nums[i - 8] == '0')
      i--;
    cout << i << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

const int nmax = 10000000;
char nums[nmax];

int main() {
  int n;
  for (int i = 2; i < nmax; i++) {
    nums[i] = '1';
  }
  for (int i = 2; i * i < nmax; i++) {
    if (nums[i] == '1') {
      for (int k = 2; k * i < nmax; k++) {
        nums[i * k] = '0';
      }
    }
  }
  while (cin >> n) {
    if (n == 0)
      break;
    int i = n;
    while (nums[i] == '0' || nums[i - 2] == '0' || nums[i - 6] == '0' ||
           nums[i - 8] == '0')
      i--;
    cout << i << endl;
  }
  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

bool era[10000001] = {false};

void makeERA() {
  for (int i = 2; i < 1000001; i++) {
    if (era[i] != true)
      continue;
    for (int j = 2;; j++) {
      if (i * j <= 1000000)
        era[i * j] = false;
      else
        break;
    }
  }
  era[2] = true;
}

int main() {
  for (int i = 0; i < 10000001; i++)
    era[i] = true;
  era[0] = false;
  era[1] = false;
  makeERA();

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

    if (n % 2 == 0)
      n--;
    for (int i = n; i >= 8; i -= 2) {
      if (era[i - 8] && era[i - 6] && !era[i - 4] && era[i - 2] && era[i]) {
        cout << i << endl;
        goto next;
      }
    }
  next:;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

bool era[10000001] = {false};

void makeERA() {
  for (int i = 2; i < 1000001; i++) {
    if (era[i] != true)
      continue;
    for (int j = 2; i * j <= 10000000; j++) {
      era[i * j] = false;
    }
  }
  era[2] = true;
}

int main() {
  for (int i = 0; i < 10000001; i++)
    era[i] = true;
  era[0] = false;
  era[1] = false;
  makeERA();

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

    if (n % 2 == 0)
      n--;
    for (int i = n; i >= 8; i -= 2) {
      if (era[i - 8] && era[i - 6] && !era[i - 4] && era[i - 2] && era[i]) {
        cout << i << endl;
        goto next;
      }
    }
  next:;
  }

  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
const int N = 10010;

bool isprime[N];

int makePrime() {
  REP(i, N) isprime[i] = true;
  isprime[0] = false;
  isprime[1] = false;

  for (int i = 2; (i * i) <= N; i++) {
    if (!isprime[i])
      continue;
    for (int j = i + i; j < N; j += i)
      isprime[j] = false;
  }
}

int main() {
  makePrime();

  int n;
  while (cin >> n && n) {
    for (int i = n; i >= 8; i--) {
      if (isprime[i] && isprime[i - 2] && isprime[i - 6] && isprime[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
const int N = 10000000;

bool isprime[N];

int makePrime() {
  REP(i, N) isprime[i] = true;
  isprime[0] = false;
  isprime[1] = false;

  for (int i = 2; (i * i) <= N; i++) {
    if (!isprime[i])
      continue;
    for (int j = i + i; j < N; j += i)
      isprime[j] = false;
  }
}

int main() {
  makePrime();

  int n;
  while (cin >> n && n) {
    for (int i = n; i >= 8; i--) {
      if (isprime[i] && isprime[i - 2] && isprime[i - 6] && isprime[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int F[11451419];
#define EPS 1e-14
bool prime(int p) {
  if (F[p] == 0)
    return false;
  if (F[p] == 1)
    return true;

  for (int i = 2; i * i <= p; i++) {
    if (F[i] == 0)
      continue;
    if (p % i == 0) {
      F[p] = 0;
      return false;
    }
  }
  F[p] = 1;
  return true;
}
int main() {
  for (int i = 1; i <= 10000000; i++)
    F[i] = -1;
  while (true) {
    int N;
    scanf("%d", &N);
    if (N == 0)
      break;
    if (N >= 13 && N <= 18) {
      printf("13\n");
      continue;
    }
    while (true) {
      if (N % 10 != 9) {
        N--;
        continue;
      }
      if (prime(N) && prime(N - 2) && prime(N - 6) && prime(N - 8)) {
        printf("%d\n", N);
        break;
      } else
        N -= 10;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int F[11451419];
#define EPS 1e-14
bool prime(int p) {
  if (F[p] == 0)
    return false;
  if (F[p] == 1)
    return true;

  for (int i = 2; i * i <= p; i++) {
    if (F[i] == 0)
      continue;
    if (p % i == 0) {
      F[p] = 0;
      return false;
    }
  }
  F[p] = 1;
  return true;
}
int main() {
  for (int i = 1; i <= 10000000; i++)
    F[i] = -1;
  while (true) {
    int N;
    scanf("%d", &N);
    if (N == 0)
      break;
    if (N >= 13 && N <= 18) {
      printf("13\n");
      continue;
    }
    while (true) {
      if (N % 10 != 9) {
        N--;
        continue;
      }
      if (N % 3 != 1) {
        N--;
        continue;
      }
      if (prime(N) && prime(N - 2) && prime(N - 6) && prime(N - 8)) {
        printf("%d\n", N);
        break;
      } else
        N -= 10;
    }
  }
  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int prime[10000011];
bool is_prime[10000011];
int MAX[10000011];

void sieve(int n) {
  int p = 0;
  rep(i, 0, n + 1) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  rep(i, 2, n + 1) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = i * 2; j <= n; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

signed main() {
  int n;
  sieve(10000001);
  MAX[9] = 0;
  rep(i, 10, 10000001) {
    MAX[i] = MAX[i - 1];
    if (is_prime[i] && is_prime[i - 2] && is_prime[i - 6] && is_prime[i - 8]) {
      MAX[i] = i;
    }
  }
  /*rep(i, 10, 30) {
          cout << i << " " << MAX[i] <<" " << is_prime[i]<< endl;
  }*/
  while (cin >> n && n) {
    cout << MAX[n] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int prime[10000011];
bool is_prime[10000011];
int MAX[10000011];

void sieve(int n) {
  int p = 0;
  rep(i, 0, n + 1) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  rep(i, 2, n + 1) {
    if (is_prime[i]) {
      prime[p++] = i;
      for (int j = i * 2; j <= n; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

signed main() {
  int n;
  sieve(10000001);
  MAX[9] = 0;
  rep(i, 10, 10000001) {
    MAX[i] = MAX[i - 1];
    if (is_prime[i] && is_prime[i - 2] && is_prime[i - 6] && is_prime[i - 8]) {
      MAX[i] = i;
    }
  }
  /*rep(i, 10, 30) {
          cout << i << " " << MAX[i] <<" " << is_prime[i]<< endl;
  }*/
  while (cin >> n && n) {
    cout << MAX[n] << endl;
  }
}
Problem p00222 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

using namespace std;

inline bool isPrime(int n) {
  int sq = sqrt(n);
  for (int i = 3; i <= sq; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {

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

    int ans = -1;
    if (n % 10 == 9)
      n++;
    else
      n = (int)(n / 10) * 10;

    for (int i = n; i > 10; i -= 10) {
      if (isPrime(i - 9)) {
        if (isPrime(i - 7)) {
          if (isPrime(i - 3)) {
            if (isPrime(i - 1)) {
              ans = i - 1;
              break;
            }
          }
        }
      }
    }
    if (ans == -1)
      ans = 13;

    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

inline bool isPrime(int n) {
  int sq = sqrt(n);
  for (int i = 3; i <= sq; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {

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

    int ans = -1;
    if (n % 10 == 9)
      n++;
    else
      n = (int)(n / 10) * 10;

    for (int i = n; i > 10; i -= 10) {
      if (isPrime(i - 9) && isPrime(i - 7) && isPrime(i - 3) &&
          isPrime(i - 1)) {
        ans = i - 1;
        break;
      }
    }
    if (ans == -1)
      ans = 13;

    cout << ans << endl;
  }

  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
const int SIZE = 10000000;
bool isprime[SIZE + 1];
vector<int> prime;
void make_prime() {
  for (int i = 2; i <= SIZE; i++) {
    isprime[i] = true;
  }
  isprime[0] = false;
  isprime[1] = false;
  for (int i = 2; i <= SIZE; i++) {
    if (isprime[i] == false)
      continue;
    for (int j = i * 2; j <= SIZE; j += i) {
      isprime[j] = false;
    }
    prime.push_back(i);
  }
}

vector<int> yotugo;
void make_list() {
  for (int i = 0; i <= (prime.size() - 4); i++) {
    if (prime[i + 1] == (prime[i] + 2) && prime[i + 2] == (prime[i] + 6) &&
        prime[i + 3] == (prime[i] + 8)) {
      yotugo.push_back(prime[i + 3]);
    }
  }
}

int check(int n) {
  int i;
  for (i = 0; yotugo[i] <= n; i++)
    ;
  return yotugo[i - 1];
}

int main() {
  make_prime();
  make_list();
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    cout << check(n) << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
const int SIZE = 10000000;
bool isprime[SIZE + 1];
vector<int> prime;
void make_prime() {
  for (int i = 2; i <= SIZE; i++) {
    isprime[i] = true;
  }
  isprime[0] = false;
  isprime[1] = false;
  for (int i = 2; i <= SIZE; i++) {
    if (isprime[i] == false)
      continue;
    for (int j = i * 2; j <= SIZE; j += i) {
      isprime[j] = false;
    }
    prime.push_back(i);
  }
}

vector<int> yotugo;
void make_list() {
  for (int i = 0; i <= (prime.size() - 4); i++) {
    if (prime[i + 1] == (prime[i] + 2) && prime[i + 2] == (prime[i] + 6) &&
        prime[i + 3] == (prime[i] + 8)) {
      yotugo.push_back(prime[i + 3]);
    }
  }
}

int check(int n) {
  int i;
  for (i = 0; yotugo[i] <= n && i < yotugo.size(); i++)
    ;
  return yotugo[i - 1];
}

int main() {
  make_prime();
  make_list();
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    cout << check(n) << endl;
  }
  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef long long ll;

ll prime[10000001];
void Eratosthenes(int n) {
  rep(i, n) prime[i] = true;
  prime[1] = false;

  REP(i, 2, (int)sqrt(n)) {
    if (prime[i]) {
      for (int j = 0; i * (j + 2) < n; j++) {
        prime[i * (j + 2)] = 0;
      }
    }
  }
}

int main() {
  Eratosthenes(10000001);

  int n;
  while (cin >> n && n) {
    ll ans = 0;
    for (int i = n; i >= 0; i--) {
      if (prime[i] && prime[i - 2] && prime[i - 6] && prime[i - 8]) {
        ans = i;
        break;
      }
    }

    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef long long ll;

bool prime[10000001];
void Eratosthenes(int n) {
  rep(i, n) prime[i] = true;
  prime[1] = false;

  REP(i, 2, (int)sqrt(n)) {
    if (prime[i]) {
      for (int j = 0; i * (j + 2) < n; j++) {
        prime[i * (j + 2)] = 0;
      }
    }
  }
}

int main() {
  Eratosthenes(10000001);

  int n;
  while (cin >> n && n) {
    ll ans = 0;
    for (int i = n; i >= 0; i--) {
      if (prime[i] && prime[i - 2] && prime[i - 6] && prime[i - 8]) {
        ans = i;
        break;
      }
    }

    cout << ans << endl;
  }
}
Problem p00222 (C++)

Buggy submission (status: Runtime Error):

#include <iostream>
using namespace std;

const int MAX_N = 1000100;
bool prime[MAX_N];
int num[MAX_N];
int main() {

  prime[0] = prime[1] = false;

  for (int i = 2; i < MAX_N; i++) {
    prime[i] = true;
  }

  for (int i = 2; i * i < MAX_N; i++) {
    if (prime[i]) {
      for (int j = i * i; j < MAX_N; j += i)
        prime[j] = false;
    }
  }

  int cnt = 0, tmp = MAX_N;

  int n, ans;
  while (true) {
    cin >> n;
    if (n == 0)
      break;

    for (int i = n - 8; i >= 0; i--) {
      if (prime[i] && prime[i + 2] && prime[i + 6] && prime[i + 8]) {
        cout << i + 8 << endl;
        break;
      }
    }
  }

  return 0;
}

Fixed submission:

#include <iostream>
using namespace std;

const int MAX_N = 10001000;
bool prime[MAX_N];
int num[MAX_N];
int main() {

  prime[0] = prime[1] = false;

  for (int i = 2; i < MAX_N; i++) {
    prime[i] = true;
  }

  for (int i = 2; i * i < MAX_N; i++) {
    if (prime[i]) {
      for (int j = i * i; j < MAX_N; j += i)
        prime[j] = false;
    }
  }

  int cnt = 0, tmp = MAX_N;

  int n, ans;
  while (true) {
    cin >> n;
    if (n == 0)
      break;

    for (int i = n - 8; i >= 0; i--) {
      if (prime[i] && prime[i + 2] && prime[i + 6] && prime[i + 8]) {
        cout << i + 8 << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
#define N 10000001
using namespace std;

int main() {
  int i, j, n, a[N];
  for (i = 2; i < N; i++)
    a[i] = 1;
  for (i = 2; i * 2 <= N; i++) {
    if (a[i] == 1) {
      for (j = i * 2; j <= N; j += i)
        a[j] = 0;
    }
  }

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

    int ans = 0;
    for (i = n; i >= 13; i--) {
      if (a[i] == 1 && a[i - 2] == 1 && a[i - 6] == 1 && a[i - 8] == 1) {
        ans = i;
        break;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
#define N 10000001
using namespace std;

int main() {
  int i, j, n;
  bool a[N];
  for (i = 2; i < N; i++)
    a[i] = 1;
  for (i = 2; i * 2 <= N; i++) {
    if (a[i] == 1) {
      for (j = i * 2; j <= N; j += i)
        a[j] = 0;
    }
  }

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

    int ans = 0;
    for (i = n; i >= 13; i--) {
      if (a[i] == 1 && a[i - 2] == 1 && a[i - 6] == 1 && a[i - 8] == 1) {
        ans = i;
        break;
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <cstdio>

int prmt[10000005] = {};

int rest[10000005] = {};

int main(void) {
  int n, i, j;
  prmt[0] = -1;
  prmt[1] = -1;
  for (i = 2; i <= 10000000; i++) {
    if (prmt[i] == -1)
      continue;
    prmt[i] = 1;
    j = i * 2;
    while (j <= 10000000) {
      prmt[j] = -1;
      j += i;
    }
  }
  j = 13;
  for (i = 13; i <= 10000000; i++) {
    if (prmt[i] == 1 && prmt[i - 2] == 1 && prmt[i - 6] == 1 &&
        prmt[i - 8] == 1)
      j = i;
    rest[i] = j;
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    printf("%d\n", rest[n]);
  }
  return 0;
}

Fixed submission:
#include <cstdio>

char prmt[10000005] = {};

int rest[10000005] = {};

int main(void) {
  int n, i, j;
  prmt[0] = -1;
  prmt[1] = -1;
  for (i = 2; i <= 10000000; i++) {
    if (prmt[i] == -1)
      continue;
    prmt[i] = 1;
    j = i * 2;
    while (j <= 10000000) {
      prmt[j] = -1;
      j += i;
    }
  }
  j = 13;
  for (i = 13; i <= 10000000; i++) {
    if (prmt[i] == 1 && prmt[i - 2] == 1 && prmt[i - 6] == 1 &&
        prmt[i - 8] == 1)
      j = i;
    rest[i] = j;
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    printf("%d\n", rest[n]);
  }
  return 0;
}
Problem p00222 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define MAX 10000100
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
bool sosu[MAX];
int main() {
  bool sosu[MAX];
  memset(sosu, true, MAX);
  for (int i = 4; i < MAX; i += 2)
    sosu[i] = false;
  for (int i = 3; i < MAX; i += 2)
    for (int j = 3 * i; j < MAX; j += 2 * i)
      sosu[j] = false;
  int n;
  while (cin >> n, n) {
    for (int i = n; i >= 0; i--) {
      if (sosu[i] && sosu[i - 2] && sosu[i - 6] & sosu[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define MAX 10000100
const double PI = acos(-1);
const double EPS = 1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
bool sosu[MAX];
int main() {
  memset(sosu, true, MAX);
  for (int i = 4; i < MAX; i += 2)
    sosu[i] = false;
  for (int i = 3; i < MAX; i += 2)
    for (int j = 3 * i; j < MAX; j += 2 * i)
      sosu[j] = false;
  int n;
  while (cin >> n, n) {
    for (int i = n; i >= 0; i--) {
      if (sosu[i] && sosu[i - 2] && sosu[i - 6] & sosu[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p00225 (C++)

Buggy submission (status: Runtime Error):
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0225
// ユニオンファインド木
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// int n;//単語の数

int par[26];
int r[26]; // rank

void init(int n) {
  for (int i = 0; i < n; i++) {
    r[i] = 0;
    par[i] = i;
  }
}

int root(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = root(par[x]);
  }
}

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) {
    return;
  }
  if (r[x] < r[y]) {
    par[x] = y;
  } else if (r[x] > r[y]) {
    par[y] = x;
  } else if (r[x] == r[y]) {
    par[x] = y;
    r[y]++;
  }
}

int main() {
  int n;

  while (cin >> n, n) {
    init(n);
    vector<string> word(n);
    for (auto &s : word) {
      cin >> s;
    }

    vector<int> in(26), out(26);
    for (auto &s : word) {
      const auto
          first = s[0] - 'a',
          last =
              s.back() -
              'a'; // 最初と最後の文字を取り出す　-'a'はa-zを0-25に対応させている
      in[first]++; // 入次数
      out[last]++; // 出次数
      unite(first, last); // 頂点(アルファべット)first,lastが同じ集合に属する
    }
    bool ok = true;
    int comp_num = 0; // 集合の数
    for (int i = 0; i < 26; i++) {
      comp_num += (in[i] && root(i) == i);
      ok &= in[i] == out[i];
    }
    ok &= (comp_num == 1);
    if (ok) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}


Fixed submission:
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0225
// ユニオンファインド木
#include <iostream>
#include <string>
#include <vector>
using namespace std;

// int n;//単語の数

int par[26];
int r[26]; // rank

void init(int n) {
  for (int i = 0; i < n; i++) {
    r[i] = 0;
    par[i] = i;
  }
}

int root(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = root(par[x]);
  }
}

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y) {
    return;
  }
  if (r[x] < r[y]) {
    par[x] = y;
  } else if (r[x] > r[y]) {
    par[y] = x;
  } else if (r[x] == r[y]) {
    par[x] = y;
    r[y]++;
  }
}

int main() {
  int n;

  while (cin >> n, n) {
    init(26);
    vector<string> word(n);
    for (auto &s : word) {
      cin >> s;
    }

    vector<int> in(26), out(26);
    for (auto &s : word) {
      const auto
          first = s[0] - 'a',
          last =
              s.back() -
              'a'; // 最初と最後の文字を取り出す　-'a'はa-zを0-25に対応させている
      in[first]++; // 入次数
      out[last]++; // 出次数
      unite(first, last); // 頂点(アルファべット)first,lastが同じ集合に属する
    }
    bool ok = true;
    int comp_num = 0; // 集合の数
    for (int i = 0; i < 26; i++) {
      comp_num += (in[i] && root(i) == i);
      ok &= in[i] == out[i];
    }
    ok &= (comp_num == 1);
    if (ok) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}
Problem p00227 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {

  int N, M;
  int n[1001] = {};

  while (1) {
    int s = 0;
    scanf("%d %d", &N, M);
    if (N == 0 && M == 0)
      break;

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

    for (int i = 1; i <= N; i++)
      for (int j = N; j > i; j--)
        if (n[j] > n[j - 1]) {
          int t = n[j - 1];
          n[j - 1] = n[j];
          n[j] = t;
        }

    for (int i = 1; i <= N; i++) {
      if (i % M != 0)
        s += n[i];
    }

    printf("%d\n", s);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {

  int N, M;
  int n[1001] = {};

  while (1) {
    int s = 0;
    scanf("%d %d", &N, &M);
    if (N == 0 && M == 0)
      break;

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

    for (int i = 1; i <= N; i++)
      for (int j = N; j > i; j--)
        if (n[j] > n[j - 1]) {
          int t = n[j - 1];
          n[j - 1] = n[j];
          n[j] = t;
        }

    for (int i = 1; i <= N; i++) {
      if (i % M != 0)
        s += n[i];
    }

    printf("%d\n", s);
  }

  return 0;
}
Problem p00227 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main() {
  int n, m, fig[1001];
  while (cin >> n >> m) {
    int ans = 0;
    for (int i = 0; i < n; i++)
      cin >> fig[i];
    sort(fig, fig + n, greater<int>());
    for (int i = 0; i < (n / m) * m; i++) {
      if ((i + 1) % m)
        ans += fig[i];
    }
    for (int i = n - 1, j = 0; j < (n % m); i--, j++)
      ans += fig[i];
    fill(fig, fig + 1001, 0);
    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main() {
  int n, m, fig[1001];
  while (cin >> n >> m, n || m) {
    int ans = 0;
    for (int i = 0; i < n; i++)
      cin >> fig[i];
    sort(fig, fig + n, greater<int>());
    for (int i = 0; i < (n / m) * m; i++) {
      if ((i + 1) % m)
        ans += fig[i];
    }
    for (int i = n - 1, j = 0; j < (n % m); i--, j++)
      ans += fig[i];
    fill(fig, fig + 1001, 0);
    cout << ans << endl;
  }
}
Problem p00227 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int a, b, i, sum = 0;
  int c[a];
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    for (i = 0; i < a; i++) {
      cin >> c[i];
      sum += c[i];
    }
    sort(c, c + a);
    reverse(c, c + a);
    for (i = b - 1; i < a; i += b) {
      sum -= c[i];
    }
    cout << sum << endl;
    sum = 0;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int a, b, i, sum = 0;
  int c[10000];
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    for (i = 0; i < a; i++) {
      cin >> c[i];
      sum += c[i];
    }
    sort(c, c + a);
    reverse(c, c + a);
    for (i = b - 1; i < a; i += b) {
      sum -= c[i];
    }
    cout << sum << endl;
    sum = 0;
  }

  return 0;
}