#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fixed(n) cout << fixed << setprecision(n);
#define mod 1000000007
#define cin(v) for (auto&i:v) cin >> i;
#define cout(v) for (auto&i:v) cout << i << " ";
#define ceil(n,m) (n / m + (n%m != 0))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
void lil_codi_vert(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
//int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// fast power
ll fastpow(ll b, ll e){
ll res = 1;
while(e){
if(e&1) res = ((res%mod) * (b%mod)) % mod;
e /= 2;
b = ((b%mod) * (b%mod)) % mod;
}
return res % mod;
}
// mod inverse
ll inverse(ll n){
return fastpow(n, mod - 2);
}
int main(){
lil_codi_vert();
ll n;
vector<ll> start, en;
cin >> n;
start.resize(n); cin(start);
en.resize(n); cin(en);
vector<ll> fact(100005, 0);
fact[0] = 1;
for(ll i = 1; i <= 100005; i++){
fact[i] = (fact[i-1] %mod) * (i % mod);
fact[i] %= mod;
}
vector<ll> res(n);
for(int i = 0; i < n ; i++){
res[i] = max(0ll, en[i] - start[i] - 1);
}
//cout(res);
ll sum = 0;
for(auto&i: res){
sum += i;
}
ll ub = 0;
if(sum <= 1e5) ub = fact[sum];
else{
ub = 1;
for(int i = 1 ; i <= sum; i++){
ub = (ub %mod) * (i %mod);
ub %= mod;
}
}
//cout << ub;
ll down = 1;
for(auto&i: res){
down = (down % mod) * (fact[i] % mod);
down %= mod;
}
cout << ((ub%mod) * inverse(down)) % mod;
return 0;
}
Copy