Source Code
//#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

void Fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void File() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
typedef long long ll;
void justify(int n,int x)
{
    string s=to_string(n);
    for(int i=0;i<x-s.size();i++)cout<<' ';
    cout<<s;
}
int gcd(int a,int b)
{
    if(a==0)return b;
    return gcd(b%a,a);
}
int mod=1000000007;
ll fact(ll n)
{
    ll res=1;
    while(n)
    {
        res=res*n%mod;
        n--;
    }
    return res;
}
ll mod_inv(ll n)
{
    int p=mod-2;
    ll res=1;
    while(p)
    {
        if(p%2)res=res*n%mod;
        n=n*n%mod;
        p/=2;
    }
    return res;
}
void solve()
{
    int n,a[200002],x;
    vector<int>v;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if((x-a[i])%i||x<a[i])
        {
            cout<<"0\n";
            return;
        }
        if((x-a[i])%i==0)
        {
            res+=(x-a[i])/i;
            v.push_back((x-a[i])/i);
        }
        
    }
    
    //if(res)
    {
        res=fact(res);
        
        for(auto i:v)
        {
            res=res*mod_inv(fact(i))%mod;
        }
    }
    cout <<res<<'\n';
   
    
}
int main()
{
    //File();
    Fast();
    
    int t=1;
   // cin>>t;
    for (int i = 1; i <= t;i++ )
    {
        //cout<<"Case "<<i<<": ";
        solve();
    }

} 
Copy
N-dimensions Ahmed_Aladdin
GNU G++17
210 ms
2.2 MB
Accepted