#include #include #include using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 template struct matrix{ vector> v; int _h,_w; matrix(vector> X){ v = X; _h = X.size(); _w = 0; if(X.size()>0)_w = X[0].size(); } matrix(int h,int w){ v.resize(h,vector(w,e0())); _h = h; _w = w; } void add_element(int from,int to,S x){ v[to][from] = op0(v[to][from],x); } matrix e(){ assert(_h==_w); matrix ret(_h,_w); for(int i=0;i<_h;i++){ for(int j=0;j<_w;j++){ if(i==j)ret.v[i][j] = e1(); else ret.v[i][j] = e0(); } } return ret; } matrix &operator*=(const matrix &another){ matrix ret(_h,another._w); for(int i=0;i<_h;i++){ for(int j=0;j ret = e(); auto temp = *this; while(cnt!=0LL){ if((cnt&1)==1){ ret *= temp; } temp *= temp; cnt>>=1; } return ret; } }; mint op0(mint a,mint b){ return a+b; } mint e0(){ return 0; } mint op1(mint a,mint b){ return a*b; } mint e1(){ return 1; } int main(){ matrix M(2,2); M.add_element(0,0,1); M.add_element(0,1,1); M.add_element(1,0,1); int N; cin>>N; mint ans = 1; rep(_,N){ long long C; cin>>C; auto temp = M.pow(C); matrix temp2(2,1); temp2.v[0][0] = 1; temp *= temp2; mint x = temp.v[0][0] + temp.v[1][0]; string D; cin>>D; while(D.size()!=0){ rep(i,D.back()-'0')ans *= x; D.pop_back(); x = x.pow(10); } } cout<