#include #define rep(i,n) for (int i = 0; i < (n); i ++) using namespace std; using ll = long long; using PL = pair; using P = pair; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; struct Debug { template static void print_value(T value,const char* name) { cout << name << ": " << value << '\n'; } template static void print_vector(vector &vec,const char* name) { for (int i = 0;i < vec.size();++i) { cout << " " << name; printf("[%d]: ",i); cout << vec[i]; } cout << '\n'; } template static void print_2dvector(vector> &vec,const char* name) { for (int i = 0;i < vec.size();++i) { for (int j = 0;j < vec[i].size();++j) { cout << " " << name; printf("[%d][%d]: ",i,j); cout << vec[i][j]; } cout << '\n'; } } template static void print_set(set &st,const char* name) { int i = 0; for (auto itr = st.begin();itr != st.end(); ++itr,++i) { cout << " " << name; printf("[%d]: ",i); cout << *itr; } cout << '\n'; } template static void print_map(map &mp,const char* name) { for (auto p: mp) { cout << " " << name << '[' << p.first << ']' << ": " << p.second; } cout << '\n'; } }; template T modpow(T N,long long K,long long mod = MOD) { long long ret = 1; while (K > 0) { if (K&1) { ret *= N; ret %= mod; } K >>= 1; N *= N; N %= mod; } return ret; } int main() { int N; cin >> N; vector L(N); rep(i,N) cin >> L[i]; vector R(N); rep(i,N) cin >> R[i]; vector D(N + 1); rep(i,N) cin >> D[i + 1]; D[0] = 0; bool plus = false; bool zero = false; rep(i,N) { if (D[i + 1] == 0) { zero = true; } else if (D[i + 1] == 9) { D[i + 1] = 0; plus = true; } else { plus = true; } } if (plus && zero) { cout << 0 << endl; return 0; } else if (zero) { cout << 1 << endl; return 0; } ll inv9 = modpow((ll)9,MOD - 2); //Debug::print_value(inv9,"inv9"); vector dp(N + 1,0); dp[0] = 1; rep(i,N) { ll x = (modpow((ll)10,R[i]) - modpow((ll)10,L[i]) + MOD)*inv9%MOD; //Debug::print_value(x,"x"); rep(j,9) { if (j == 0) { if ((j + D[i])%9 == D[i + 1]) dp[i + 1] += dp[i] * (x + 1) % MOD; } else { if ((j + D[i])%9 == D[i + 1]) dp[i + 1] += dp[i] * x % MOD; } dp[i + 1] %= MOD; } } //Debug::print_vector(dp,"dp"); cout << dp[N] << endl; return 0; }