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


#include <stdio.h>
char primes[10000001];
int a;
int main() {
  int i, j, x;
  for (i = 2; i <= 4000; i++) {
    if (primes[i] == 1)
      continue;
    for (j = i * i; j <= 10000000; j += i)
      primes[j] = 1;
  }
  while (scanf("%d", &a), a) {
    for (i = a; i >= 13; i--) {
      if ((primes[i] == 0 && primes[i - 2] == 0 && primes[i - 6] == 0 &&
           primes[i - 8] == 0)) {
        printf("%d\\n", i);
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
bool primes[10000001], a;
int main() {
  int i, j, x;
  while (scanf("%d", &x), x) {
    a = 13;
    for (i = 2; i <= x; i++) {
      if (primes[i] == 1)
        continue;
      for (j = i * i; j <= x; j += i)
        primes[j] = 1;
      if (i >= 8 && primes[i - 2] == 0 && primes[i - 6] == 0 &&
          primes[i - 8] == 0)
        a = i;
    }
    printf("%d\\n", a);
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int prime(int a, int b, int c, int d) {
  for (int e = 3;; e += 2) {
    if (a % e == 0 || b % e == 0 || c % e == 0 || d % e == 0)
      return false;
    if ((e + 1) * (e + 1) > d)
      return true;
  }
}
int main() {
  while (1) {
    int a;
    cin >> a;
    if (a == 0)
      break;
    int b = a - (a % 6) + 1;
    if (a % 6 == 0)
      b = a - 5;
    for (;; b -= 6) {
      if (prime(b, b - 2, b - 6, b - 8)) {
        cout << b << endl;
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int prime(int a) {
  if (a % 2 == 0)
    return false;
  if (a % 3 == 0)
    return false;
  for (int b = 5; b < a; b += 2) {
    if (a % b == 0)
      return false;
    if ((b + 1) * (b + 1) > a)
      return true;
  }
}
int main() {
  while (1) {
    int a;
    cin >> a;
    if (a == 0)
      break;
    for (int b = a - (a % 6) + 1;; b -= 6) {
      if (prime(b) && prime(b - 2) && prime(b - 6) && prime(b - 8)) {
        cout << b << endl;
        break;
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int i;
  vector<char> prime;

  for (i = 0; i < 10000000; i++) {
    prime.push_back('1');
  }

  prime[0] = prime[1] = '0';

  for (i = 0; i < 10000000; i++) {
    if (prime[i] == '1') {
      for (int j = 2; j * i < 10000000; j++) {
        prime[j * i] = '0';
      }
    }
  }
  for (i = 0; i < 10000000; i++) {
    if (i + 8 < 10000000) {
      if ((prime[i] == '1' || prime[i] == '2') &&
          (prime[i + 2] == '1' || prime[i + 2] == '2') &&
          (prime[i + 6] == '1' || prime[i + 6] == '2') &&
          (prime[i + 8] == '1' || prime[i + 8] == '2')) {
        prime[i + 8] = '2';
      }
    }
  }

  for (;;) {
    cin >> n;
    if (n == 0)
      break;

    for (; prime[n] != '2'; --n) {
    }
    cout << n << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int i;
  vector<int> prime, prime2;
  vector<int> fourprime;

  for (i = 0; i < 10000000; i++) {
    prime.push_back(1);
  }

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

  for (i = 0; i < 10000000; i++) {
    if (prime[i] == 1) {
      prime2.push_back(i);
      for (int j = 2; j * i < 10000000; j++) {
        prime[j * i] = 0;
      }
    }
  }
  prime.clear();
  for (i = 0; i < prime2.size(); i++) {
    if (i + 8 < prime2.size()) {
      if (prime2[i] + 2 == prime2[i + 1] && prime2[i] + 6 == prime2[i + 2] &&
          prime2[i] + 8 == prime2[i + 3]) {
        fourprime.push_back(prime2[i + 3]);
      }
    }
  }
  prime2.clear();

  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    if (fourprime[fourprime.size() - 1] <= n)
      cout << fourprime[fourprime.size() - 1] << endl;
    else {
      for (i = 0; i < fourprime.size(); ++i) {
        if (fourprime[i] > n) {
          cout << fourprime[i - 1] << endl;
          break;
        }
        if (fourprime[i] == n) {
          cout << fourprime[i] << endl;
          break;
        }
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

const int N_prime = 10000001;

int main() {
  vector<char> used(N_prime, '1');
  int n;

  for (int i = 2; i < sqrt(N_prime); i++) {
    if (used[i] == '0') {
      continue;
    }
    for (int j = i * 2; j < N_prime; j += i) {
      used[j] = '0';
    }
  }

  while (cin >> n, n) {
    int res;
    for (int i = n; i >= 13; i--) {
      if (used[i] == '1' && used[i - 2] == '1') {
        if (used[i - 2] == '1' && used[i - 6] == '1') {
          if (used[i - 6] == '1' && used[i - 8] == '1') {
            res = i;
            break;
          }
        }
      }
    }
    cout << res << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

const int N_prime = 10000000;

class prime {
public:
  prime();
  bool used[N_prime];
};

prime::prime() {
  memset(used, N_prime, sizeof(used));
  // 一千万までの素数
  int lim = sqrt(N_prime);
  for (int i = 2; i < lim; i++) {
    if (used[i] == false) {
      continue;
    }

    for (int j = i * 2; j < N_prime; j += i) {
      used[j] = false;
    }
  }
}

int main() {
  prime obj;

  int n;
  while (cin >> n, n) {
    int res;
    for (int i = n; i >= 13; i--) {
      if (obj.used[i] && obj.used[i - 2]) {
        if (obj.used[i - 2] && obj.used[i - 6]) {
          if (obj.used[i - 6] && obj.used[i - 8]) {
            res = i;
            break;
          }
        }
      }
    }
    cout << res << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

int main() {
  const int N = 10000000;
  deque<bool> isp(N + 1, true);
  isp[0] = isp[1] = false;
  rep(i, N + 1) if (isp[i]) for (int j = i + i; j <= N; j += i) isp[j] = false;

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

int main() {
  const int N = 10000000;
  bool *isp = new bool[N + 1];
  fill(isp, isp + N + 1, true);
  isp[0] = isp[1] = 0;
  rep(i, N + 1) if (isp[i]) for (int j = i + i; j <= N; j += i) isp[j] = false;
  vi ps;
  rep(i, N + 1) if (isp[i]) ps.push_back(i);
  delete[] isp;

  for (int n; cin >> n, n;) {
    int res = 0;
    for (int i = 3; ps[i] <= n; i++)
      if (ps[i] - ps[i - 3] == 8)
        res = ps[i];
    cout << res << endl;
  }

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

#include <iostream>
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
using namespace std;
const int MAX = 10000001;
bool p[MAX];

int main() {
  p[0] = p[1] = 1;
  for (int i = 2; i * i < MAX; ++i) {
    if (!p[i]) {
      for (int j = i * i; j < MAX; j += i) {
        p[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n, n) {
    for (int i = n; i >= 13; i--) {
      if (!p[i] && !p[i - 2] && !p[i - 6] && !p[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
}

Error: -11

Fixed submission:

#include <iostream>
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
using namespace std;

int main() {
  bool p[10000001] = {};
  p[0] = p[1] = 1;
  rep2(i, 2, 1001) {
    if (!p[i]) {
      for (int j = i * i; j <= 10000000; j += i) {
        p[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n, n) {
    for (int i = n; i >= 13; i--) {
      if (!p[i] && !p[i - 2] && !p[i - 6] && !p[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
bool flag[10000001];

int main() {
  int n;
  for (int i = 0; i <= 10000000; i++) {
    if (i <= 1)
      flag[i] = false;
    else
      flag[i] = true;
  }
  for (int i = 2; i * i <= 10000000; i++) {
    if (flag[i] == true) {
      for (int j = i * 2; j <= 10000000; j = j + i) {
        flag[j] = false;
      }
    }
  }
  while (cin >> n, n) {
    for (int i = n; i != 0; i--) {
      if (flag[i] && flag[i - 2] && flag[i - 6] && flag[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
bool flag[10000001];

int main() {
  int n;
  for (int i = 0; i <= 1000000; i++) {
    if (i <= 1)
      flag[i] = false;
    else
      flag[i] = true;
  }
  for (int i = 2; i <= 1001; i++) {
    if (flag[i] == true) {
      for (int j = i * 2; j <= 1000000; j = j + i) {
        flag[j] = false;
      }
    }
  }
  while (cin >> n, n) {
    for (int i = n; i != 0; i--) {
      if (flag[i] && flag[i - 2] && flag[i - 6] && flag[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
bool prime[10000000];

int main() {
  long long n, ans;
  rep(i, 10000001) prime[i] = true;
  prime[0] = prime[1] = false;
  rep(i, 10000) {
    if (!prime[i])
      continue;
    for (int j = i * 2; j < 10000001; j += i) {
      prime[j] = false;
    }
  }
  while (cin >> n, n) {
    for (int i = n; i >= 8; i--) {
      if (prime[i - 8] && prime[i - 6] && prime[i - 2] && prime[i]) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
bool prime[10000000];

int main() {
  long long n, ans;
  rep(i, 10000000) prime[i] = true;
  prime[0] = prime[1] = false;
  rep(i, 5000) {
    if (!prime[i])
      continue;
    for (int j = i * 2; j < 10000000; j += i) {
      prime[j] = false;
    }
  }
  while (cin >> n, n) {
    loop(i, 8, n + 1) {
      if (prime[i - 8] && prime[i - 6] && prime[i - 2] && prime[i])
        ans = i;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  bool p[10000000];
  p[0] = p[1] = false;
  for (int i = 2; i < 10000000; i++) {
    p[i] = true;
  }
  for (int i = 2; i * i < 10000000; i++) {
    if (p[i])
      for (int j = i * i; j < 10000000; j += i) {
        p[j] = false;
      }
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool p[10000000];
  p[0] = p[1] = false;
  for (int i = 2; i < 10000000; i++) {
    p[i] = true;
  }
  for (int i = 2; i * i < 10000000; i++) {
    if (p[i])
      for (int j = i * i; j < 10000000; j += i) {
        p[j] = false;
      }
  }

  while (1) {
    bool x = true;
    int N;
    cin >> N;
    if (N == 0)
      break;
    for (int i = N; i != 0; i--) {
      if (p[i - 8] && p[i - 6] && p[i - 2] && p[i] && x) {
        cout << i << endl;
        x = false;
      }
    }
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
bool a[10000001];
int main() {
  long long b[5000] = {0}, c = 0, i, j;
  for (i = 2; i < 10000001; i++) {
    if (!a[i])
      for (j = i + i; j < 10000001; j += i)
        a[j] = 1;
  }
  for (i = 5; i < 10000001 - 9; i++)
    if (a[i] == 0 && a[i + 2] == 0 && a[i + 6] == 0 && a[i + 8] == 0)
      b[c++] = i + 8;
  while (cin >> j, j) {
    for (i = 0; i < c; i++) {
      if (j < b[i])
        break;
    }
    if (i--)
      ;
    cout << b[i] << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[10000001] = {0}, b[5000] = {0}, c = 0, i, j;
  for (i = 2; i < 10000001; i++) {
    if (!a[i])
      for (j = i + i; j < 10000001; j += i)
        a[j] = 1;
  }
  for (i = 5; i < 10000001 - 9; i++)
    if (a[i] == 0 && a[i + 2] == 0 && a[i + 6] == 0 && a[i + 8] == 0)
      b[c++] = i + 8;
  for (c = i = 0; i < 10000001; i++) {
    if (i >= b[c + 1])
      c++;
    a[i] = b[c];
  }
  while (cin >> c, c)
    cout << a[c] << endl;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
#define MAX_LIST 10000000

int main() {
  bool *prime = (bool *)malloc(sizeof(bool) * MAX_LIST);
  // bool prime[MAX_LIST];
  for (int i = 0; i < MAX_LIST; i++) {
    prime[i] = 1;
  }
  prime[0] = prime[1] = 0;
  for (int i = 0; i * i < MAX_LIST; i++) {
    if (prime[i] == 1) {
      for (int j = i * 2; j < MAX_LIST; j = j + i) {
        prime[j] = 0;
      }
    }
  }
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = n; i > 0; i--) {
      if ((prime[i] == 1) && (prime[i - 2] == 1) && (prime[i - 6] == 1) &&
          (prime[i - 8] == 1)) {
        ans = i;
        break;
      }
    }

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

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
#define MAX_LIST 10000000

int main() {
  // bool *prime=(bool *)malloc(sizeof(bool)*MAX_LIST);
  bool prime[MAX_LIST];
  for (int i = 0; i < MAX_LIST; i++) {
    prime[i] = 1;
  }
  prime[0] = prime[1] = 0;
  for (int i = 0; i * i < MAX_LIST; i++) {
    if (prime[i] == 1) {
      for (int j = i * 2; j < MAX_LIST; j = j + i) {
        prime[j] = 0;
      }
    }
  }
  // int *primelist=(int *)malloc(sizeof(int)*MAX_LIST);
  /*
  int primelist[MAX_LIST];
  int j=0;
  for(int i=0;i<MAX_LIST;i++){
          if(prime[i]==1){
                  primelist[j]=i;
                  j++;
                  }
          }
  }*/
  // int *prime_num=(int*)malloc(sizeof(int)*MAX_LIST);
  /*
  int prime_num[MAX_LIST];
  prime_num[0]=1;
  for(int i=1;i<MAX_LIST;i++){
          prime_num[i]=prime_num[i-1]+prime[i];
  }*/
  /*
  int n;
  while(cin>>n,n){
          int ans=0;
          int s;
          int num=MAX_LIST-1;
          for(int i=num;i>0;i--){
                  if(primelist[i]>n){
                  }else{
                          if((primelist[i]-primelist[i-1]==2)
                                  &&(primelist[i-2]-primelist[i-3]==2)
                                  &&(primelist[i-1]-primelist[i-2]==4)){
                                          ans=primelist[i];
                                          break;
                          }
                  }
          }

          cout<<ans<<endl;
  }*/
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

bool is_prime[10000001];

int main() {

  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 10000001; i++) {
    is_prime[i] = true;
  }

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

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

    if (n == 0)
      break;

    while (n >= 13) {
      if ((is_prime[n] & is_prime[n - 2]) & (is_prime[n - 6] & is_prime[n - 8]))
        break;
      n--;
    }
    cout << n << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool is_prime[10000001];

int main() {

  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 10000001; i++) {
    is_prime[i] = true;
  }

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

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

    if (n == 0)
      break;

    while (n >= 13) {
      if ((is_prime[n] && is_prime[n - 2]) &&
          (is_prime[n - 6] && is_prime[n - 8]))
        break;
    }
    cout << n << endl;
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <stdio.h>
int n;
int a[10000001];
int i, j;

int main() {
  a[0] = 0;
  a[1] = 0;
  for (i = 2; i <= 10000000; i++)
    a[i] = 1;

  for (i = 2; i * i <= 10000000; i++) {
    if (a[i] == 1) {
      for (j = i * i; j <= 10000000; j += i) {
        a[j] = 0;
      }
    }
  }

  for (i = 10000000; i >= 13; i--) {
    if (a[i] == 1 && a[i - 2] == 1 && a[i - 6] == 1 && a[i - 8]) {
      a[i] = i;
    } else {
      a[i] = 0;
    }
  }

  for (i = 14; i <= 10000000; i++) {
    if (a[i] == 0)
      a[i] = a[i - 1];
  }

  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    printf("%d\\n", a[n]);
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;
#define SIZE 10000000

int isP[SIZE + 1];
int ans[SIZE + 1];

void make_table() {
  for (int i = 0; i <= SIZE; i++)
    isP[i] = true;
  isP[0] = isP[1] = false;
  for (int i = 2; i * i <= SIZE; i++) {
    if (isP[i] == false)
      continue;
    for (int j = i * i; j <= SIZE; j += i)
      isP[j] = false;
  }
  ans[13] = 13;
  for (int i = 14; i <= SIZE; i++) {
    ans[i] = ans[i - 1];
    if (isP[i] && isP[i - 2] && isP[i - 6] && isP[i - 8])
      ans[i] = i;
  }
}

int main() {
  make_table();
  int n;
  while (cin >> n && n)
    cout << ans[n] << endl;
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: -11

Fixed submission:

#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;
}