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)

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=5e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void Add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int cnt[N],w[N],c[N],cmn[N],vis[N],fac[N],ifac[N],st[N];
int n,x,y,na,res,size,top;
void dfs(int u){
	if(++cnt[c[u]]==1)st[++top]=c[u];
	vis[u]=1,++size;
	go(u)if(!vis[v])dfs(v);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&n,&x,&y);res=1;
	fp(i,1,n)scanf("%d%d",&c[i],&w[i]),assert(c[i]<=n);
	w[0]=1e9+7;
	fp(i,1,n)if(w[i]<w[cmn[c[i]]])cmn[c[i]]=i;
	fp(i,1,n)if(cmn[i]&&w[cmn[i]]<w[na])na=cmn[i];
	fp(i,1,n)if(i!=cmn[c[i]]&&w[i]+w[cmn[c[i]]]<=x)Add(i,cmn[c[i]]),Add(cmn[c[i]],i);
		else if(i!=na&&w[i]+w[na]<=y)Add(i,na),Add(na,i);
	fac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
	size=0,top=0;
	dfs(na);
	R int ret=fac[size];
	fp(i,1,top)ret=mul(ret,ifac[cnt[st[i]]]);
	fp(i,1,top)cnt[st[i]]=0;
	res=mul(res,ret);
	printf("%d\n",res);
	return 0;
}