#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

class BIT{
    public:
    int size;
    vector<long long> tree;
    
    BIT(int n){
        size = n;
        tree = vector<long long>(n, 0);
        return;
    }
    
    void add(int n, long long a) {
        assert(n < size);
        int x = n;
        while (x < size){
            tree[x] += a;
            x |= x+1;
        }
        return;
    }
    
    long long getsum(int n) {
        assert(n < size);
        int x = n+1;
        long long sum = 0;
        while (x > 0) {
            sum += tree[x-1];
            x &= x-1;
        }
        return sum;
    }

};

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] += i;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        B[i] += i;
    }
    {
        vector<ll> C = A, D = B;
        sort(C.begin(), C.end());
        sort(D.begin(), D.end());
        if (C != D) {
            cout << -1 << endl;
            return 0;
        }
    }
    map<ll, ll> mp;
    set<ll> st;
    map<ll, ll> cnt;
    for (int i = 0; i < N; i++) {
        st.insert(A[i]);
        cnt[A[i]]++;
    }
    ll t = 0;
    for (ll n : st) {
        mp[n] = t;
        t += cnt[n];
    }
    map<ll, ll> cnt2;
    for (int i = 0; i < N; i++) {
        ll pre = A[i];
        A[i] = mp[A[i]]+cnt2[A[i]];
        cnt2[pre]++;
    }
    cnt2.clear();
    for (int i = 0; i < N; i++) {
        ll pre = B[i];
        B[i] = mp[B[i]]+cnt2[B[i]];
        cnt2[pre]++;
    }
    {
        vector<ll> tmp(N);
        for (int i = 0; i < N; i++) {
            tmp[B[i]] = i;
        }
        for (int i = 0; i < N; i++) {
            A[i] = tmp[A[i]];
        }
    }
    ll ans = 0;
    BIT bit(N);
    for (ll i = 0; i < N; i++) {
        ans += i - bit.getsum(A[i]);
        bit.add(A[i], 1);
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
//#include <atcoder/modint.hpp>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
const int mod2=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using Vd=vector<ld>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;
using VVd=vector<vector<ld>>;
//using mint=atcoder::modint1000000007;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<mod>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >>n;
    ll m;cin >>m;
    ll r=m;
    ll x=0;
    for (int i = 0; i < n; ++i) {
        int a;cin >>a;
        x+=(a+1);
        r-=a;
    }
    x++;
//    cout <<x<<" "<<r<<"\n";
    //((x,r))を求めたい　つまり(x+r-1,x-1)を求めたい
    mint ans=1;
    for (int i = 1; i <=x-1; ++i) {
//        cout<<x+r-i<<" "<<i<<"\n";
        ans*=(x+r-i);
        ans/=i;
    }
    cout <<ans<<"\n";
    return 0;
}

