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;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=200005,mod=1000000007;
vector<int> v[N];
int c[N],w[N],father[N],q[N],vis[N],x,y,n;
inline int getfather(int x){
	return father[x]==x?x:father[x]=getfather(father[x]);
}
map<int,int> M[N];
inline int ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
inline bool cmp(int a,int b){
	return w[a]<w[b];
}
void ins (int a,int b){
	//cout<<a<<" "<<b<<" "<<w[a]<<" "<<w[b]<<endl;
	int t1=getfather(a),t2=getfather(b);
	if(t1!=t2)father[t2]=t1;
}
int main(){
	n=read(); x=read(); y=read();
	for(int i=1;i<=n;i++){
		c[i]=read(); w[i]=read(); v[c[i]].push_back(i); father[i]=q[i]=i;
	}
	for(int i=1;i<=n;i++)if(v[i].size()){
		sort(v[i].begin(),v[i].end(),cmp); vis[v[i][0]]=1;
		for(unsigned j=1;j<v[i].size();i++)if(w[v[i][j]]+w[v[i][0]]<=x)ins(v[i][0],v[i][j]);
	}
	sort(&q[1],&q[n+1],cmp); int jb=0;
	for(int i=2;i<=n;i++){
		int t=q[i];  
		if(c[t]!=c[q[1]]){
			if(w[t]+w[q[1]]<=y)ins(q[1],t); if(!jb)jb=t;
		}else{
			if(w[t]+w[jb]<=y)ins(jb,t);
		}
	}//else cout<<w[i]<<" "<<i<<" "<<father[i]<<endl;
	for(int i=1;i<=n;i++)if(c[i]==c[q[1]]&&w[jb]+w[i]<=y)ins(jb,i);
	for(int i=1;i<=n;i++)M[getfather(i)][c[i]]++;
	ll ans=1;
	for(int i=1;i<=n;i++)if(getfather(i)==i){
		int sum=0;
		for(map<int,int>::iterator it=M[i].begin();it!=M[i].end();it++){
			sum+=it->second; for(int j=1;j<=it->second;j++)ans=ans*ksm(j,mod-2)%mod;
		}
		//cout<<i<<" "<<sum<<" "<<ans<<endl;
		for(int j=1;j<=sum;j++)ans=ans*j%mod;
	}
	cout<<ans<<endl;
}