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<bits/stdc++.h>

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0LL)
# define debug(x) cerr<< #x << " = " << x << endl
# define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
# define tdebug(x, y, z) cerr<< #x << " = " << x  << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
# define bin(x) cerr<< #x << " : " << bitset<4>(x) << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define MP make_pair
# define uop(x, y) pii(min(x, y), max(x, y))

const int MAXN = 200 * 1000 + 10, MOD = 1000 * 1000 * 1000 + 7;
vector <int> v[MAXN];
int mn[MAXN], m1[MAXN], m2[MAXN], fact[MAXN];

int _pow(int a, int p)
{
	if (!p)
		return 1;
	return _pow(a * a % MOD, p / 2) * ((p & 1) ? a : 1) % MOD;
}

int rev(int a)
{
	return _pow(a, MOD - 2);
}

int choose(int k, int n)
{
	return fact[n] * rev(fact[k] * fact[n - k]) % MOD;
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n, x, y;
	cin >> n >> x >> y;

	memset(mn, 63, sizeof mn);
	for (int i = 0; i < n; i ++)
	{
		int c, w;
		cin >> c >> w;
		v[c].PB(w);
		smin(mn[c], w);
	}

	fact[0] = 1;
	for (int i = 1; i <= n + 5; i ++)
		fact[i] = fact[i - 1] * i % MOD;

	m1[0] = INT_MAX;
	for (int i = 1; i <= n; i ++)
		m1[i] = min(m1[i - 1], mn[i]);

	m2[n + 1] = INT_MAX;
	for (int i = n; i >= 1; i --)
		m2[i] = min(m2[i + 1], mn[i]);

	int ans = 1, sum = 0;
	for (int i = 1; i <= n; i ++)
	{
		if (mn[i] + min(m1[i - 1], m2[i + 1]) > y)
			continue;

		int cnt = 0;
		for (int a : v[i])
			cnt += (a + mn[i] <= x || a + min(m1[i - 1], m2[i + 1]) <= y);
		sum += cnt;
		ans *= choose(cnt, sum);
		ans %= MOD;
	}
	cout << ans << endl;

	return 0;
}