Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn=2e5+5,pps=1e9+7;

bool vis[maxn];
int n,x,y,tot,ans=1,top;
int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
int sum[maxn],now[maxn],pre[maxn<<2],son[maxn<<2],color[maxn];

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

struct Ball {
	int c,w,id;
}b[maxn];

int quick(int a,int b) {
	int sum=1;
	while(b) {
		if(b&1)sum=1ll*sum*a%pps;
		a=1ll*a*a%pps,b>>=1;
	}
	return sum;
}

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

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

void add(int a,int b) {
	pre[++tot]=now[a];
	now[a]=tot,son[tot]=b;
}

void work1() {
	int lst=0;
	for(int i=1;i<=n;i++) {
		if(b[i].c!=b[lst].c) {
			lst=i;continue;
		}
		if(b[i].w+b[lst].w<=x) {
			add(b[i].id,b[lst].id);
			add(b[lst].id,b[i].id);
		}
	}
}

void work2() {
	for(int i=2;i<=n;i++)
		if(b[i].c!=b[1].c) {
			if(b[i].w+b[1].w>y)break;
			add(b[i].id,b[1].id);
			add(b[1].id,b[i].id);
		}
}

void prepare() {
	fac[0]=inv[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%pps;
	inv[n]=quick(fac[n],pps-2);
	for(int i=n-1;i;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%pps;
}

void dfs(int u) {
	vis[u]=1;
	int c=color[u];
	if(!insta[c]) {
		sta[++top]=c;
		insta[c]=top;
		sum[top]=1;
	}
	else sum[insta[c]]++;
	for(int p=now[u],v=son[p];p;p=pre[p],v=son[p])
		if(!vis[v])dfs(v);
}

void calc() {
	int cnt=0;
	while(top) {
		ans=1ll*ans*inv[sum[top]]%pps;
		cnt+=sum[top],insta[sta[top]]=0,sta[top]=0,sum[top]=0,top--;
	}
	ans=1ll*ans*fac[cnt]%pps;
}

int main() {
	n=read(),x=read(),y=read(),prepare();
	for(int i=1;i<=n;i++)
		color[i]=b[i].c=read(),b[i].w=read(),b[i].id=i;
	sort(b+1,b+n+1,cmp1);work1();
	sort(b+1,b+n+1,cmp2);work2();
	for(int i=1;i<=n;i++)
		if(!vis[i])dfs(i),calc();
	printf("%d\n",ans);
	return 0;
}
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn=2e5+5,pps=1e9+7;

bool vis[maxn];
int n,x,y,tot,ans=1,top;
int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
int sum[maxn],now[maxn],pre[maxn<<3],son[maxn<<3],color[maxn];

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

struct Ball {
	int c,w,id;
}b[maxn];

int quick(int a,int b) {
	int sum=1;
	while(b) {
		if(b&1)sum=1ll*sum*a%pps;
		a=1ll*a*a%pps,b>>=1;
	}
	return sum;
}

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

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

void add(int a,int b) {
	pre[++tot]=now[a];
	now[a]=tot,son[tot]=b;
}

void work1() {
	int lst=0;
	for(int i=1;i<=n;i++) {
		if(b[i].c!=b[lst].c) {
			lst=i;continue;
		}
		if(b[i].w+b[lst].w<=x) {
			add(b[i].id,b[lst].id);
			add(b[lst].id,b[i].id);
		}
	}
}

void work2() {
	for(int i=2;i<=n;i++)
		if(b[i].c!=b[1].c) {
			if(b[i].w+b[1].w>y)break;
			add(b[i].id,b[1].id);
			add(b[1].id,b[i].id);
		}
}

void prepare() {
	fac[0]=inv[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%pps;
	inv[n]=quick(fac[n],pps-2);
	for(int i=n-1;i;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%pps;
}

void dfs(int u) {
	vis[u]=1;
	int c=color[u];
	if(!insta[c]) {
		sta[++top]=c;
		insta[c]=top;
		sum[top]=1;
	}
	else sum[insta[c]]++;
	for(int p=now[u],v=son[p];p;p=pre[p],v=son[p])
		if(!vis[v])dfs(v);
}

void calc() {
	int cnt=0;
	while(top) {
		ans=1ll*ans*inv[sum[top]]%pps;
		cnt+=sum[top],insta[sta[top]]=0,sta[top]=0,sum[top]=0,top--;
	}
	ans=1ll*ans*fac[cnt]%pps;
}

int main() {
	n=read(),x=read(),y=read(),prepare();
	for(int i=1;i<=n;i++)
		color[i]=b[i].c=read(),b[i].w=read(),b[i].id=i;
	sort(b+1,b+n+1,cmp1);work1();
	sort(b+1,b+n+1,cmp2);work2();
	for(int i=1;i<=n;i++)
		if(!vis[i])dfs(i),calc();
	printf("%d\n",ans);
	return 0;
}


Compiler output:
a.cc:115:11: error: redefinition of 'const int maxn'
  115 | const int maxn=2e5+5,pps=1e9+7;
      |           ^~~~
a.cc:5:11: note: 'const int maxn' previously defined here
    5 | const int maxn=2e5+5,pps=1e9+7;
      |           ^~~~
a.cc:115:22: error: redefinition of 'const int pps'
  115 | const int maxn=2e5+5,pps=1e9+7;
      |                      ^~~
a.cc:5:22: note: 'const int pps' previously defined here
    5 | const int maxn=2e5+5,pps=1e9+7;
      |                      ^~~
a.cc:117:6: error: redefinition of 'bool vis [200005]'
  117 | bool vis[maxn];
      |      ^~~
a.cc:7:6: note: 'bool vis [200005]' previously declared here
    7 | bool vis[maxn];
      |      ^~~
a.cc:118:5: error: redefinition of 'int n'
  118 | int n,x,y,tot,ans=1,top;
      |     ^
a.cc:8:5: note: 'int n' previously declared here
    8 | int n,x,y,tot,ans=1,top;
      |     ^
a.cc:118:7: error: redefinition of 'int x'
  118 | int n,x,y,tot,ans=1,top;
      |       ^
a.cc:8:7: note: 'int x' previously declared here
    8 | int n,x,y,tot,ans=1,top;
      |       ^
a.cc:118:9: error: redefinition of 'int y'
  118 | int n,x,y,tot,ans=1,top;
      |         ^
a.cc:8:9: note: 'int y' previously declared here
    8 | int n,x,y,tot,ans=1,top;
      |         ^
a.cc:118:11: error: redefinition of 'int tot'
  118 | int n,x,y,tot,ans=1,top;
      |           ^~~
a.cc:8:11: note: 'int tot' previously declared here
    8 | int n,x,y,tot,ans=1,top;
      |           ^~~
a.cc:118:15: error: redefinition of 'int ans'
  118 | int n,x,y,tot,ans=1,top;
      |               ^~~
a.cc:8:15: note: 'int ans' previously defined here
    8 | int n,x,y,tot,ans=1,top;
      |               ^~~
a.cc:118:21: error: redefinition of 'int top'
  118 | int n,x,y,tot,ans=1,top;
      |                     ^~~
a.cc:8:21: note: 'int top' previously declared here
    8 | int n,x,y,tot,ans=1,top;
      |                     ^~~
a.cc:119:5: error: redefinition of 'int fac [200005]'
  119 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |     ^~~
a.cc:9:5: note: 'int fac [200005]' previously declared here
    9 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |     ^~~
a.cc:119:15: error: redefinition of 'int inv [200005]'
  119 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |               ^~~
a.cc:9:15: note: 'int inv [200005]' previously declared here
    9 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |               ^~~
a.cc:119:25: error: redefinition of 'int sta [200005]'
  119 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |                         ^~~
a.cc:9:25: note: 'int sta [200005]' previously declared here
    9 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |                         ^~~
a.cc:119:35: error: redefinition of 'int insta [200005]'
  119 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |                                   ^~~~~
a.cc:9:35: note: 'int insta [200005]' previously declared here
    9 | int fac[maxn],inv[maxn],sta[maxn],insta[maxn];
      |                                   ^~~~~
a.cc:120:5: error: redefinition of 'int sum [200005]'
  120 | int sum[maxn],now[maxn],pre[maxn<<3],son[maxn<<3],color[maxn];
      |     ^~~
a.cc:10:5: note: 'int sum [200005]' previously declared here
   10 | int sum[maxn],now[maxn],pre[maxn<<2],son[maxn<<2],color[maxn];
      |     ^~~
a.cc:120:15: error: redefinition of 'int now [200005]'
  120 | int sum[maxn],now[maxn],pre[maxn<<3],son[maxn<<3],color[maxn];
      |               ^~~
a.cc:10:15: note: 'int now [200005]' previously declared here
   10 | int sum[maxn],now[maxn],pre[maxn<<2],son[maxn<<2],color[maxn];
      |               ^~~
a.cc:120:25: error: conflicting declaration 'int pre [1600040]'
  120 | int sum[maxn],now[maxn],pre[maxn<<3],son[maxn<<3],color[maxn];
      |                         ^~~
a.cc:10:25: note: previous declaration as 'int pre [800020]'
   10 | int sum[maxn],now[maxn],pre[maxn<<2],son[maxn<<2],color[maxn];
      |                         ^~~
a.cc:120:38: error: conflicting declaration 'int son [1600040]'
  120 | int sum[maxn],now[maxn],pre[maxn<<3],son[maxn<<3],color[maxn];
      |                                      ^~~
a.cc:10:38: note: previous declaration as 'int son [800020]'
   10 | int sum[maxn],now[maxn],pre[maxn<<2],son[maxn<<2],color[maxn];
      |                                      ^~~
a.cc:120:51: error: redefinition of 'int color [200005]'
  120 | int sum[maxn],now[maxn],pre[maxn<<3],son[maxn<<3],color[maxn];
      |                                                   ^~~~~
a.cc:10:51: note: 'int color [200005]' previously declared here
   10 | int sum[maxn],now[maxn],pre[maxn<<2],son[maxn<<2],color[maxn];
      |                                                   ^~~~~
a.cc:122:5: error: redefinition of 'int read()'
  122 | int read() {
      |     ^~~~
a.cc:12:5: note: 'int read()' previously defined here
   12 | int read() {
      |     ^~~~
a.cc:129:8: error: redefinition of 'struct Ball'
  129 | struct Ball {
      |        ^~~~
a.cc:19:8: note: previous definition of 'struct Ball'
   19 | struct Ball {
      |        ^~~~
a.cc:131:2: error: conflicting declaration 'int b [200005]'
  131 | }b[maxn];
      |  ^
a.cc:21:2: note: previous declaration as 'Ball b [200005]'
   21 | }b[maxn];
      |  ^
a.cc:133:5: error: redefinition of 'int quick(int, int)'
  133 | int quick(int a,int b) {
      |     ^~~~~
a.cc:23:5: note: 'int quick(int, int)' previously defined here
   23 | int quick(int a,int b) {
      |     ^~~~~
a.cc:142:6: error: redefinition of 'bool cmp1(Ball, Ball)'
  142 | bool cmp1(Ball a,Ball b) {
      |      ^~~~
a.cc:32:6: note: 'bool cmp1(Ball, Ball)' previously defined here
   32 | bool cmp1(Ball a,Ball b) {
      |      ^~~~
a.cc:147:6: error: redefinition of 'bool cmp2(Ball, Ball)'
  147 | bool cmp2(Ball a,Ball b) {
      |      ^~~~
a.cc:37:6: note: 'bool cmp2(Ball, Ball)' previously defined here
   37 | bool cmp2(Ball a,Ball b) {
      |      ^~~~
a.cc:152:6: error: redefinition of 'void add(int, int)'
  152 | void add(int a,int b) {
      |      ^~~
a.cc:42:6: note: 'void add(int, int)' previously defined here
   42 | void add(int a,int b) {
      |      ^~~
a.cc:157:6: error: redefinition of 'void work1()'
  157 | void work1() {
      |      ^~~~~
a.cc:47:6: note: 'void work1()' previously defined here
   47 | void work1() {
      |      ^~~~~
a.cc:170:6: error: redefinition of 'void work2()'
  170 | void work2() {
      |      ^~~~~
a.cc:60:6: note: 'void work2()' previously defined here
   60 | void work2() {
      |      ^~~~~
a.cc:179:6: error: redefinition of 'void prepare()'
  179 | void prepare() {
      |      ^~~~~~~
a.cc:69:6: note: 'void prepare()' previously defined here
   69 | void prepare() {
      |      ^~~~~~~
a.cc:188:6: error: redefinition of 'void dfs(int)'
  188 | void dfs(int u) {
      |      ^~~
a.cc:78:6: note: 'void dfs(int)' previously defined here
   78 | void dfs(int u) {
      |      ^~~
a.cc:201:6: error: redefinition of 'void calc()'
  201 | void calc() {
      |      ^~~~
a.cc:91:6: note: 'void calc()' previously defined here
   91 | void calc() {
      |      ^~~~
a.cc:210:5: error: redefinition of 'int main()'
  210 | int main() {
      |     ^~~~
a.cc:100:5: note: 'int main()' previously defined here
  100 | int main() {
      |     ^~~~