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<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>

template<typename T>inline bool check_min(T a,T &b){return a<b?b=a,1:0;}
template<typename T>inline bool check_max(T a,T &b){return a>b?b=a,1:0;}

namespace pu
{
	typedef long long ll;
	const int N=201000,MOD=1000000007;
	ll inv(ll x){return x==1?1:(-(MOD/x)*inv(MOD%x)%MOD);}
	ll fact[N],ifact[N];
	ll C(int n,int m){return fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;}

	std::vector<int> V[N];
	int pos[N];
	int n,X,Y;
	void initialize()
	{
		scanf("%d%d%d",&n,&X,&Y);
		for(int i=1,c,x;i<=n;i++)
		{
			scanf("%d%d",&c,&x);
			V[c].push_back(x);
		}
		for(int i=1;i<=n;i++)
			std::sort(V[i].begin(),V[i].end());

		fact[0]=1;
		for(int i=1;i<N;i++)fact[i]=fact[i-1]*i%MOD;
		ifact[N-1]=inv(fact[N-1]);
		for(int i=N-1;i;i--)ifact[i-1]=ifact[i]*i%MOD;
	}
	void getpos()
	{
		int minw=2147483647,w,id=0;
		for(int i=1;i<=n;i++)
		{
			if(V[i].empty())continue;

			w=V[i][0];
			if(w==minw)id=0;
			if(check_min(w,minw))id=i;

			pos[i]=std::upper_bound(V[i].begin(),V[i].end(),X-w)-V[i].begin();
		}

		int dmin=2147483647;

		for(int i=1;i<=n;i++)
		{
			if(V[i].empty())continue;
			if(i==id)continue;

			check_min(V[i][0],dmin);

			w=std::upper_bound(V[i].begin(),V[i].end(),Y-minw)-V[i].begin();

			if(!w)pos[i]=0;
			else check_max(w,pos[i]);
		}

		if(!id)return;

		w=std::upper_bound(V[id].begin(),V[id].end(),Y-dmin)-V[id].begin();
		if(!w)pos[id]=0;
		else check_max(w,pos[id]);
	}
	ll calc()
	{
		int cnt=0;
		ll ret=1;
		for(int i=1;i<=n;i++)cnt+=pos[i];

		for(int i=1;i<=n;i++)
			ret=ret*C(cnt,pos[i])%MOD,cnt-=pos[i];

		return (ret%MOD+MOD)%MOD;
	}
	void solve()
	{
		initialize();
		getpos();
		printf("%lld\n",calc());
	}
}
int main()
{
	pu::solve();
	return 0;
}