Language: C++

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
	template <class Arg1, class... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* sep = strchr(names + 1, ',');
		cerr.write(names, sep - names) << " : " << arg1 << "  ";
		__f(sep + 1, args...);
	}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<char,int> pci;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
 


#define pb push_back
 
// order_of_key (k), find_by_order(k)
#define fi first
#define se second
#define input_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
#define initialise(a, x) memset(a, x, sizeof(a))
#define endl '\n'
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX 1000020
#define maxn 200005
#define eps 0.0000001

const ll mod=1e9+7;
const ll inf=1e18+2;


#define int ll

int n;
int c[maxn];
int w[maxn];
int x,y;


ll pwr(ll base, ll expo)
{
	ll res=1;
	while(expo>0)
	{
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;
	}
	return res;
}

int fact[maxn];
int inv[maxn];

int par[maxn];
int size[maxn];

int find(int x)
{
	if(par[x]==x) return par[x];
	return par[x]=find(par[x]);
}
void merge(int x,int y)
{
	int parx=find(x);
	int pary=find(y);

	if(pary==parx) return;

	if(size[parx]>=size[pary])
	{
		size[parx]+=size[pary];
		par[pary]=parx;
		return;
	}
	size[pary]+=size[parx];
	par[parx]=pary;
}

int par2[maxn];
int size2[maxn];

int find2(int x)
{
	if(par2[x]==x) return par2[x];
	return par2[x]=find2(par2[x]);
}
void merge2(int x,int y)
{
	int par2x=find2(x);
	int par2y=find2(y);

	if(par2y==par2x) return;

	if(size2[par2x]>=size2[par2y])
	{
		size2[par2x]+=size2[par2y];
		par2[par2y]=par2x;
		return;
	}
	size2[par2y]+=size2[par2x];
	par2[par2x]=par2y;
}

std::vector<pair<int,int> > weights[maxn];
int mn_wt[maxn];
int mn_ix[maxn];





signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	fact[0]=1;
	inv[0]=1;
	for(int i=1;i<maxn;i++)
	{
		fact[i]=(i*fact[i-1])%mod;
		inv[i]=(inv[i-1]*pwr(i,mod-2))%mod;
	}


	for(int i=0;i<maxn;i++) {par[i]=i;size[i]=1;mn_wt[i]=(ll)1e10;}
	for(int i=0;i<maxn;i++) {par2[i]=i;size2[i]=1;mn_wt[i]=(ll)1e10;}


	cin>>n>>x>>y;

	for(int i=0;i<n;i++)
	{
		cin>>c[i]>>w[i];
		weights[c[i]].pb({w[i],i});

		if(w[i]<mn_wt[c[i]])
		{
			mn_wt[c[i]]=w[i];
			mn_ix[c[i]]=i;
		}
	}

	set<pair<int,int>> st;

	for(int i=0;i<maxn;i++)
	{
		if(mn_wt[i]<(ll)5e9)
		{
			st.insert({mn_wt[i],mn_ix[i]});
			// trace(mn_wt[i],mn_ix[i],i);
		}
	}

	for(int i=1;i<maxn;i++)
	{
		if(weights[i].size())
		{
			sort(weights[i].begin(), weights[i].end());

			for(int j=weights[i].size()-1;j>0;j--)
			{
				// trace(i);
				if(weights[i][j].fi+weights[i][0].fi<=x)
				{
					// trace(weights[i][j].fi,weights[i][0].fi);
					merge2(weights[i][j].se,weights[i][0].se);
					merge(weights[i][j].se,weights[i][0].se);
				}
			}
			if(st.size())
			{
				int mn_now=(*st.begin()).fi;
				int mn_indx=(*st.begin()).se;

				for(int j=weights[i].size()-1;j>=0;j--)
				{
					if(weights[i][j].fi+mn_now<=y)
					{
						// trace(weights[i][j].se,mn_indx,mn_now);
						merge(weights[i][j].se,mn_indx);
					}
				}
			}

			st.insert({mn_wt[i],mn_ix[i]});
		}
	}


	bool vis[n];
	initialise(vis,0);

	int ans=1;

	for(int i=0;i<n;i++)
	{
		if(vis[find(i)]==0)
		{
			// trace(i);
			vis[find(i)]=1;
			ans*=fact[size[find(i)]];
			ans%=mod;
		}
	}

	// trace(ans);

	for(int i=1;i<maxn;i++)
	{
		if(weights[i].size()>1)
		{
			for(int j=weights[i].size()-1;j>0;j--)
			{
				if(find(weights[i][j].se)==find(weights[i][0].se))
				{
					merge2(weights[i][j].se,weights[i][0].se);
				}
			}
		}
	}

	initialise(vis,0);

	for(int i=0;i<n;i++)
	{
		if(vis[find2(i)]==0)
		{
			vis[find2(i)]=1;
			ans*=inv[size2[find2(i)]];
			ans%=mod;
		}
	}

	cout<<ans<<'\n';
	
	

	return 0;
}

Compiler output:
a.cc: In function 'void merge(ll, ll)':
a.cc:92:12: error: reference to 'size' is ambiguous
   92 |         if(size[parx]>=size[pary])
      |            ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~
a.cc:92:24: error: reference to 'size' is ambiguous
   92 |         if(size[parx]>=size[pary])
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~
a.cc:94:17: error: reference to 'size' is ambiguous
   94 |                 size[parx]+=size[pary];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~
a.cc:94:29: error: reference to 'size' is ambiguous
   94 |                 size[parx]+=size[pary];
      |                             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~
a.cc:98:9: error: reference to 'size' is ambiguous
   98 |         size[pary]+=size[parx];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~
a.cc:98:21: error: reference to 'size' is ambiguous
   98 |         size[pary]+=size[parx];
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:154:43: error: reference to 'size' is ambiguous
  154 |         for(int i=0;i<maxn;i++) {par[i]=i;size[i]=1;mn_wt[i]=(ll)1e10;}
      |                                           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~
a.cc:230:35: error: reference to 'size' is ambiguous
  230 |                         ans*=fact[size[find(i)]];
      |                                   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:78:5: note:                 'll size [200005]'
   78 | int size[maxn];
      |     ^~~~