Source Code
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include<functional>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include<iterator>
#include <stdio.h>
#include <string.h>
#define T int t=0;cin>>t;while(t--)
#define F(i,n) for(ll i=0;i<n;i++)
#define fo(i,a)for(auto&i:a)
#define all(a) a.begin(),a.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define ll long long
#define ld long double
#define endl "\n"
#define vl vector<ll>
#define vi vector<int>
#define cost first
#define from second.first
#define to second.second
#define sz(X) X.size()
using namespace std;
const ll mod = 1000000007;
void code();
long long pow_mod(long long base,long long power) {
	long long res = 1;
	while(power) {
		if(power&1) res = res * base % mod;
		base = base * base % mod;
		power >>= 1;
	}
	return res;
}
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*>> # str main # <<*-*-*-*-*-*-*-*-*-*-*-*-*-*-*///
int main()
{
    code();
    const ll N=10000005;
    long long fact[N],inv[N];
    fact[0] = inv[0] = inv[1] = fact[1] = 1;
    for(long long i = 2;i < N;i++)
        fact[i] = fact[i-1]*i%mod, inv[i] = pow_mod(fact[i],mod-2);
    int n;cin>>n;
    vl a(n);
    fo(i,a)cin>>i;
    ll sum=1;
    int ii=0;
    fo(i,a)
    {
        ii++;
        ll x;
        cin>>x;
        if(i>x||(x-i)%(ii)!=0)return cout<<0,0;
        i=abs(x-i)/sum;
        sum++;
    }
    sum=0;
    ll ans=1;
    fo(i,a)
    {
        ans*=inv[i];
        ans%=mod;
        sum+=i;}
    sum=fact[sum];
    ans*=sum;
    cout<<ans%mod;

}
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-*>> # end main # <<*-*-*-*-*-*-*-*-*-*-*-*-*-*-*///
void code()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(6);
}
Copy
N-dimensions ABD_ALMABOUD
GNU G++17
1711 ms
158.4 MB
Accepted