#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(s) (int)(s.size())
const ll N = 2472113+10, mod = 1e9+7;
const ll OO = 6e18;
const auto EPS = 1e-6;
const auto PI = acos(-1);
using namespace std;
int DX[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int DY[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dx[] = { 1,0,-1,0 } ,dy[] = { 0,1,0,-1 };
ll mult(ll x, ll y)
{
return ((x%mod)*(y%mod))%mod;
}
ll fpow(ll x, ll n)
{
ll res = 1;
while(n)
{
if(n&1)
{
res = mult(res,x);
}
n >>= 1LL;
x = mult(x,x);
}
return res;
}
ll fact[N+5];
ll n, p[N+6], q[N+6];
void testCase()
{
fact[0] = 1;
for(int i=1;i<=N;i++)
{
fact[i] = mult(fact[i-1], i);
}
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> p[i];
}
for(int i=1;i<=n;i++)
{
cin >> q[i];
}
ll bast = 0, maqam = 1;
bool ok = 1;
for(int i=1;i<=n;i++)
{
if((q[i] - p[i])%i != 0)
{
ok = 1;
break;
}
ll x = abs(q[i] - p[i])/i;
bast += x;
maqam = mult(maqam, fact[x]);
}
if(!ok)
{
cout << 0;
return;
}
bast = fact[bast];
cout << mult(bast, fpow(maqam, mod-2));
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1; // cin >> t;
for(int tc = 1;tc<=t;tc++)
{
//cout << "Case #" << tc << ": ";
testCase();
}
return 0;
}
Copy