Source Code
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define md 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
    return (y + x % y) % y;
}
void fast()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

#ifdef ONLINE_JUDGE
    //freopen("crosses.in", "r", stdin);

    //freopen("crosses.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
}
ll f[(int)1e7];
ll inv(ll x, ll p)
{
	if (p == 0)return 1;
	if (p == 1)return x;
	ll res = inv(x, p / 2)%md;
	res = (res*res) % md;
	if (p % 2)res = (res*x) % md;
	return res;
}
int main()
{
    Mohammed_Atef_Hassan
    f[0]=f[1]=1;
    for(ll i=2;i<1e7;i++)
    {
        f[i]=f[i-1]*i;
        f[i]%=md;
    }
    int n;
    cin>>n;
    vector<ll>p(n),q(n);
    for(int i=0;i<n;i++)cin>>p[i];
    bool valid=1;
    ll b=1,a=0;
    for(int i=0;i<n;i++)
    {
        cin>>q[i];
        if((q[i]-p[i])%(i+1))valid=0;
        b*=f[(q[i]-p[i])/(i+1)];
        a+=(q[i]-p[i])/(i+1);
        b%=md;
    }
    if(!valid)cout<<0;
    else
    {
        cout<<f[a]*inv(b,md-2)%md<<finl;
    }

}
Copy
N-dimensions MuhammedAtefHassan
GNU G++17
151 ms
81.7 MB
Runtime Error