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)

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 200010;
const int mod = 1e9 + 7;
typedef long long LL;
typedef pair<int, int> pii;
vector<pii> b;
vector<int> t[N];
int n, x, y, lc[N], col[N], ls[N], tc[N], w[N];

#define bi b[i].second

int f[N], st[N];
int f_f(int x) { return x == f[x] ? x : f[x] = f_f(f[x]);} 

void merge(int x1, int x2)
{
	int f1 = f_f(x1), f2 = f_f(x2);
	if (f1 != f2) f[f1] = f2;
}

LL p[N];
LL qpow(LL a, LL b)
{
	LL ret = 1, base = a;
	while (b) {
		if (b & 1) ret = ret * base % mod;
		base = base * base % mod, b >>= 1;
	}
	return ret;
}
LL C(int a, int b) {return p[a] * qpow(p[b], mod - 2) % mod * qpow(p[a - b], mod - 2) % mod;}

int main()
{
	scanf("%d%d%d", &n, &x, &y);
	Rep(i, n){
		scanf("%d%d", &col[i], &w[i]);
		b.push_back(mp(w[i], i));
		f[i] = i;
	}
	sort(b.begin(), b.end());
	
	memset(ls, -1, sizeof(ls));
	
	Rep(i, n - 1){
		int tmp = ls[col[bi]];
		if (tmp != -1 && b[i].first + b[tmp].first <= x) merge(bi, b[tmp].second);
		if (col[bi] != col[b[0].second] && b[i].first + b[0].first <= y) merge(bi, b[0].second);
		if (!ls[col[bi]]) ls[col[bi]] = i;
	}
	
	Rep(i, n) t[f_f(i)].push_back(col[i]);
	p[0] = 1;
	Rep(i, n) p[i] = p[i - 1] * i % mod;
	
	LL ans = 1;
	
	Rep(i, n) if (t[i].size()) {
		sort(t[i].begin(), t[i].end());	
		int top = 0, cnt = 0;
		for (int j = 0; j < t[i].size(); j ++){
			if (t[i][j] != t[i][j - 1] && j != 0) st[++ top] = cnt, cnt = 0;
			cnt ++;
		}
		int tmp = cnt;
		LL tans = 1;
		while (top){
			tans = tans * C(tmp + st[top], st[top]) % mod;
			tmp += st[top], top --;
		}
		ans = ans * tans % mod;
	}
	printf("%lld\n", ans);
	
	return 0;
}