Source Code
#include <iostream>

using namespace std;

#define mod 1000000007

long long fact[1000001],inverse[1000001];

long long power(long long x,long long n)
{
    if (n == 0) {
        return 1;
    }
    long long pow = power(x, n / 2)%mod;
    if (n & 1) {
        return ((((x%mod) * (pow%mod))%mod) * pow%mod)%mod;
    }
    return ((pow%mod) * (pow%mod))%mod;
}

long long solve(long long a,long long b){
    return((fact[a]*inverse[b])%mod*inverse[a-b])%mod;
}

int main()
{
    long long t,a,b;
    fact[0] = inverse[0] = fact[1] = inverse[1] = 1;
    for(int i = 2;i<=1e6;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
        inverse[i] = power(fact[i],mod-2);
    }
    long long n,p = 0,ans = 0;
    cin>>n;
    int ar1[n],ar2[n];
    for(int i = 0;i<n;i++){
        cin>>ar1[i];
    }for(int i = 0;i<n;i++){
        cin>>ar2[i];
        ans+=abs(ar2[i]-ar1[i])/(i+1);
        if(ar2[i]!=ar1[i])p++;
    }
    cout<<solve(ans,p);
    return 0;
}
Copy
N-dimensions Ahmed57
GNU G++17
487 ms
17.5 MB
Wrong Answer