Problem:
四つ子素数
(
a, a+2, a+6, a+8
) のように並んだ 4 つの素数の組を四つ子素数といいます。四つ子素数を構成する四つの素数のうち、最大の数をその四つ子素数の大きさと呼びます。例えば、最も小さい大きさの四つ子素数は、(5, 7, 11, 13) の組であり、その大きさは 13 です。次に大きい四つ子素数は、(11, 13, 17, 19) の組で、その大きさは 19 です。
整数
n
(13 ≤
n
≤ 10,000,000) を入力とし、大きさが
n
以下になるような四つ子素数のうち、最大となるものの大きさを出力するプログラムを作成してください。
Input
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットとして１つの整数
n
が１行に与えられます。
データセットの数は 2000 を超えません。
Output
入力データセットごとに、最大となる四つ子素数の大きさを1行に出力します。
Sample Input
13
14
15
16
17
18
19
20
10000
0
Output for the Sample Input
13
13
13
13
13
13
19
19
9439

Submitted solutions:

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

int main() {
	int n;
	vector<bool> isprime(10000000, true);
	isprime[0] = false;
	for (int i = 2; i * i <= 10000000; i++) {
		if (isprime[i - 1]) {
			for (int j = 2 * i - 1; j < 10000000; j += i) isprime[j] = false;
		}
	}
	while (1) {
		cin >> n;
		if (n == 0) break;
		for (int i = n - 8; i >= 2; i--) {
			if (isprime[i - 1]) {
				if (isprime[i + 1]) {
					if (isprime[i + 5]) {
						if (isprime[i + 7]) {
							cout << i + 8 << endl;
							break;
						}
					}
				}
			}
		}
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4608
final_rank: 2

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

using ll = long long;

int main() {
    vector<int> prime;
    vector<bool> is_prime(1e7+1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<is_prime.size(); ++i) {
        if(is_prime[i]) {
            prime.push_back(i);
            for(int j=i+i; j<is_prime.size(); j+=i) {
                is_prime[j] = false;
            }
        }
    }
    vector<int> quad;
    for(int i=3; i<prime.size(); ++i) {
        if(prime[i] == prime[i-1] + 2 && prime[i] == prime[i-2] + 6 && prime[i] == prime[i-3] + 8) {
            quad.push_back(prime[i]);
        }
    }
    int n;
    while(cin >> n, n) {
        cout << *(upper_bound(quad.begin(), quad.end(), n) - 1) << endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 10288
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    vector<int> p(10000001,1);
    p[0]=p[1]=0;
    for(int i=2;i<=10000000;i++){
        if(!p[i]) continue;
        for(int j=i*2;j<=10000000;j+=i){
            p[j]=0;
        }
    }

    vector<int> v;
    for(int i=1;i<=10000000-8;i++){
        if(p[i]&&p[i+2]&&p[i+6]&&p[i+8]) v.push_back(i+8);
    }

    for(int n;cin>>n,n!=0;){
        cout<<*prev(upper_bound(all(v), n))<<"\n";
    }
}
accuracy: 1
time_ms: 150
memory_kb: 42488
final_rank: 20

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

const int N = 10000000;
bool f[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    f[0] = f[1] = true;
    vector<int> res;
    for (int i = 2; i < N; i++) {
        if (f[i]) continue;
        for (int j = i + i; j < N; j += i) {
            f[j] = true;
        }
        if (i >= 8 and !f[i] and !f[i - 2] and !f[i - 6] and !f[i - 8]) res.push_back(i);
    }
    int n;
    while (cin >> n, n) {
        auto it = lower_bound(res.begin(), res.end(), n + 1) - res.begin();
        cout << res[it - 1] << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 13152
final_rank: 5

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

int main(){
    const int lim = 10000050;
    vector<bool> isprime(lim, true);
    isprime[0] = isprime[1] = false;
    for(int i = 2; i < lim; i++){
        if(!isprime[i]) continue;
        for(int j = i+i; j < lim; j += i) isprime[j] = false;
    }

    vector<int> ans;
    for(int i = 2; i < lim; i++){
        if(isprime[i] && isprime[i+2] && isprime[i+6] && isprime[i+8]){
            ans.emplace_back(i+8);
        }
    }

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

        int ac = -1, wa = ans.size();
        while(wa-ac > 1){
            int wj = (wa+ac)/2;
            (ans[wj] <= n ? ac : wa) = wj;
        }
        cout << ans[ac] << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3936
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vvvvvll = vector<vvvvll>;
using vvvvvvll = vector<vvvvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vvvvd = vector<vvvd>;
using vvvvvd = vector<vvvvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;


template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (a == 0)return b;
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}

/*
using mint = modint998244353;
//using Mint = modint;
vector<mint> fact, factinv, inv;
const ll mod = 998244353;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact[0] = fact[1] = 1;
    factinv[0] = factinv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact[i] = (fact[i - 1] * i);
        inv[i] = mod - (inv[mod % i] * (mod / i));
        factinv[i] = (factinv[i - 1] * inv[i]);
    }

}

mint nCk(ll n, ll k) {
    if (n < k || k < 0) return 0;
    return fact[n] * (factinv[k] * factinv[n - k]);
}
*/

template<class T>
vector<vector<T>> mul(vector<vector<T>> A, vector<vector<T>> B) {
    ll N = A.size();
    vector<vector<T>> res(N, vector<T>(N, 0));
    rep(i, N)rep(j, N)rep(k, N) {
        res[i][j] += A[i][k] * B[k][j];
    }
    return res;
}

vll S(vll V,ll A){
    A--;
    vll res;
    res.push_back(V[A]);
    rep(i,V.size()){
        if(i!=A)res.push_back(V[i]);
    }
    return res;
}

int main() {

    
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll INF=1e7+10;
    vb P(INF,1);
    P[0]=P[1]=0;
    rep(i,INF)if(P[i])for(int j=i+i;j<INF;j+=i)P[j]=0;
    vll M;
    rep(i,INF)if(P[i]&&P[i+2]&&P[i+6]&&P[i+8])M.push_back(i+8);
    while(1){
        cin>>INF;
        if(INF==0)return 0;
        auto p=upper_bound(all(M),INF);
        p--;
        cout<<*p<<endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 4060
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
bitset<10000001> bs;
int main(void){
    bs.set();
    ll i,j;
    for(i=2;i<sqrt(10000001);i++){
        if(bs[i]){
            for(j=i*i;j<10000001;j+=i){
                bs[j]=0;
            }
        }
    }
    while(cin>>i,i){
        i-=(i-1)%6;
        while(!(bs[i] && bs[i-2] && bs[i-6] && bs[i-8])){
            i-=6;
        }
        cout<<i<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4660
final_rank: 1

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

// 1 以上 N 以下の整数が素数かどうかを返す
vector<bool> Eratosthenes(int N) {
    // テーブル
    vector<bool> isprime(N+1, true);

    // 0, 1 は予めふるい落としておく
    isprime[0] = isprime[1] = false;

    // ふるい
    for (int p = 2; p <= N; ++p) {
        // すでに合成数であるものはスキップする
        if (!isprime[p]) continue;

        // p 以外の p の倍数から素数ラベルを剥奪
        for (int q = p * 2; q <= N; q += p) {
            isprime[q] = false;
        }
    }

    // 1 以上 N 以下の整数が素数かどうか
    return isprime;
}
int main(){
  vector<bool> isprime = Eratosthenes(10000000);
  vector<int> ans(10000001);
  ans[13] = 13;
  for(int i = 14; i <= 10000000; i++){
    ans[i] = ans[i-1];
    if(isprime[i] && isprime[i-2] && isprime[i-6] && isprime[i-8]) ans[i] = i;
  }
  
  while(true){
    int x;
    cin >> x;
    if(x == 0) return 0;
    cout << ans[x] << endl;
  }
}
accuracy: 1
time_ms: 50
memory_kb: 42852
final_rank: 17

code_snippet: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
 
void makeprime(vector<bool>&prime,int N){
   
   prime[0]=prime[1]=false;
   prime[2]=prime[3]=true;
   int i=2;
    while (true){
        if (i*2>=N) 
            break;
        else{
            prime[i*2]=false;
            i+=1;
        }
    }
    i=0;
        while(true){
            if (3+2*i>=N)break;
            int j=2;
                if (prime[3+2*i]==true){
                while ((3+2*i)*j<N){
                    prime[(3+2*i)*j]=false;
                    j+=1;
                }
                }
            i+=1;
        }
}

int main(void){
long N=10000001;
vector<bool>prime(N,true);

makeprime(prime,N);

    int n;
    while (true){
        cin>>n;
        if (n==0) return 0;
        int m=n;
        while (true){
            if (prime[m]==true and prime[m-2]==true and prime[m-6]==true and prime[m-8]==true){
                std::cout << m << std::endl;
                break;
            }else
                m-=1;
            
        }
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3944
final_rank: 8

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<climits>
#include<iomanip>
#include<cctype>
#include<sstream>
#include<regex>
#include<bitset>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int Mod=998244353;
const int inf=mod*mod;
const double eps=1e-9;
bool prime[10000001];
int ans[10000001];
signed main(){
	for(int i=2;i<=10000000;i++)
		prime[i]=1;
	for(int i=2;i*i<=10000000;i++)
		if(prime[i])
			for(int j=i*i;j<=10000000;j+=i)
				prime[j]=0;
	for(int i=8;i<=10000000;i++){
		if(prime[i-8]&&prime[i-6]&&prime[i-2]&&prime[i])
			ans[i]=i;
		else
			ans[i]=ans[i-1];
	}
	int n;
	while(cin>>n,n)
		cout<<ans[n]<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 91252
final_rank: 19

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

int main(){
  vector<bool> IsPrime(10000001,true);
  for(int i=2;i<=10000000;i++){
    if(!IsPrime[i]) continue;
    for(int j=i*2;j<=10000000;j+=i) IsPrime[j] = false;
  }
  vector<int> ans(10000001,0);
  for(int i=13;i<=10000000;i++){
    if(IsPrime[i] && IsPrime[i-2] && IsPrime[i-6] && IsPrime[i-8]) ans[i] = i;
    else ans[i] = ans[i-1];
  }
  for(;;){
    int n;
    cin >> n;
    if(n == 0) break;
    cout << ans[n] << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 42964
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    int m=10000000;
    vector<bool> p(m+1,true);
    set<int> S;
    p[0]=p[1]=false;
    for(int i=2;i<=m;i++){
        if(!p[i])continue;
        if(i>=13&&p[i]&&p[i-2]&&p[i-6]&&p[i-8]){
            S.insert(i);
        }
        for(int j=2*i;j<=m;j+=i){
            p[j]=false;
        }
    }
    int n;
    while(1){
        in(n);
        if(n==0)return 0;
        auto it=S.upper_bound(n);
        it--;
        out(*it);
    }
}
accuracy: 1
time_ms: 40
memory_kb: 4160
final_rank: 4

code_snippet: #define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








std::vector<bool> isPrime;

void Eratosthenes(int n){
    if(n + 1 <= int(isPrime.size())) return;
    isPrime.resize(n+1, true);
    isPrime[0] = isPrime[1] = false;

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

int main(){
    Eratosthenes(10'000'001);
    int n;
    std::vector<int> ans(10'000'001);
    ans[13] = 13;
    for(int i{14}; i <= 10'000'000; ++i){
        ans[i] = ans[i-1];
        if(isPrime[i] && isPrime[i-2] && isPrime[i-6] && isPrime[i-8]){
            ans[i] = i;
        }
    }
    while(1){
        std::cin >> n;
        if(!n) return 0;
        std::cout << ans[n] << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 42928
final_rank: 15

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
using P = pair<int,int>;
using ll = long long;

const long double EPS = 1e-10;
const int MAX = 10000100;
bool prime[MAX];

void eratosthenes(){
  for(int i = 0 ; i < MAX ; i++)
    prime[i] = true;
  prime[0] = prime[1] = false;
  for(int i = 4 ; i < MAX ; i += 2)
    prime[i] = false;
  for(int i = 3 ; i < (int)sqrt(MAX) ; i += 2){
    if(prime[i]){
      for(int j = i*2 ; j < MAX ; j += i)
        prime[j] = false;
    }
  }
}

int main(){

  ll n;

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

}
accuracy: 1
time_ms: 50
memory_kb: 12856
final_rank: 12

code_snippet: //#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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


#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
bool p[10000001];

void terminAtor()
{
	p[0]=p[1]=1;
	vector<ll> a;
	for(ll i=2;i<10000001;i++)
	{
	    if(p[i]==0)
	    {
	        a.pb(i);
	        for(ll j=i*i;j<10000001;j+=i)
	            p[j]=1;
	    }
	}
	
	ll n;
	while(cin>>n)
	{
	    auto it=lower_bound(all(a),n);
	    ll m;
	    if(it==a.end()){
	        m=a.size();
	        m--;
	    }
	    else
	    {
	        m=it-a.begin();
	    }
	    while(m>0)
	    {
	        if(a[m]>n)
	            m--;
	        if(p[a[m]]==0&&p[a[m]-2]==0&&p[a[m]-6]==0&&p[a[m]-8]==0)
	        {
	            cout<<a[m]<<"\n";
	            break;
	        }
	        m--;
	    }
	}

}

int main()
{	
	checkpoint1();
/********************************************************/	
	
/*******************************************************/	
	
	terminAtor();


/*******************************************************/	
	
/*******************************************************/		
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 20828
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

const int m = 10000000;
bool np[m + 1];
int main() {
    init();

    for (int i = 2; i <= m; ++i) {
        if (np[i])continue;
        for (int j = i * 2; j <= m; j += i)
            np[j] = true;
    }

    for (int n; cin >> n, n;) {
        for (;; --n)if (!(np[n] || np[n - 2] || np[n - 6] || np[n - 8])) {
            print(n);
            break;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 13056
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n"
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

const int m = 10000000;
bool np[m + 1];
int main() {
    init();

    for (int i = 2; i <= m; ++i) {
        if (np[i])continue;
        for (int j = i * 2; j <= m; j += i)
            np[j] = true;
    }

    for (int n; cin >> n, n;) {
        for (;; --n)if (!(np[n] || np[n - 2] || np[n - 6] || np[n - 8])) {
            print(n);
            break;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 12904
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n"
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

const int m = 10000000;
bool np[m + 1];
int main() {
    init();

    for (int i = 2; i <= m; ++i) {
        if (np[i])continue;
        for (int j = i * 2; j <= m; j += i)
            np[j] = true;
    }

    for (int n; cin >> n, n;) {
        for (;; --n)if (!(np[n] || np[n - 2] || np[n - 6] || np[n - 8])) {
            print(n);
            break;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 12984
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n"
#ifdef _DEBUG
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

const int m = 10000000;
bool np[m + 1];
int main() {
    init();

    for (int i = 2; i <= m; ++i) {
        if (np[i])continue;
        for (int j = i * 2; j <= m; j += i)
            np[j] = true;
    }

    for (int n; cin >> n, n;) {
        for (;; --n)if (!(np[n] || np[n - 2] || np[n - 6] || np[n - 8])) {
            print(n);
            break;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 12984
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n"
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

const int m = 10000000;
bool np[m + 1];
int main() {
    init();

    VI p;
    for (int i = 2; i <= m; ++i) {
        if (np[i])continue;
        if (13 <= i && !(np[i] || np[i - 2] || np[i - 6] || np[i - 8]))
            p.emplace_back(i);
        for (int j = i * 2; j <= m; j += i)
            np[j] = true;
    }

    for (int n; cin >> n, n;)
        print(*--upper_bound(all(p), n));

    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 13120
final_rank: 13