//never give up.... just cry when you have to do 🌵🙂
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) v.size()
#define mem(dp) memset(dp, 0 , sizeof dp)
long double pi = acos(-1);
void FILe() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); }
void FAST() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); }
ll mod = 1e9 + 7;
ll n, a[200005], b, facts[2000006], sum = 0;
map<ll ,ll>freq;
ll fpow(ll n, ll x, int mod)
{
if (x == 0) return 1 % mod;
else if (x == 1) return n % mod;
ll ans = fpow(n, x / 2, mod);
ans = ans * ans % mod;
if (x & 1) ans = ans * n % mod;
return ans;
}
void get_fact()
{
facts[0]=facts[1] = 1;
for (ll i = 2;i < 2000006;i++)
facts[i] = ((i%mod) * (facts[i - 1]%mod))%mod;
}
int main()
{
FAST();
//freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
cin >> n;
for (int i = 1;i <= n;i++)cin >> a[i];
for (int i = 1;i <= n;i++)
{
cin >> b;
freq[i] += ((b - a[i]) / i);
sum = ((sum%mod) + (((b - a[i]) / i)%mod))%mod;
}
get_fact();
//cout << facts[sum] << "\n";
ll ans1 = facts[sum];
for (auto i : freq)
{
ans1 = (ans1 * fpow(facts[i.second], mod - 2, mod)) % mod;
}
cout << ans1;
return 0;
}
Copy