#include using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n; vector a(n); ll mi=inf,mx=-1; REP(i,n){ cin >> a[i]; chmin(mi,a[i]); chmax(mx,a[i]); } if(mi==0){ cout << -1 << endl; return 0; } ll m=mod; if(mx>=4){ cout << m << endl; return 0; } vector fac(4); fac[1]=1,fac[2]=2,fac[3]=6; ll ans=1; REP(i,n){ ll res=1; REP(j,fac[a[i]]){ res*=a[i]; } if(ans*res>m){ cout << m << endl; return 0; } ans*=res; } cout << m%ans << endl; }