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 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

#define NITEM(arr) (sizeof(arr)/sizeof(arr[0]))
#define MODU 1000000007LL

#define N_MAX 200000


ll gcd(ll a, ll b)
{
	ll c;

	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


ll memo[101][51];


ll nCm(int n, int m)
{
	static int work[N_MAX+1];
	int i, j, t, d;
	ll r;

	if(m*2>n) m=n-m;
	if(n<=100)
	{
		if(memo[n][m]>0) return memo[n][m];
	}

	for(i=0;i<m;i++) work[i]=n-i;
	for(i=1;i<=m;i++)
	{
		t=i;
		for(j=0;j<m;j++)
		{
			d=gcd(t, work[j]);
			if(d>1)
			{
				work[j]/=d;
				t/=d;
			}
		}
	}

	r=1;
	for(i=0;i<m;i++)
	{
		r=(r*work[i])%MODU;
	}

	if(n<=100)
	{
		memo[n][m]=r;
	}

	return r;
}


typedef struct
{
	int c, w;
}ball_t;


ball_t ball[N_MAX+1];
int c_num[N_MAX+1];
int movable[N_MAX+1];


int cmp(const void *pa, const void *pb)
{
	const ball_t *a, *b;

	a=pa;
	b=pb;
	if(a->w<b->w) return -1;
	return (a->w>b->w);
}


int cmp2(const void *pa, const void *pb)
{
	const ball_t *a, *b;

	a=pa;
	b=pb;
	if(a->c<b->c) return -1;
	if(a->c>b->c) return 1;

	if(a->w<b->w) return -1;
	return (a->w>b->w);
}


ll calc(int c_num[], int n)
{
	ll ret=1;
	int i, sum;

	sum=0;
	for(i=0;i<n;i++)
	{
		if(c_num[i]==0) continue;

		sum+=c_num[i];
		ret=(ret*nCm(sum, c_num[i]))%MODU;
	}
	return ret;
}


int main(void)
{
	int N, X, Y;
	int i, second, light;

	while(scanf("%d%d%d", &N,&X,&Y)==3)
	{
		for(i=0;i<N;i++)
		{
			scanf("%d%d", &ball[i].c, &ball[i].w);
		}

		qsort(ball, N, sizeof(ball[0]), cmp2);
		light=0;
		for(i=1;i<N;i++)
		{
			if(ball[light].c==ball[i].c)
			{
				if(ball[light].w+ball[i].w<=X)
				{
					ball[i].w=ball[light].w;
				}
			}
			else
			{
				light=i;
			}
		}

		qsort(ball, N, sizeof(ball[0]), cmp);

		for(second=1;second<N;second++)
		{
			if(ball[second].c!=ball[0].c) break;
		}

		if(second>=N)
		{
			printf("1\n");
			continue;
		}

		memset(movable, 0, sizeof(movable));
		for(i=0;i<N;i++)
		{
			if(ball[0].c!=ball[i].c)
			{
				if(ball[0].w+ball[i].w<=Y) movable[i]=1;
			}
			if(ball[second].c!=ball[i].c)
			{
				if(ball[second].w+ball[i].w<=Y) movable[i]=2;
			}
		}

		memset(c_num, 0, sizeof(c_num));
		for(i=0;i<N;i++)
		{
			if(movable[i]) c_num[ball[i].c]++;
		}
		printf("%d\n", (int)calc(c_num+1, N));
	}
	return 0;
}