QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53234#4612. 福若格斯JohnAlfnov#100 ✓265ms19436kbC++204.2kb2022-10-04 20:32:422022-10-04 20:33:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-04 20:33:06]
  • 评测
  • 测评结果:100
  • 用时:265ms
  • 内存:19436kb
  • [2022-10-04 20:32:42]
  • 提交

answer

#include<bits/stdc++.h>
#define em surnum(0) //inf
#define zer surnum(1) //0
#define on surnum(2) //1
#define mon surnum(3) //-1
#define hal surnum(4) //1/2
#define mhal surnum(5) //-1/2
#define upp surnum(6) //up
#define dow surnum(7) //down
#define str surnum(8) //star
#define mod 998244353
#define MX 1000000000
using namespace std;
struct surnum{
	int zz;
	bool operator==(const surnum &other)const{
		return zz==other.zz;
	}
	surnum(int zz=0):zz(zz){}
}f[250];
surnum operator+(surnum a,surnum b){
	if(a==em&&b==em)return zer;
	if(a==em&&b==zer)return mon;
	if(a==em&&b==on)return zer;
	if(a==em&&b==hal)return zer;
	if(a==em&&b==mhal)return mon;
	if(a==em&&b==upp)return zer;
	if(a==em&&b==dow)return mon;
	if(a==em&&b==str)return zer;
	if(a==zer&&b==em)return on;
	if(a==zer&&b==zer)return str;
	if(a==zer&&b==on)return hal;
	if(a==zer&&b==mon)return mhal;
	if(a==zer&&b==dow)return str;
	if(a==zer&&b==str)return upp;
	if(a==mon&&b==em)return zer;
	if(a==mon&&b==on)return zer;
	if(a==mon&&b==zer)return mhal;
	if(a==mhal&&b==em)return zer;
	if(a==upp&&b==dow)return str;
	if(a==str&&b==zer)return dow;
	assert(0);
	return em;
}
surnum dfs(int zt){
	if(f[zt].zz>=0)return f[zt];
	int aa[15];
	int xx=zt;
	for(int i=4;i>=0;--i)aa[i]=xx%3,xx/=3;
	surnum L=em,R=em;
	for(int i=0;i<4;++i)if(aa[i]==0&&aa[i+1]==2){
		swap(aa[i],aa[i+1]);
		int zt=0;
		for(int j=0;j<=4;++j)zt=zt*3+aa[j];
		L=dfs(zt);
		swap(aa[i],aa[i+1]);
	}
	for(int i=0;i<3;++i)if(aa[i]==0&&aa[i+1]==1&&aa[i+2]==2){
		swap(aa[i],aa[i+2]);
		int zt=0;
		for(int j=0;j<=4;++j)zt=zt*3+aa[j];
		L=dfs(zt);
		swap(aa[i],aa[i+2]);
	}
	for(int i=1;i<=4;++i)if(aa[i]==1&&aa[i-1]==2){
		swap(aa[i],aa[i-1]);
		int zt=0;
		for(int j=0;j<=4;++j)zt=zt*3+aa[j];
		R=dfs(zt);
		swap(aa[i],aa[i-1]);
	}
	for(int i=2;i<=4;++i)if(aa[i]==1&&aa[i-1]==0&&aa[i-2]==2){
		swap(aa[i],aa[i-2]);
		int zt=0;
		for(int j=0;j<=4;++j)zt=zt*3+aa[j];
		R=dfs(zt);
		swap(aa[i],aa[i-2]);
	}
	return f[zt]=L+R;
}
int powdv(int x,int y=mod-2){
	int ans=1;
	while(y){
		if(y&1)ans=1ll*ans*x%mod;
		y>>=1,x=1ll*x*x%mod;
	}
	return ans;
}
int di[1000005],id[1000005];
int CCC(int n,int m){
	if(n<0||m<0||n<m)return 0;
	return 1ll*di[n]*id[m]%mod*id[n-m]%mod;
}
int s[1000005];
int tt[1000005];
int main(){
	di[0]=1;
	for(int i=1;i<=1000000;++i)di[i]=1ll*i*di[i-1]%mod;
	id[1000000]=powdv(di[1000000]);
	for(int i=1000000-1;i>=0;--i)id[i]=1ll*id[i+1]*(i+1)%mod;
	for(int i=0;i<243;++i)f[i].zz=-1;
	dfs(22);
	int tcs;
	scanf("%d",&tcs);
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		int A=0,B=0,C=0,D=0,E=0;
		int F=0,G=0,H=0;
		for(int i=1;i<=n;++i){
			char op[15];
			int a;
			scanf("%s%d",op+1,&a);
			int zt=0;
			for(int j=1;j<=5;++j){
				int aa=0;
				if(op[j]=='R')aa=1;
				else if(op[j]=='_')aa=2;
				zt=zt*3+aa;
			}
			int zz=f[zt].zz;
			assert(zz);
			if(zz==1)C+=a;
			else if(zz==2)E+=a;
			else if(zz==3)A+=a;
			else if(zz==4)D+=a;
			else if(zz==5)B+=a;
			else if(zz==6)G+=a;
			else if(zz==7)F+=a;
			else H+=a;
		}
		for(int i=0;i<=A+E;++i){
			s[i+1]=(s[i]+CCC(A+E,i))%mod;
		}
		int aA=0,aB=0,aC=0;
		for(int i=-B;i<=D;++i){
			int cj=CCC(B+D,i+B);
			int lb=max(-1,min(E,(-i-1+MX)/2-MX/2)+A)+1;
			int rb=min(A+E+1,max(-A,(-i+MX)/2-MX/2+1)+A)+1;
			aA=(aA+1ll*cj*s[lb])%mod;
			aC=(aC+1ll*cj*(0ll+s[A+E+1]-s[rb-1]+mod))%mod;
		}
		aB=(0ll+powdv(2,A+B+D+E)-aA-aC+mod+mod)%mod;
		int pd=powdv(2,C);
		aA=1ll*aA*pd%mod,aB=1ll*aB*pd%mod,aC=1ll*aC*pd%mod;
		int dp=powdv(2,F+G+H);
		aA=1ll*aA*dp%mod,aC=1ll*aC*dp%mod;
		int c0=0,c1=0;
		if(!H)c0=1;
		else c0=c1=powdv(2,H-1);
		for(int i=0;i<=F+G;++i){
			tt[i]=CCC(F+G,i);
		}
		int aaA=0,aaB=0;
		int aD=0,aE=0;//=0,||0
		for(int i=0;i<=F+G;++i){
			if(i<F){
				aaA=(aaA+1ll*c0*tt[i])%mod;
			}else if(i==F){
				aD=(aD+1ll*c0*tt[i])%mod;
			}else{
				aaB=(aaB+1ll*c0*tt[i])%mod;
			}
			if(i<F-1){
				aaA=(aaA+1ll*c1*tt[i])%mod;
			}else if(i<=F+1){
				aE=(aE+1ll*c1*tt[i])%mod;
			}else{
				aaB=(aaB+1ll*c1*tt[i])%mod;
			}
		}
		aA=(aA+1ll*aaA*aB)%mod;
		aC=(aC+1ll*aaB*aB)%mod;
		aD=1ll*aB*aD%mod;
		aE=1ll*aB*aE%mod;
		printf("%d %d %d %d\n",aC,aA,aE,aD);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 4ms
memory: 11520kb

input:

1 100
1
LLR_R 1
1
LLR_R 1
1
LRR_L 1
1
_RLRL 1
1
RLRL_ 1
1
LRR_L 1
1
R_LLR 1
1
LRR_L 1
1
L_RLR 1
1
L_RLR 1
1
RLR_L 1
1
LR_RL 1
1
R_RLL 1
1
LRL_R 1
1
R_LLR 1
1
_RLLR 1
1
_RLLR 1
1
_RLRL 1
1
_LLRR 1
1
RLR_L 1
1
LRL_R 1
1
R_RLL 1
1
LLR_R 1
1
L_RLR 1
1
R_LLR 1
1
RL_LR 1
1
RL_LR 1
1
LLRR_ 1
1
_RLRL 1
1
L_...

output:

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

result:

ok 400 numbers

Test #2:

score: 5
Accepted
time: 15ms
memory: 11600kb

input:

2 100
3
LLRR_ 1
LR_RL 1
RR_LL 1
1
_LRLR 1
4
LRR_L 1
RL_LR 1
R_LLR 1
R_LRL 1
5
LRL_R 1
LRRL_ 1
LR_LR 1
RL_LR 1
_RLRL 1
3
LLRR_ 1
LRR_L 1
RLR_L 1
2
LLR_R 1
L_LRR 1
4
LL_RR 1
LRL_R 1
R_LLR 1
_RLLR 1
4
LRRL_ 1
LR_RL 1
R_RLL 1
_RLRL 1
2
LRRL_ 1
LR_LR 1
5
LLRR_ 1
LRLR_ 1
LRRL_ 1
_RLLR 1
_RLRL 1
2
L_RLR 1
...

output:

0 4 0 4
0 0 0 2
8 0 0 8
16 8 4 4
0 0 0 8
1 1 0 2
0 8 4 4
2 11 0 3
2 0 0 2
4 16 0 12
0 0 2 2
0 0 16 16
2 0 0 2
16 0 8 8
20 8 0 4
0 12 2 2
24 0 0 8
1 2 0 1
0 2 0 2
2 2 0 4
10 2 0 4
0 4 0 4
13 2 0 1
8 0 0 8
0 4 2 2
8 5 2 1
4 16 8 4
0 12 0 4
16 4 8 4
0 2 0 2
0 0 0 2
8 4 0 4
0 10 4 2
8 0 4 4
4 22 0 6
0 2...

result:

ok 400 numbers

Test #3:

score: 5
Accepted
time: 7ms
memory: 11572kb

input:

3 100
8
LRL_R 1
LRR_L 1
LR_LR 1
LR_RL 1
RLRL_ 1
RL_LR 1
R_LLR 1
R_RLL 1
8
LL_RR 1
LRRL_ 1
LR_RL 1
RLR_L 1
RRL_L 1
R_LRL 1
_LLRR 1
_LRLR 1
8
LLRR_ 1
LLR_R 1
LL_RR 1
LRR_L 1
LR_LR 1
R_LRL 1
_LLRR 1
_LRLR 1
8
LLRR_ 1
LLR_R 1
LRL_R 1
LR_LR 1
LR_RL 1
R_LLR 1
_RLLR 1
_RLRL 1
8
LL_RR 1
LRLR_ 1
L_LRR 1
L_RL...

output:

96 96 32 32
192 32 16 16
0 64 128 64
0 232 16 8
56 128 48 24
96 64 64 32
40 192 16 8
128 64 32 32
0 224 16 16
16 208 16 16
128 80 24 24
192 16 32 16
0 224 16 16
176 48 0 32
128 32 64 32
192 16 32 16
80 80 0 96
16 176 32 32
128 64 32 32
32 200 16 8
152 32 48 24
80 80 64 32
128 32 48 48
80 128 0 48
40...

result:

ok 400 numbers

Test #4:

score: 5
Accepted
time: 9ms
memory: 11520kb

input:

4 100
10
LLR_R 1
LL_RR 1
LRL_R 1
LRRL_ 1
LRR_L 1
LR_RL 1
L_LRR 1
L_RLR 1
R_RLL 1
_RLRL 1
10
LRL_R 1
LRRL_ 1
LR_RL 1
L_LRR 1
L_RLR 1
RLRL_ 1
R_LLR 1
R_RLL 1
_LLRR 1
_RLRL 1
10
LRL_R 1
LRR_L 1
L_LRR 1
L_RLR 1
RLRL_ 1
R_LLR 1
R_LRL 1
R_RLL 1
_RLLR 1
_RLRL 1
10
LLR_R 1
LL_RR 1
LRLR_ 1
LR_RL 1
L_LRR 1
L_...

output:

152 728 96 48
368 512 96 48
128 704 128 64
416 416 128 64
320 512 128 64
320 416 192 96
544 288 128 64
512 192 160 160
128 704 128 64
0 896 64 64
752 128 96 48
288 544 128 64
368 512 96 48
832 64 64 64
64 576 256 128
256 512 128 128
560 176 192 96
512 368 96 48
608 320 0 96
512 192 160 160
192 768 0...

result:

ok 400 numbers

Test #5:

score: 5
Accepted
time: 86ms
memory: 19264kb

input:

5 100
1
LL_RR 838546
1
RRL_L 520881
1
LLRR_ 999980
1
RRL_L 2
1
RLRL_ 9
1
LRL_R 2
1
RL_LR 7
1
LLR_R 14
1
RLRL_ 753547
1
LRLR_ 17
1
LLR_R 722783
1
LR_LR 999985
1
LRL_R 999981
1
RLRL_ 431962
1
_LRLR 999992
1
LRRL_ 14
1
_RLLR 709382
1
RR_LL 999991
1
RL_LR 16
1
L_RLR 999992
1
LR_LR 13
1
L_RLR 999995
1
L_...

output:

0 0 50932616 50932616
378274767 0 0 1
0 0 0 242222522
3 0 0 1
511 0 0 1
0 0 2 2
127 0 0 1
0 16383 0 1
451252114 0 0 1
0 0 0 131072
0 462894643 0 1
0 0 0 763410233
0 0 242222522 242222522
805483386 0 0 1
0 0 0 886807583
16383 0 0 1
0 860243854 0 1
0 0 0 942525968
65535 0 0 1
0 0 942525968 942525968
0...

result:

ok 400 numbers

Test #6:

score: 5
Accepted
time: 133ms
memory: 19436kb

input:

6 100
1
L_RLR 6
1
LR_LR 9
1
L_RLR 598544
1
_RLLR 11
1
LRR_L 999982
1
RL_LR 275578
1
L_LRR 489165
1
RRL_L 999987
1
_LLRR 15
1
RLR_L 28814
1
RR_LL 999983
1
R_RLL 999992
1
R_LRL 109447
1
LLRR_ 999987
1
LL_RR 11
1
RL_LR 999989
1
_LLRR 999985
1
LRLR_ 99274
1
RLR_L 609917
1
_LLRR 789302
1
LRL_R 1
1
_RLLR ...

output:

0 0 32 32
0 0 0 512
0 0 563598354 563598354
0 2047 0 1
0 0 0 968890088
172890601 0 0 1
840438312 0 0 1
58907872 0 0 1
0 0 0 32768
0 0 0 569958573
0 0 0 939535823
0 886807582 0 1
0 0 0 2446897
0 0 0 58907873
0 0 1024 1024
235631491 0 0 1
0 0 0 763410233
0 0 0 380698432
0 0 0 842690390
0 0 0 133505680...

result:

ok 400 numbers

Test #7:

score: 5
Accepted
time: 11ms
memory: 11688kb

input:

7 100
1
R_LRL 500
2
RLR_L 320
R_RLL 180
2
RR_LL 261
R_LRL 239
1
RR_LL 500
3
RLR_L 278
RRL_L 199
RR_LL 23
4
RLR_L 52
RRL_L 205
RR_LL 232
R_LRL 11
1
RRL_L 500
1
RRL_L 500
2
RRL_L 276
R_RLL 224
1
R_LRL 500
3
RRL_L 23
R_LRL 154
R_RLL 323
2
RLR_L 185
R_RLL 315
3
RR_LL 141
R_LRL 42
R_RLL 317
3
RLR_L 96
RR...

output:

0 0 0 616118644
0 997240333 0 617122664
0 0 0 616118644
0 0 0 616118644
684067419 0 0 930295578
8875191 0 0 607243453
616118643 0 0 1
616118643 0 0 1
537776684 201371198 0 875215115
0 0 0 616118644
795839458 220997578 0 597525961
0 99297351 0 516821293
0 736474409 0 877888588
0 0 0 616118644
0 0 0 6...

result:

ok 400 numbers

Test #8:

score: 5
Accepted
time: 101ms
memory: 13864kb

input:

8 100
3
RLR_L 245574
RRL_L 154512
R_LRL 199914
2
RLR_L 507948
RRL_L 92052
3
RR_LL 62618
R_LRL 75910
R_RLL 461472
2
RLR_L 584457
RR_LL 15543
3
RRL_L 199727
R_LRL 267713
R_RLL 132560
4
RLR_L 93412
RRL_L 204396
RR_LL 261031
R_LRL 41161
5
RLR_L 205717
RRL_L 55856
RR_LL 37924
R_LRL 156194
R_RLL 144309
3
...

output:

589933168 0 0 64289885
372141343 0 0 282081710
0 200036663 0 454186390
0 0 0 654223053
530840957 112226214 0 11155882
394133210 0 0 260089843
945425698 467886576 0 239155132
170651780 433193248 0 50378025
804125194 0 0 848342212
0 599201709 0 55021344
0 0 0 654223053
681848735 44767448 0 925851223
6...

result:

ok 400 numbers

Test #9:

score: 5
Accepted
time: 15ms
memory: 11596kb

input:

9 100
16
LRLR_ 1
LRRL_ 9
LRR_L 2
LR_LR 6
LR_RL 8
RLRL_ 1
RLR_L 10
RL_LR 3
RRL_L 10
RR_LL 4
R_LLR 5
R_LRL 10
R_RLL 4
_LRLR 1
_RLLR 15
_RLRL 11
1
RR_LL 100
16
LRLR_ 7
LRRL_ 9
LRR_L 6
LR_LR 3
LR_RL 10
RLRL_ 9
RLR_L 6
RL_LR 8
RRL_L 4
RR_LL 5
R_LLR 2
R_LRL 5
R_RLL 9
_LRLR 2
_RLLR 8
_RLRL 7
6
LRR_L 15
LR_...

output:

404444034 391392352 0 86663332
0 0 0 882499718
131959415 927271783 0 821512873
474227274 67875396 0 340397048
523009412 174432988 0 185057318
519149019 916510610 0 445084442
78002240 460795054 0 343702424
0 0 0 882499718
766865590 441249859 0 672628622
653955650 386822154 0 839966267
127683925 14082...

result:

ok 400 numbers

Test #10:

score: 5
Accepted
time: 178ms
memory: 14292kb

input:

10 100
1
_LRLR 700000
1
RLR_L 700000
16
LRLR_ 48839
LRRL_ 44669
LRR_L 84201
LR_LR 51510
LR_RL 83993
RLRL_ 18715
RLR_L 25237
RL_LR 72656
RRL_L 29299
RR_LL 9204
R_LLR 14056
R_LRL 6221
R_RLL 19193
_LRLR 118525
_RLLR 71307
_RLRL 2375
16
LRLR_ 29471
LRRL_ 120527
LRR_L 14969
LR_LR 67351
LR_RL 66814
RLRL_ ...

output:

0 0 0 702777662
0 0 0 702777662
332242024 821001879 0 547778112
335337504 37938615 0 329501543
118490378 714032319 0 868499318
831255045 305910895 0 563856075
0 705279817 0 995742198
982523351 906099528 0 810643489
398014437 109520096 0 195243129
0 0 0 702777662
486613555 369377464 0 845030996
31045...

result:

ok 400 numbers

Test #11:

score: 5
Accepted
time: 11ms
memory: 11680kb

input:

11 100
16
LLRR_ 1
LRLR_ 1
LRR_L 1
LR_LR 1
LR_RL 1
L_RLR 1
RLRL_ 1
RLR_L 1
RRL_L 1
RR_LL 1
R_LLR 1
R_LRL 1
R_RLL 1
_LLRR 1
_RLLR 1
_RLRL 1
1
LRLR_ 16
5
LRLR_ 1
LRL_R 5
RR_LL 1
R_LLR 4
R_LRL 5
14
LLRR_ 1
LRLR_ 1
LRL_R 1
LRRL_ 1
LRR_L 1
LR_LR 1
LR_RL 1
L_RLR 1
RLRL_ 1
RL_LR 1
R_RLL 3
_LRLR 1
_RLLR 1
_R...

output:

12288 43008 5120 5120
0 0 0 65536
0 0 32768 32768
6784 53376 2688 2688
42368 14848 4160 4160
65483 10 0 43
0 0 0 65536
0 0 0 65536
0 61440 2048 2048
32768 0 0 32768
0 0 0 65536
27648 27648 5120 5120
12288 43008 5120 5120
32 65152 176 176
38400 16896 5120 5120
37888 17408 5120 5120
0 0 32768 32768
65...

result:

ok 400 numbers

Test #12:

score: 5
Accepted
time: 172ms
memory: 14588kb

input:

12 100
7
LR_LR 157600
RLRL_ 17039
RLR_L 213866
RRL_L 150323
R_LLR 113530
R_RLL 112238
_RLRL 35404
2
LRL_R 75922
LRR_L 724078
2
LR_RL 690984
RL_LR 109016
9
LRLR_ 128359
LR_RL 47906
RLR_L 167269
RL_LR 51548
RR_LL 145556
R_LLR 50595
R_RLL 27503
_LLRR 51843
_RLRL 129421
20
LLRR_ 38165
LRLR_ 17214
LRL_R ...

output:

940802264 171318240 0 480349095
0 0 297112623 297112623
747010002 552206767 0 293252830
324891631 460789163 0 806788805
272500237 228650626 545659368 545659368
320812140 0 136706553 136706553
530270951 0 0 63954295
338739530 349282822 951345800 951345800
766080882 144707713 340840502 340840502
0 0 0...

result:

ok 400 numbers

Test #13:

score: 5
Accepted
time: 10ms
memory: 11596kb

input:

13 100
10
LLR_R 2
LRRL_ 3
LRR_L 1
LR_RL 1
L_LRR 1
RLRL_ 1
RR_LL 2
R_LRL 1
_LLRR 1
_LRLR 1
14
LRLR_ 1
LRL_R 1
LRRL_ 1
LRR_L 1
L_LRR 1
L_RLR 1
RLRL_ 1
RRL_L 1
RR_LL 1
R_LLR 1
R_LRL 1
R_RLL 1
_LLRR 1
_LRLR 1
7
LLR_R 2
LRLR_ 2
LR_LR 2
L_LRR 2
R_LLR 3
_LLRR 1
_RLLR 2
14
LLR_R 1
LRRL_ 1
LRR_L 1
LR_LR 1
LR...

output:

15424 768 0 192
12288 1024 2048 1024
1280 13568 0 1536
9792 4672 1280 640
10112 4352 1280 640
4096 10240 1536 512
8192 5888 1536 768
2048 12032 1536 768
13568 1280 1024 512
0 0 0 16384
15876 396 88 24
0 0 8192 8192
2048 12288 1024 1024
0 0 0 16384
14912 320 576 576
2048 12800 1024 512
5120 8960 1536...

result:

ok 400 numbers

Test #14:

score: 5
Accepted
time: 265ms
memory: 18640kb

input:

14 100
7
LRLR_ 205240
LRL_R 78053
LRR_L 117478
LR_LR 181169
L_LRR 123470
RLR_L 38145
RL_LR 156445
9
LRL_R 49578
LRRL_ 133473
LRR_L 99644
RLR_L 98826
RL_LR 78104
RR_LL 41245
R_LLR 96478
R_LRL 43326
_LLRR 259326
7
LLRR_ 226267
LRLR_ 103046
L_RLR 25019
RLRL_ 82826
RLR_L 76224
RRL_L 242226
R_LRL 144392
...

output:

815679376 0 928130740 619889036
194353719 0 585550540 585550540
198024949 0 583714925 583714925
168935695 886558158 0 309960946
613456471 348504046 747623136 654115499
895483140 623073264 368961478 476181270
88353558 648410782 813467406 813467406
0 0 183605223 183605223
0 0 0 367210446
917755086 568...

result:

ok 400 numbers

Test #15:

score: 5
Accepted
time: 4ms
memory: 11588kb

input:

15 100
12
LLRR_ 1
LLR_R 1
LRRL_ 1
LRR_L 1
L_LRR 1
RLRL_ 1
RRL_L 1
RR_LL 1
R_LRL 1
_LRLR 1
_RLLR 1
_RLRL 1
5
LLRR_ 4
LLR_R 1
LRL_R 1
RL_LR 3
R_LLR 3
12
LLRR_ 1
LLR_R 1
LL_RR 1
LRL_R 1
LR_LR 1
LR_RL 1
RLRL_ 1
R_LLR 1
R_RLL 1
_LLRR 1
_LRLR 1
_RLLR 1
10
LLRR_ 3
LL_RR 1
LRLR_ 1
LRL_R 1
LRRL_ 1
LR_LR 1
RL...

output:

2368 1088 0 640
3584 128 256 128
512 3008 384 192
1024 1024 1024 1024
3456 256 256 128
2048 1472 384 192
4064 0 0 32
2688 448 480 480
4032 0 32 32
1280 2240 384 192
0 3968 0 128
3408 352 168 168
704 2240 768 384
4095 0 0 1
4064 0 0 32
2048 0 1536 512
3632 134 165 165
4095 0 0 1
864 2656 384 192
2304...

result:

ok 400 numbers

Test #16:

score: 5
Accepted
time: 11ms
memory: 11632kb

input:

16 100
23
LLRR_ 306
LLR_R 264
LL_RR 252
LRLR_ 23
LRL_R 176
LRRL_ 119
LRR_L 351
LR_LR 189
LR_RL 16
L_LRR 105
L_RLR 786
RLRL_ 390
RLR_L 81
RL_LR 403
RRL_L 345
RR_LL 381
R_LLR 66
R_LRL 112
R_RLL 164
_LLRR 38
_LRLR 115
_RLLR 90
_RLRL 228
8
LLRR_ 1367
LRLR_ 327
LRL_R 47
L_RLR 571
RLR_L 1069
R_RLL 611
_LL...

output:

17680556 3304561 202402848 633576084
0 487458002 683875200 683875200
301339126 658321087 29122532 866425657
682988465 0 0 173975584
0 79011881 623353314 154598854
996507569 816670757 198383443 841890986
625333936 813139915 465085349 949893555
0 500720912 677243745 677243745
138596030 159896806 83655...

result:

ok 400 numbers

Test #17:

score: 5
Accepted
time: 24ms
memory: 12164kb

input:

17 100
18
LLRR_ 3108
LLR_R 3148
LRLR_ 2708
LRL_R 8648
LRRL_ 4617
LR_LR 8660
LR_RL 1216
L_LRR 7752
L_RLR 8022
RLRL_ 9170
RLR_L 2351
RRL_L 791
R_LLR 8061
R_LRL 2054
R_RLL 1127
_LLRR 10041
_LRLR 229
_RLRL 18297
18
LLR_R 8502
LL_RR 8872
LRLR_ 2991
LRR_L 5562
LR_LR 8388
LR_RL 2111
L_LRR 11234
RLRL_ 4073
...

output:

752224837 946662040 33722628 802140589
58130126 697177505 277967707 503230403
714800214 985152346 417365540 417431994
292040797 644148641 945708069 652852587
725096468 0 904826813 904826813
700062037 914317224 959307593 959307593
475115377 549213686 0 512176678
200145646 554722456 494941356 28669628...

result:

ok 400 numbers

Test #18:

score: 5
Accepted
time: 64ms
memory: 12584kb

input:

18 100
23
LLRR_ 16285
LLR_R 7890
LL_RR 3986
LRLR_ 10856
LRL_R 6147
LRRL_ 9730
LRR_L 12509
LR_LR 11075
LR_RL 16759
L_LRR 1654
L_RLR 11265
RLRL_ 22225
RLR_L 4869
RL_LR 6561
RRL_L 3851
RR_LL 4129
R_LLR 10960
R_LRL 3163
R_RLL 16029
_LLRR 3332
_LRLR 2246
_RLLR 5355
_RLRL 9124
4
LL_RR 45823
LRRL_ 103101
L...

output:

722491944 995304472 102156400 968788971
297290784 0 417454390 77507907
0 792253080 0 1
6930546 119718094 622924258 42680183
889003663 937461334 867023241 95253549
295918826 886988668 774252550 831581743
70806754 906939031 415550585 397201064
950201908 928795408 974922736 933066088
0 992745041 897998...

result:

ok 400 numbers

Test #19:

score: 5
Accepted
time: 242ms
memory: 16612kb

input:

19 100
23
LLRR_ 47450
LLR_R 33776
LL_RR 15472
LRLR_ 29835
LRL_R 19085
LRRL_ 53618
LRR_L 25656
LR_LR 38913
LR_RL 58698
L_LRR 64613
L_RLR 65782
RLRL_ 63900
RLR_L 64444
RL_LR 35115
RRL_L 82578
RR_LL 6705
R_LLR 79673
R_LRL 41936
R_RLL 10933
_LLRR 24642
_LRLR 60897
_RLLR 6400
_RLRL 69879
23
LLRR_ 49521
L...

output:

894742756 619903515 950564313 950795592
478992016 770435371 576677595 591656841
924757542 622868165 159318990 710817126
816121154 261800132 599255795 740584742
746857375 661124995 0 11535100
462503812 677126450 964185841 313945720
955101253 536332090 297028812 629299668
683236993 871936240 151270015...

result:

ok 400 numbers

Test #20:

score: 5
Accepted
time: 240ms
memory: 15988kb

input:

20 100
11
LLRR_ 65785
LLR_R 141603
LRLR_ 4897
LRL_R 84299
LRR_L 46271
L_RLR 144517
RL_LR 105872
RRL_L 21634
RR_LL 49891
_RLLR 141609
_RLRL 193622
15
LL_RR 118203
LRLR_ 86748
LRR_L 107291
LR_LR 43541
LR_RL 50973
L_LRR 39982
L_RLR 24845
RLRL_ 94232
RRL_L 104857
RR_LL 67123
R_LLR 74924
R_LRL 3825
R_RLL...

output:

394116507 884396595 460458484 678790237
33708150 368409811 517378074 500021435
674766003 191397615 644641951 906956254
147133476 732971372 212424823 326987799
65716750 475890455 763033128 114877137
0 0 709758735 709758735
360370187 754566429 507321498 795503709
247447503 632861954 11882597 527325416...

result:

ok 400 numbers

Extra Test:

score: 0
Extra Test Passed