#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define clr(v,d) memset(v,d,sizeof(v));
const int N = 2475000;
const ll mod = 1e9 + 7;
int n ;
ll fact[N] , a[N] , b[N];
ll fast_power_mod(ll n, ll m, ll k)
{
if(!m)return 1;
ll ans = fast_power_mod(n,m/2,k)%k;
ans=(ans*ans)%k;
if(m%2)
{
ans*=n%k;
}
ans%=k;
return ans;
}
ll modInversePrime ( ll a ,ll mod)
{
return fast_power_mod(a,mod -2 , mod);
}
int main()
{
cin.tie(0);
cin.sync_with_stdio(0);
fact[0] = fact[1] = 1;
for (int i = 2; i < N; ++i) {
fact[i] = fact[i-1] * i ;
fact[i] %= mod ;
}
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i] ;
}
for (int i = 0; i < n; ++i) {
cin >> b[i] ;
}
ll sum = 0, te = 1 ;
for (int i = 0; i < n; ++i) {
if((b[i]- a[i])%(i+1) || b[i] < a[i]) return cout << 0 ,0 ;
sum += (b[i]-a[i])/(i+1);
te *= fact[(b[i]-a[i])/(i+1)];
te %= mod;
}
te = modInversePrime(te , mod);
te *= fact[sum];
te %= mod;
cout << te ;
return 0;
}
Copy