#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fixed(n) cout << fixed << setprecision(n);
#define mod 1000000007
#define cin(v) for (auto&i:v) cin >> i;
#define cout(v) for (auto&i:v) cout << i << " ";
#define ceil(n,m) (n / m + (n%m != 0))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
void lil_codi_vert(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
//int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// fast power
ll fastpow(ll b, ll e){
ll res = 1;
while(e){
if(e&1) res = ((res%mod) * (b%mod)) % mod;
e /= 2;
b = ((b%mod) * (b%mod)) % mod;
}
return res % mod;
}
// mod inverse
ll inverse(ll n){
return fastpow(n, mod - 2);
}
ll factorial(ll x){
ll fact = 1;
for(ll i = 1; i <= x; i++){
fact = ((fact%mod) * (i % mod)) % mod;
}
return fact % mod;
}
int main(){
lil_codi_vert();
ll n; cin >> n;
vector<ll> start(n), en(n);
cin(start); cin(en);
vector<ll> fact(200005, 0), inv(200005);
fact[0] = 1;
inv[0] = inverse(1);
for(ll i = 1; i <= 200005; i++){
fact[i] = (fact[i-1] %mod) * (i % mod);
fact[i] %= mod;
inv[i] = inverse(fact[i]);
}
vector<ll> diff(n);
for(int i = 0; i < n ; i++){
if(en[i] < start[i]) return cout << 0, 0;
ll x = en[i] - start[i];
if(x % (i+1) != 0) return cout << 0,0;
else diff[i] = x / (i+1);
}
ll sum = 0;
for(auto&i: diff) sum += i;
ll total = factorial(sum);
for(auto&i: diff){
total = ((total % mod) * (inv[i] % mod)) % mod;
}
cout << total;
return 0;
}
Copy