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: Wrong Answer)

/**
 *    author:  [itmo] enot.1.10
 *    created: 03.04.2017 20:47:57       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 2e5 + 10;
const int mod = 1e9 + 7;


namespace math
{
    const int N = 3e5 + 10;
    
    int fact[N];
    int revfact[N];

    int revx[N];

    void init()
    {
        fact[0] = 1;
        for (int i = 1; i < N; ++i) fact[i] = fact[i - 1] * (ll)i % mod;
        revfact[0] = revfact[1] = 1;
        revx[1] = 1;
        for (int i = 2; i < N; ++i)
        {
            int c = mod / i + 1;
            revx[i] = revx[c * i - mod] * (ll)c % mod;
            revfact[i] = revfact[i - 1] * (ll)revx[i] % mod;
        }
    }

    int cnk(int n, int k)
    {
        if (k < 0 || k > n) return 0;
        return fact[n] * (ll)revfact[n - k] % mod * revfact[k] % mod;
    }
}


pi a[N];
int n;

int X, Y;

int id[N];
int intotal[N];


int last = 0;
int cnt[N];



int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    math::init();

    scanf("%d%d%d", &n, &X, &Y);
    forn(i, n) scanf("%d%d", &a[i].F, &a[i].S);
    sort(a, a + n);
    forn(i, n)
    {
        int j = i + 1;
        while (j < n && a[j].F == a[i].F) ++j;
        
        id[i] = ++last;
        for (int k = i + 1; k < j; ++k)
        {
            if (a[i].S + a[k].S <= X) id[k] = id[i];
            else id[k] = ++last;
        }
        i = j - 1;
    }

    int badcolor = -1;
    forn(_, 2)
    {
        int x = -1;
        forn(i, n) if (a[i].F != badcolor && (x == -1 || a[i].S < a[x].S))
        {
            x = i;
        }
        if (x == -1) break;

        if (badcolor == -1) intotal[id[x]] = 1;
        forn(i, n) if (a[i].F != a[x].F && a[i].S + a[x].S <= Y) intotal[id[i]] = 1;

        badcolor = a[x].F;
    }

    int total = 0;
    forn(i, n) cnt[id[i]]++;

    int res = 1;
    forn(i, N)
    {
        if (intotal[i])
        {
            res = res * (ll)math::cnk(total + cnt[i], cnt[i]);
            total += cnt[i];
        }
        else
        {
            //res = res * (ll)math::fact[cnt[i]] % mod;
        }
    }
    //res = res * (ll)math::fact[total] % mod;

    printf("%d\n", res);
        
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}