#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define forr(_a, _b, _c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a, _b, _c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a, _b, _c) for(_a = (_b); _a < (_c); ++_a)
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define sz(_v) _v.begin(), _v.end()
#define mask(_x) (1ll << (_x))
#define bit(_x,_y) (((_x) >> (_y)) & 1)
string yes[2] = {"NO\n","YES\n"};
const ld eps = ld(1e-7);
const ll inf = ll(1e16) + 1;
const ll mod = ll(1e9) + 7;
const int N = 3e6 + 5;
ll n = N - 5, i, gt[N] = {1}, rgt[N], t, a[N], b[N], o = 1, tt;
ll po(ll x, ll y) {
if(!y) return 1;
if(!(y & 1)) return po((x * x) % mod,y >> 1);
return (x * po(x,y ^ 1)) % mod;
}
ll nCk(ll n, ll k) {
return gt[n] * rgt[k] % mod * rgt[n - k] % mod;
}
void solve() {
cin >> n;
forr(i,1,n) cin >> a[i];
forr(i,1,n) {
cin >> b[i];
if(b[i] < a[i] || (b[i] - a[i]) % i != 0) {
cout << 0;
return;
}
t += (b[i] - a[i]) / i;
}
forr(i,1,n) {
tt = (b[i] - a[i]) / i;
o = (o * nCk(t,tt)) % mod;
t -= tt;
}
cout << o;
}
void precalc() {
forr(i,1,n) {
gt[i] = (gt[i - 1] * i) % mod;
}
rgt[n] = po(gt[n],mod - 2);
ford(i,n,1) {
rgt[i - 1] = (rgt[i] * i) % mod;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifdef umf
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
#endif
int tc = 1;
// cin >> tc;
precalc();
while(tc --> 0) {
solve();
}
return 0;
}
Copy