Source Code
/*
+---------------------------------------------+
|                                             |
|  Copytright, MinaMagdy, 25/04/2022 (21:38)  |
|                                             |
+---------------------------------------------+
*/
/*
        .@@@@@@@@   @@@                                              @@       @@
    ,@@@@@@     @@ .@@@      @@    @@@        @@@%@@@@.   @@@        @@  @@  @@@@/      @@@
    /& @@@@    @@@ *@@@     @@@#  @@@&@@@    @@@@@@@#&@@ @@@%&,      @@ @@@@  @@@@    @@@&
        @@@  .@@@   /@%@     @@@  @@@@   @@& .@@@         @@&&&@      @@ @@@@  >@@@@ @@@@
        %@@@@@@&     /&&&     %@&  @&@     @& @&@&         &&@#%@%.   &@@ &@&#   %@@@@@@
        @@@@@        /@&%@%&@@@&@  @&&    ,@@ @@&&@@&@@@   &@@ /@@&/  @@, @@@/    %@@@@
        @@@.         *@@@@#,  @@@  @@@   ,@@  @@@.         @@@   @@@@@@@  %@@/   @@@@@@%
        @@@          *@@%     @@@   @@@@@@#    @@@@@@@@@@  @@@    ,@@@@    @@& .@@@  @@@@
        &@@,          @@%      @@                          @@@                 @@      @@@
                                                            &*
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace __gnu_cxx;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
#define endl "\n"
#define NumOfDig(w) log10(w) + 1
#define MOD 1000000007
#define INF 2000000000
#define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
#define EPS 1e-9
#define PI1 acos(-1)
#define PI2 3.141592653
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define sz(x) int(x.size())
#define init(x, c) memset(x, c, sizeof(x))
#define getlineCh(s, c) getline(cin >> ws, s, c)
// #define TC int testcases = 1; cin >> testcases; for (ll test = 1; test <= testcases; test++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

/**
 * @author MiinaMagdy
 * @remark Time limit - memory limit (EFFICIENCY)
 * @remark (OVERFLOW) long long
 * @remark freopen() file
 * @remark (CORNER) test case
 * @remark division by (ZERO) || Out of array's (RANGE)
 * @remark use logarithm if you want to compare two products
 * @remark Brute Force means try all possible solutions remember (MAXPOINT - CodeChef)
 * @remark '/0' takes all input in getline string
 */

void phoenix()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
    #endif
    Time
}

ll fast_pow(ll b, ll e, ll mod){
    ll power = 1;
    while(e){
        if(e & 1) power = ((power % mod) * (b % mod)) % mod;
        e >>= 1;
        b = ((b % mod) * (b % mod)) % mod;
    }
    return power % mod;
}

int main(void)
{
    phoenix();
    int testcase = 1;
    // cin >> testcase;
    while (testcase--)
    {
        int n;
        cin >> n;
        ll s[n + 5], e[n + 5]; // start, end
        for (int i = 1; i <= n; i++) {
            cin >> s[i];
        }
        ll p[n + 5], total = 0;
        bool flag = true;
        for (int i = 1; i <= n; i++) {
            cin >> e[i];
            p[i] = (e[i] - s[i]);
            flag &= (p[i] >= 0) && (p[i] % i == 0);
            p[i] /= i;
            total += p[i];
        }
        if (flag) {
            ll factorial[200005];
            factorial[0] = factorial[1] = 1;
            for (int i = 2; i <= 200003; i++) {
                factorial[i] = (i % MOD * factorial[i - 1] % MOD) % MOD;
            }
            ll denom = 1;
            for (int i = 1; i <= n; i++) {
                denom = (denom % MOD * factorial[p[i]] % MOD) % MOD;
            }
            ll nom = 1;
            for (int i = 1; i <= total; i++) {
                nom = (nom % MOD * i % MOD) % MOD;
            }
            cout << (nom % MOD * fast_pow(denom, MOD - 2, MOD) % MOD) % MOD << endl;
        }
        else {
            cout << 0 << endl;
        }
        
    }
    return 0;
}
Copy
N-dimensions MiinaMagdy
GNU G++17
76 ms
6.6 MB
Accepted