#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include ///////// #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define P(p) cout<<(p)< ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// const int NumMax = 5000000; bool pdp[NumMax+1]; vector prime; //2からNまでの素数を作る-usingめぐちゃん void makePrime(int N){ for(int i=2; i<= N; ++i){ if(pdp[i] == false){ prime.push_back(i); for(int j = i+i; j<= N; j += i){ pdp[j] = true; } } } return ; } void NumCount(int num,int* A,bool flag=false){ int n = num; while(n!=0){ if(flag == true){ --A[(n%10)]; }else{ ++A[(n%10)]; } n /= 10; } return; } int check(bool* A,int* Num){ rep(i,10){ if(A[i] == false && Num[i] > 0){// return 0;//使っちゃダメ } if(A[i] == true && Num[i] == 0){ return 1;//数字が足りない } } return 2;//OK } int main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;// cout << setprecision(10);// makePrime(NumMax); int N; cin>>N; string str; bool A[10]; rep(i,10)A[i] = false; rep(i,N){ cin>>str; A[str[0]-'0'] = true; } if(N==10){ P(5000000-1); return 0; } vector::iterator Left,Right; Left = prime.begin(); Right = prime.begin(); int NumNum[10]; rep(i,10)NumNum[i]=0; NumCount(*Right,NumNum); int ans = -1; int temp; int checkRes; while( Left != prime.end() ){ //cout << *Left << " " << *Right << endl; checkRes = check(A,NumNum); while( checkRes != 0 ){//範囲でcheck if( checkRes == 2){ if(Right == prime.end()-1){ temp = 5000000; }else{ temp = *(Right+1)-1; } if(Left == prime.begin() ){ temp = temp - 1; }else{ temp = temp - *(Left-1) - 1; } if( ans < temp ){ ans = temp; //cout << *Left << " " << *Right << " " << ans << endl; } } ////// if(Right != prime.end() -1 ){ ++Right; NumCount(*Right,NumNum); }else{ break; } checkRes = check(A,NumNum); } //checkRes ==0 || Right == prime.end()-1 if(Left == prime.end() -1){ break; } else if(Left == Right){ ++Right; NumCount(*Right,NumNum); }else{ NumCount(*Left,NumNum,true); ++Left; } } P(ans); return 0; }