#include #include using namespace std; using namespace atcoder; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (ll i = (s); i < (ll)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (ll i = (ll)(s - 1); i >= (ll)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() typedef long long ll; typedef vector vi; typedef vector vl; template T chmax(T& a, const U& b) { if (a >= b) return false; a = b; return true; } template T chmin(T& a, const U& b) { if (a <= b) return false; a = b; return true; } void yes_no(bool f, string yes = "Yes", string no = "No") { cout << (f ? yes : no) << "\n"; } template struct Mat { array, SZ> d; const int n; Mat() : n(SZ) { array tmp; d.fill(tmp); } Mat(const array, SZ>& d) : n(SZ), d(d) {} Mat operator*(const Mat& mt) const { Mat ret; rep(i, SZ) rep(j, SZ) { rep(k, SZ) { ret.d[i][j] += (d[i][k] * mt.d[k][j]); } } return ret; } Mat& operator*=(const Mat& mt) { *this = *this * mt; return *this; } Mat& operator=(const Mat& mt) { d = mt.d; return *this; } Mat(Mat&&) = default; array& operator[](const int n) { return d[n]; } Mat pow(ll n) const { Mat tmp(this->d); Mat ret; rep(i, SZ) ret.d[i][i] = 1LL; while (n > 0) { if (n & 1LL) ret = ret * tmp; tmp *= tmp; n >>= 1; } return ret; } }; void solve() { int n; cin >> n; using mint = modint1000000007; mint ans = 1; rep(ni, n) { ll c; cin >> c; Mat x; x.d[0][0] = 1; x.d[0][1] = 1; x.d[1][0] = 1; x.d[1][1] = 0; auto y = x.pow(c - 1); mint z = 0; rep(i, 2) rep(j, 2) z += y.d[i][j]; using mint2 = static_modint<(int)1e9 + 6>; mint2 d = 0; string s; cin >> s; rep(i, s.size()) { d *= 10; d += (s[i] - '0'); } ans *= z.pow(d.val()); } cout << ans.val() << "\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); int t = 1; // multi-testcase // cin >> t; rep(ti, t) solve(); return 0; }