Problem:
Score : 1000 points

Problem Statement

Snuke arranged N colorful balls in a row.
The i-th ball from the left has color c_i and weight w_i.

He can rearrange the balls by performing the following two operations any number of times, in any order:

Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.

Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.

How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.

Constraints

1 ≤ N ≤ 2 × 10^5

1 ≤ X, Y ≤ 10^9

1 ≤ c_i ≤ N

1 ≤ w_i ≤ 10^9

X, Y, c_i, w_i are all integers.

Input

Input is given from Standard Input in the following format:

N X Y
c_1 w_1
:
c_N w_N

Output

Print the answer.

Sample Input 1

4 7 3
3 2
4 3
2 1
4 4

Sample Output 1

2

The sequence of colors (2,4,3,4) can be obtained by swapping the positions of the first and third balls by operation 2.

It is also possible to swap the positions of the second and fourth balls by operation 1, but it does not affect the sequence of colors.

Sample Input 2

1 1 1
1 1

Sample Output 2

1

Sample Input 3

21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15

Sample Output 3

129729600

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#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';
}