alexjercan/bugnet huggingface dataset:
Problem p00222 (C++) — buggy submission, verdict: 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;
  }
}

Error: MLE

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, verdict: 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) && isPrime(i - 7) && isPrime(i - 3) &&
          isPrime(i - 1)) {
        ans = i - 1;
        break;
      }
    }
    if (ans == -1)
      ans = 13;

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

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)) {
        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;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

#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;
}
Problem p00222 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>

using namespace std;

char prime[9973220];

void make(void);

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

    if (n >= 9973220)
      n = 9973219;

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

void make(void) {
  for (int i = 0; i < 9973220; i++)
    prime[i] = 1;

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

  for (int i = 2; i * i < 9973220; i++) {
    if (prime[i] == 1) {
      for (int j = i * 2; j < 9973220; j += i)
        prime[j] = 0;
    }
  }
}

Error: MLE

Fixed submission:

#include <iostream>

using namespace std;

int prime[9973220];

void make(void);

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

    if (n > 9973219)
      n = 9973220;

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

void make(void) {
  for (int i = 0; i < 9973220; i++)
    prime[i] = 1;

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

  for (int i = 2; i * i < 9973220; i++) {
    if (prime[i] == 1) {
      for (int j = i * 2; j <= 9973220; j += i)
        prime[j] = 0;
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: 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 < 10000001; i++) {
    if (era[i] != true)
      continue;
    for (int j = 2;; j++) {
      if (i * j <= 10000000)
        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;
}

Error: TLE

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 (long i = 2; i < 1000001; i++) {
    if (era[i] != true)
      continue;
    for (long 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;
}
Problem p00222 (C++) — buggy submission, verdict: 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; 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;
}

Error: TLE

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;; 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;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>

#define max 9973219

using namespace std;

int main() {
  int n, a[900], p = 0;
  char prime[max + 1];
  fill(prime, prime + (max + 1), 1);

  prime[0] = prime[1] = 0;
  for (int i = 2; i <= max; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= max; j += i) {
        prime[j] = 0;
      }
    }
  }

  for (int i = 0; i + 19 <= max; i += 30) {
    if (prime[i + 11] && prime[i + 13] && prime[i + 17] && prime[i + 19]) {
      a[p++] = i + 19;
    }
  }

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    if (n < 19) {
      cout << 13 << endl;
      continue;
    }
    if (max < n) {
      cout << max << endl;
      continue;
    }

    for (int i = 1; i < p; i++) {
      if (a[i] > n) {
        n = i - 1;
        break;
      }
    }

    cout << a[n] << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>

#define max 9973219

using namespace std;

int main() {
  int n, a[900], p = 0;
  char prime[max + 1];
  fill(prime, prime + (max + 1), 1);

  prime[0] = prime[1] = 0;
  for (int i = 2; i <= max; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= max; j += i) {
        prime[j] = 0;
      }
    }
  }

  for (int i = 0; i + 19 <= max; i += 30) {
    if (prime[i + 11] && prime[i + 13] && prime[i + 17] && prime[i + 19]) {
      a[p++] = i + 19;
    }
  }

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    if (n < 19) {
      cout << 13 << endl;
      continue;
    }
    if (max < n) {
      cout << max << endl;
    }

    for (int i = 1; i < p; i++) {
      if (a[i] > n) {
        n = i - 1;
        break;
      }
    }

    cout << a[n] << endl;
  }

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

