#include <iostream>
#include <iomanip>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <set>
#include <cstdio>
#include <string>
#include <stack>
#include <map>
#include <sstream>
#define ll long long
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
using namespace std;
void AIA()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void file()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int OO = 1e9 + 7;
const long double PI = acos(-1);
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dx4[] = {0, 1, 0, -1};
int dy[] = {1, -1, 0, 0, 1, -1, -1, 1}, dy4[] = {1, 0, -1, 0};
ll fastPowWithMod(ll n, ll pow, int mod)
{
n %= mod;
ll res = 1;
while (pow != 0)
{
if ((pow & 1) == 1)
{
res = res * n % mod;
}
n = n * n % mod;
pow /= 2;
}
return res;
}
ll modInv(ll n)
{
return fastPowWithMod(n, OO - 2, OO);
}
int main()
{
// Verify Your thought before Coding.
AIA();
file();
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1), diff(n + 1);
int fact[200001] = {0};
fact[0] = 1;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
for (int i = 1; i <= n; i++)
diff[i] = b[i] - a[i];
for (int i = 1; i <= 200000; i++)
fact[i] = fact[i - 1] * i % OO;
ll all = 0, res = 1;
for (int i = 1; i <= n; i++)
{
if (diff[i] < 0 || diff[i] % i != 0)
{
cout << 0;
return 0;
}
res = res * modInv(fact[diff[i] / i]) % OO;
all += diff[i] / i;
}
res = res * fact[all] % OO;
cout << res;
}
Copy