Language: C++

// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

// ModInt (ref. anta) {{{
template<int MOD>
struct ModInt{
    static const int Mod = MOD;
    unsigned val;
    ModInt():val(0){}
    ModInt(unsigned x):val(x%MOD){}
    ModInt(signed x) {
        int y = x % MOD;
        if(y < 0) y += MOD;
        val = y;
    }
    ModInt(signed long long x) {
        int y = (int)(x % MOD);
        if(y < 0) y += MOD;
        val = y;
    }

    ModInt &operator+=(ModInt rhs) {
        val += rhs.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    ModInt &operator-=(ModInt rhs) {
        val += MOD - rhs.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    ModInt &operator*=(ModInt rhs) {
        val = (unsigned)((unsigned long long)val * rhs.val % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt rhs) {
        return *this *= rhs.inv();
    }

    ModInt inv() const {
        signed a = val, b = MOD, u = 1, v = 0;
        while(b) {
            signed t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        if(u < 0) u += MOD;
        ModInt res;
        res.val = u;
        return res;
    }

    ModInt operator+(ModInt rhs) const {
        return ModInt(*this) += rhs;
    }
    ModInt operator-(ModInt rhs) const {
        return ModInt(*this) -= rhs;
    }
    ModInt operator*(ModInt rhs) const {
        return ModInt(*this) *= rhs;
    }
    ModInt operator/(ModInt rhs) const {
        return ModInt(*this) /= rhs;
    }

    // compare
    bool operator==(ModInt rhs) const {
        return val == rhs.val;
    }
    bool operator!=(ModInt rhs) const {
        return val != rhs.val;
    }
    bool operator< (ModInt rhs) const {
        return val <  rhs.val;
    }
    bool operator<=(ModInt rhs) const {
        return val <= rhs.val;
    }
    bool operator> (ModInt rhs) const {
        return val >  rhs.val;
    }
    bool operator>=(ModInt rhs) const {
        return val >= rhs.val;
    }
};
template<int MOD>
ostream& operator << (ostream& os, const ModInt<MOD> m) {
    return os << m.val;
}
template<int MOD, typename T>
ModInt<MOD> pow(ModInt<MOD> a, T b) {
    if(b == 0) {
        return 1;
    } else {
        auto w = pow(a*a, b/2);
        if(b&1) w *= a;
        return w;
    }
}
// }}}
typedef ModInt<1000000007> mint;
// {{{
template<typename T, typename Comp=less<T>>
class SparseTable{
private:
    Comp comp;
    int N, K;
    vector<T> value;
    vector<vector<int>> idx;

    inline int log2(int x) {
        return 31 - __builtin_clz(x);
    }

public:
    SparseTable(const vector<T>& v) : value(v) {
        N = (int)v.size();
        K = log2(N) + 1;

        idx.resize(K);
        idx[0].resize(N);
        REP(i, N) idx[0][i] = i;

        for(int log = 0; log+1 < K; log++) {
            const int L = N+1 - (1<<(log+1));
            idx[log+1].resize(L);
            for(int i = 0; i < L; i++) {
                const int p = idx[log][i];
                const int q = idx[log][i+(1<<log)];
                idx[log+1][i] = (comp(v[p], v[q]) ? p : q);
            }
        }
    }

    // return index of minimum/maximum value in v[b], ..., v[e-1]
    int query_idx(int b, int e) {
        const int log = log2(e-b);
        const int p = idx[log][b];
        const int q = idx[log][e-(1<<log)];
        return (comp(value[p], value[q]) ? p : q);
    }

    // return minimum/maximum value in v[b], ..., v[e-1]
    T query(int b, int e) {
        assert(b >= 0);
        b = max(0, b);
        assert(e <= N);
        e = min(N, e);
        if(e - b <= 0) return LLONG_MAX; // only this code
        return value[query_idx(b, e)];
    }
};

// }}}

#define int long long

// {{{
struct AddMinimum {
    typedef long long T;
    static constexpr T INF = 1LL<<60;
    int M;
    vector<T> part, data;
    AddMinimum(int N=1): M(2<<__lg(max(1, N))), part(2*M), data(2*M) {}
    AddMinimum(const vector<T> &A): M(2<<__lg(max(1, (int)A.size()))), part(2*M), data(2*M) {
        for (int i=0; i<(int)A.size(); i++) data[i+M] = A[i];
        for (int i=M; --i;) data[i] = min(data[2*i], data[2*i+1]);
    }
    void add(int x, int y, const T &v) { add(x, y, 1, 0, M, v); }
    T add(int x, int y, int k, int l, int r, const T &v) {
        if (x <= l && r <= y) return (part[k] += v) + data[k];
        if (y <= l || r <= x) return part[k] + data[k];
        return part[k] + (data[k] = min(add(x, y, k*2, l, (l+r)/2, v), add(x, y, k*2+1, (l+r)/2, r, v)));
    }
    T minimum(int x, int y) { return minimum(x, y, 1, 0, M); }
    T minimum(int x, int y, int k, int l, int r) {
        if (x <= l && r <= y) return part[k] + data[k];
        if (y <= l || r <= x) return INF;
        return part[k] + min(minimum(x, y, k*2, l, (l+r)/2), minimum(x, y, k*2+1, (l+r)/2, r));
    }
};
//}}}
int N;
LL A, B;

#define error(...) 
#define assert(...)


mint calc(const vector<LL>& v) {
    error(v.size());
    if(v.size() == 1) {
        return mint(2);
    }

    assert(A < B && A >= 1 && B >= 1);
    vector<LL> diffs;
    for(int i = 0; i+1 < v.size(); i++) {
        assert(v[i+1] - v[i] < B);
        diffs.push_back(v[i+1] - v[i]);
    }
    diffs.push_back(LLONG_MAX);
    SparseTable<LL> sp(diffs);

    vector<mint> dp(v.size()+1);
    dp[0] = 1;

    for(int i = 0; i < v.size(); i++) {
        error(i, dp[i]);
        if(!(i > 0 && v[i] - v[i-1] < A)) {
            // a
            dp[i+1] += dp[i];
            error(dp[i+1]);
        }
        {
            // b
            const LL nx = v[i] + B;
            size_t ni = lower_bound(v.begin(), v.end(), nx) - v.begin();
            if(ni - i == 1) {
                error(ni, v.size());
                assert(ni == v.size());
                dp[ni] += dp[i];
            } else {
                LL min_diff = (ni - i >= 2 ? sp.query(i+1, (int)ni) : LLONG_MAX);
                if(i+1 < v.size() && i-1 >= 0) {
                    min_diff = min(min_diff, v[i+1] - v[i-1]);
                }
                if(min_diff >= A) {
                    dp[ni] += dp[i];
                }
                error(nx, ni, min_diff, A, dp[ni]);
            }
        }
    }

    return dp.back();
}

signed main(){
    iostream_init();
    while(cin >> N >> A >> B) {
        if(A > B) swap(A, B);

        vector<vector<LL>> VS;
        vector<LL> cur;
        REP(i, N) {
            LL x;
            cin >> x;
            if(cur.size() > 0 && cur.back() + B <= x) {
                VS.push_back(cur);
                cur.assign(1, x);
            } else {
                cur.push_back(x);
            }
        }
        VS.push_back(cur);

        mint res = 1;
        for(const auto& v : VS) {
            res *= calc(v);
        }

        cout << res << endl;
        // break;
    }

    return 0;
}



Compiler output:
a.cc:207:9: warning: "error" redefined
  207 | #define error(...)
      |         ^~~~~
a.cc:10:9: note: this is the location of the previous definition
   10 | #define error(args...)
      |         ^~~~~
a.cc:208:9: warning: "assert" redefined
  208 | #define assert(...)
      |         ^~~~~~
In file included from /usr/include/c++/14/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:106,
                 from a.cc:2:
/usr/include/assert.h:102:11: note: this is the location of the previous definition
  102 | #  define assert(expr)                                                  \
      |           ^~~~~~
a.cc: In constructor 'AddMinimum::AddMinimum(long long int)':
a.cc:185:39: error: no matching function for call to 'max(int, long long int&)'
  185 |     AddMinimum(int N=1): M(2<<__lg(max(1, N))), part(2*M), data(2*M) {}
      |                                    ~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:185:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  185 |     AddMinimum(int N=1): M(2<<__lg(max(1, N))), part(2*M), data(2*M) {}
      |                                    ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:185:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  185 |     AddMinimum(int N=1): M(2<<__lg(max(1, N))), part(2*M), data(2*M) {}
      |                                    ~~~^~~~~~
a.cc: In constructor 'AddMinimum::AddMinimum(const std::vector<long long int>&)':
a.cc:186:50: error: no matching function for call to 'max(int, long long int)'
  186 |     AddMinimum(const vector<T> &A): M(2<<__lg(max(1, (int)A.size()))), part(2*M), data(2*M) {
      |                                               ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:186:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
  186 |     AddMinimum(const vector<T> &A): M(2<<__lg(max(1, (int)A.size()))), part(2*M), data(2*M) {
      |                                               ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:186:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  186 |     AddMinimum(const vector<T> &A): M(2<<__lg(max(1, (int)A.size()))), part(2*M), data(2*M) {
      |                                               ~~~^~~~~~~~~~~~~~~~~~