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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 2e5+5;
const int MOD = 1e9+7;

int N, X, Y;
int C[MX_N], W[MX_N];
int mn[MX_N], cnt[MX_N], f[MX_N];

int expo(int b, int p) {
    if (p == 0) return 1;
    if (p == 1) return b;
    int x = expo(b,p/2);
    x = (ll)x*x % MOD;
    if (p&1) x = (ll)x*b % MOD;
    return x;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> X >> Y;
    W[0] = 1e9+5;
    FOR(i,1,N) mn[i] = 0;
    FOR(i,1,N){
        cin >> C[i] >> W[i];
        if (W[i] < W[mn[C[i]]]) mn[C[i]] = i;
    }

    int a = 0, b = 0;
    FOR(i,1,N){
        if (W[mn[i]] < W[a]) b = a, a = mn[i];
        else if (W[mn[i]] < W[b]) b = mn[i];
    }

    f[0] = f[1] = 1;
    FOR(i,2,N){ f[i] = (ll)f[i-1]*i % MOD; }
    int tot = 0;
    FOR(i,1,N){
        if (W[i]+W[C[i]==C[a]?b:a] <= Y || (W[mn[C[i]]]+W[C[i]==C[a]?b:a] <= Y && W[mn[C[i]]]+W[i] <= X))
            ++tot, ++cnt[C[i]];
    }
    int ans = f[tot];
    FOR(i,1,N){
        ans = (ll)ans*expo(f[cnt[i]],MOD-2) % MOD;
    }
    cout << ans << '\n';
}

