stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int maxn = 1100;

const int maxm = 220000;



int u[maxm], v[maxm];

vector<int> g[maxn];

bool chk[maxn][maxn];

int root;

bool vis[maxn];



namespace SCC {

	const int N = 1100;

	int T, qn;

	int q[N], vis[N];

	vector<int> adj[N], radj[N];

	

	void dfs(int u) {

		vis[u] = 1;

		for (int v : adj[u]) {

			if (!vis[v]) dfs(v);

		}

		q[++qn] = u;

	}

	

	void rdfs(int u) {

		vis[u] = T;

		for (int v : radj[u]) {

			if (!vis[v]) rdfs(v);

		}

	}

	

	void SCC(int n) {

		memset(vis, 0, sizeof(int) * (n + 1));

		qn = 0;

		for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i);

		memset(vis, 0, sizeof(int) * (n + 1));

		for (int i = n; i > 0; i--) if (!vis[q[i]]) ++T, rdfs(q[i]);

	}

};



inline void dfs(int u) {

	vis[u] = true;

	for(auto v : g[u]) {

		if(vis[v]) {

			if(u == root) chk[root][v] = false;

			continue;

		}

		dfs(v);

		if(u == root) chk[root][v] &= true;

		else chk[root][v] = false;

	}

}



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int n, m; cin >> n >> m;

	for(int i = 0; i < m; ++ i) {

		cin >> u[i] >> v[i];

		g[u[i]].push_back(v[i]);

		SCC::adj[u[i]].push_back(v[i]);

		SCC::radj[v[i]].push_back(u[i]);

	}

	// get SCC

	SCC::SCC(n);

	// check the u -> v edge is the unique way.

	for(int i = 1; i <= n; ++ i) for(int j = 1; j <= n; ++ j) chk[i][j] = true;

	for(int step = 0; step < 2; ++ step) {

		for(int i = 1; i <= n; ++ i) {

			root = i;

			if(step) reverse(g[i].begin(), g[i].end());

			memset(vis, false, sizeof vis);

			dfs(i);

		}

	}

	for(int i = 0; i < m; ++ i) {

		int flag = SCC::vis[u[i]] == SCC::vis[v[i]];

		if(chk[u[i]][v[i]] == flag) cout << "diff\n";

		else cout << "same\n";

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1616915040531777x):
#include <cstdio>

#include <vector>

#include <algorithm>

using namespace std;



const int MAXN = 1000;

const int MAXM = 200000;



vector<int>G[MAXN + 5]; int to[MAXM + 5];

void addedge(int u, int i) {G[u].push_back(i);}



int tag[MAXN + 5], que[2*MAXN + 5];

bool ans1[MAXM + 5], ans2[MAXM + 5];



int n, m;

