//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;// 2472171
ll n, a[200005], b, facts[2472179], 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 <= 2472175;i++)
facts[i] = ((i%mod) * (facts[i - 1]%mod))%mod;
}
ll modInverse(ll a,ll b)
{
return(a * fpow(b, mod - 2, 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;
ll tmp = modInverse((b - a[i]), i);
freq[i] += tmp;
sum = ((sum%mod) + ((tmp)%mod))%mod;
}
get_fact();
//cout << facts[sum] << "\n";
ll ans1 = facts[sum];
for (auto i : freq)
{
ans1 = modInverse(ans1, facts[i.second]);//(ans1 * fpow(facts[i.second], mod - 2, mod)) % mod;
}
cout << ans1;
return 0;
}
Copy