Source Code
//never give up.... just cry when you have to do 🌵🙂 
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) v.size()
#define mem(dp) memset(dp, 0 , sizeof dp)
long double pi = acos(-1);
void FILe() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); }
void FAST() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); }
ll mod = 1e9 + 7;//       2472171
ll n, a[200005], b, facts[2472179], sum = 0;
map<ll, ll>freq;
ll fpow(ll n, ll x, int mod)
{
	if (x == 0) return 1 % mod;
	else if (x == 1) return n % mod;
	ll ans = fpow(n, x / 2, mod);
	ans = ((ans % mod) * (ans % mod)) % mod;
	if (x & 1) ans = ((ans % mod) * (n % mod)) % mod;
	return ans % mod;
}
void get_fact()
{
	facts[0] = facts[1] = 1;
	for (ll i = 2;i <= 2472175;i++)
		facts[i] = ((i % mod) * (facts[i - 1] % mod)) % mod;
}
ll modInverse(ll a, ll b)
{
	return((a % mod) * fpow(b, mod - 2, mod)) % mod;
}
int main()
{
	FAST();
	//freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
	get_fact();
	cin >> n;
	ll ans2 = 1;
	for (int i = 1;i <= n;i++)cin >> a[i];
	for (int i = 1;i <= n;i++)
	{
		cin >> b;
		ll tmp = (b - a[i]) / i;
		if (b < a[i] || (b - a[i]) % i != 0)
			return cout << 0, 0;

		ans2 = ((ans2 % mod) * (facts[tmp] % mod)) % mod;
		sum = ((sum % mod) + ((tmp) % mod)) % mod;
	}
	ll ans1 = facts[sum];
	cout << modInverse(ans1 , ans2);

	return 0;
}
Copy
N-dimensions Doaa_Saad
GNU G++17
186 ms
21.2 MB
Accepted