Source Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int OO = 1e9+7 ,N=2e5+5;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; // dir array
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
void File(){
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
ll power(ll x, ll k)
{
    ll ret = 1;
    while (k){
        if (k & 1) ret = (ret*x) % OO;
        k >>= 1; x = (x*x) % OO;
    }
    return ret;
}
ll modInverse(ll a, ll m) {
    return power(a, m - 2);
}

int solve(){
    int n;cin>>n;
    ll sum=0;
    ll madrob[N];
    
    madrob[0]=madrob[1]=1;
    for(ll i=2;i<N;i++){
        madrob[i] = (i*madrob[i-1])%OO;
    }
    vector<int>a(n+1),b(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        int x;cin>>x;
        b[i] = x-a[i];
        if(x<a[i])return cout<<0,0;
        if(b[i]%i)return cout<<0,0;
        b[i]/=i;
        sum+=b[i];
    }
    sum=madrob[sum];
    for(int i:b){
        if(i){
            ll x = modInverse(madrob[i],OO);
            sum = ((sum%OO)*(x))%OO;
        }
    }
    cout<<sum;

    return 0;
}
int main() {
    File();
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
//    int t,i=1;cin>>t;
//    while(t--)
        solve();

}
//Solve on paper first
//Overflooooooow
//Reverse Thinking
//If there's an equation, transform it into an easy one
//READ ALL PROBLEMS
//Verify Your thought before Coding
Copy
N-dimensions ahmes
GNU G++17
48 ms
3.5 MB
Runtime Error