#include <math.h>
#include <stdio.h>
#include <string.h>
int a, s, d[10000000], f, g, h;
int main(void) {
  int i, j, k;
  for (i = 2; i <= 10000000; i++)
    d[i] = 1;
  d[1] = 0;
  d[2] = 1;
  for (i = 2; i * i <= 10000000; i++) {
    if (d[i] == 1) {
      for (j = 2; j <= 5000000; j++) {
        if (i * j > 10000000)
          break;
        d[i * j] = 0;
      }
    }
  }
  // for(i=0;i<10000000;i++) if(d[i]==1) printf("%d  ",i);
  while (1) {
    g = 0;
    scanf("%d", &a);
    if (a == 0)
      break;
    for (i = a; i > 12; i--) {
      if (d[i] == 1 && d[i - 2] == 1 && d[i - 6] == 1 && d[i - 8] == 1) {
        g = i;
        break;
      }
    }
    printf("%d\\n", g);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <string.h>
long long int a, s, d[210000000], f, g, h;
int main(void) {
  long long int i, j, k;
  for (i = 2; i <= 10000000; i++)
    d[i] = 1;
  d[1] = 0;
  d[2] = 1;
  for (i = 2; i * i <= 10000000; i++) {
    if (d[i] == 1) {
      for (j = 2; j <= 5000000; j++) {
        if (i * j > 10000000)
          break;
        d[i * j] = 0;
      }
    }
  }
  while (1) {
    g = 0;
    scanf("%lld", &a);
    if (a == 0)
      break;
    for (i = a; i > 12; i--) {
      if (d[i] == 1 && d[i - 2] == 1 && d[i - 6] == 1 && d[i - 8] == 1) {
        g = i;
        break;
      }
    }
    printf("%lld\\n", g);
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

// 2013/11/25(Mon)

#include <iostream>
using namespace std;
bool is_prime[10000000];
int main() {

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

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

  int n;

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

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

Error: 0

Fixed submission:

// 2013/11/25(Mon)

#include <iostream>
using namespace std;

int main() {
  bool is_prime[10000];
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 10000; i++)
    is_prime[i] = true;

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

  int n;

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

    for (int i = n; i >= 13; i--) {
      if (is_prime[i] && is_prime[i - 2] && is_prime[i - 6] &&
          is_prime[i - 8]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

// 2014/04/27 Tazoe

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

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

  return 0;
}

Error: -11

Fixed submission:

// 2014/04/27 Tazoe

#include <iostream>
using namespace std;

int main() {
  bool is_prime[10000001];

  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;

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

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

// 2010/12/27 Tazoe

#include <iostream>
using namespace std;

bool prime3200[3200];

void eratos3200() {
  prime3200[0] = false;
  prime3200[1] = false;

  for (int i = 2; i < 3200; i++)
    prime3200[i] = true;

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

bool primeq(int n) {
  if (n < 13)
    return false;

  if (n % 2 == 0)
    return false;

  if (n < 3200)
    return prime3200[n] && prime3200[n - 2] && prime3200[n - 6] &&
           prime3200[n - 8];

  for (int i = 3; i * i <= n; i += 2) {
    if (!prime3200[i])
      continue;
    if (n % i == 0 || (n - 2) % i == 0 || (n - 6) % i == 0 || (n - 8) % i == 0)
      return false;
  }

  return true;
}

int main() {
  eratos3200();

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

    for (int i = n; i >= 13; i--)
      if (primeq(i)) {
        cout << i << endl;
        break;
      }
  }

  return 0;
}

Error: TLE

Fixed submission:

// 2010/12/27 Tazoe

#include <iostream>
using namespace std;

bool prime3200[3200];

void eratos3200() {
  prime3200[0] = false;
  prime3200[1] = false;

  for (int i = 2; i < 3200; i++)
    prime3200[i] = true;

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

bool prime(int n) {
  if (n <= 1)
    return false;

  if (n < 3200)
    return prime3200[n];

  if (n % 2 == 0)
    return false;

  for (int i = 3; i * i <= n; i += 2) {
    if (!prime3200[i])
      continue;
    if (n % i == 0)
      return false;
  }

  return true;
}

int main() {
  eratos3200();

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

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

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 30;

// Óé¢@N10^8Å5s­ç¢
const int N = 10240000; // MAXPRIME
const int M = 3200;     // SQRT(N)
const int K = 1643297;  // NUMBER OF PRIMES, CHOOSE 9/8 * N / LOG(N)
vector<int> iterSieve() {
  static int p[K], table[M];
  for (int i = 2; i < M; ++i)
    p[i] = i;
  for (int i = 2; i * i < M; ++i)
    if (p[i])
      for (int j = i * i; j < M; j += i)
        p[j] = 0;
  p[0] = p[1] = 0;
  int num = remove(p, p + M, 0) - p;
  for (int m = M; m < N; m += M) {
    for (int x = m; x < m + M; ++x)
      table[x - m] = x;
    for (int i = 0, j; p[i] * p[i] < m + M; ++i) {
      if (p[i] >= m)
        j = p[i] * p[i];
      else if (m % p[i] == 0)
        j = m;
      else
        j = m - (m % p[i]) + p[i];
      for (; j < m + M; j += p[i])
        table[j - m] = 0;
    }
    num = remove_copy(table, table + M, p + num, 0) - p;
  }
  return vector<int>(p, p + num);
}

#define N 1000100

int main() {
  vector<int> v = iterSieve();
  int n;
  while (cin >> n, n) {
    for (int i = upper_bound(ALL(v), n) - v.begin() - 1; v[i] >= 13; --i) {
      int a = v[i];
      if (v[i - 1] == a - 2 && v[i - 2] == a - 6 && v[i - 3] == a - 8) {
        cout << a << endl;
        break;
      }
    }
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 30;

vector<int> eratosthenes(int n) {
  vector<int> v(n);
  for (int i = 2; i < n; i++)
    v[i] = i;
  for (int i = 2; i * i < n; i++)
    if (v[i])
      for (int j = i * i; j < n; j += i)
        v[j] = 0;
  v.erase(remove(ALL(v), 0),
          v.end()); // ツつアツつアツづーツづつつッツづェツづ篠素ツ青板δ環スツト
  return v;
}

int main() {
  vector<int> prime = eratosthenes(10001000);
  int n;
  while (cin >> n, n) {
    for (int i = upper_bound(ALL(prime), n) - prime.begin() - 1; prime[i] >= 13;
         --i) {
      int a = prime[i];
      if (prime[i - 1] == a - 2 && prime[i - 2] == a - 6 &&
          prime[i - 3] == a - 8) {
        cout << a << endl;
        break;
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
#define N 10000000
int main() {
  int *a;
  int b;
  int i, j, p;
  int c[100000];
  int d[100000];
  a = new int[N];
  p = 1;
  while (1 == 1) {
    scanf("%d", &c[p]);
    if (c[p] != 0)
      p++;
    else
      break;
  }
  b = (int)pow(N, 0.5);
  a[0] = -1;
  for (i = 2; i <= b; i++) {
    for (j = 2; j <= N / i; j++) {
      a[i * j - 1] = -1;
    }
  }
  for (i = 1; i < p; i++) {
    for (j = c[i]; j > 0; j--) {
      if (a[j - 1] != -1) {
        if (a[j - 2 - 1] != -1 && a[j - 6 - 1] != -1 && a[j - 8 - 1] != -1) {
          d[i] = j;
          j = 0;
        }
      }
    }
    printf("%d\\n", d[i]);
  }
  delete[] a;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
#define N 10000000

int main() {
  int *a;
  int b;
  int i, j, p;
  int c[1000];
  int d[1000];
  a = new int[N];
  p = 1;
  while (1 == 1) {
    scanf("%d", &c[p]);
    if (c[p] != 0)
      p++;
    else
      break;
  }
  b = (int)pow(N, 0.5);
  a[0] = -1;
  for (i = 2; i <= b; i++) {
    for (j = 2; j <= N / i; j++) {
      a[i * j - 1] = -1;
    }
  }
  for (i = 1; i < p; i++) {
    for (j = c[i]; j > 0; j--) {
      if (a[j - 1] != -1) {
        if (a[j - 2 - 1] != -1 && a[j - 6 - 1] != -1 && a[j - 8 - 1] != -1) {
          d[i] = j;
          j = 0;
        }
      }
    }
    printf("%d\\n", d[i]);
  }
  delete[] a;

  return 0;
}