Source Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int OO = 1e9+7 ,N=1e6+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);
}
ll nCr(ll n, ll r){
    ll ans = 1;
    ll div = 1; // r!
    for (ll i = r + 1; i <= n; i++){
        ans = ans * i;
        ans = ((ans%OO)* modInverse(div,OO))%OO;
        div++;
    }
    return ans;
}

int solve(){
    int n;cin>>n;
    ll res=0,sum=0;
    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(b[i]%i)return cout<<0,0;
        sum+=(b[i]/i);
    }
    if(sum<n)return cout<<0,0;
    cout<<nCr(sum,n);

    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
162 ms
1.9 MB
Wrong Answer