#include <bits/stdc++.h>
using namespace std;
#define fast cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
#define ll long long
#define ld long double
#define EPS 1e-9
#define INF INT_MAX
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rep(i, k, n) for(int i=k; i < n ; i++)
#define rev(i, n, k) for(int i = n; i>= k; i--)
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define NIL -1
// alt + ctrl + l
// يا رب
const ll MOD = 1e9+7;
const ll N = 2e5 + 5;
const ll K = 5;
//const ll M = 100;
double const pi = 3.14159265359;
const int OO=0x3f3f3f3f;
const ll LOO=0x3f3f3f3f3f3f3f3f;
int dx8[] = {+0, +0, -1, +1, +1, +1, -1, -1};
int dy8[] = {-1, +1, +0, +0, +1, -1, +1, -1};
int dx4[] = {+0, +0, -1, +1};
int dy4[] = {-1, +1, +0, +0};
//struct cmp {
// bool operator()(M const& p1, M const& p2)
// {
// return p1.dis > p2.dis;
// }
//};
ll add(ll a, ll b){
return (a + b)%MOD;
}
ll mul (ll a, ll b){
return (a * b)%MOD;
}
ll fact[N];
ll power(ll x,ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Returns n^(-1) mod p
ll modInverse(ll n,
ll p)
{
return power(n, p - 2, p);
}
ll nCrModPFermat(ll n,ll r, ll p)
{
ll a = fact[n];
ll b = mul(fact[r], fact[n - r]);
ll c = modInverse(b, p);
return mul(a, c);
}
int main() {
fast
ll T = 1;
// cin >> T;
fact[0] = fact[1] = 1;
for (int i = 2; i <= 2e5; ++i) {
fact[i] = mul(fact[i - 1], i);
}
while (T--) {
ll n;
cin >> n;
vector<ll> a(n), b(n);
bool ok = true;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
vector<ll> c(n);
for (int i = 0; i < n; ++i) {
if(b[i] - a[i] < 0){
ok = false;
}
else if((b[i] - a[i]) % (i + 1)){
ok = false;
}
c[i] = (b[i] - a[i])/(i + 1);
}
if(!ok){
cout << 0 << endl;
}
else{
if(n == 1){
cout << 1 << endl;
return 0;
}
ll ans = nCrModPFermat(c[0] + c[1], c[0], MOD);
ll sum = c[0] + c[1];
for (int i = 2; i < n; ++i) {
sum += c[i];
ans = nCrModPFermat(sum, c[i], MOD);
}
cout << ans << endl;
}
}
}
Copy