#include using namespace std; const long long int MOD = 1e9 + 7; __int128 mypow(__int128 x,long long int n) { __int128 res = 1; while(n > 0) { if(n%2) { res = ((res%MOD)*(x%MOD)%MOD); res%=MOD; } x = ((x%MOD)*(x%MOD)%MOD); x%=MOD; n/=2; } return res; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n,t; vector > v; cin >> n; bool flag = true; int cnt = 1; for(int i=0;i> t; if(t==0) { cout << 0 << '\n'; return 0; } else if(t > 1) { if(flag==false) { v.push_back(make_pair(1,cnt)); flag = true; cnt = 0; } v.push_back(make_pair(t,1)); } else { if(flag) { flag = false; cnt = 0; } cnt++; } } if(!flag) { v.push_back(make_pair(1,cnt)); } long long int res = 1; for(int i=0;i= 1e9) break; if(v[j].first==1) { res = ((res%MOD)*(mypow(mul,cnt*v[i].second)%MOD)%MOD); res%=MOD; } else { res = ((res%MOD)*(mypow(mul,cnt)%MOD)%MOD); res%=MOD; } } } //cout << res << ' ' << (long long int)(mypow(5,100000)) << '\n'; cout << res << '\n'; return 0; }