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

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

vector<int> pr;
vector<int> Qpr;
bool isp[11451419];

void eratos(int mx) {
  for (int i = 0; i <= mx; i++)
    isp[i] = true;

  isp[0] = false;
  isp[1] = false;

  for (int i = 2; i <= mx; i++) {
    if (isp[i]) {
      pr.push_back(i);
      for (int j = 2 * i; j <= mx; j += i)
        isp[j] = false;
    }
  }
  return;
}

int main() {
  eratos(11451400);
  for (int i = 3; i < pr.size(); i++) {
    int a = pr[i - 3];
    int b = pr[i - 2];
    int c = pr[i - 1];
    int d = pr[i];

    if (b - a == 2 && c - b == 4 && d - c == 2)
      Qpr.push_back(d);
  }
  int n;
  while (cin >> n, n) {
    int ans = 0;

    for (int i = 0; i < Qpr.size(); i++) {
      if (Qpr[i] > n)
        break;
      ans = Qpr[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

vector<int> pr;
vector<int> Qpr;
bool isp[11451419];

void eratos(int mx) {
  for (int i = 0; i <= mx; i++)
    isp[i] = true;

  isp[0] = false;
  isp[1] = false;

  for (int i = 2; i <= mx; i++) {
    if (isp[i]) {
      pr.push_back(i);
      for (int j = 2 * i; j <= mx; j += i)
        isp[j] = false;
    }
  }
  return;
}

int main() {
  eratos(11451400);
  int n;
  while (cin >> n, n) {
    for (int i = 3; i < pr.size(); i++) {
      int a = pr[i - 3];
      int b = pr[i - 2];
      int c = pr[i - 1];
      int d = pr[i];

      if (b - a == 2 && c - b == 4 && d - c == 2)
        Qpr.push_back(d);
    }
    int ans = 0;
    for (int i = 0; i < Qpr.size(); i++) {
      if (Qpr[i] > n)
        break;
      ans = Qpr[i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: 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;

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

Error: MLE

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;

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

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

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

#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int a[10000001];

int main() {
  rep(i, 2, 10000001) {
    if (!a[i]) {
      for (int j = i * 2; j < 10000001; j += i) {
        a[j] = 1;
      }
    }
  }
  int sum;
  rep(i, 1, 9999993) {
    if (!a[i] && !a[i + 2] && !a[i + 6] && !a[i + 8])
      sum = i + 8;
    a[i] = sum;
  }

  int b;
  while (cin >> b && b) {
    cout << a[b - 8] << endl;
  }
}

Error: MLE

Fixed submission:

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

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

#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int a[10000001];
int ans[10000001];

int main() {
  rep(i, 2, 10000001) {
    if (!a[i]) {
      for (int j = i * 2; j < 10000001; j += i) {
        a[j] = 1;
      }
    }
  }
  int sum;
  rep(i, 13, 10000001) {
    if (!a[i] && !a[i - 2] && !a[i - 6] && !a[i - 8])
      sum = i;
    ans[i] = sum;
  }

  int b;
  while (cin >> b && b) {
    cout << ans[b] << endl;
  }
}
Problem p00222 (C++) — buggy submission, verdict: 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() {
  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;
      }
    }
  }
}

Error: -11

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

#include <cstdio>
#include <iostream>

bool prime[10000000];
void primenum(void) {
  for (int i = 0; i < 10000000; i++) {
    prime[i] = true;
    if (i % 2 == 0)
      prime[i] = false;
  }
  prime[1] = prime[0] = false;
  prime[2] = true;
  for (int i = 3; i * i < 10000000; i += 2) {
    for (int j = i * 2; j < 10000000; j += i) {
      prime[j] = false;
    }
  }
}

int main(void) {
  int n;
  primenum();
  while (scanf("%d", &n), n) {
    for (int i = n; 0 <= i; i--) {
      if (prime[i] && prime[i - 2] && prime[i - 6] && prime[i - 8]) {
        printf("%d\\n", i);
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

bool prime[10000000];
void primenum(void) {
  for (int i = 0; i < 10000000; i++) {
    prime[i] = true;
  }
  prime[1] = prime[0] = false;
  for (int i = 2; i * i < 10000000; i++) {
    for (int j = i * 2; j < 10000000; j += i) {
      prime[j] = false;
    }
  }
}

int main(void) {
  int n;
  primenum();
  while (scanf("%d", &n), n) {
    for (int i = n; 0 <= i; i--) {
      if (prime[i] && prime[i - 2] && prime[i - 6] && prime[i - 8]) {
        printf("%d\\n", i);
        break;
      }
    }
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // sort などのアルゴリズム
#include <ctype.h>   // C の文字種用
#include <iostream>  // C++の入出力
#include <stdio.h>   // C の入出力
#include <string.h>  // C の文字列用
#include <string>    // C++の文字列
using namespace std;
const int Max = 10000000;
bool prime[Max];
int main(void) {
  int in, i;
  for (int i = 0; i < Max; i++)
    prime[i] = true;
  prime[1] = false;
  for (int i = 2; i < Max; i++) {
    if (prime[i]) {
      for (int s = i * 2; s <= Max; s += i)
        prime[s] = false;
    }
  }
  while (1) {
    cin >> in;
    if (in == 0)
      break;
    for (i = in; i > 0; i--) {
      if (prime[i] == true && prime[i - 2] == true && prime[i - 6] == true &&
          prime[i - 8]) {
        cout << i << "\\n";
        break;
      }
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm> // sort などのアルゴリズム
#include <iostream>  // C++の入出力
#include <string>    // C++の文字列
using namespace std;
const int Max = 10000000;
int main(void) {
  bool prime[Max];
  int in, i;
  for (int i = 0; i < Max; i++)
    prime[i] = true;
  prime[1] = false;
  for (int i = 2; i < Max; i++) {
    if (prime[i]) {
      for (int s = i * 2; s <= Max; s += i)
        prime[s] = false;
    }
  }
  while (1) {
    cin >> in;
    if (in == 0)
      break;
    for (i = in; i > 0; i--) {
      if (prime[i] == true && prime[i - 2] == true && prime[i - 4] == true &&
          prime[i - 8]) {
        cout << i << "\\n";
        break;
      }
    }
  }
  return 0;
}
Problem p00222 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

bool prime[10000001];

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

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

bool prime[1000000001];

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

#include <iostream>
using namespace std;

const int MAX_N = 10000001;

bool is_prime[MAX_N];

void calc_prime(int n) {
  for (int i = 0; i <= n; ++i)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = 0;

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

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

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

const int MAX_N = 10000001;

bool is_prime[MAX_N];

void calc_prime(int n) {
  for (int i = 0; i <= n; ++i)
    is_prime[i] = true;
  is_prime[0] = is_prime[1] = 0;

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

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

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

#include <algorithm>
#include <stdio.h>
char prime[10000001];
int main() {

  for (int i = 2; i * i <= 10000000; i++) {
    if (prime[i] == 0) {
      prime[i] = 1;
      for (int j = i * 2; j <= 10000000; j += i)
        prime[j] = -1;
    }
  }
  for (int i = 3162; i <= 10000000; i++)
    if (prime[i] == 0)
      prime[i] = 1;
  int a;
  while (scanf("%d", &a), a) {
    do {
      if (a > 7 && prime[a] == 1 && prime[a - 2] == 1 && prime[a - 6] == 1 &&
          prime[a - 8] == 1) {
        printf("%d\\n", a);
        break;
      }
    } while (a--);
    if (a == 0)
      printf("0\\n");
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
int prime[10000001];
int max4[10000001];
int main() {

  for (int i = 2; i * i <= 10000000; i++) {
    if (prime[i] == 0) {
      prime[i] = 1;
      for (int j = i * 2; j <= 10000000; j += i)
        prime[j] = -1;
    }
  }
  for (int i = 3162; i <= 10000000; i++)
    if (prime[i] == 0)
      prime[i] = 1;
  for (int i = 13; i <= 10000000; i++) {
    if (prime[i] == 1 && prime[i - 2] == 1 && prime[i - 6] == 1 &&
        prime[i - 8] == 1)
      max4[i] = i;
    else
      max4[i] = max4[i - 1];
  }
  int a;
  while (scanf("%d", &a), a)
    printf("%d\\n", max4[a]);
}
Problem p00222 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const int INF = 1 << 29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int, int> P;

bool is_prime[10000001];

int main() {
  fill(is_prime, is_prime + 10000001, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i < 10000001; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j < 10000001; j += i) {
        is_prime[j] = false;
      }
    }
  }

  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;

    while (1) {
      if (is_prime[n] && is_prime[n - 2] && is_prime[n - 6] &&
          is_prime[n - 8]) {
        cout << n << endl;
        break;
      }
      n--;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const int INF = 1 << 29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int, int> P;

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

  while (1) {
    int n;
    scanf("%d", &n);
    if (!n)
      break;

    while (1) {
      if (is_prime[n] && is_prime[n - 2] && is_prime[n - 4] &&
          is_prime[n - 8]) {
        cout << n << endl;
        break;
      }
      n--;
    }
  }

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

#include <iostream>
using namespace std;

int main() {
  bool prime[10000000];

  prime[0] = prime[1] = false;
  for (int i = 2; i < 10000000; i++) {
    prime[i] = true;
  }
  for (int i = 2; i * i < 10000000; i++) {
    if (prime[i]) {
      for (int j = i * i; j < 10000000; j += i) {
        prime[j] = false;
      }
    }
  }
  //???????????§?´???°??¨
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = n; i > 0; i--) {
      if (prime[i - 8] && prime[i - 6] && prime[i - 2] && prime[i]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool prime[1000000];

  prime[0] = prime[1] = false;
  for (int i = 2; i < 1000000; i++) {
    prime[i] = true;
  }
  for (int i = 2; i * i < 1000000; i++) {
    if (prime[i]) {
      for (int j = i * i; j < 1000000; j += i) {
        prime[j] = false;
      }
    }
  }
  //???????????§?´???°??¨
  int n = 0;
  int x = 0;

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

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

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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \\
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;

const int MAX = 10000000;
bool is_prime[MAX + 1];

int quad(int n) {
  for (int i = n;; --i) {
    if (is_prime[i] && is_prime[i - 2] && is_prime[i - 6] && is_prime[i - 8])
      return i;
  }
}
int main() {
  fill(is_prime, is_prime + MAX + 1, true);
  for (int i = 2, until = (int)sqrt((double)MAX) + 1; i <= until; ++i) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= MAX; j += i)
        is_prime[j] = false;
    }
  }

  int q = -1;

  int n;
  while (scanf("%d", &n), n)
    printf("%d\\n", quad(n));

  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \\
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;

const int MAX = 10000000;
bool is_prime[MAX + 1];
int quad[MAX + 1];

int main() {
  fill(is_prime, is_prime + MAX + 1, true);
  for (int i = 2, until = (int)sqrt((double)MAX) + 1; i <= until; ++i) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= MAX; j += i)
        is_prime[j] = false;
    }
  }

  int q = -1;
  for (int i = 13; i <= MAX; ++i) {
    if (is_prime[i] && is_prime[i - 2] && is_prime[i - 6] && is_prime[i - 8])
      q = i;
    quad[i] = q;
  }

  int n;
  while (scanf("%d", &n), n)
    printf("%d\\n", quad[n]);

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

#include <cmath>
#include <iostream>
using namespace std;

#define MAX 10000000
bool arr[MAX];

int main() {
  for (int i = 0; i < MAX; i++) {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(MAX); i++) {
    if (arr[i]) {
      for (int j = 0; i * (j + 2) < MAX; j++) {
        arr[i * (j + 2)] = 0;
      }
    }
  }
  while (1) {
    int a;
    cin >> a;
    if (a == 0)
      break;
    for (int i = a; i > 0; i--) {
      if (arr[i] == 1) {
        if (arr[i - 2] == 1) {
          if (arr[i - 6] == 1) {
            if (arr[i - 8] == 1) {
              cout << i << endl;
              break;
            }
          }
        }
      }
    }
  }
}


Error: -11

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

#define MAX 10000000

int main() {
  bool arr[MAX];
  for (int i = 0; i < MAX; i++) {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(MAX); i++) {
    if (arr[i]) {
      for (int j = 0; i * (j + 2) < MAX; j++) {
        arr[i * (j + 2)] = 0;
      }
    }
  }
  while (1) {
    int a;
    cin >> a;
    if (a == 0)
      break;
    for (int i = a; i > 0; i--) {
      if (arr[i] == 1) {
        if (arr[i - 2] == 1) {
          if (arr[i - 6] == 1) {
            if (arr[i - 8] == 1) {
              cout << i << endl;
              break;
            }
          }
        }
      }
    }
  }
}
Problem p00222 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair<INT, INT> II;
typedef vector<II> VII;

template <class T> ostream &operator<<(ostream &os, vector<T> v) {
  for (typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) {
    os << *it_i << ", ";
  }
  return os;
}

const int SIZE = 10000000;
VI P;
bool isPrime[SIZE];

int main() {
  fill(isPrime, isPrime, false);
  for (int i = 3; i < SIZE; i += 2) {
    isPrime[i] = true;
  }
  P.push_back(2);
  for (int i = 3; i < SIZE; i += 2) {
    if (!isPrime[i])
      continue;
    P.push_back(i);
    for (int j = i + i; j < SIZE; j += i) {
      isPrime[j] = false;
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair<INT, INT> II;
typedef vector<II> VII;

template <class T> ostream &operator<<(ostream &os, vector<T> v) {
  for (typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) {
    os << *it_i << ", ";
  }
  return os;
}

const int SIZE = 10000000;
bool isPrime[SIZE];
VI P;

int main() {
  P.clear();
  fill(isPrime, isPrime, false);
  register int i, j;
  for (i = 3; i < SIZE; i += 2) {
    isPrime[i] = true;
  }
  P.push_back(2);
  for (i = 3; i < SIZE; i += 2) {
    if (!isPrime[i])
      continue;
    P.push_back(i);
    for (j = i + i; j < SIZE; j += i) {
      isPrime[j] = false;
    }
  }

  int n;
  while (cin >> n && n) {
    for (VI::reverse_iterator it_i = lower_bound(P.rbegin(), P.rend(), n);
         it_i != P.rend(); ++it_i) {
      int p = *it_i;
      if (p > n)
        continue;
      if (isPrime[p - 2] && isPrime[p - 6] && isPrime[p - 8]) {
        cout << p << endl;
        break;
      }
    }
  }
  return 0;
}