#include <bits/stdc++.h>
using namespace std;
    #define get at

    int c[200010];
    int w[200010];
    long long fac [200010];
    const int mod = 1000000000 + 7;

    long long modpow(long long b, int e) {
        if(e == 0) return 1;
        if((e & 1) == 1) return (modpow(b, e-1) * b) % mod;
        long long m = modpow(b, e >> 1);
        return (m * m) % mod; 
    }
    long long inverse(long long x) {
        return modpow(x, mod - 2);
    }
    struct Dsu {
        int par[200010];
        vector <int> t[200010]; 
        Dsu () {}
        Dsu (int n) {
            for(int i = 0; i <= n; i++) {
                par[i] = i;
                t[i].push_back(c[i]);
            }
        }
        void merge(int p, int q) {
            p = root(p);
            q = root(q);
            if(t[p].size() > t[q].size()) {
                int temp = p;
                p = q;
                q = temp;
            }
            if(p == q) return ;
            par[p] = q;
            for(auto i : t[p]) {
                t[q].push_back(i);
            }
            t[p].clear();
        }
        int root(int p) {
            if(par[p] == p) return p;
            else return par[p] = root(par[p]);
        }
        long long size(int p) {
            map <int, int> s;
            for(auto i : t[root(p)]) {
                s[i] += 1;
            }
            long long   ans = fac[ t[root(p)].size() ];
            for(auto i : s) {
                ans *= inverse( fac[i.second] );
                ans %= mod;
            }
            return ans;
        }
    } t;
    vector <pair <int, int> > g [200010];

    int main() {
        int n;
        int x, y;
        scanf("%d %d %d", &n, &x, &y);

        for(int i = 1; i <= n; i++) {
            scanf("%d %d", c + i, w + i);
            g[c[i]].push_back(make_pair(w[i], i));
        }
        for(int i = 1; i <= n; i++) {
            sort(g[i].begin(), g[i].end());
        }   

        int first = -1;
        int second = -1;

        for(int i = 1; i <= n; i++) {
            if(first == -1 || w[first] > w[i]) {
                first = i;
            }
        }
        for(int i = 1; i <= n; i++) {
            if(c[i] == c[first]) continue;
            if(second == -1 || w[second] > w[i]) {
                second = i;
            }
        }   

        t = Dsu(n);
        for(int i = 1; i <= n; i++) {
            if(g[i].empty()) continue;

            int p = x - g[i].get(0).first;

            int q;
            if(c[first] == i) {
                if(second == -1) q = -1;
                else q = y - w[second];
            } else {
                q = y - w[first];
            }

            int low = -1;
            for(int j = 0; j < g[i].size(); j++) {
                if(g[i].get(j).first <= p || g[i].get(j).first <= q) {
                    low = j;
                }
            }
            for(int j = 1; j <= low; j++) {
                t.merge(g[i].get(j-1).second, g[i].get(j).second);
            }

            if(c[first] == i && w[first] + g[i].get(0).first <= x) {
                t.merge(first, g[i].get(0).second);
            } 
            else if (c[first] != i && w[first] + g[i].get(0).first <= y) {
                t.merge(first, g[i].get(0).second);
            }

            if(second != -1 && c[second] == i && w[second] + g[i].get(0).first <= x) {
                t.merge(second, g[i].get(0).second);
            } 
            else if (second != -1 && c[second] != i && w[second] + g[i].get(0).first <= y) {
                t.merge(second, g[i].get(0).second);
            }
        }
        if(second != -1 && w[first] + w[second] <= y) {
            t.merge(first, second);
        }

        fac[0] = 1;
        for(int i = 1; i <= n; i++) {
            fac[i] = fac[i - 1] * i;
            fac[i] %= mod;
        }

        long long ans = 1;
        set <int> ext;
        for(int i = 1; i <= n; i++) {
            if(!ext.count(t.root(i))) {
                ext.insert(t.root(i));
                ans *= t.size(i);
                ans %= mod;
            }
        }
        printf("%lld\n", ans);
    }

Measured memory_bytes: 38272