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;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int f[200005];
int Find(int x){
    if(f[x]==x)return x;
    return f[x]=Find(f[x]);
}
map<int,int> m;
LL fra[200005];
LL inv[200005];
int mod=1e9+7;
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
map<int,int> cnt[200005];
int main(){ 
    fra[0]=1;
    for(int i = 1;i<200005;i++)
        fra[i]=fra[i-1]*i%mod;
    inv[200000]=f_pow(fra[200000],mod-2);
    for(int i = 199999;i>=0;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
    int n,x,y;
    scanf("%d %d %d",&n,&x,&y);
    pii p[200005];
    for(int i = 0;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        p[i]=mp(y,x);
    }
    sort(p,p+n);
    for(int i = 0;i<n;i++)
        f[i]=i;
    vector<int> v;
    for(int i = 0;i<n;i++){
        if(m.find(p[i].y)==m.end()){
            m[p[i].y]=i;
            v.pb(i);
        }
        if(p[m[p[i].y]].x+p[i].x<=x){
            int a=Find(m[p[i].y]);
            int b=Find(i);
            f[a]=b;
        }
        if(p[i].y==p[v[0]].y){
            if(v.size()!=1&&p[i].x+p[v[1]].x<=y){
                int a=Find(v[1]);
                int b=Find(i);
                f[a]=b;
            }
        }
        else{
            if(p[i].x+p[v[0]].x<=y){
                int a=Find(v[0]);
                int b=Find(i);
                f[a]=b;
            }
        }
    }
    for(int i = 0;i<n;i++){
        cnt[Find(i)][p[i].y]++;
    }
    LL ans=1;
    for(int i = 0;i<n;i++){
        int tot=0;
        for(auto it:cnt[i]){
            tot+=it.y;
            ans=ans*inv[it.y]%mod;
        }
        ans=ans*fra[tot]%mod;
    }
    printf("%lld\n",ans);
}
/*
2 2 1
3 2 3
4 2 4 4 7

*/