#include #include using namespace std; int N, D[100100]; long long L[100100], R[100100]; const long long mod = 1000000007; struct matrix{ matrix(){ for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) a[i][j] = 0; } long long a[9][9]; matrix operator +(matrix t){ matrix r; for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++){ r.a[i][j] = (a[i][j] + t.a[i][j]) % mod; } return r; } matrix operator *(matrix t){ matrix r; for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++){ r.a[i][j] = 0; for (int k = 0; k < 9; k++){ r.a[i][j] = (r.a[i][j] + a[i][k] * t.a[k][j]) % mod; } } return r; } }iden, all, base; pair fpow(matrix a, long long n) { if (n == 0) return { iden, matrix() }; if (n == 1) return { a, iden }; auto half = fpow(a * a, n / 2); half.second = half.second * (iden + a); if (n % 2){ half.second = half.second + half.first; half.first = half.first * a; } return half; } int main() { for (int i = 0; i < 9; i++){ iden.a[i][i] = 1; for (int j = 0; j < 9; j++) all.a[i][j] = 1; } for (int i = 0; i < 9; i++) for (int j = 0; j < 10; j++) base.a[i][(i + j) % 9]++; scanf ("%d", &N); for (int i = 0; i < N; i++) scanf ("%lld", &L[i]); for (int i = 0; i < N; i++) scanf ("%lld", &R[i]); for (int i = 0; i < N; i++) scanf ("%d", &D[i]); int s = 0; while (s < N && D[s] == 0) s++; for (int i = s; i < N; i++) if (D[i] == 0){ puts("0"); return 0; } for (int i = s; i < N; i++){ L[i - s] = L[i]; R[i - s] = R[i]; D[i - s] = D[i]; } N -= s; long long ans = 1; int ld = 0; for (int i = 0; i < N; i++){ int nd = (D[i] + 9 - ld) % 9; auto low = fpow(base, L[i]); auto upp = fpow(base, R[i] - L[i]); matrix p = all * low.first * upp.second; ans = ans * (p.a[0][nd] + (nd == 0)) % mod; ld = nd; } bool g = 1; for (int i = 0; i < N; i++) if (D[i] != 9) g = 0; if (g) ans = (ans + mod - 1) % mod; printf ("%lld\n", ans); return 0; }