#include "bits/stdc++.h" using namespace std; using namespace std::chrono; typedef long long ll; typedef unsigned long long ull; typedef pair pll; #define _overload4(_1,_2,_3,_4,name,...) name #define _overload3(_1,_2,_3,name,...) name #define _overload2(_1,_2,name,...) name #define _re(n) _rep(i,n) #define _rep(i,n) _repi(i,0,n) #define _repi(i,a,b) for(ll i=a;i=a;i--) #define _rrepc(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c) #define rrep(...) _overload4(__VA_ARGS__,_rrepc,_rrepi,_rrep,_rre)(__VA_ARGS__) #define rbr(i,a) for(auto&& i:a) #define sum(...) accumulate(range(__VA_ARGS__),0) #define _range(i) (i).begin(),(i).end() #define _rangek(i,k) (i).begin(),(i).begin()+k #define range(...) _overload2(__VA_ARGS__,_rangek,_range)(__VA_ARGS__) #define LINF 0x3999999999999999LL #define MOD ll(1000000007) #define MODD ll(998244353) #define INF 0x39999999 #define Yes(i) out(i?"Yes":"No") #define YES(i) out(i?"YES":"NO") #define elif else if //#define START auto start=system_clock::now() //#define END auto end=system_clock::now();cerr<(end-start).count()<<" ms\n" #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__) #define STR(...) string __VA_ARGS__;in(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;in(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;in(__VA_ARGS__) #define vec(type,name,size) vector name(size); #define VEC(type,name,size) vector name(size);in(name) #define vi(name,size,value) vectorname(size,value) #define vv(type,name,h,w,value) vector>name(h,vector(w,value)) struct aaa{aaa(){cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout< inline constexpr T gcd (T a,T b) {if(a==b)return a;else return gcd(b,(a-1)%b+1);} inline void in() {} template istream& operator >> (istream& is, vector& vec); template istream& operator >> (istream& is, array& vec); template istream& operator >> (istream& is, pair& p); template ostream& operator << (ostream& os, vector& vec); template ostream& operator << (ostream& os, pair& p); template istream& operator >> (istream& is, vector& vec){for(T& x: vec) is >> x;return is;} template istream& operator >> (istream& is, pair& p){is >> p.first;is >> p.second;return is;} template ostream& operator << (ostream& os, vector& vec){os << vec[0];rep(i,1,vec.size()){os << ' ' << vec[i];}return os;} template ostream& operator << (ostream& os, pair& p){os << p.first << " " << p.second;return os;} ostream &operator<<(ostream &dest, __uint128_t value) { ostream::sentry s(dest); if (s) { char buffer[128]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(ios_base::badbit); } } return dest; } template inline void in(Head&& head,Tail&&... tail){cin>>head;in(move(tail)...);} template inline void out(T t){cout< inline void out(Head head,Tail... tail){cout<> 1; } return ans; } bool suspect(int a, int s, __uint128_t d, __uint128_t n) { __uint128_t x = bigPowMod(a, d, n); if (x == 1) return true; for (int r = 0; r < s; ++r) { if (x == n - 1) return true; //x = x * x % n; x = bigMul(x, x, n); } return false; } int test[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,-1}; bool MillerRabin(__uint128_t n) { if (n <= 1 || (n > 2 && n % 2 == 0)) return false; __uint128_t d = n - 1; int s = 0; while (d % 2 == 0){ s++; d /= 2; } for (int i = 0; test[i] < n && test[i] != -1; ++i) if (!suspect(test[i], s, d, n)) return false; return true; } bool is_prime(__uint128_t n){ if (n < 2) return false; if (n < 4) return true; if (!(n % 2)) return false; if (!(n % 3)) return false; __uint128_t sq = sqrt(n); for(int i = 5 ;i < 32; i += 4 - i % 6 / 2){ if (sq < i) return true; if (!(n % i)) return false; } if(MillerRabin(n))return true; return false; } __uint128_t perm(int at,vector list,__uint128_t s){ if(at==0)return is_prime(s)?s:0; __uint128_t cnt; if(at==1){ rep(i,0,14)if(list[i]){ if((cnt=perm(0,vector(),s*(i<10?10:100)+i)))return cnt; return 0; } return 0; } if(!list[1]&&!list[3]&&!list[7]&&!list[9]&&!list[11]&&!list[13])return 0; rrep(i,0,10){ if(i-1){ if(list[i]){ list[i]--; if((cnt=perm(at-1,list,s*(i<10?10:100)+i)))return cnt; list[i]++; } } else rrep(j,0,10){ if(j>3){ if(list[1]&&list[j]){ list[1]--; list[j]--; if((cnt=perm(at-2,list,s*100+10+j)))return cnt; list[1]++; list[j]++; } } elif(j-1){ if(list[10+j]){ list[10+j]--; if((cnt=perm(at-1,list,s*100+10+j)))return cnt; list[10+j]++; }elif(list[1]&&list[j]){ list[1]--; list[j]--; if((cnt=perm(at-2,list,s*100+10+j)))return cnt; list[1]++; list[j]++; } }else{ cnt=0; __uint128_t cnt2=0; if(list[1]){ list[1]--; cnt=perm(at-1,list,s*10+1); list[1]++; } if(list[11]){ list[11]--; cnt2=perm(at-1,list,s*100+11); list[11]++; } if(max(cnt,cnt2))return max(cnt,cnt2); } } } return 0; } int main(){ INT(n); vec(int,a,14); rep(n){ INT(m); a[m]++; } __uint128_t cnt; if((cnt=perm(n,a,0)))out(cnt); else out(-1); }