int main() {

	scanf("%d%d", &n, &m);

	for(int i=1;i<=m;i++) {

		int a; scanf("%d%d", &a, &to[i]);

		addedge(a, i);

	}

	for(int i=1;i<=n;i++) {

		for(int j=1;j<=n;j++) tag[j] = 0;

		int s = 1, t = 0;

		for(int p=0;p<G[i].size();p++)

			tag[que[++t] = to[G[i][p]]] = G[i][p];

		while(s<=t) {

			int x = que[s++], y = tag[x];

			for(int p=0;p<G[x].size();p++) {

				int q = to[G[x][p]];

				if( q != i ) {

					if( tag[q] != -1 ) {

						if( tag[q] == 0 )

							tag[que[++t] = q] = y;

						else if( tag[q] != y )

							tag[que[++t] = q] = -1;

					}

				}

				else ans1[G[x][p]] = 1;

			}

		}

		for(int p=0;p<G[i].size();p++)

			if( tag[to[G[i][p]]] == -1 ) ans2[G[i][p]] = 1;

	}

	for(int i=1;i<=m;i++)

		puts(ans1[i] ^ ans2[i] ? "diff" : "same");

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<vector>

#define MAX 200200

#define MOD 1000000007

using namespace std;

#define ll long long

inline int read()

{

	int x=0;bool t=false;char ch=getchar();

	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();

	if(ch=='-')t=true,ch=getchar();

	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();

	return t?-x:x;

}

int n,X,Y,ans;

struct Ball{int c,w;}B[MAX];

bool operator<(Ball a,Ball b){if(a.c!=b.c)return a.c<b.c;return a.w<b.w;}

int jc[MAX],jv[MAX],inv[MAX];

int pmn[MAX],smn[MAX],sz[MAX],W[MAX],p[MAX];

bool cmp(int i,int j){return W[i]<W[j];}

int main()

{

	n=read();X=read();Y=read();

	for(int i=1;i<=n;++i)B[i].c=read(),B[i].w=read();

	jc[0]=jv[0]=inv[0]=inv[1]=1;

	for(int i=2;i<=n;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;

	for(int i=1;i<=n;++i)jc[i]=1ll*jc[i-1]*i%MOD,jv[i]=1ll*jv[i-1]*inv[i]%MOD;

	sort(&B[1],&B[n+1]);

	memset(pmn,63,sizeof(pmn));

	memset(smn,63,sizeof(smn));

	memset(W,63,sizeof(W));

	for(int i=1,j;i<=n;i=j+1)

	{

		j=i;while(j<n&&B[i].c==B[j+1].c)++j;

		pmn[B[i].c]=smn[B[i].c]=B[i].w;

	}

	for(int i=1;i<=n;++i)pmn[i]=min(pmn[i],pmn[i-1]);

	for(int i=n;i>=1;--i)smn[i]=min(smn[i],smn[i+1]);

	for(int i=1,j;i<=n;i=j+1)

	{

		j=i;while(j<n&&B[i].c==B[j+1].c)++j;

		int d=min(pmn[B[i].c-1],smn[B[i].c+1]);

		int cnt=1;

		for(int k=i+1;k<=j;++k)

			if(B[i].w+B[k].w<=X||B[k].w+d<=Y)++cnt;

			else break;

		sz[B[i].c]=cnt;W[B[i].c]=B[i].w;

	}

	for(int i=1;i<=n;++i)p[i]=i;

	sort(&p[1],&p[n+1],cmp);

	for(int i=1;i<=n;++i)

		if(i==1||W[p[i]]+W[p[1]]<=Y)

			ans+=sz[p[i]];

	ans=jc[ans];

	for(int i=1;i<=n;++i)

		if(i==1||W[p[i]]+W[p[1]]<=Y)

			ans=1ll*ans*jv[sz[p[i]]]%MOD;

	printf("%d\n",ans);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.409111869744875x):
#include<bits/stdc++.h>

using namespace std;

const int P=1e9+7,N=2e5+7;

int c[N],w[N],d[N],f[N],iv[N],fc[N],fciv[N];

int main(){

	int n,x,y,i,j,t=0,mn=2e9,mn2=2e9,ans=1;

	scanf("%d%d%d",&n,&x,&y);

	memset(d,63,n+1<<2);

	for(i=1;i<=n;++i)scanf("%d%d",c+i,w+i),d[c[i]]=min(d[c[i]],w[i]);

	for(i=1;i<=n;++i)if(d[i]<mn)mn2=mn,mn=d[i];else if(d[i]<mn2)mn2=d[i];

	if(mn+mn2>y)return puts("1"),0;

	fc[1]=iv[1]=fciv[1]=1;

	for(i=2;i<=n;++i)iv[i]=(P-P/i)*1ll*iv[P%i]%P,fc[i]=fc[i-1]*1ll*i%P,fciv[i]=fciv[i-1]*1ll*iv[i]%P;

	for(i=1;i<=n;++i)if((w[i]+d[c[i]]<=x)||(w[i]+(d[c[i]]==mn?mn2:mn)<=y))++f[c[i]];

	for(i=1;i<=n;++i)if(d[i]+mn<=y)t+=f[i],ans=ans*1ll*fciv[f[i]]%P;

	printf("%d",ans*1ll*fc[t]%P);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int mod=(1e9+7);

int n;

int fac[200001],inv[200001];

int qpow(int a,int b){

	int ans=1;

	for(;b;b>>=1,a=a*a%mod)

	if(b&1)ans=ans*a%mod;

	return ans;

}

int C(int n,int m){

	if(!n)return 1;

	if(m<n)return 0;

	return fac[m]*inv[m-n]%mod*inv[n]%mod;

}

void init(){

	fac[0]=1;

	for(int i=1;i<=n;++i)fac[i]=i*fac[i-1]%mod;

	inv[n]=qpow(fac[n],mod-2);

	for(int i=n-1;~i;--i)inv[i]=inv[i+1]*(i+1)%mod;

}

int col[200001];

int w[200001];

int allmin=0x7fffffff,secmin=0x7fffffff;

int minpos,secpos;

int minn[200001];

int A,B;

int sum[200001],allsum;

signed main(){

	memset(minn,0x7f,sizeof(minn));

	scanf("%lld%lld%lld",&n,&A,&B);

	init();

	for(int i=1;i<=n;++i){

		scanf("%lld%lld",&col[i],&w[i]);

		minn[col[i]]=min(minn[col[i]],w[i]);

		if(w[i]<allmin){

			secpos=minpos;

			minpos=i;

			secmin=allmin;

			allmin=w[i];

		}

		else if(w[i]<secmin){

			secpos=i;

			secmin=w[i];

		}

	}

	for(int i=1;i<=n;++i){

		if(minn[col[i]]+w[i]<=A){

			w[i]=minn[col[i]];

		}

		if(col[i]!=col[minpos]&&w[i]+w[minpos]<=B){

			allsum++;

			sum[col[i]]++;

		}

		if(col[i]==col[minpos]&&w[i]+w[secpos]<=B){

			allsum++;

			sum[col[i]]++;

		}

	}

	int ans=1;

	for(int i=1;i<=n;++i){

		if(sum[i]){

			ans=(ans*C(sum[i],allsum))%mod;

			allsum-=sum[i];

		}

	}

	printf("%lld\n",ans);

}

// Faster C++ solution for the same problem (measured speedup: 2.607955211277739x):
#include<bits/stdc++.h>

using namespace std;

const int P=1e9+7,N=2e5+7;

int c[N],w[N],d[N],f[N],iv[N],fc[N],fciv[N];

int main(){

	int n,x,y,i,j,t=0,mn=2e9,mn2=2e9,ans=1;

	scanf("%d%d%d",&n,&x,&y);

	memset(d,63,n+1<<2);

	for(i=1;i<=n;++i)scanf("%d%d",c+i,w+i),d[c[i]]=min(d[c[i]],w[i]);

	for(i=1;i<=n;++i)if(d[i]<mn)mn2=mn,mn=d[i];else if(d[i]<mn2)mn2=d[i];

	if(mn+mn2>y)return puts("1"),0;

	fc[1]=iv[1]=fciv[1]=1;

	for(i=2;i<=n;++i)iv[i]=(P-P/i)*1ll*iv[P%i]%P,fc[i]=fc[i-1]*1ll*i%P,fciv[i]=fciv[i-1]*1ll*iv[i]%P;

	for(i=1;i<=n;++i)if((w[i]+d[c[i]]<=x)||(w[i]+(d[c[i]]==mn?mn2:mn)<=y))++f[c[i]];

	for(i=1;i<=n;++i)if(d[i]+mn<=y)t+=f[i],ans=ans*1ll*fciv[f[i]]%P;

	printf("%d",ans*1ll*fc[t]%P);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define MAXN 200005

#define INF 0x3f3f3f3f



typedef long long lint;



using namespace std;



const int mod = 1e9 + 7;

int n, x, y;

int c[MAXN], w[MAXN], mini[MAXN];

int sum[MAXN], amount;

int first, second, firstc;

lint fac[MAXN], inf[MAXN];



int read() {

    char c = getchar();

    int x = 0;

    while (!isdigit(c))

        c = getchar();

    while (isdigit(c)) {

        x = (x << 3) + (x << 1) + c - '0';

        c = getchar();

    }

    return x;

}



lint power(lint a, int b) {

    lint res = 1;

    while (b) {

        if (b & 1)

            res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}



void init() {

    fac[0] = inf[0] = 1;

    for (int i = 1; i <= n; ++i)

        fac[i] = fac[i - 1] * i % mod;

    inf[n] = power(fac[n], mod - 2);

    for (int i = n - 1; i >= 1; --i)

        inf[i] = inf[i + 1] * (i + 1) % mod;

}



int main() {

//    freopen("15.txt", "r",stdin);

    n = read();

    x = read();

    y = read();

    init();

    memset(mini, 0x3f, sizeof(mini));

    for (int i = 1; i <= n; ++i) {

        c[i] = read();

        w[i] = read();

        mini[c[i]] = min(mini[c[i]], w[i]);

    }

    for (int i = 1; i <= n; ++i)

        if (mini[c[i]] + w[i] <= x)

            w[i] = mini[c[i]];

    first = second = INF;

    for (int i = 1; i <= n; ++i)

        if (mini[i] < first) {

            second = first;

            first = mini[i];

            firstc = i;

        }

        else if (mini[i] < second)

            second = mini[i];

//    printf("%d %d\n", first, second);

    if (first + second <= y)

        for (int i = 1; i <= n; ++i)

            if (c[i] == firstc && w[i] != first && w[i] + second <= y)

                w[i] = first;

    for (int i = 1; i <= n; ++i)

        if (c[i] == firstc && w[i] == first) {

//            cout << "first: " << i << endl;

            ++sum[c[i]];

            ++amount;

        }

        else if (c[i] != firstc && w[i] + first <= y) {

//            cout << "second: " << i << endl;

            ++sum[c[i]];

            ++amount;

        }

    lint res = fac[amount];

    for (int i = 1; i <= n; ++i)

        res = res * inf[sum[i]] % mod;

    printf("%lld\n", res);

}


// Faster C++ solution for the same problem (measured speedup: 1.7919050447943614x):
#include<bits/stdc++.h>

using namespace std;

const int P=1e9+7,N=2e5+7;

int c[N],w[N],d[N],f[N],iv[N],fc[N],fciv[N];

int main(){

	int n,x,y,i,j,t=0,mn=2e9,mn2=2e9,ans=1;

	scanf("%d%d%d",&n,&x,&y);

	memset(d,63,n+1<<2);

	for(i=1;i<=n;++i)scanf("%d%d",c+i,w+i),d[c[i]]=min(d[c[i]],w[i]);

	for(i=1;i<=n;++i)if(d[i]<mn)mn2=mn,mn=d[i];else if(d[i]<mn2)mn2=d[i];

	if(mn+mn2>y)return puts("1"),0;

	fc[1]=iv[1]=fciv[1]=1;

	for(i=2;i<=n;++i)iv[i]=(P-P/i)*1ll*iv[P%i]%P,fc[i]=fc[i-1]*1ll*i%P,fciv[i]=fciv[i-1]*1ll*iv[i]%P;

	for(i=1;i<=n;++i)if((w[i]+d[c[i]]<=x)||(w[i]+(d[c[i]]==mn?mn2:mn)<=y))++f[c[i]];

	for(i=1;i<=n;++i)if(d[i]+mn<=y)t+=f[i],ans=ans*1ll*fciv[f[i]]%P;

	printf("%d",ans*1ll*fc[t]%P);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std ;

#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )

#define re register

#define int long long

int gi() {

	char cc = getchar() ; int cn = 0, flus = 1 ;

	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }

	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;

	return cn * flus ;

}

const int P = 1e9 + 7 ; 

const int N = 2e5 + 5 ; 

const int inf = 1e9 + 9 ;

int n, X, Y, fa[N], vis[N], sz[N], fac[N], cnt[N], inv[N], Ans ; 

struct Col {

	int w, c ; 

} a[N] ;

vector<int> Go[N] ;

int fpow( int x, int k ) {

	int ans = 1, base = x ; 

	while( k ) {

		if( k & 1 ) ans = ans * base % P ; 

		base = base * base % P, k >>= 1 ; 

	} return ans ; 

}

bool cmp( Col x, Col y ) {

	return x.w < y.w ; 

}

int fd( int x ) {

	return ( x == fa[x] ) ? x : fa[x] = fd(fa[x]) ;

}

void merge( int x, int y ) {

	int u = fd(x), v = fd(y) ;

	if( u != v ) fa[u] = v, sz[v] += sz[u] ;

}

int st[N], top ; 

signed main()

{

	n = gi(), X = gi(), Y = gi() ; 

	rep( i, 1, n ) a[i].c = gi(), a[i].w = gi(), fa[i] = i, sz[i] = 1 ;

	sort( a + 1, a + n + 1, cmp ) ; fac[0] = 1 ; 

	rep( i, 1, n ) fac[i] = fac[i - 1] * i % P, inv[i] = fpow( fac[i], P - 2 ) ;

	int Ans = 1, Mi1 = 0, Mi2 = 0 ; a[0].w = inf ;

	rep( i, 1, n ) if( a[i].w < a[Mi1].w ) Mi1 = i ;

	rep( i, 1, n ) if( a[i].c != a[Mi1].c && a[i].w < a[Mi2].w ) Mi2 = i ;

	for( re int i = 1; i <= n; ++ i ) {

		if( !vis[a[i].c] ) vis[a[i].c] = i ;

		else if( a[vis[a[i].c]].w + a[i].w <= X ) merge( vis[a[i].c], i ) ;

		if( a[i].c == a[Mi1].c ) {

			if( a[i].w + a[Mi2].w <= Y && Mi2 ) merge( i, Mi2 ) ;

		}

		else if( a[i].w + a[Mi1].w <= Y ) merge( i, Mi1 ) ;

	}

	rep( i, 1, n ) Go[fd(i)].push_back(i) ; inv[0] = 1 ; 

	rep( i, 1, n ) if( fa[i] == i ) Ans = 1ll * Ans * fac[sz[i]] % P ; 

	rep( i, 1, n )

		if( i == fa[i] ) {

			for( auto j : Go[i] ) ++ cnt[a[j].c] ;

			for( auto j : Go[i] ) Ans = Ans * inv[cnt[a[j].c]] % P, cnt[a[j].c] = 0 ;

		}

	cout << Ans << endl ;

	return 0 ;

}

// Faster C++ solution for the same problem (measured speedup: 6.4903187389473995x):
#include<bits/stdc++.h>

using namespace std;

const int P=1e9+7,N=2e5+7;

int c[N],w[N],d[N],f[N],iv[N],fc[N],fciv[N];

int main(){

	int n,x,y,i,j,t=0,mn=2e9,mn2=2e9,ans=1;

	scanf("%d%d%d",&n,&x,&y);

	memset(d,63,n+1<<2);

	for(i=1;i<=n;++i)scanf("%d%d",c+i,w+i),d[c[i]]=min(d[c[i]],w[i]);

	for(i=1;i<=n;++i)if(d[i]<mn)mn2=mn,mn=d[i];else if(d[i]<mn2)mn2=d[i];

	if(mn+mn2>y)return puts("1"),0;

	fc[1]=iv[1]=fciv[1]=1;

	for(i=2;i<=n;++i)iv[i]=(P-P/i)*1ll*iv[P%i]%P,fc[i]=fc[i-1]*1ll*i%P,fciv[i]=fciv[i-1]*1ll*iv[i]%P;

	for(i=1;i<=n;++i)if((w[i]+d[c[i]]<=x)||(w[i]+(d[c[i]]==mn?mn2:mn)<=y))++f[c[i]];

	for(i=1;i<=n;++i)if(d[i]+mn<=y)t+=f[i],ans=ans*1ll*fciv[f[i]]%P;

	printf("%d",ans*1ll*fc[t]%P);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cmath>

#include<cstring>

#include<algorithm>

#include<vector>

#define ll long long

#define re register

#define il inline

#define pb push_back

#define fp(i,a,b) for(re int i=a;i<=b;++i)

#define fq(i,a,b) for(re int i=a;i>=b;--i)

using namespace std;

const int N=2e5+100,mod=1e9+7;

int n,x,X,Y,mn[N],mn1=mod,mn2=mod,ans=1,inv[N],tot;

vector<int>V[N];

il ll gi()

{

  re ll x=0,t=1;

  re char ch=getchar();

  while(ch!='-'&&(ch<'0'||ch>'9')) x=x*10+ch-48,ch=getchar();

  if(ch=='-') t=-1,ch=getchar();

  while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();

  return x*t;

}

int main()

{

  n=gi();X=gi();Y=gi();

  inv[0]=inv[1]=1;

  fp(i,1,n) x=gi(),V[x].pb(gi());

  fp(i,2,n) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;

  fp(i,2,n) inv[i]=1ll*inv[i]*inv[i-1]%mod;

  fp(i,1,n)

    if(V[i].size())

      {

    sort(V[i].begin(),V[i].end());

        mn2=min(mn2,mn[i]=V[i][0]);

    if(mn2<mn1) swap(mn1,mn2);

      }

    else mn[i]=mod;

  fp(i,1,n)

    {

      re int mm=(mn[i]==mn1?mn2:mn1),sz=V[i].size();

      while(sz>1&&V[i][sz-1]+mm>Y&&V[i][sz-1]+mn[i]>X) --sz;

      if(mm+mn[i]<=Y) ans=1ll*ans*inv[sz]%mod,tot+=sz;

    }

  fp(i,1,tot) ans=1ll*ans*i%mod;

  printf("%d\n",ans);

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.482028271199717x):
#include <cstdio>

#include <cstring> 

#include <iostream>

#define ll long long

using namespace std;

const ll N=2e5+10,mo=1e9+7,inf=0x3f3f3f3f;

ll n,x,y,r,num,ans=1,p=1,Mn=inf,mn[N],c[N],w[N],cnt[N],fac[N],inv[N];

ll ksm(ll a,ll b) { for (r=1;b;b>>=1,a=a*a%mo) if (b&1) r=r*a%mo; return r; }

int main()

{

	scanf("%lld%d%d",&n,&x,&y),memset(mn,0x3f,sizeof(mn));

	fac[0]=1; for (ll i=1;i<=n;i++) fac[i]=fac[i-1]*i%mo;

	inv[n]=ksm(fac[n],mo-2); for (ll i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mo;

	for (ll i=1;i<=n;i++) scanf("%lld%d",&c[i],&w[i]),mn[c[i]]=min(mn[c[i]],w[i]),++cnt[c[i]];

	for (ll i=1;i<=n;i++) if (mn[i]<mn[p]) p=i;

	for (ll i=1;i<=n;i++) if (i!=p) Mn=min(Mn,mn[i]);

	for (ll i=1;i<=n;i++) if (!(w[i]!=mn[c[i]]&&w[i]+mn[c[i]]<=x||c[i]!=p&&w[i]+mn[p]<=y||c[i]==p&&w[i]+Mn<=y)) cnt[c[i]]--;

	num=cnt[p]; for (ll i=1;i<=n;i++) if (i!=p&&mn[p]+mn[i]<=y) num+=cnt[i];

	for (ll i=1;i<=n;i++) if (mn[i]!=inf&&(i==p||mn[i]+mn[p]<=y)) ans=ans*inv[cnt[i]]%mo;

	for (ll i=1;i<=num;i++) ans=ans*i%mo;

	printf("%lld",ans);

}
// Slower C++ solution:
#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],inv[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(),Mnq[0]=Mnh[n+1]=2e9;

    inv[0]=inv[1]=jic[0]=jic[1]=1;

    for(R i=2;i<=n;++i)jic[i]=1ll*i*jic[i-1]%mod;

    inv[n-1]=Qpow(jic[n-1],mod-2);

    for(R i=n-2;i>=2;--i)inv[i]=1ll*inv[i+1]*(i+1)%mod;

    for(R i=1;i<=n;++i)

        c[i]=gi(),w[i]=gi(),G[c[i]].push_back(w[i]);

    for(R i=1;i<=n;++i)sort(G[i].begin(),G[i].end());

    for(R i=1,j;i<=n;++i){

        Mnq[i]=Mnq[i-1],j=G[i].size();

        if(j)Mnq[i]=min(Mnq[i],G[i][0]);

    }

    for(R i=n,j;i>=1;--i){

        Mnh[i]=Mnh[i+1],j=G[i].size();

        if(j)Mnh[i]=min(Mnh[i],G[i][0]);

    }

    for(R i=1,lim;i<=n;++i){

        lim=G[i].size();

        if(!lim)continue;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=inv[Q[1].sz];

    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*inv[Q[i].sz]%mod;

        else break;

    }

    cout<<1ll*jic[len]*ans%mod<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.484608337580902x):
#include<bits/stdc++.h>

#define LL long long

using namespace std;

const LL mod=1e9+7,N=2e5+7;

const LL inf=0x3f3f3f3f;

LL g[N],c[N],w[N],cnt[N];

LL jc[N],iv[N],n,u,v,ans=1;

LL qp(LL x,LL k){

	LL res=1;

	for(;k;x=x*x%mod,k>>=1)

		if(k&1)res=res*x%mod;

	return res;

}

int main(){

	scanf("%lld%lld%lld",&n,&u,&v);

	memset(g,0x3f,sizeof(g)),jc[0]=1;

	for(LL i=1;i<=n;i++)jc[i]=jc[i-1]*i%mod;

	iv[n]=qp(jc[n],mod-2);

	for(LL i=n-1;i>=0;i--)

		iv[i]=iv[i+1]*(i+1)%mod;

	for(LL i=1;i<=n;++i)

		scanf("%lld%lld",&c[i],&w[i]),

		g[c[i]]=min(g[c[i]],w[i]),++cnt[c[i]];

	LL mn=1,mi=inf;

	for(LL i=1;i<=n;++i)

		if(g[i]<g[mn])mn=i; 

	for(LL i=1;i<=n;++i)

		if(i!=mn)mi=min(g[i],mi); 

	for(LL i=1;i<=n;++i){

		if(w[i]!=g[c[i]]&&w[i]+g[c[i]]<=u)continue; 

		if(c[i]!=mn&&w[i]+g[mn]<=v)continue;

		if(c[i]==mn&&w[i]+mi<=v)continue; 

		--cnt[c[i]];

	}

	LL num=cnt[mn];

	for(LL i=1;i<=n;++i)

		if(i!=mn&&g[mn]+g[i]<=v) 

			num+=cnt[i];

	for(LL i=1;i<=n;++i)

		if(g[i]!=inf&&(i==mn||g[i]+g[mn]<=v))

			ans=ans*iv[cnt[i]]%mod;

	for(LL i=1;i<=num;++i)ans=ans*i%mod; 

	printf("%lld",ans),exit(0);

}
// Slower C++ solution:
#include<vector>

#include<cstdio>

#include<cstring>

#include<algorithm>

#define fr first

#define sc second

#define gt getchar()

#define ll long long

#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)

inline int in()

{

	int k=0;char ch=gt;

	while(ch<'-')ch=gt;

	while(ch>'-')k=k*10+ch-'0',ch=gt;

	return k;

}

const int N=2e5+5,inf=1e9,YL=1e9+7;

inline int ksm(int a,int k){int r=1;while(k){if(k&1)r=1ll*r*a%YL;a=1ll*a*a%YL,k>>=1;}return r;}

int col[N],w[N],mn[N],siz[N],fnv[N],fac[N],id[N],o[N];

using std::min;

#define mk std::make_pair

std::vector<int>G[N];

inline bool cmp(const int &a,const int &b){return w[a]<w[b];}

int main()

{

	int n=in(),X=in(),Y=in(),mn1=YL,mn2=YL;fac[0]=fnv[0]=1;

	for(int i=1;i<=n;++i)fac[i]=1ll*fac[i-1]*i%YL;fnv[n]=ksm(fac[n],YL-2);

	for(int i=n;i>=2;--i)fnv[i-1]=1ll*fnv[i]*i%YL;

	for(int i=1,x;i<=n;++i)x=in(),G[x].push_back(in());

	for(int i=1;i<=n;++i)

		if(G[i].size())

		{

			std::sort(G[i].begin(),G[i].end());

			mn2=min(mn2,mn[i]=G[i][0]);

			if(mn2<mn1)std::swap(mn1,mn2);

		}

		else mn[i]=YL;

	int ans=1,tot=0;

	for(int i=1;i<=n;++i)

	{

		int mm=mn[i]==mn1?mn2:mn1,sz=G[i].size();

		while(sz>1&&G[i][sz-1]+mn[i]>X&&G[i][sz-1]+mm>Y)--sz,G[i].pop_back();

		if(mn[i]+mn1<=Y)ans=1ll*ans*fnv[sz]%YL,tot+=sz;

	}

	printf("%d\n",1ll*ans*fac[tot]%YL);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.451515637720134x):
#include<bits/stdc++.h>

#define LL long long

using namespace std;

const LL mod=1e9+7,N=2e5+7;

const LL inf=0x3f3f3f3f;

LL g[N],c[N],w[N],cnt[N];

LL jc[N],iv[N],n,u,v,ans=1;

LL qp(LL x,LL k){

	LL res=1;

	for(;k;x=x*x%mod,k>>=1)

		if(k&1)res=res*x%mod;

	return res;

}

int main(){

	scanf("%lld%lld%lld",&n,&u,&v);

	memset(g,0x3f,sizeof(g)),jc[0]=1;

	for(LL i=1;i<=n;i++)jc[i]=jc[i-1]*i%mod;

	iv[n]=qp(jc[n],mod-2);

	for(LL i=n-1;i>=0;i--)

		iv[i]=iv[i+1]*(i+1)%mod;

	for(LL i=1;i<=n;++i)

		scanf("%lld%lld",&c[i],&w[i]),

		g[c[i]]=min(g[c[i]],w[i]),++cnt[c[i]];

	LL mn=1,mi=inf;

	for(LL i=1;i<=n;++i)

		if(g[i]<g[mn])mn=i; 

	for(LL i=1;i<=n;++i)

		if(i!=mn)mi=min(g[i],mi); 

	for(LL i=1;i<=n;++i){

		if(w[i]!=g[c[i]]&&w[i]+g[c[i]]<=u)continue; 

		if(c[i]!=mn&&w[i]+g[mn]<=v)continue;

		if(c[i]==mn&&w[i]+mi<=v)continue; 

		--cnt[c[i]];

	}

	LL num=cnt[mn];

	for(LL i=1;i<=n;++i)

		if(i!=mn&&g[mn]+g[i]<=v) 

			num+=cnt[i];

	for(LL i=1;i<=n;++i)

		if(g[i]!=inf&&(i==mn||g[i]+g[mn]<=v))

			ans=ans*iv[cnt[i]]%mod;

	for(LL i=1;i<=num;++i)ans=ans*i%mod; 

	printf("%lld",ans),exit(0);

}