#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const long long& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator<<(ostream& os, const mi& a) { return os << a.val; }
    friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
    friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
    mi operator-() const { return mi(-val); }
    mi& operator+=(const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator-=(const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator*=(const mi& m) { val = (long long) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, long long p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator/=(const mi& m) { return (*this) *= inv(m); }
    friend mi operator+(mi a, const mi& b) { return a += b; }
    friend mi operator-(mi a, const mi& b) { return a -= b; }
    friend mi operator*(mi a, const mi& b) { return a *= b; }
    friend mi operator/(mi a, const mi& b) { return a /= b; }
};
const int MAX = 2e5 + 5;
const int INF = 2e9;
int n, x, y;
mi fact[MAX], ifact[MAX];
int main(){
    fact[0] = ifact[0] = 1;
    for(int i = 1; i < MAX; i++){
        fact[i] = fact[i - 1] * i;
        ifact[i] = ifact[i - 1] / i;
    }
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> x >> y;
    vector<vector<int>> w(n);
    for(int i = 0; i < n; i++){
        int ci, wi; cin >> ci >> wi;
        ci--; w[ci].push_back(wi);
    }
    for(auto& v: w) sort(v.begin(), v.end());
    vector<int> good(n, -1);
    pair<int, int> small = make_pair(INF, INF);
    for(int i = 0; i < n; i++){
        if((int) w[i].size() == 0) continue;
        for(int j = 0; j < (int) w[i].size(); j++){
            if(w[i][0] + w[i][j] <= x){
                good[i] = max(good[i], j);
            }
            small = min(small, make_pair(w[i][j], i));
        }
    }
    pair<int, int> other = make_pair(INF, INF);
    for(int i = 0; i < n; i++){
        if((int) w[i].size() == 0) continue;
        if(i == small.second) continue;
        for(int j = 0; j < (int) w[i].size(); j++){
            other = min(other, make_pair(w[i][j], i));
        }
    }
    int direct = -1;
    for(int j = 0; j < (int) w[small.second].size(); j++){
        if(w[small.second][j] + other.first <= y){
            direct = max(direct, j);
        }
    }
    vector<int> permute(n, -1);
    for(int i = 0; i < n; i++){
        if((int) w[i].size() == 0) continue;
        if(i == small.second){
            permute[i] = good[i];
            continue;
        }
        for(int j = 0; j < (int) w[i].size(); j++){
            if(small.first + w[i][j] <= y){
                permute[i] = max(permute[i], j);
            }
        }
    }
    int tot = 0;
    for(int i = 0; i < n; i++){
        if(i == small.second) permute[i] = max(permute[i], direct);
        if(permute[i] == -1) continue;
        permute[i] = max(permute[i], good[i]);
    }
    for(int x: permute) tot += (x + 1);
    mi ans = fact[tot];
    for(int x: permute) ans *= ifact[x + 1];
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 15336