alexjercan/bugnet huggingface dataset:
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[10000000] = {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 < 10000000; i++)
    era[i] = true;
  era[0] = false;
  era[1] = false;
  makeERA();

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

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

  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 <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) cout << (#x) << ":" << x << endl

const int SIEVE_MAX = 12525252;

int main() {
  vector<bool> sieve(SIEVE_MAX, true);
  vector<int> ans(SIEVE_MAX, 0);
  sieve[0] = sieve[1] = false;
  REP(i, SIEVE_MAX) {
    if (!sieve[i]) {
      if (i > 0)
        ans[i] = ans[i - 1];
      continue;
    }
    int x = i << 1;
    while (x < SIEVE_MAX) {
      sieve[x] = false;
      x += i;
    }
    if (i >= 9 && sieve[i - 2] && sieve[i - 6] && sieve[i - 8]) {
      ans[i] = i;
    } else {
      ans[i] = ans[i - 1];
    }
  }
  while (true) {
    int x;
    scanf("%d", &x);
    if (x == 0)
      break;
    printf("%d\\n", ans[x]);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <assert.h>
#include <math.h>
#include <stdio.h>

#define N 10000000

#define DEBUG(x) printf("%s : %d\\n", (#x), x)

int main() {
  int x, y = 0;
  while (true) {
    scanf("%d", &x);
    if (x == 0)
      break;
    y++;
  }
  if (y >= 1000)
    assert(false);
  puts("nikko nikko ni~~~~~~~~~~\\n");

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


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

Error: 0

Fixed submission:


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

#include <iostream>
#include <vector>

using namespace std;

const int N = 10000000;

int main() {
  int n;
  vector<bool> is_prime(N + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= N; ++i) {
    for (int j = 2; i * j <= N; ++j) {
      is_prime[i * j] = false;
    }
  }
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int k = n; true; --k) {
      if (k % 6 == 1 and is_prime[k] and is_prime[k - 2] and is_prime[k - 6] and
          is_prime[k - 8]) {
        cout << k << endl;
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

bool is_prime(int n) {
  for (int p = 2; p * p <= n; ++p) {
    if (n % p == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int k = n; true; --k) {
      if (is_prime(k) and is_prime(k - 2) and is_prime(k - 6) and
          is_prime(k - 8)) {
        cout << k << endl;
        break;
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bitset>
#include <stdio.h>
const int N = 10000001;
std::bitset<N> p;
int main() {
  p.set();
  int i, j;
  for (i = 2; i * i < N; ++i)
    if (p[i])
      for (j = i * i; j < N; j += i)
        p[j] = 0;
  while (scanf("%d", &i), i) {
    i -= (i - 1) % 6;
    while (!(p[i] && p[i - 2] && p[i - 6] && p[i - 8]))
      i -= 6;
    printf("%d\\n", i);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

#define MAX 10000001

bool is_prime[MAX];

void Sieve() {
  fill(is_prime, is_prime + MAX, true);
  is_prime[0] = is_prime[1] = false;

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

int main() {

  Sieve();

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

  return 0;
}

Error: TLE

Fixed submission:

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

#define MAX 10000001

bool is_prime[MAX];

void Sieve() {
  fill(is_prime, is_prime + MAX, true);
  is_prime[0] = is_prime[1] = false;

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

int main() {

  Sieve();

  int n;
  while (cin >> n && n) {
    vector<int> dat;
    for (int i = 2; i + 8 <= n; i++) {
      if (is_prime[i] && is_prime[i + 2] && is_prime[i + 6] &&
          is_prime[i + 8]) {
        dat.push_back(i + 8);
      }
    }
    cout << dat.back() << endl;
  }

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

#include <stdio.h>

char prime[10000001];

int main() {
  int i, j, n;

  for (i = 2; i < 10000000; i++)
    prime[i] = 1;

  for (i = 2; i <= 10000000; i++)
    if (prime[i])
      for (j = i + i; j <= 10000000; j += i)
        prime[j] = 0;

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

    if (n % 2 == 0)
      n--;

    for (i = n; i > 13; i -= 2) {
      if (prime[i] + prime[i - 2] + prime[i - 6] + prime[i - 8] == 4) {
        break;
      }
    }

    printf("%d\\n", i);
  }
  return 0;
}

Error: -11

Fixed submission:


#include <stdio.h>

int main(void) {
  long long int i, j, p, n;
  char prime[10000001];

  while (scanf("%lld", &n), n) {

    for (i = 2; i < 10000000; i++)
      prime[i] = 1;

    for (i = 2; i <= n; i++)
      if (prime[i])
        for (j = i + i; j <= n; j += i)
          prime[j] = 0;

    n = (n % 2 ? n : n - 1);

    for (i = n; i > 8; i -= 2)
      if (prime[i] + prime[i - 2] + prime[i - 6] + prime[i - 8] == 4)
        break;

    printf("%lld\\n", i);
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  bool is_prime[10000000];
  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;
      }
    }
  }
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    for (int i = n; i != 0; i--) {
      if (is_prime[i - 8] && is_prime[i - 6]) {
        if (is_prime[i - 2] && is_prime[i]) {
          cout << i << endl;
          break;
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define MAX 10000001

bool isPrime[MAX];
vector<int> res;

void calc() {
  for (int i = 5; i < MAX - 8; i += 2) {
    if (isPrime[i] && isPrime[i + 2] && isPrime[i + 6] && isPrime[i + 8]) {
      res.push_back(i + 8);
    }
  }
}

void eratos() {
  fill(isPrime, isPrime + MAX, true);
  for (int i = 2; i < MAX; i++) {
    if (!isPrime[i])
      continue;
    for (int j = i + i; j < MAX; j += i) {
      isPrime[j] = false;
    }
  }
}

int main() {
  eratos();
  calc();
  while (true) {
    int n;
    cin >> n;
    if (!n)
      return 0;
    for (int i = 0; i < res.size(); i++) {
      if (res[i] > n) {
        cout << res[i - 1] << endl;
        break;
      }
      if (i == res.size() - 1) {
        cout << res[i] << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
#define MAX 10000001

bool isPrime[MAX];

void eratos() {
  fill(isPrime, isPrime + MAX, true);
  for (int i = 2; i < MAX; i++) {
    if (!isPrime[i])
      continue;
    for (int j = i + i; j < MAX; j += i) {
      isPrime[j] = false;
    }
  }
}

int main() {
  eratos();
  while (true) {
    int n;
    cin >> n;
    if (!n)
      return 0;
    int ans = 0;
    for (int i = 5; i <= n - 8; i += 2) {
      if (isPrime[i] && isPrime[i + 2] && isPrime[i + 6] && isPrime[i + 8]) {
        ans = i + 8;
      }
    }
    cout << ans << endl;
  }
}
Problem p00222 (C++) — buggy submission, verdict: 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 < 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;
}

Error: 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++)
    ;
  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, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;

int main() {
  vector<bool> era(10000000, true);
  for (int i = 2; i <= sqrt(10000000); i++) {
    if (era[i]) {
      for (int j = i * i; j <= 10000000; j += i) {
        era[j] = false;
      }
    }
  }
  int n;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = n; i >= 13; i--) {
      if (era[i] && era[i - 2] && era[i - 6] && era[i - 8]) {
        printf("%d\\n", i);
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
const int UPTO = 10000000;
const int USUM = sqrt(UPTO);
int main() {
  vector<bool> sos(UPTO + 1, true);
  sos[0] = sos[1] = false;
  for (int i = 2; i <= USUM; i++) {
    if (sos[i]) {
      for (int j = i * 2; j <= UPTO; j += i) {
        sos[j] = false;
      }
    }
  }
  int n;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    int yo = 1, last = 2, max = -1;
    for (int i = 13; i <= n; i++) {
      if (sos[i]) {
        if (sos[i - 2] && sos[i - 6] && sos[i - 8]) {
          max = i;
        }
      }
    }
    printf("%d\\n", max);
  }
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <iostream>
#include <stdio.h>

using namespace std;

void MakePrimeArray(deque<bool> &A, int n) {

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

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

void yotuko(deque<int> &A) {
  deque<int>::iterator it = A.begin();
  for (int i = 0; i < A.size() - 3; i++) {
    if ((*(it + 1) == ((*it) + 2) && (*(it + 2)) == (*it + 6)) &&
        (*(it + 3) == (*it + 8)))
      A.erase(it);
    else
      it++;
  }
}

int main() {

  int n = 10000001;

  deque<bool> primearray;

  primearray.resize(n);

  MakePrimeArray(primearray, n);
  /*
  deque<int> prime;

  for(int i=13;i<n;i++){
          if(primearray[i]){
                  prime.push_back(i);
          }
  }

  yotuko(prime);
*/
  while (true) {
    int innum;
    cin >> innum;
    // scanf("%d",&innum);

    if (innum == 0)
      break;

    int answer = 0;
    answer = innum;
    while (true) {
      if (primearray[answer] && primearray[answer - 2] &&
          primearray[answer - 6] && primearray[answer - 8]) {
        break;
      }
      answer--;
    }
    cout << answer << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <stdio.h>

using namespace std;

void MakePrimeArray(deque<bool> &A, int n) {

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

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

void yotuko(deque<int> &A) {
  deque<int>::iterator it = A.begin();
  for (int i = 0; i < A.size(); i++) {
    if (!(*(it + 1) == ((*it) + 2) && (*(it + 2)) == (*it + 6)) &&
        (*(it + 3) == (*it + 8)))
      A.erase(it);
    else
      it++;
  }
}

int main() {

  int n = 10000000;

  deque<bool> primearray;

  primearray.resize(n);

  MakePrimeArray(primearray, n);

  deque<int> prime;

  for (int i = 13; i < n; i++) {
    if (primearray[i]) {
      prime.push_back(i);
    }
  }

  yotuko(prime);

  while (true) {
    int innum;
    cin >> innum;
    // scanf("%d",&innum);

    if (innum == 0)
      break;
    deque<int>::iterator it = prime.begin();
    while (*it + 1 > innum) {
      it++;
    }
    // printf("%d \\n",answer);
    cout << *it << endl;
  }

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

#include <stdio.h>
int f[10000000];
int main(void) {
  int n, i, j, flg, w, a, b, c, d, l = 0;
  for (i = 2; i < 10000000; i++)
    f[i] = 1;
  for (i = 2; i * i <= 10000000; i++) {
    for (j = 2; i * j <= 10000000; j++) {
      f[j * i] = 0;
    }
  }
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    a = 0;
    b = 0;
    c = 0;
    d = 0;
    for (i = n; i >= 5; i--) {
      if (f[i] != 0) {
        d = c;
        c = b;
        b = a;
        a = i;
      }
      if (a + 8 == d && b + 6 == d && c + 2 == d)
        break;
    }
    printf("%d\\n", d);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, i, j, flg, w, a, b, c, d;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    a = 0;
    b = 0;
    c = 0;
    d = 0;
    for (i = n; i >= 5; i--) {
      flg = 1;
      for (j = 2; j < i / 2; j++) {
        w = i % j;
        if (w == 0) {
          flg = 0;
          break;
        }
      }
      if (flg == 1) {
        d = c;
        c = b;
        b = a;
        a = i;
      }
      if (d == c + 2 && d == b + 6 && d == a + 8)
        break;
    }
    printf("%d\\n", d);
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) for (int i = 0; i < a; i++)

using namespace std;
bool prime[10000001];

int main() {
  rep(i, 10000001) { prime[i] = true; }
  prime[0] = prime[1] = false;

  loop(i, 2, 10001) {
    if (prime[i]) {
      for (int j = i * 2; j < 10000001; j += i) {
        prime[j] = false;
      }
    }
  }

  int ord;
  while (1) {
    cin >> ord;
    if (ord == 0) {
      break;
    }
    while (ord) {
      if (prime[ord] && prime[ord - 2] && prime[ord - 6] && prime[ord - 8]) {
        cout << ord << endl;
        break;
      } else {
        ord--;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) for (int i = 0; i < a; i++)

using namespace std;
bool prime[10000001];

int main() {
  rep(i, 10000001) { prime[i] = true; }
  prime[0] = prime[1] = false;

  loop(i, 2, 10001) {
    if (prime[i]) {
      for (int j = i * 2; j < 10000001; j += i) {
        prime[j] = false;
      }
    }
  }

  int ord;
  while (1) {
    cin >> ord;
    while (ord) {
      if (ord == 0) {
        break;
      }
      if (prime[ord] && prime[ord - 2] && prime[ord - 6] && prime[ord - 8]) {
        cout << ord << endl;
        break;
      } else {
        ord--;
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: 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 (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;
}

Error: TLE

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 (prime(N) && prime(N - 2) && prime(N - 6) && prime(N - 8)) {
        printf("%d\\n", N);
        break;
      } else
        N -= 10;
    }
  }
  return 0;
}