#include <iostream>
using namespace std;
#define mod 1000000007
long long fact[1000001];
long long power(long long x,long long n,long long mo)
{
if (n == 0) {
return 1;
}
long long pow = power(x, n / 2,mo)%mo;
if (n & 1) {
return ((((x%mo) * (pow%mo))%mo) * pow%mo)%mo;
}
return ((pow%mo) * (pow%mo))%mo;
}
int main()
{
long long t,a,b;
fact[0] = fact[1] = 1;
for(int i = 2;i<=1e6;i++){
fact[i]=fact[i-1]*i;
fact[i]%=mod;
}
long long n,p = 0;
cin>>n;
int ar1[n],ar2[n];
for(int i = 0;i<n;i++){
cin>>ar1[i];
}
int fl = 1;
int ans[n] = {0};
for(int i = 0;i<n;i++){
cin>>ar2[i];
if(ar2[i]<ar1[i])fl = 0;
if((ar2[i]-ar1[i])%(i+1)!=0)fl = 0;
ans[i]=(ar2[i]-ar1[i])/(i+1);
p+=(ar2[i]-ar1[i])/(i+1);
}
if(!fl){
cout<<0<<"\n";
return 0;
}
long long ba = 1;
for(int i = 0;i<n;i++){
ba*=fact[ans[i]]%mod;
ba%=mod;
}
cout<<(fact[p]*power(ba,mod-2,mod))%mod;
return 0;
}
Copy