#include #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll ILL=2167167167167167167; const int INF=2100000000; const ll mod=1e9+7; #define rep(i,a) for (ll i=0;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";} template void vec_out(vector &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<0){ a*=2; if(H%a!=0){ H-=a/2; c*=b; c%=z; } b*=b; b%=z; } //ここまで return c; } void solve(); // oddloop int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t=1; //cin>>t; rep(i,t) solve(); } void solve(){ int N; cin>>N; vector L(N),R(N),D(N); rep(i,N) cin>>L[i]; rep(i,N) cin>>R[i]; rep(i,N) cin>>D[i]; auto po_mul=[&](vector p,vector q)->vector{ vector ans(9); rep(i,9) rep(j,9){ ans[(i+j)%9]=((p[i]*q[j])%mod+ans[(i+j)%9])%mod; }return ans; }; auto po_pow=[&](ll X)->vector{ vector base(9,1),ans(9,0); ans[0]=1; base[0]=2; while(X){ if(X&1) ans=po_mul(ans,base); X>>=1; base=po_mul(base,base); } ans[0]=(ans[0]+mod-1)%mod; return ans; }; int J=0; ll ans=1; rep(i,N){ if(D[i]==0){ if(J){ cout<<"0\n"; return ; } continue; } ll tmp=po_pow(R[i]-L[i])[(D[i]-J+9)%9]; tmp=(tmp*jyo(10,L[i],mod))%mod; if(J==D[i]) tmp++; ans=(ans*tmp)%mod; J=D[i]; } cout<