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>
#define R register int
#define ll long long 
using namespace std;
const int N=200002;
const int mod=1e9+7;
int n,x,y,len,ans,tot,jic[N],w[N],c[N],Mnq[N],Mnh[N];
struct Qs{int sz,vl;}Q[N];
int cmp(const Qs &x,const Qs &y){return x.vl<y.vl;}
vector<int>G[N];
int Qpow(R x,R y){
	R ans=1,bas=x;
	while(y){
		if(y&1)ans=1ll*ans*bas%mod;
		bas=1ll*bas*bas%mod,y>>=1;
	}return ans;
}
int gi(){
	R x=0,k=1;char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')k=-1,c=getchar();
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*k;
}
int main(){
	n=gi(),x=gi(),y=gi(),jic[0]=1,Mnq[0]=Mnh[n+1]=2e9;
	for(R i=1;i<=n;++i){
		c[i]=gi(),w[i]=gi();
		G[c[i]].push_back(w[i]);
		jic[i]=1ll*i*jic[i-1]%mod;
	}
	for(R i=1;i<=n;++i){
		if((int)G[i].size()==0){Mnq[i]=Mnq[i-1];continue;}
		sort(G[i].begin(),G[i].end());
		Mnq[i]=min(Mnq[i-1],G[i][0]);
	}
	for(R i=n;i>=1;--i){
		if((int)G[i].size()==0){Mnh[i]=Mnh[i+1];continue;}
		Mnh[i]=min(Mnh[i+1],G[i][0]);
	}
	for(R i=1,lim=G[i].size();i<=n;++i,lim=G[i].size()){
		if(!lim)continue;tot++,Q[tot].vl=G[i][0],Q[tot].sz=1;
		for(R j=1;j<lim;++j)
			if(G[i][0]+G[i][j]<=x&&G[i][j]+min(Mnq[i-1],Mnh[i+1])<=y)
				Q[tot].sz++;
			else break;
	}
	sort(Q+1,Q+tot+1,cmp),len=Q[1].sz,ans=Qpow(jic[Q[1].sz],mod-2);
	if(tot==1)return puts("1"),0;
	for(R i=2;i<=tot;++i){
		if(Q[i].vl+Q[1].vl<=y)
			len+=Q[i].sz,ans=1ll*ans*Qpow(jic[Q[i].sz],mod-2)%mod;
		else break;
	}
	cout<<1ll*jic[len]*ans%mod<<endl;
	return 0;
}