#include using namespace std; #define ll long long #define PI acos(-1) const int mod = 1e9+7; ll bigMod(ll a,ll b) { ll ans=1; while(b) { if(b&1) ans = (ans*a); a = (a*a); b >>=1; } return ans; } int main() { int n; cin >> n; vectorarr(n); for(int i=0; i> arr[i]; } sort(arr.begin(),arr.end()); ll answer = 1; ll mn = *min_element(arr.begin(),arr.end()); ll mx = *max_element(arr.begin(),arr.end()); if(mn == 0) answer = -1; else if(mx >=4 )answer = mod; else { ll ans = 1; for(ll x : arr) { if(x==1)ans = ans; if(x==2)ans = (ans * bigMod(x,2)); if(x==3)ans = (ans * bigMod(x,6)); if(ans>mod) { answer = mod; break; } answer = mod % ans; } } cout << answer << endl; }