QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#659809#5169. 夹娃娃QBF100 ✓1161ms514096kbC++146.8kb2024-10-19 22:12:292024-10-19 22:12:29

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 22:12:29]
  • 评测
  • 测评结果:100
  • 用时:1161ms
  • 内存:514096kb
  • [2024-10-19 22:12:29]
  • 提交

answer

#include<bits/stdc++.h>
#define ci const int
#define ll long long
using namespace std;
char buf[1<<20],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
int read(){int res(0);char ch(getchar());while(ch<48||ch>57)ch=getchar();while(ch>=48&&ch<=57)res=(res<<1)+(res<<3)+(ch^48),ch=getchar();return res;}
void out(ci x){
	if(x>9)out(x/10);
	putchar(x%10+48);
}
int n,q;
namespace sol1{
	ci mod=998244353,V=520,M=2080;
	inline void add(int &x,ci v){
		x+=v,x-=x<mod?0:mod;
	}
	inline void sub(int &x,ci v){
		x-=v,x+=x<0?mod:0;
	}
	ll qk(ll x,int y=mod-2){
		ll ans=1;
		while(y){
			if(y&1)ans=ans*x%mod;
			x=x*x%mod,y>>=1;
		}
		return ans;
	}
	int cnt[1<<15];
	int co[16][525];
	int pw[2100][525];
	struct DAT{
		int co[6][525];
		int val[6][525][2100];//val[i][<=k]
		int g[525][1<<5][2100];//g[k][s]
		int f[1<<5][2100],F[1<<5][525];//f[s]
		void Solve(){
			for(int i=1;i<=5;++i)
				for(int x=1;x<=M;++x)
					for(int j=0;j<=V;++j)
						val[i][j][x]=((ll)pw[x][j]*co[i][j]+(j?val[i][j-1][x]:0))%mod;
			F[0][0]=1;
			for(int s=1;s<1<<5;++s){
				ci b=__builtin_ctz(s&-s)+1;
				for(int i=0;i<=V;++i)
					for(int j=0;i+j<=V;++j)
						add(F[s][i+j],(ll)F[s^(s&-s)][i]*co[b][j]%mod);
			}
			for(int s=0;s<1<<5;++s)
				for(int x=1;x<=M;++x)
					for(int j=0;j<=V;++j)
						add(f[s][x],(ll)F[s][j]*pw[x][j]%mod);
			for(int k=1;k<=V;++k){
				for(int x=1;x<=M;++x)g[k][0][x]=1;
				for(int s=1;s<1<<5;++s){
					if(cnt[s]*k>V)continue;
					ci b=__builtin_ctz(s&-s)+1;
					for(int x=1;x<=M;++x)
						g[k][s][x]=(mod-(ll)g[k][s^(s&-s)][x]*val[b][k-1][x]%mod)%mod;
				}
				for(int s=0;s<1<<5;++s)
					for(int x=1;x<=M;++x)
						g[k][s][x]=(ll)g[k][s][x]*f[s^31][x]%mod;
				for(int i=1;i<=5;++i)
					for(int s=0;s<1<<5;++s)
						if(s>>(i-1)&1)
							for(int x=1;x<=M;++x)
								add(g[k][s][x],g[k][s^(1<<i-1)][x]);
			}
		}
	}DL,DM,DR;
	int la[2100][2100],poly[2100],tmp[2100];
	int main(){
		for(int i=1;i<=15;++i)co[i][0]=1;
		for(int i=1;i<=n;++i){
			for(int k=read();k;--k){
				ci b=read(),c=read();
				for(int j=b;j<=V;++j)add(co[i][j],co[i][j-b]);
				for(int j=V;~j;--j)co[i][j]=(co[i][j]-(j>=(c+1)*b?co[i][j-(c+1)*b]:0)+mod)%mod;
			}
		}
		for(int s=0;s<1<<15;++s)cnt[s]=cnt[s>>1]+(s&1);
		for(int x=1;x<=M;++x){
			pw[x][0]=1;
			for(int i=1;i<=V;++i)pw[x][i]=(ll)pw[x][i-1]*x%mod;
		}
		for(int i=1;i<=5;++i)
			for(int j=0;j<=V;++j)
				DL.co[i][j]=co[i][j],
				DM.co[i][j]=co[i+5][j],
				DR.co[i][j]=co[i+10][j];
		DL.Solve(),DM.Solve(),DR.Solve();
		poly[0]=1;
		for(int i=1;i<=M;++i)
			for(int j=M;~j;--j)
				poly[j]=((j?poly[j-1]:0)-(ll)i*poly[j]%mod+mod)%mod;
		for(int i=1;i<=M;++i){
			for(int j=0;j<=M;++j)tmp[j]=poly[j];
			for(int j=M;j;--j)la[i][j-1]=tmp[j],add(tmp[j-1],(ll)tmp[j]*i%mod);
			int co=1;
			for(int j=1;j<=M;++j)if(i!=j)co=(ll)co*(i-j+mod)%mod;
			co=qk(co);
			for(int j=0;j<=M;++j)la[i][j]=(ll)la[i][j]*co%mod;
			for(int j=1;j<=M;++j)add(la[i][j],la[i][j-1]);
		}
		while(q--){
			int s1=0,s2=0,s3=0;
			for(int i=1;i<=n;++i){
				char c=getchar();
				while(c!='0'&&c!='1')c=getchar();
				if(c=='1'){
					if(i<=5)s1|=1<<i-1;
					else if(i<=10)s2|=1<<i-5-1;
					else s3|=1<<i-10-1;
				}
			}
			ci m=read(),k=read();
			if((cnt[s1]+cnt[s2]+cnt[s3])*k>m){
				puts("0");
				continue;
			}
			__uint128_t ans=0;
			for(int x=1;x<=M;++x){
				ans+=(__uint128_t)DL.g[k][s1][x]*DM.g[k][s2][x]*DR.g[k][s3][x]*la[x][m];
				if((x&127)==0||x==M)ans%=mod;
			}
			out(ans%mod),putchar(10);
		}
		return 0;
	}
}
namespace sol2{
	ci mod=1e9+7,V=520,M=2080;
	inline void add(int &x,ci v){
		x+=v,x-=x<mod?0:mod;
	}
	inline void sub(int &x,ci v){
		x-=v,x+=x<0?mod:0;
	}
	ll qk(ll x,int y=mod-2){
		ll ans=1;
		while(y){
			if(y&1)ans=ans*x%mod;
			x=x*x%mod,y>>=1;
		}
		return ans;
	}
	int cnt[1<<15];
	int co[16][525];
	int pw[2100][525];
	struct DAT{
		int co[6][525];
		int val[6][525][2100];//val[i][<=k]
		int g[525][1<<5][2100];//g[k][s]
		int f[1<<5][2100],F[1<<5][525];//f[s]
		void Solve(){
			for(int i=1;i<=5;++i)
				for(int x=1;x<=M;++x)
					for(int j=0;j<=V;++j)
						val[i][j][x]=((ll)pw[x][j]*co[i][j]+(j?val[i][j-1][x]:0))%mod;
			F[0][0]=1;
			for(int s=1;s<1<<5;++s){
				ci b=__builtin_ctz(s&-s)+1;
				for(int i=0;i<=V;++i)
					for(int j=0;i+j<=V;++j)
						add(F[s][i+j],(ll)F[s^(s&-s)][i]*co[b][j]%mod);
			}
			for(int s=0;s<1<<5;++s)
				for(int x=1;x<=M;++x)
					for(int j=0;j<=V;++j)
						add(f[s][x],(ll)F[s][j]*pw[x][j]%mod);
			for(int k=1;k<=V;++k){
				for(int x=1;x<=M;++x)g[k][0][x]=1;
				for(int s=1;s<1<<5;++s){
					if(cnt[s]*k>V)continue;
					ci b=__builtin_ctz(s&-s)+1;
					for(int x=1;x<=M;++x)
						g[k][s][x]=(mod-(ll)g[k][s^(s&-s)][x]*val[b][k-1][x]%mod)%mod;
				}
				for(int s=0;s<1<<5;++s)
					for(int x=1;x<=M;++x)
						g[k][s][x]=(ll)g[k][s][x]*f[s^31][x]%mod;
				for(int i=1;i<=5;++i)
					for(int s=0;s<1<<5;++s)
						if(s>>(i-1)&1)
							for(int x=1;x<=M;++x)
								add(g[k][s][x],g[k][s^(1<<i-1)][x]);
			}
		}
	}DL,DM,DR;
	int la[2100][2100],poly[2100],tmp[2100];
	int main(){
		for(int i=1;i<=15;++i)co[i][0]=1;
		for(int i=1;i<=n;++i){
			for(int k=read();k;--k){
				ci b=read(),c=read();
				for(int j=b;j<=V;++j)add(co[i][j],co[i][j-b]);
				for(int j=V;~j;--j)co[i][j]=(co[i][j]-(j>=(c+1)*b?co[i][j-(c+1)*b]:0)+mod)%mod;
			}
		}
		for(int s=0;s<1<<15;++s)cnt[s]=cnt[s>>1]+(s&1);
		for(int x=1;x<=M;++x){
			pw[x][0]=1;
			for(int i=1;i<=V;++i)pw[x][i]=(ll)pw[x][i-1]*x%mod;
		}
		for(int i=1;i<=5;++i)
			for(int j=0;j<=V;++j)
				DL.co[i][j]=co[i][j],
				DM.co[i][j]=co[i+5][j],
				DR.co[i][j]=co[i+10][j];
		DL.Solve(),DM.Solve(),DR.Solve();
		poly[0]=1;
		for(int i=1;i<=M;++i)
			for(int j=M;~j;--j)
				poly[j]=((j?poly[j-1]:0)-(ll)i*poly[j]%mod+mod)%mod;
		for(int i=1;i<=M;++i){
			for(int j=0;j<=M;++j)tmp[j]=poly[j];
			for(int j=M;j;--j)la[i][j-1]=tmp[j],add(tmp[j-1],(ll)tmp[j]*i%mod);
			int co=1;
			for(int j=1;j<=M;++j)if(i!=j)co=(ll)co*(i-j+mod)%mod;
			co=qk(co);
			for(int j=0;j<=M;++j)la[i][j]=(ll)la[i][j]*co%mod;
			for(int j=1;j<=M;++j)add(la[i][j],la[i][j-1]);
		}
		while(q--){
			int s1=0,s2=0,s3=0;
			for(int i=1;i<=n;++i){
				char c=getchar();
				while(c!='0'&&c!='1')c=getchar();
				if(c=='1'){
					if(i<=5)s1|=1<<i-1;
					else if(i<=10)s2|=1<<i-5-1;
					else s3|=1<<i-10-1;
				}
			}
			ci m=read(),k=read();
			if((cnt[s1]+cnt[s2]+cnt[s3])*k>m){
				puts("0");
				continue;
			}
			__uint128_t ans=0;
			for(int x=1;x<=M;++x){
				ans+=(__uint128_t)DL.g[k][s1][x]*DM.g[k][s2][x]*DR.g[k][s3][x]*la[x][m];
				if((x&127)==0||x==M)ans%=mod;
			}
			out(ans%mod),putchar(10);
		}
		return 0;
	}
}
int main(){
	n=read(),q=read();
	if(read()==998244353)return sol1::main();
	else return sol2::main();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 739ms
memory: 512560kb

input:

1 521 998244353
39 520 520 11 22 414 8 95 18 229 356 26 407 316 10 24 26 19 61 11 130 482 476 420 15 192 193 208 24 19 233 494 217 275 294 26 28 439 20 272 277 28 198 5 335 22 8 28 17 154 78 6 13 175 17 2 5 477 256 200 4 1 36 427 371 439 23 10 65 426 25 24 27 121 29 28 13 12 453
0 520 1
1 519 1
1 51...

output:

38813347
922143638
98254957
38813343
922143633
38813338
98254946
922143620
98254933
922143604
38813302
38813288
922143562
38813247
38813220
38813188
38813150
98254715
38813047
922143273
98254516
38812814
922142999
98254191
922142723
38812257
38812058
98253436
922141847
38811240
922141173
38810463
38...

result:

ok 521 lines

Test #2:

score: 3
Accepted
time: 720ms
memory: 512420kb

input:

2 1561 998244353
151 520 520 511 30 121 396 25 16 113 11 6 175 242 20 8 5 61 13 518 447 404 8 220 177 4 19 18 15 70 233 9 14 26 512 17 9 9 19 30 8 495 20 13 27 277 22 396 14 4 29 345 442 19 25 14 5 16 295 19 65 134 10 10 296 245 6 7 30 253 15 187 26 482 454 28 414 170 404 11 27 27 25 13 509 1 5 291 ...

output:

883965618
144348435
762074635
112296779
385763651
821718611
673974966
879750066
927942969
136450507
436584627
612945970
768262217
613885343
39304132
852224740
215596261
151746110
965953558
969833936
664053020
458247365
881060255
878484499
781573019
616944059
850325449
296113117
674829177
887392623
6...

result:

ok 1561 lines

Subtask #2:

score: 13
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 13
Accepted
time: 732ms
memory: 511568kb

input:

3 4160 998244353
444 520 520 26 332 29 183 25 479 175 14 13 16 1 447 2 293 4 20 64 472 491 11 21 259 75 22 390 401 8 508 405 3 137 4 15 154 164 1 484 13 257 14 44 20 7 13 26 15 26 432 14 9 478 24 18 10 22 28 8 21 260 25 431 22 7 6 20 26 8 27 239 19 1 134 2 322 16 225 6 42 517 6 197 407 268 500 433 5...

output:

516056999
990096150
497048298
345860798
899328070
577475723
191997503
533625761
516056999
863614705
652318084
514747110
811600228
92531482
136793394
218097588
352553395
821305819
739754364
569418540
402235631
844207347
78271439
896568337
516056999
243958673
201200148
634787992
552693501
893938722
98...

result:

ok 4160 lines

Test #4:

score: 13
Accepted
time: 759ms
memory: 512448kb

input:

4 8320 998244353
303 520 520 288 10 15 24 306 456 495 124 20 419 24 473 7 462 365 405 4 30 1 29 15 25 29 324 407 14 30 184 425 451 6 414 7 417 155 12 18 20 2 475 78 174 467 23 300 26 13 15 345 319 10 27 497 25 21 51 24 485 359 268 87 20 509 13 18 261 13 6 20 237 305 26 245 330 514 29 21 197 25 345 1...

output:

857239630
694514392
340827658
834331936
573150389
560202020
302111919
422193966
147386541
201821565
447255018
322990367
192787601
197802108
461775999
315804262
316164169
338416167
240429979
359914423
321666890
541700460
506123940
701447430
823947537
621301718
62107305
163486246
380210777
211911024
9...

result:

ok 8320 lines

Test #5:

score: 13
Accepted
time: 1161ms
memory: 512360kb

input:

4 52099 998244353
103 520 520 12 485 23 1 337 514 374 486 210 29 29 1 19 299 3 11 11 22 282 14 12 9 341 286 18 501 3 3 29 364 264 477 22 6 434 14 11 117 22 8 30 268 22 28 10 12 311 58 14 15 234 177 17 238 71 64 14 1 396 23 492 4 1 13 6 8 197 4 7 27 11 370 19 242 12 13 20 185 432 399 24 32 2 516 36 4...

output:

51769626
700322830
226311543
862334239
622358370
748398901
344771107
59670026
558254404
668258250
91212841
493756321
360353830
36696310
321158867
563614481
998042994
565120563
709404804
783802088
511531306
396636746
513730575
451308648
594545675
544172685
900482622
791631384
368742309
537404993
6927...

result:

ok 52099 lines

Subtask #3:

score: 14
Accepted

Dependency #2:

100%
Accepted

Test #6:

score: 14
Accepted
time: 801ms
memory: 509824kb

input:

7 52099 998244353
375 520 520 5 295 315 14 25 329 20 137 280 8 286 20 23 15 1 2 21 48 2 16 11 481 18 3 343 18 75 26 103 449 190 270 451 241 15 18 16 142 8 105 159 446 418 15 76 24 384 23 17 514 504 20 497 18 15 367 11 268 425 449 15 456 8 308 517 468 17 6 8 308 22 1 4 465 14 125 434 111 28 384 22 31...

output:

749892128
0
0
0
0
0
260438093
290693060
0
448909491
0
219322656
387184158
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
619977128
447966638
0
681308080
0
0
681648223
0
0
214156868
691259433
912802497
929329058
63245351
0
944326280
86464571
0
0
815255897
146151793
0
0
0
0
0
863159042
312726953
980444251
0
600279...

result:

ok 52099 lines

Test #7:

score: 14
Accepted
time: 936ms
memory: 513744kb

input:

8 52099 998244353
40 520 520 460 30 231 518 11 249 12 19 4 393 288 9 15 27 285 59 19 26 211 6 379 410 422 405 380 375 456 371 319 27 26 402 140 24 70 20 271 312 319 29 368 310 16 456 9 291 13 508 26 65 5 22 401 3 365 127 211 3 17 98 24 290 26 171 409 28 17 9 516 93 2 18 24 25 181 2 6 141
315 520 520...

output:

0
121472646
0
0
868501509
0
0
0
0
311676707
0
0
0
0
0
0
708345252
0
0
0
0
186486401
0
0
467064132
0
0
154691791
0
0
0
0
0
0
0
798981714
0
0
733168043
733528284
0
0
0
80512352
0
235570507
0
0
0
0
78997839
0
0
452560485
0
0
0
0
46384876
0
0
433696320
653100986
0
299555135
0
593915472
0
0
534577853
0
0...

result:

ok 52099 lines

Test #8:

score: 14
Accepted
time: 1001ms
memory: 512416kb

input:

8 52099 998244353
27 520 520 137 195 11 296 397 165 52 434 18 30 7 392 364 205 347 226 175 292 16 69 8 24 54 15 26 29 121 75 23 22 321 11 88 3 19 100 54 118 5 30 2 30 77 11 420 20 4 4 19 1 24 6
117 520 520 8 96 357 13 23 4 147 415 113 86 499 18 14 23 12 15 431 27 3 406 8 13 26 23 102 19 12 24 26 357...

output:

611640132
300436849
327055017
766720771
275032937
904593053
463655376
369893628
214854225
929700933
174664089
812989004
625111481
812138767
845347445
833479053
735408106
735408106
503061044
986829167
458414549
917511270
397433661
828381114
545635279
261016968
690895096
234181435
793843962
377062472
...

result:

ok 52099 lines

Subtask #4:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 994ms
memory: 509868kb

input:

15 52099 998244353
1 9 3
1 9 4
1 9 2
1 8 10
1 4 4
1 3 1
1 2 5
1 4 9
1 1 4
1 9 4
1 7 6
1 1 6
1 2 5
1 5 2
1 3 5
101000000001010 516 1
010001001010101 520 2
000000101000001 519 2
101011111100011 518 1
010110001000111 520 2
000110111100111 516 1
000100101001011 519 3
000111001010011 518 1
00001110010111...

output:

993379058
496689529
866368587
797687294
481245176
481245176
39022588
269889529
552778235
769822588
331666941
99789529
903956470
112750588
756797435
519045176
870912000
361582588
594280447
494747647
597778941
178845176
435456000
493445999
461733882
308912117
271186941
496689529
919511294
85533882
894...

result:

ok 52099 lines

Test #10:

score: 10
Accepted
time: 988ms
memory: 512332kb

input:

15 52099 998244353
1 444 1
1 184 2
1 427 1
1 23 1
1 513 2
1 413 4
1 304 2
1 214 5
1 108 2
1 304 1
1 283 5
1 465 1
1 277 1
1 57 2
1 160 4
111010111100101 520 25
010010011100110 520 3
010000011011000 519 36
110011011100110 516 21
010110001101101 516 42
100001101000111 520 31
110001100010001 519 10
110...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 52099 lines

Test #11:

score: 10
Accepted
time: 997ms
memory: 512684kb

input:

15 52099 998244353
1 5 5
1 43 5
1 25 5
1 30 3
1 34 4
1 32 3
1 45 4
1 27 4
1 30 5
1 22 2
1 26 4
1 5 4
1 23 2
1 13 1
1 3 3
010111011010001 519 2
101000001100000 518 66
001011100110000 518 52
001100000000010 520 42
000110000110100 518 40
100011100010011 518 34
101000111100000 520 9
101010011100100 519 ...

output:

11101681
0
0
0
1142004
0
36064398
16061763
2645108
0
0
10591435
746157
1803184
0
0
16192453
0
0
0
0
20456968
0
3582238
805462
14505464
0
0
0
0
0
0
0
26667881
0
0
0
0
0
0
4674341
0
0
0
0
0
0
0
0
0
0
0
21963213
8597667
4334676
43539633
0
0
0
0
0
2382160
5712673
2788111
1352473
0
0
0
0
0
0
0
0
47306134...

result:

ok 52099 lines

Test #12:

score: 10
Accepted
time: 1004ms
memory: 512192kb

input:

10 52099 998244353
1 5 1
1 23 1
1 27 4
1 19 4
1 12 2
1 30 5
1 28 2
1 16 4
1 30 3
1 6 5
0011010111 519 23
0000001001 517 49
0010110011 517 60
0001111100 520 44
1101101010 518 37
1010011010 519 33
0010010001 519 43
0110001001 517 29
1110101110 518 38
1011010010 520 49
0000000011 520 29
0011111011 518 ...

output:

37275
0
0
0
0
0
0
0
0
0
79991
0
0
0
15342
0
0
0
20344
0
56202
0
0
0
50043
0
0
0
181532
0
0
0
0
52937
0
0
0
0
0
55478
56473
0
255272
0
22226
0
0
18671
236899
0
16685
0
0
31629
0
0
0
0
0
0
87684
0
0
84149
0
0
0
127178
0
0
0
0
0
0
0
0
0
0
0
159291
0
0
0
41794
70377
83979
0
0
56097
0
106432
0
0
0
0
1131...

result:

ok 52099 lines

Test #13:

score: 10
Accepted
time: 992ms
memory: 512236kb

input:

9 52099 998244353
1 18 1
1 8 3
1 36 5
1 47 2
1 47 3
1 34 3
1 38 5
1 35 5
1 45 5
110110111 520 8
001110101 519 42
010101000 516 37
101001001 516 9
110111111 518 33
100111010 519 41
000010000 520 116
010110110 519 25
001011011 517 17
001100000 517 104
000010101 518 79
111100110 517 34
011100111 516 1
...

output:

5039
4726
0
24816
0
0
24712
0
19695
0
3683
0
13040
0
10500
23330
0
0
52779
0
3146
3023
8773
9949
0
0
0
11047
0
30494
0
6016
7291
0
6836
16605
0
0
0
0
6209
14419
0
0
0
14987
0
0
0
0
0
13850
0
0
0
0
4210
11509
0
43740
0
21261
0
74429
0
0
15553
0
5876
33640
0
0
0
12734
0
14637
0
39701
2277
0
0
0
0
0
0
...

result:

ok 52099 lines

Test #14:

score: 10
Accepted
time: 733ms
memory: 510664kb

input:

1 1000 998244353
1 5 1
0 516 28
1 517 106
1 517 22
0 519 4
0 516 37
0 518 10
1 517 62
0 519 32
1 518 58
1 519 72
1 516 82
1 520 56
1 516 59
1 520 79
0 517 122
1 517 2
1 517 53
0 518 93
0 520 149
1 520 86
0 520 53
1 517 120
1 518 41
1 517 94
0 519 76
0 517 46
1 520 48
0 519 31
0 519 4
0 516 24
0 516 ...

output:

2
0
0
2
2
2
0
2
0
0
0
0
0
0
2
1
0
2
2
0
2
0
0
0
2
2
0
2
2
2
2
0
2
2
2
2
0
0
0
2
2
0
0
2
2
2
2
0
0
2
0
2
0
0
2
2
0
2
2
0
0
2
2
2
0
0
2
0
0
2
0
2
0
0
2
0
0
0
0
2
2
0
0
0
1
2
2
2
2
2
2
2
2
0
0
2
2
2
0
2
2
0
0
2
0
2
0
2
0
2
2
0
0
0
0
0
2
2
2
2
2
0
2
0
0
0
0
0
2
2
2
0
2
0
2
0
0
2
2
0
0
2
2
0
2
0
2
2
0
0
...

result:

ok 1000 lines

Subtask #5:

score: 25
Accepted

Dependency #3:

100%
Accepted

Test #15:

score: 25
Accepted
time: 1018ms
memory: 512624kb

input:

15 52099 998244353
187 520 520 21 25 475 247 297 180 3 22 17 13 8 362 153 23 203 492 444 270 7 17 12 27 30 5 316 281 441 11 518 34 10 23 12 403 213 467 351 22 178 8 54 37 28 22 29 209 209 25 16 286 447 7 6 25 334 14 25 29 304 9 347 26 63 199 470 72 25 151 29 289 38 3 484 16 202 28 410 25 1 16 25 6 1...

output:

201142254
985793518
564689787
837651171
952915437
762762080
897212365
485394694
151682224
355049473
991697782
935162062
569171609
820415101
307382351
656056448
129648294
453468980
525403207
592935067
213396919
885501164
267000229
922880031
692668969
196055884
417004259
335278083
351024493
143284895
...

result:

ok 52099 lines

Test #16:

score: 25
Accepted
time: 1012ms
memory: 512904kb

input:

15 52099 998244353
147 520 520 2 5 2 5 1 5 16 5 8 5 8 5 4 5 4 5 4 5 2 5 4 5 2 5 8 5 2 5 8 5 4 5 16 5 8 5 2 5 4 5 16 5 4 5 1 5 4 5 2 5 4 5 4 5 8 5 8 5 1 5 16 5 1 5 2 5 2 5 16 5 8 5 1 5 2 5 16 5 1 5 16 5 4 5 8 5 2 5 4 5 16 5 4 5 2 5 8 5 8 5 1 5 4 5 16 5 4 5 4 5 2 5 4 5 2 5 2 5 1 5 8 5 4 5 16 5 8 5 2 5...

output:

242417177
440189754
889617603
872166379
495149640
410397532
183799467
284271642
567153945
819885956
936067343
97379760
591656668
809313699
337549710
743302501
750522784
760325366
729888829
154371602
870414451
492621070
841959842
937587879
518704893
551082366
51801361
87581241
46911456
641967497
2452...

result:

ok 52099 lines

Test #17:

score: 25
Accepted
time: 995ms
memory: 511004kb

input:

15 52099 998244353
56 520 520 1 5 4 5 2 5 8 5 16 5 2 5 2 5 2 5 1 5 16 5 2 5 8 5 2 5 1 5 2 5 4 5 1 5 16 5 16 5 1 5 8 5 1 5 8 5 16 5 8 5 1 5 4 5 4 5 2 5 4 5 16 5 16 5 8 5 1 5 2 5 2 5 2 5 16 5 16 5 16 5 1 5 16 5 1 5 8 5 2 5 16 5 1 5 2 5 2 5 4 5 8 5 16 5 16 5 2 5 2 5
199 520 520 16 5 4 5 2 5 16 5 8 5 8 ...

output:

655514914
814949076
757709972
457383073
190861256
943066055
683365019
620023365
113342367
366236790
468534272
38507289
978444179
331515147
89203381
366707024
465727606
115760514
322816596
872589670
566974623
824662974
652567121
91850187
989609674
11616535
486994045
986455197
709337366
713384782
5428...

result:

ok 52099 lines

Test #18:

score: 25
Accepted
time: 966ms
memory: 514096kb

input:

14 52099 998244353
116 520 520 14 12 17 142 291 15 9 29 24 403 9 51 16 326 174 334 24 306 487 214 349 23 15 231 455 225 230 204 2 30 2 24 512 17 110 475 471 14 30 16 103 501 183 4 29 318 1 106 288 24 222 3 19 183 113 243 292 289 18 41 33 171 7 14 482 142 382 1 87 376 215 384 506 78 122 249 21 12 2 7...

output:

8371400
844306488
885156868
444566620
368294157
441091937
644142943
526182367
425264040
580334976
198436702
789421193
10493696
403876127
386807460
20311851
340533200
103448772
266752233
584259456
693866903
285081465
223535903
282713591
670411142
77966699
87636356
605820420
840821710
829639544
529904...

result:

ok 52099 lines

Test #19:

score: 25
Accepted
time: 964ms
memory: 510884kb

input:

13 52099 998244353
336 520 520 111 475 105 21 259 6 6 494 6 437 5 12 17 21 44 23 28 297 30 399 1 14 91 11 291 3 443 20 21 413 8 106 145 20 10 4 6 14 21 486 4 23 406 10 519 51 23 284 205 488 201 9 24 15 121 9 182 243 8 1 11 17 2 377 20 336 19 499 90 315 21 3 387 8 371 11 7 14 202 6 114 82 114 3 25 48...

output:

978898530
781859008
0
727762075
0
370868626
0
0
491054504
110691014
163646677
455857511
0
318488813
538388935
630014668
453220220
386981233
660702143
0
895630263
0
580231647
0
0
0
0
0
0
528281068
503934902
356945029
343373205
0
0
0
168756452
412241222
0
537181294
0
0
0
490347899
280674870
0
0
701148...

result:

ok 52099 lines

Test #20:

score: 25
Accepted
time: 981ms
memory: 513896kb

input:

15 52099 998244353
370 520 520 256 22 2 87 142 59 338 17 489 450 3 56 21 22 497 29 6 18 248 286 19 29 427 6 286 367 116 25 27 3 469 28 24 27 30 453 127 22 108 24 2 30 160 262 41 325 22 39 6 7 151 26 236 505 224 25 10 500 241 22 90 24 308 376 303 436 4 337 68 29 14 87 489 316 227 255 121 16 391 363 2...

output:

432288070
651018473
862263277
275458172
219422514
748518338
903371000
291669367
616572740
86170696
2517068
674702278
985641600
130816407
681640370
452342456
935323386
9171509
873128820
396446302
803413024
188736584
756359993
202520176
961216817
566688437
444955439
416142168
755398657
924127646
95009...

result:

ok 52099 lines

Subtask #6:

score: 15
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #21:

score: 15
Accepted
time: 951ms
memory: 513316kb

input:

15 52099 998244353
378 520 520 5 1 23 481 2 26 326 322 299 146 233 7 382 148 17 7 22 28 204 286 19 8 24 351 16 349 26 261 159 30 13 10 484 298 3 4 2 73 4 18 392 31 273 30 15 22 10 86 436 30 2 29 162 20 24 10 22 25 16 135 6 466 25 122 95 264 20 418 197 18 438 132 21 232 26 78 168 14 276 179 23 12 5 4...

output:

624081149
547753985
927123620
546655148
159110294
663024387
226798367
325958712
19571503
199424073
888536020
74697377
907017749
627287017
481239017
823403803
902695366
825690350
439910885
370166525
50202155
499762139
239730182
611888569
548804422
710568499
896807380
213177670
434171092
629099628
417...

result:

ok 52099 lines

Test #22:

score: 15
Accepted
time: 1003ms
memory: 513764kb

input:

15 52099 998244353
15 520 520 8 5 8 5 1 5 1 5 16 5 2 5 8 5 1 5 4 5 1 5 1 5 4 5 8 5 4 5
282 520 520 8 5 4 5 16 5 16 5 16 5 2 5 2 5 8 5 2 5 2 5 8 5 1 5 16 5 16 5 4 5 2 5 4 5 2 5 1 5 2 5 2 5 16 5 2 5 4 5 1 5 16 5 16 5 16 5 4 5 16 5 16 5 2 5 1 5 8 5 4 5 4 5 1 5 8 5 8 5 1 5 2 5 1 5 2 5 16 5 2 5 4 5 2 5 4...

output:

0
750966989
0
136343695
31893210
740887135
151676890
146520932
527189810
717159642
0
0
0
0
0
130979525
738995553
715075172
712489484
471231266
792233051
0
177016371
0
0
0
507018959
0
305144441
921520055
0
684516760
0
238070190
0
0
219252566
0
0
177010616
495177445
0
0
0
0
0
529658827
0
3864468
11638...

result:

ok 52099 lines

Test #23:

score: 15
Accepted
time: 1002ms
memory: 512820kb

input:

15 52099 998244353
20 520 520 16 5 4 5 16 5 4 5 1 5 16 5 16 5 4 5 4 5 1 5 4 5 8 5 2 5 4 5 520 520 1 5 2 5 16 5 16 5
107 520 520 4 5 1 5 1 5 4 5 2 5 4 5 2 5 16 5 1 5 1 5 2 5 1 5 2 5 2 5 4 5 4 5 1 5 4 5 2 5 1 5 2 5 4 5 1 5 4 5 16 5 2 5 4 5 16 5 1 5 16 5 2 5 4 5 8 5 4 5 4 5 1 5 4 5 16 5 8 5 8 5 16 5 8 ...

output:

416962830
498828715
69284364
459053393
421862888
900858004
883856743
882640433
977358262
940752331
916127503
584326988
37913820
997702565
234181830
891104768
94176534
130825702
248527619
766633123
428144822
960075465
63200099
650529368
149875518
355969247
981952464
517328969
474216667
298231019
3352...

result:

ok 52099 lines

Test #24:

score: 15
Accepted
time: 988ms
memory: 513556kb

input:

14 52099 998244353
468 520 520 22 15 258 502 23 235 367 410 24 27 402 5 24 12 18 25 331 359 7 209 14 362 320 388 56 26 1 421 106 6 91 222 156 24 407 29 14 16 445 247 29 15 369 266 240 30 3 15 20 227 12 126 199 8 15 6 29 22 318 25 8 1 10 3 10 511 170 230 417 18 211 9 157 25 168 27 2 3 19 504 71 29 13...

output:

889964548
264667894
58941029
51473963
567530911
151870864
50959159
460354505
383460979
804718039
834697743
140009368
332117484
510713089
659082678
385022062
964993120
652805505
341078787
19659461
241302441
936920253
198362256
688468583
748667214
883457275
308812106
160914594
5044549
627510330
741386...

result:

ok 52099 lines

Test #25:

score: 15
Accepted
time: 976ms
memory: 513004kb

input:

13 52099 998244353
423 520 520 230 205 456 270 19 69 425 1 9 14 263 264 22 19 352 23 21 46 29 2 22 185 483 309 24 441 36 3 8 1 32 215 93 26 27 361 314 329 30 16 76 71 12 5 494 250 185 417 6 61 51 242 305 16 194 22 404 279 2 256 487 420 450 162 4 304 229 6 5 473 9 4 5 21 20 12 12 12 20 17 345 290 18 ...

output:

6053851
20499727
638166899
938911481
776681098
338066436
951490573
250860769
482066282
235869560
650676072
27973218
344588330
694475657
438901321
868934429
313105951
31143565
109871252
692909861
572513236
286031824
772914098
464099602
684840038
315914272
210709908
100695616
28933316
483447145
845536...

result:

ok 52099 lines

Test #26:

score: 15
Accepted
time: 1002ms
memory: 513564kb

input:

15 52099 998244353
508 520 520 62 27 12 506 12 23 30 29 12 446 8 27 17 26 11 20 372 18 8 8 21 4 12 20 334 17 105 196 13 26 26 454 1 2 342 20 55 123 53 338 17 6 4 159 313 316 22 8 43 502 16 2 391 240 368 19 379 17 26 248 1 115 417 30 421 490 192 4 13 2 10 323 4 10 211 87 23 14 29 10 93 387 364 16 156...

output:

183591012
0
841320848
681814440
708205623
297679717
329861153
825927030
156979226
240270011
729065863
943708004
237735265
277765490
677052501
323057095
538332062
756054622
896786238
444920055
105114
332722403
604388256
706858465
580672002
309577628
222746926
442007338
35180013
203410329
578830591
30...

result:

ok 52099 lines

Subtask #7:

score: 20
Accepted

Dependency #6:

100%
Accepted

Test #27:

score: 20
Accepted
time: 1033ms
memory: 513728kb

input:

15 52099 1000000007
10 520 520 17 2 519 15 194 270 486 22 16 16 113 178 8 118 9 27 9 37
480 520 520 288 200 305 2 15 461 200 116 14 116 15 22 189 277 511 24 19 192 99 520 29 465 133 238 22 500 264 447 9 17 22 17 6 380 141 12 496 222 283 90 364 5 10 27 465 248 331 307 466 231 58 222 195 158 351 6 23 ...

output:

979139845
669650464
870491326
429861464
498271939
418296044
302375786
177135674
459820943
798718972
794362192
135876948
117873352
686056661
830393199
865828639
243609141
205889922
185690616
707733533
917842534
510244679
27748921
233505365
512059792
758799994
461902578
25995302
619107174
251671013
44...

result:

ok 52099 lines

Test #28:

score: 20
Accepted
time: 1069ms
memory: 513772kb

input:

15 52099 1000000007
404 520 520 16 25 23 4 326 131 327 19 358 442 17 13 139 509 2 511 2 129 76 26 28 26 63 471 28 132 9 21 5 48 466 26 430 6 425 14 30 121 6 7 13 135 349 19 144 421 488 1 10 4 9 7 462 24 20 259 23 7 27 30 257 7 19 24 9 19 476 18 30 15 2 501 2 392 4 48 31 250 270 9 4 201 11 6 2 23 470...

output:

133095211
12529660
168938391
438773464
688816392
961629545
744474583
813148059
728187682
619294278
102028023
903406689
611835757
335235114
888653789
750801918
813938886
502248097
206146794
367149645
707503297
23095993
601573798
630903914
648894521
787676730
854509551
661950617
343635508
149373941
59...

result:

ok 52099 lines