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: Time Limit Exceeded)

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)





template<int um> class UF {
public:
	vector<int> par;
	UF() { par = vector<int>(um, 0); rep(i, 0, um) par[i] = i; }
	int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
	void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
};
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
int mul(int x, int y) { return 1LL * x * y % mod; }
int modpow(int a, long long b) {
	int ret = 1;
	while (b > 0) {
		if (b & 1) ret = 1LL * ret * a % mod;
		a = 1LL * a * a % mod; b >>= 1;
	}
	return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }

int fac[201010], ifac[201010];
void initfac() {
	fac[0] = ifac[0] = 1;
	rep(i, 1, 201010) fac[i] = 1LL * i * fac[i - 1] % mod;
	rep(i, 1, 201010) ifac[i] = modinv(fac[i]);
}
//-----------------------------------------------------------------------------------
int N, X, Y, C[201010], W[201010];
UF<201010> uf;
void merge() {
	rep(a, 0, N) rep(b, a + 1, N) {
		if (C[a] == C[b] && W[a] + W[b] <= X) uf(a, b);
		if (C[a] != C[b] && W[a] + W[b] <= Y) uf(a, b);
	}
}
int count() {
	map<int, vector<int>> group;
	rep(i, 0, N) group[uf[i]].push_back(i);

	int res = 1;
	for (auto g : group) {
		auto v = g.second;

		int com = fac[v.size()];

		map<int, int> cnt;
		for (int i : v) cnt[C[i]]++;
		for (auto p : cnt) com = mul(com, ifac[p.second]);

		res = mul(res, com);
	}

	return res;
}
//-----------------------------------------------------------------------------------
int main() {
	initfac();
	cin >> N >> X >> Y;
	rep(i, 0, N) scanf("%d%d", &C[i], &W[i]);

	merge();
	cout << count() << endl;
}