stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#define db double

using namespace std;



int n;

db x,d,ans,tmp;



int main()

{

	int i,j;

	cin>>n>>d>>x;

	for(;n;n--)

	{

		ans+=(d*2.0+(db)(2*n-1)*x)/2.0;

		tmp=d;

		d+=d/(db)n+5.0*x/(db)(2*n);

		x+=2.0*x/(db)n;

//		cout<<ans<<" "<<d<<" "<<x<<endl;

	}

	printf("%.10f",ans);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n;

double d,x;

int main()

{

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

	int m=2*n;

	double ans=0;

	while(m)

	{

		ans+=(2.0*x+(1.0*m-1.0)*d)/2.0;

		x=((1.0*m+2.0)*x+5.0*d)/(1.0*m);

		d=(1.0*m+4.0)*d/(1.0*m);

		m-=2;

	}

	printf("%.10f\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;



int n,k,t,l;

double a,p,ans;



int main()

{

	scanf("%d%lf%lf",&n,&a,&p);

	a-=p;

	t=2*n;

	l=n;

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

	{

		ans+=(double)(a*t+p*t*(t+1)/2)/t;

		a=a+a/l+3*p/(2*l);

		p=p+2*p/l;

		l--;

		t-=2;

	}

	printf("%.9lf",ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

int main()

{

	ll n;

	double x,d;

	scanf("%lld%lf%lf",&n,&x,&d);

	double ans=0;

	ll m=2*n;

	while(m){

		ans+=(2*x+(m-1)*d)*1.0/2;

        x=((m+2)*x+5*d)*1.0/m;

        d=(m+4)*d*1.0/m;

        m-=2;

	}

	printf("%.10f",ans);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



const int N = (int)1e5 + 10;

const double eps = 1e-8;



template <typename T> inline T gcd(T a, T b) { a = abs(a), b = abs(b); while ( b ) { a %= b; swap(a, b); } return a; }

vector <pair <int, int> > adj[N + 7];





int main() {

	ios_base::sync_with_stdio(0);

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

	int n, m;

	cin >> n >> m;

	vector <pair <ll, ll> > arr(n);

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

		cin >> arr[i].first >> arr[i].second;

	}

	sort(arr.begin(), arr.end());

	int total = 0;

	ll taka = 0;

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

		int temp = m - total;

		if ( arr[i].second <= temp ) {

			total += arr[i].second;

			taka += (arr[i].second * arr[i].first);

		} else if ( arr[i].second > temp ) {

			taka += ((m - total) * arr[i].first);

			total = m;

		}

		if ( total >= m ) break;

	}

	cout << taka << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

struct pp{

	int a,b;

}e[100010];

int cmp(const pp&a,const pp&b)

{

	if(a.a<b.a) return 1;

	return 0;

}

int main ()

{

	int n,m,i;

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

	for(i=1;i<=n;++i) scanf("%d%d",&e[i].a,&e[i].b);

	sort(e+1,e+1+n,cmp);

	long long ans=0;

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

	{

		if(m>e[i].b)

		{

			m-=e[i].b;

			ans+=(long long)e[i].b*e[i].a; 

		}

		else

		{

			ans+=(long long)e[i].a*m;

			break;

		}

	} 

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

void p(int x)

{

    int i,j;

    for(i=2;i<=1000000;i++)

    {

        if(x==1){printf("\n"); return;}

        while(x%i==0)

        {

            printf(" %d",i);

            x=x/i;

        }

    }

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

}

int main()

{

    int x;

    scanf("%d",&x);

    printf("%d:",x);

    p(x);

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include <math.h>

int prime(int num)

{

	if(num == 1)

	{

		return 0;

	}

	int tmp = sqrt(num) + 1;

	for(int i = 2; i < tmp; i++)

	{

		if(num % i == 0)

		{

			return 0;

		}

	}

	return 1;

}

int main()

{

	int n,i,j,k;

	scanf("%d",&n);

	

	

	printf("%d:",n);

	if(prime(n))

	{

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

		return 0;

	}

	for(i=2;n!=1;)

	{

		if(n%i!=0)

		{

			//if(n==2)

			i++;

			//else

			//i+=2;

		}

		else

		{

			printf(" %d",i);

			n/=i;

		}

	}

	printf("\n");

	

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<bits/stdc++.h>

#include<math.h>

#include<stdlib.h>

#include<stdio.h>

#include<string.h>

#include<sstream>

using namespace std;

void p(int x)

{

    int i,j;

    for(i=2;i<=1000000;i++)

    {

    if(x==1) { printf("\n"); return; }



    while(x%i==0)

      {

        printf(" %d",i);

        x=x/i;

      }

    }

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

}



int main()

{

    int x;cin>>x;

    printf("%d:",x);

    p(x);



return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include <math.h>

int prime(int num)

{

	if(num == 1)

	{

		return 0;

	}

	int tmp = sqrt(num) + 1;

	for(int i = 2; i < tmp; i++)

	{

		if(num % i == 0)

		{

			return 0;

		}

	}

	return 1;

}

int main()

{

	int n,i,j,k;

	scanf("%d",&n);

	

	

	printf("%d:",n);

	if(prime(n))

	{

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

		return 0;

	}

	for(i=2;n!=1;)

	{

		if(n%i!=0)

		{

			//if(n==2)

			i++;

			//else

			//i+=2;

		}

		else

		{

			printf(" %d",i);

			n/=i;

		}

	}

	printf("\n");

	

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h> //Ithea Myse Valgulious

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return 0&pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=2e5;

typedef int fuko[yuzu|10];

fuko u,v;int vis[2][yuzu>>6][yuzu>>6];

vector<int> lj[yuzu|10];



void dfs(int id,int p,int u,int col){

if (vis[id][p][u]) return;

vis[id][p][u]=col;

for (int i:lj[u]) dfs(id,p,i,col);

}



int main(){

int i,n=read(),m=read();

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

  u[i]=read(),v[i]=read();

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

  } 

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

  vis[0][i][i]=vis[1][i][i]=1;

  int now=0;for (int j:lj[i]) dfs(0,i,j,++now);

  if (lj[i].size()) for (int j=lj[i].size()-1;~j;--j) dfs(1,i,lj[i][j],j+1);

  }

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

  puts((vis[0][u[i]][v[i]]!=vis[1][u[i]][v[i]])^(vis[0][v[i]][u[i]]>0)?"diff":"same");

  }

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<vector>

using namespace std;

int n,m,u[210000],v[210000],tmp[1100][2];

bool ans1[1100][1100],ans2[1100][1100];

vector<int> vec[1100];

void dfs(int u,int rt){

    ans1[rt][u]=true;

    for(int i=0;i<vec[u].size();i++)

        if (!ans1[rt][vec[u][i]]) dfs(vec[u][i],rt);

}

void dfs2(int u,int num,int f){

    tmp[u][f]=num;

    for(int i=0;i<vec[u].size();i++)

        if (!tmp[vec[u][i]][f]) dfs2(vec[u][i],num,f);

}

int main(){

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

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

        scanf("%d%d",&u[i],&v[i]);

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

    }

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

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

        memset(tmp,0,sizeof(tmp));

        tmp[i][0]=-1; tmp[i][1]=-1;

        for (int j=0;j<vec[i].size();j++)

            if (!tmp[vec[i][j]][0]) dfs2(vec[i][j],j+1,0);

        for (int j=vec[i].size()-1;j>=0;j--)

            if (!tmp[vec[i][j]][1]) dfs2(vec[i][j],j+1,1);

        for (int j=0;j<vec[i].size();j++)

            if (tmp[vec[i][j]][0]!=j+1||tmp[vec[i][j]][1]!=j+1) ans2[i][vec[i][j]]=true;

    }

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

        if (ans1[v[i]][u[i]]==ans2[u[i]][v[i]]) puts("same");

        else puts("diff");

    

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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");

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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 ;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define int long long

using namespace std;

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

int c[N],w[N];

int minn[N];

int numcol[N];

int cnt=0;

int n;

int fac[N],inv[N];

int poww(int x,int y)

{

	int sum=1ll;

	while(y)

	{

		if(y&1)sum=(sum*x)%mod;

		x=(x*x)%mod;

		y>>=1;

	}

	return sum;

}

void prec()

{

	fac[0]=1;

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

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

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

}

int C(int x,int y)

{

	return ((fac[y]*inv[y-x])%mod*inv[x])%mod;

}

signed main()

{

	memset(minn,127,sizeof(minn));

	int x,y;

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

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

	{

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

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

	}

	int fir_min=0,sec_min=0;

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

	{

		if(minn[i]<minn[fir_min])

		{

			sec_min=fir_min;

			fir_min=i;

		}

		else if(minn[i]<minn[sec_min])sec_min=i;

	}

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

	{

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

		if((c[i]==fir_min&&minn[sec_min]+w[i]<=y)||(c[i]!=fir_min&&minn[fir_min]+w[i]<=y))

		{

			numcol[c[i]]++;

			cnt++;

		}

	}

	prec();

	int ans=1;

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

	{

		if(numcol[i])

		{

			ans=(ans*C(numcol[i],cnt))%mod;

			cnt-=numcol[i];

		}

	}

	printf("%lld",ans);

	return 0;

}

/*

4 7 3

3 2

4 3

2 1

4 4

*/

// Optimized solution to the same problem (faster):
//Created Time:2019年12月17日 星期二 18时41分06秒

#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>

#define N 200005

#define mod 1000000007



using namespace std;



int n, x, y, mn = 999999999, cnt;

int c[N], a[N], ifac[N], fac[N];



struct Ball{

	int col, w;

}b[N];



int read();

int quick_pow(int ,int);



int main(){

	n = read(), x = read(), y = read();

	memset(c, 127, sizeof c); fac[0] = ifac[0] = 1;

	int pos = 1, poss = 1;

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

		int col = read(), w = read();

		c[col] = min(c[col], w); b[i] = (Ball){col, w};

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

	}

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

		if(c[i] < c[pos]) poss = pos, pos = i;

		else if(c[i] < c[poss]) poss = i;

	ifac[n] = quick_pow(fac[n], mod - 2);

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

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

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

		int col = b[i].col, w = b[i].w;

		if((pos != col && (w + c[pos] <= y || (w + c[col] <= x && c[col] + c[pos] <= y))) || (col == pos && (w + c[pos] <= x || (w + c[poss] <= y && c[poss] + c[pos] <= y))))

			++cnt, ++a[col];

	}

	int ans = fac[cnt];

//	cout << cnt << endl;

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

		ans = 1ll * ans * ifac[a[i]] % mod;

	cout << ans << endl;

	return 0;

}



int read(){

	int x = 0; char ch = getchar();

	for(; !isdigit(ch); ch = getchar());

	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);

	return x;

}



int quick_pow(int x, int y){

	int sum = 1;

	for(; y; y >>= 1, x = 1ll * x * x % mod) if(y & 1) sum = 1ll * sum * x % mod;

	return sum;

}


// Fastest known solution for this problem: