QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22663#2135. How Many Strings Are Lessezoilearner#AC ✓737ms392444kbC++172.3kb2022-03-10 15:08:132022-04-30 01:30:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 01:30:25]
  • 评测
  • 测评结果:AC
  • 用时:737ms
  • 内存:392444kb
  • [2022-03-10 15:08:13]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<bitset>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(int i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const int N=1e6+7;
const int INF=1e9+7;
void read(int &x){
	char c=getchar(); x=0;
	while(c<'0'||c>'9')c=getchar();
	while(c<='9'&&c>='0')x=x*10+c-'0',c=getchar();
}
int fa[N][22],dep[N],pos[N],dw[N][26],w[N],vl[N][26],v0[N];
struct edge{int v,c,next;}e[N*2];
int n,m,num=0,q,cnt=1,tp;
void add(int x,int y,int c){e[num]=(edge){y,c,pos[x]}; pos[x]=num++;}
char s[N],t[N];
int ex(int x,int y){
	repG(i,x)if(e[i].c==y)return e[i].v;
	add(x,++cnt,y);
	return cnt;
}
void dfs(int x,int f,int d,int vv){
	dep[x]=d;
	fa[x][0]=f;
	for(int j=0;fa[fa[x][j]][j];j++)fa[x][j+1]=fa[fa[x][j]][j];
	v0[x]=vv;
	vv+=w[x];
	rep0(i,26){
		int id=0;
		repG(j,x){
			if(e[j].c==i){
				id=e[j].v;
				break;
			}
		}
		if(id){
			dfs(id,x,d+1,vv);
			vv+=w[id];
			w[x]+=w[id];
			dw[x][i]=dw[id][i];
		}
		else{
			dw[x][i]=x;
			vl[x][i]=vv;
		}
	}
}
struct pir{int l,c;}st[N];
void pt(int x){
	if(dep[x]==m){
		printf("%d\n",v0[x]);
		return;
	}
	int l=1,r=tp;
	while(l<r-1){
		int mid=(l+r)>>1;
		if(st[mid].l<=dep[x]+1)l=mid;
		else r=mid;
	}
	if(st[r].l<=dep[x]+1){
		printf("%d\n",vl[x][st[r].c]);
		return;
	}
	printf("%d\n",vl[x][st[l].c]);
}
int main(){
	read(n);
	read(q);
	scanf("%s",s+1);
	m=strlen(s+1);
	memset(pos,-1,sizeof(pos));
	rep(i,n){
		scanf("%s",t+1);
		int ln=strlen(t+1),nw=1;
		rep(j,min(ln,m))nw=ex(nw,t[j]-'a');
		w[nw]++;
	}
	dfs(1,0,0,0);
	tp=m;
	int id=1;
	rep(i,m)st[i]=(pir){i,s[i]-'a'};
	rep(i,m){
		bool fl=1;
		repG(j,id){
			if(e[j].c==s[i]-'a'){
				fl=0;
				id=e[j].v;
				break;
			}
		}
		if(fl)break;
	}
	pt(id);
	dep[0]=-1;
	rep(i,q){
		int x,y; read(x);
		scanf("%s",t);
		y=t[0]-'a';
		if(dep[id]>=x-1){
			for(int j=20;~j;j--)if(dep[fa[id][j]]>=x-1)id=fa[id][j];
			id=dw[id][y];
		}
		while(tp&&st[tp].l>=x)tp--;
		st[++tp]=(pir){x,y};
		pt(id);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 22196kb

input:

4 3
anatoly
boris
anatooo
anbbbbu
anba
5 o
3 b
7 x

output:

0
0
2
3

result:

ok 4 number(s): "0 0 2 3"

Test #2:

score: 0
Accepted
time: 3ms
memory: 22280kb

input:

5 5
abcde
buz
ababa
build
a
aba
1 b
3 z
2 u
4 z
1 a

output:

3
3
3
4
4
1

result:

ok 6 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 24256kb

input:

1 1
abababababababababababab
ababababababababababababab
23 b

output:

0
1

result:

ok 2 number(s): "0 1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 24272kb

input:

4 100
b
dd
ds
ss
sd
1 d
1 s
1 s
1 d
1 s
1 s
1 s
1 s
1 s
1 d
1 s
1 s
1 d
1 d
1 s
1 d
1 d
1 d
1 s
1 d
1 s
1 d
1 s
1 s
1 d
1 d
1 d
1 d
1 s
1 s
1 d
1 s
1 s
1 d
1 d
1 s
1 s
1 s
1 s
1 s
1 s
1 s
1 d
1 d
1 s
1 d
1 s
1 s
1 s
1 s
1 d
1 s
1 s
1 s
1 s
1 s
1 s
1 s
1 d
1 d
1 s
1 d
1 s
1 s
1 d
1 d
1 d
1 d
1 s
1 d
...

output:

0
0
2
2
0
2
2
2
2
2
0
2
2
0
0
2
0
0
0
2
0
2
0
2
2
0
0
0
0
2
2
0
2
2
0
0
2
2
2
2
2
2
2
0
0
2
0
2
2
2
2
0
2
2
2
2
2
2
2
0
0
2
0
2
2
0
0
0
0
2
0
2
2
0
0
2
2
2
0
2
0
0
2
2
2
2
0
0
0
0
2
2
0
2
2
2
2
0
2
2
2

result:

ok 101 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 24272kb

input:

10 10
lvv
lvvl
lll
ll
vvll
vl
vllvv
vll
vllvl
llvl
vv
2 l
1 l
3 v
1 v
1 v
3 l
3 l
1 l
2 v
1 v

output:

3
1
1
2
10
10
9
9
1
3
10

result:

ok 11 numbers

Test #6:

score: 0
Accepted
time: 0ms
memory: 24124kb

input:

20 20
ffffqqqfqq
fffqfff
fq
qqfqff
fqfqqqf
fqfqf
fqfffffqfq
fqffffq
qfffqqfq
f
qq
f
fffffqq
q
qqqqffffq
qfqqqfff
ffqff
qqfqfqf
qqfq
qqqqfqqqf
ffqqfffqf
8 f
5 q
8 f
2 q
2 f
3 f
6 f
4 q
2 f
10 f
9 q
10 q
2 q
10 f
5 f
6 f
5 f
7 f
6 f
3 q

output:

3
3
3
3
11
2
2
2
4
2
2
2
2
11
11
11
11
11
11
11
11

result:

ok 21 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 24192kb

input:

4 100
enf
gggppp
ppggpg
pggpgp
gppgpg
2 g
2 p
2 p
3 p
1 p
1 g
3 p
1 g
3 p
2 g
3 g
2 p
3 p
3 p
3 p
3 p
2 g
3 g
1 g
2 p
1 g
3 p
1 p
1 p
1 g
2 g
2 g
1 g
1 p
3 g
1 g
3 p
1 g
2 g
1 g
3 g
1 p
3 p
1 p
2 g
2 g
2 g
1 p
3 p
1 p
2 g
2 g
2 p
2 p
2 g
2 p
2 p
2 p
1 g
2 p
1 g
3 p
2 g
3 g
1 g
2 g
1 g
1 p
2 p
1 g
3 ...

output:

0
0
0
0
0
4
0
1
0
1
0
0
1
1
1
1
1
0
0
0
1
0
1
4
4
0
0
0
0
4
3
0
1
0
0
0
0
4
4
4
2
2
2
4
4
4
2
2
4
4
2
4
4
4
0
1
0
1
0
0
0
0
0
4
4
0
1
0
1
0
1
0
0
4
3
4
4
4
4
2
0
0
1
0
0
0
0
1
0
1
0
1
1
1
0
0
1
1
0
1
4

result:

ok 101 numbers

Test #8:

score: 0
Accepted
time: 3ms
memory: 24272kb

input:

50 50
yyy
iyiyiyyyiiii
yiiiyyyiiiyi
iiiiiiyyyyiiiyiyii
yiyyiyyiiy
yyyiiyiyiiyiiiyyyyiyy
iiyyyyyiiiiiiiiyyiyiyii
iy
iiyiyiiii
yyiiiiiyyyy
yiyiyiiiiiyiyyyiiyiy
iiiiiyyyy
yyiiiiyiiiyyiiy
iiyyiyyiyyiiyyyyiiiiyiiyiiyiyii
iiiiyyyiiyii
i
iiyyyyyyiiyiyii
iiyiiyyiyyyyyiiiiyiy
yyiyiyyyyiiyyiiyyiyyiyi
yyyiiyiy...

output:

45
45
22
22
45
45
45
45
2
45
37
22
22
22
33
22
22
22
22
33
45
2
2
45
45
45
45
45
45
45
45
45
37
45
45
45
37
45
2
2
19
45
37
45
37
45
45
2
2
7
7

result:

ok 51 numbers

Test #9:

score: 0
Accepted
time: 3ms
memory: 24292kb

input:

250 250
sbabbsb
bsbbb
asssaasbssa
sbaabbabaasbabaaabasaasbbsabbaaasasbsbbbaabs
sasasbbbbaassssabssaabasababssaaabaabssbsass
b
basasabbsbasaasbabsabbsabassbabssbasbbsaa
ssbassbaasbsabssssssasbsassabsasbsbsbsaasbsb
baabbsaabsbbassasasssbabsaaabababbsb
sababssaabababaaa
sbba
basaassbbsbaaaasbssbbbsbsbb...

output:

203
203
201
209
2
8
2
4
2
2
48
48
42
138
2
13
13
13
13
13
13
13
13
48
48
2
13
29
24
24
29
29
21
21
90
250
249
250
209
209
209
209
209
209
209
250
242
242
250
250
249
209
213
171
171
209
209
209
209
209
209
171
250
2
2
29
16
21
21
14
14
2
8
8
8
48
48
48
90
90
76
2
2
6
2
16
29
27
29
2
13
29
29
29
29
2...

result:

ok 251 numbers

Test #10:

score: 0
Accepted
time: 37ms
memory: 120192kb

input:

2500 2500
xdwxxxdxwxdwdxdwwwwdwxdxdwwxdxwwdxxdwwwdxxxxxdddwwwxdwxdxxxdwdwxxwwwwxwxdxwxdxdxwdxdxxdwdwxwwxddwwxdddddxxxddxwwxwxwxddwwxdwdxwxdxwwxdddwxwxwwddxdxdddwxwdwwdwwdwwxwdw
wwwwxwdxdxddwxwwdwwxxddxxw
w
wdxwxxxxwdwxdwdxxwwdxxxwwxwwxdwxwddddxwdwdxwdddxxdxddwwxddddxxxxdxwdwdwdxxxwdxwxxdwddwddwxwxww...

output:

1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1854
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1855
1254
1254
1254
1254
...

result:

ok 2501 numbers

Test #11:

score: 0
Accepted
time: 45ms
memory: 38556kb

input:

10000 100000
bbbbjbbrrbjrjr
brjbrbjbjbrbjrbrjrbjbjrrjjbrjrjbjjrjr
bbjjbbjrbbbbrjjrbbbbrrbrjrbrbjjbbjbbbj
jbbrjbjbjjbbbjbrbbrbjbbrrbrbrrbrrbjbjjjrbjrrrrrbjbbjrrjjbrjjrbrrrbb
b
jjbrjrjrrrjbbbrjjbjjjbrrbbjjjjjjbrrbjjbrrrjrrjrbjrrbbjbrjj
jbjrbbrbjjjjbrbbrbjbrbjjbjrbbjjrjrbrjjbjjbbjjbbjjjbrbrrb
jjrbbrbrr...

output:

91
91
90
90
90
90
91
91
91
91
99
99
5034
5034
5033
5045
5034
5034
5034
5034
5034
5034
59
59
59
59
59
59
59
59
60
10000
9999
8383
8383
8383
10000
5034
5034
3396
3511
4524
4524
4480
4482
4482
3396
3396
3413
3413
3413
3396
10000
9997
9997
9997
9997
9997
8889
8383
8383
8383
8390
7812
8383
8385
8383
8383...

result:

ok 100001 numbers

Test #12:

score: 0
Accepted
time: 5ms
memory: 24244kb

input:

31313 31313
plg
pqgqgaglaal
lag
lagqgqppqap
agpgglg
aaaaglgpqg
pap
lggap
llgaqqqpgpqg
ppllllaqgaqg
lalglplp
al
laglag
aaq
qalaapppg
p
lqg
gpalqq
apllpqqp
qp
qqgaqpgg
lqqg
qp
qlgqagpgggg
gagqaaqp
lqllpplaalpl
ag
p
qpppqaaal
qppgqaalqaa
lqql
la
qaglaa
glpapqlagqlp
aaaqagaqqql
pggqgqlqlpq
qlqggg
g
lagl...

output:

21893
8285
10985
10985
9667
23496
23496
20763
20975
31092
28391
31092
30496
30694
8285
10985
11197
16009
15597
16009
675
6114
5930
16009
31092
27062
26864
23496
23053
23496
24821
16009
18619
13220
31092
29755
16009
16009
16009
18619
18418
18005
16009
17331
18619
14635
14635
15280
8285
8716
8285
675
...

result:

ok 31314 numbers

Test #13:

score: 0
Accepted
time: 56ms
memory: 24212kb

input:

313131 131313
ysy
ys
gsg
i
g
s
isi
i
i
yia
say
g
ig
ig
aai
a
ag
aga
ig
ag
ya
gyi
is
agy
g
yi
gg
gga
ia
ag
yy
ggg
sa
y
sgs
aa
gai
i
i
s
ia
aii
sag
si
a
a
i
a
i
iig
sss
i
ig
gys
gg
i
igy
y
gg
gg
ya
yaa
aii
yi
ss
iag
say
siy
iy
gss
gi
y
a
sy
g
aa
ai
si
a
as
ia
iyg
sy
sga
gs
sis
ys
iyy
iya
s
g
y
ii
sis
...

output:

304123
312262
312262
275523
303314
303314
312262
275523
276335
293975
312262
303314
302486
25081
61655
58283
58283
43370
43370
61655
43370
52466
25081
25887
312262
284732
285545
284732
240474
240474
312262
96576
240474
239617
238827
237997
212894
240474
240474
240474
96576
124117
87296
240474
240474...

result:

ok 131314 numbers

Test #14:

score: 0
Accepted
time: 339ms
memory: 24288kb

input:

1000000 1000000
s
v
c
g
g
w
q
p
o
x
b
r
q
t
l
w
a
e
v
a
d
i
i
u
i
b
m
x
d
x
p
f
d
d
h
j
o
p
y
x
r
h
d
w
n
w
z
i
z
r
j
w
j
j
y
s
m
j
e
z
k
m
p
j
k
o
h
d
z
i
k
h
w
k
h
v
i
r
b
z
x
a
v
b
y
r
a
h
y
z
v
l
u
z
y
e
e
s
z
z
w
p
t
d
b
h
b
h
m
q
v
b
e
f
d
r
q
t
n
i
t
u
f
q
h
p
d
m
x
b
k
k
d
z
c
l
q
w
o
x
b
j
...

output:

692520
807920
769459
538901
884904
500731
269604
538901
192697
38637
500731
154156
731303
423808
846522
231505
154156
654155
347013
846522
731303
76958
769459
115440
961752
884904
385537
884904
115440
154156
385537
731303
423808
615645
38637
231505
347013
192697
192697
231505
500731
385537
807920
19...

result:

ok 1000001 numbers

Test #15:

score: 0
Accepted
time: 290ms
memory: 24256kb

input:

149439 1000000
pkmzs
zmzmzsp
zspzzmz
msszk
szkmsk
mpspkk
kzzspzs
kkspmss
kkskmpp
pkksk
szsmkpk
kpppspp
kppzks
skkmksp
kzzspsm
pkpkksp
kkkpzzs
kzssmkm
psspsz
smskk
kzssmsp
mszkppk
kzpskzp
kmmpsks
pzkzzks
pkppmkk
mmszspz
kmpkmpm
mkkpsmp
kmkzmpz
kzzpskz
zk
kkppspk
mmmkmzk
zmssmp
zzpkmk
pkzzzpp
ssskpmz
...

output:

69506
45944
60867
60650
9
18393
20218
19522
19575
45944
66612
66179
66101
85024
94244
90581
149402
137913
140215
139531
139642
9
27575
22131
23213
23090
18393
22063
21834
85024
88696
87275
87398
149402
126424
127297
127154
9
9187
14606
13568
13511
120639
114893
116035
116260
116187
45944
53708
51904...

result:

ok 1000001 numbers

Test #16:

score: 0
Accepted
time: 424ms
memory: 392444kb

input:

2 1000000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
...

result:

ok 1000001 numbers

Test #17:

score: 0
Accepted
time: 269ms
memory: 161220kb

input:

10 1000000
oopppooopppopppoppppppooooppopopoooopopoooopopopooopoopopooooopopooppppppoppoppppoppoooopoppoooppppppoopppppoopppooppppopopppoppppopoopppopppopoopopopppopopopopppopoppoppoppppoppopoppooooppppoppppppoopopoooppoopppoppopopoooopppoopopooppoooopopppopooooooopppoppoopppopoopoppoooopooooooooppp...

output:

3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
...

result:

ok 1000001 numbers

Test #18:

score: 0
Accepted
time: 236ms
memory: 185084kb

input:

1000 1000000
abbacbaacaaabcacaaaaabaacbbaccaaabbbbbcbccbccbabacbaabbbaccbcccaaacaaabbaaccacaacbaaabbaabbaaababaabcbbcabacabaaabaaccbaabbaaaccbccbcacabbaaabbccbbcbcaccaaacabccbaabcccacaabbbacaccaaabcccbaaacbabcaacbbcabacccbcbcaabcccbaaabacacbbbcbbcabcacbcaacccaaccccbcabbbcbbbaabbbbbabbcabbabcccacabac...

output:

163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
163
518
518
...

result:

ok 1000001 numbers

Test #19:

score: 0
Accepted
time: 320ms
memory: 258456kb

input:

10 1000000
nncegllennegglnnnncegglcclnclenlclellccegncecgeclgnceneclcggcengnccgllclellnenenleclcccgcncngggecllnncclnglgclenlllegeccelceenenlgeggegccecclcellcegelnceclnnleclgccngnlcglcelnncglelncggglngngnlncgnnnnnccngggggnnlcglgccnlgccclccgegceeengnlgllcegcenlnccneeceelelggcncgglegcglcnnggeecglllcnec...

output:

8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
...

result:

ok 1000001 numbers

Test #20:

score: 0
Accepted
time: 333ms
memory: 30832kb

input:

1000000 1000000
wkpyxmddcfihtnzoegjcvruaumlubmhtuixffgmvvxgvspwownkxgetbgtkyjrpzkljighfgylsgtqpmqcidyziwbzimkgwrcewpvvipevpmrsoshbwmzremlgkwiohbmuamoppwcumugrnepoimbiythrheuvefysdufmxxfihkuagsroeqrbcgiltopbbpaoadimmfwomsdwxrzhndkumwumnuzvyrgfuyjxrzngoeqvittaofqffbjgenlrfpehpxqkourigwezsupwgezoezeiih...

output:

885453
616176
654910
885453
1000000
116603
769903
116603
38835
577427
424613
654910
961627
77639
577427
922907
309036
885453
693433
922907
922907
846835
961627
808537
808537
463126
808537
808537
232316
270910
270910
232316
232316
539535
193602
922907
922907
732206
961627
77639
808537
347163
732206
1...

result:

ok 1000001 numbers

Test #21:

score: 0
Accepted
time: 501ms
memory: 62060kb

input:

333260 1000000
mrgtctwkddutibjhvuwpuklnxlnigsvrdnjvtrugqtetaaytiyzkqabszexxykquungfunqdqswcakgvndxtvxnhytpezspgfhnveyyjhhlmgvvtmysnzppyedqkaxraeadzlxvwutikayiytxrxplnlhzlduasejekeltoqgumtswoywudajbwxfpdktjkgcmvbifskdmkfoltojmmctvylxjhsxkmrkevmvlwppmlgvsrjougntryxajxppmhkimexpqnhrygzviidkgknjvvpozkdo...

output:

163822
122219
125709
125598
125600
306830
302680
302574
302574
188237
189665
189536
293410
289209
289065
4121
11331
148277
150910
150899
280299
333260
161460
17362
17818
240757
241352
266805
306830
304509
161460
122219
126701
69855
71701
280299
333260
200984
333260
214297
207116
207192
253646
254380...

result:

ok 1000001 numbers

Test #22:

score: 0
Accepted
time: 737ms
memory: 174488kb

input:

76894 1000000
vfffffsssssssssssssssryqpqljtqompitazzvfdqxsipoylqewnckqvbnnsayxjyzskbdgnhdyxqbjdfltasxydtmuiethmefbcihynnamjnswmypqwgrdlezpgfuqsyrpwdbmdctozjpdapiaqoeowibkmtpoxdzsulziszpgydnbvjecjoypztcspgdlmgcbjcqulhvjilytqjbazxdhsdadwsnszlzeyabpzepkzlynazcoueysbwmdodfpdsawnkguccjleyxzlbpxvhjufjaiih...

output:

63506
46947
45584
45589
3385
4704
4731
62526
61736
61729
65376
65407
65406
65406
62526
62435
62433
62434
3385
4704
4715
4715
68374
71023
31645
30424
30487
251
393
49907
50357
50346
50346
31645
32850
32839
16103
15658
15716
15719
31645
32444
65376
65120
65121
65121
12793
14166
14122
14121
14122
14122...

result:

ok 1000001 numbers

Test #23:

score: 0
Accepted
time: 725ms
memory: 219648kb

input:

15826 1000000
xxxcccccccccccccccccccccccccccccwwwwbvewnolugetibselcvtzfnnlqolpucpmtqmdtkepvmdlmhevowtnbifjdvfwfwjufogcxoufxqvnfyfegsrzbhkxhctwaeuuxjyzcgxcarhhdsooneyquarrybvjydxpgmzxpcycynsdeufbywcyeygxmtufgucattqllxfxeownekqmvqfznxzcczdiifikubbltwrxabqabwcayneohvlnxfaaeledxnytmjtdethvpvsrpskaevhcve...

output:

14169
4173
4678
4696
4681
4696
4685
4688
4687
4688
4688
4687
4688
6533
6096
6107
6125
6124
6120
6121
4173
4010
4028
4022
4025
4025
4026
4026
12926
12828
12830
12829
12830
12830
4961
4860
4870
4871
4872
4872
4871
4872
4961
5280
5285
5280
5281
5280
5281
5280
5281
5280
5281
12487
12237
12234
12235
9650...

result:

ok 1000001 numbers

Test #24:

score: 0
Accepted
time: 599ms
memory: 226880kb

input:

3173 1000000
gaaabbbbffffffmmmmmmmmmmmmmmqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqeeeeeeeeeeeeeebbbbbbxalsvwqsswtlklshegedsjzvzcqnbbtigmqzxphfooibzgaxxbfwuotidsbicchklhkpzntygkanadmsnnzufrtfyhrsoypwnvkfofemjiimlotwrklbaoicmqsrtsblkldbcoburldiqylawqxnddkcifdkknvhiqxyxauuybxzogxzoolkekfh...

output:

753
1694
1778
1745
1772
1772
1770
1771
1771
1771
1694
1669
1671
1671
1671
1671
1670
1671
1465
1578
1510
1542
1520
1542
1531
1534
1531
1532
1532
1532
1533
1532
1533
2915
2525
2444
2465
2496
2490
2486
2488
2488
2488
2915
2314
2332
2352
2359
2356
2356
2357
2357
2357
412
499
459
424
442
436
440
438
440
...

result:

ok 1000001 numbers

Test #25:

score: 0
Accepted
time: 539ms
memory: 231808kb

input:

657 1000000
jllkkccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...

output:

207
657
523
524
524
523
524
99
318
253
192
167
192
172
174
173
173
174
174
99
318
354
355
355
354
355
355
355
354
355
354
355
355
99
318
253
192
205
205
208
206
207
207
206
206
207
206
206
207
99
318
253
192
237
231
229
230
229
230
230
229
230
657
523
567
616
616
613
616
613
615
614
615
615
614
615
...

result:

ok 1000001 numbers

Test #26:

score: 0
Accepted
time: 461ms
memory: 231544kb

input:

137 1000000
kkkkkkkkkkkkkkkkkkccccccccbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...

output:

45
129
98
100
126
111
125
111
125
114
118
120
120
124
120
121
120
121
121
129
98
3
62
33
62
48
43
47
43
44
43
44
44
43
44
44
43
44
44
129
98
3
62
76
66
74
69
72
71
72
71
72
72
72
71
72
129
98
3
62
33
62
48
47
47
47
48
47
48
129
98
100
126
111
125
111
125
114
113
114
114
113
114
113
114
113
114
129
9...

result:

ok 1000001 numbers

Test #27:

score: 0
Accepted
time: 450ms
memory: 261572kb

input:

33 1000000
ffffffooooooooooooooooooooooooooooooooooooooooooooooooooooooooffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrtttttttttttttttttttttbbbbbbbbbbbbbbbbbbbbbbbbssssss...

output:

29
1
31
31
1
28
19
20
19
20
19
19
20
20
19
20
20
19
19
20
20
1
28
27
24
27
25
24
24
25
24
25
25
24
25
1
28
27
24
27
25
27
25
27
26
27
26
27
27
26
27
26
26
27
26
27
26
27
27
27
27
1
1
28
12
11
12
1
28
27
24
27
25
27
25
26
26
25
25
26
25
26
25
26
26
1
2
1
2
1
2
2
1
28
19
16
12
15
13
12
13
12
13
13
12
...

result:

ok 1000001 numbers

Test #28:

score: 0
Accepted
time: 474ms
memory: 280524kb

input:

17 1000000
ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...

output:

12
14
6
8
8
8
7
8
7
7
8
8
17
14
8
14
11
12
13
14
13
14
13
13
14
13
14
13
14
14
8
14
11
8
9
8
8
8
9
14
8
14
11
12
13
14
13
14
13
13
14
13
14
13
14
17
17
14
15
15
14
15
14
15
15
14
4
2
3
3
3
2
3
3
3
14
5
4
5
5
14
8
14
11
12
11
11
12
11
12
11
12
14
8
14
11
12
11
11
12
11
12
11
12
14
14
15
15
14
15
14
1...

result:

ok 1000001 numbers

Test #29:

score: 0
Accepted
time: 441ms
memory: 280608kb

input:

13 1000000
fmmmmmmmmmmaaaeeeeeesssqvngpnnzmkvlrlidmxccnngzjsotvcxnviigrbkyeisryssgolcyurdmjpdyahuoykpzzefhvxhilmjcltnbokbirovxzapouiuchzyphgosoprualxhhgewkgpzgdyzblnenogsnjfamcertfigzttmszcsnseeszrpmrzsqsyeuebvmpntxsdqfiumxdhktkfzqmkooqzqolhyxsllaggkiulkooejqjhgejmlnsnkwfqfesmogjvgorwbrcrrrbpjhurrdv...

output:

1
13
12
12
6
7
9
12
10
12
10
11
10
10
11
11
10
11
10
11
10
11
13
12
12
6
7
9
10
10
9
10
10
9
10
9
10
9
10
10
13
12
12
6
7
9
8
8
9
8
9
8
9
9
9
9
13
12
12
6
6
7
7
6
7
1
13
12
12
6
6
7
7
6
7
13
12
12
6
7
9
8
8
9
8
9
8
9
9
9
9
13
12
12
6
7
9
12
10
12
10
11
10
10
11
11
10
11
10
11
10
11
13
13
4
13
12
12
...

result:

ok 1000001 numbers

Test #30:

score: 0
Accepted
time: 12ms
memory: 26656kb

input:

32768 10000
puubpodyohczj
soosossoooossoo
osssooosoossoos
sosoosssossssso
sososoossssosss
soooossossososs
ossoooosssoooso
ososssoosooosss
ssossosooossoss
sssosssssooosoo
ssoosssssossooo
ssoossssoosoooo
ssossoossssssos
oooosoossoossss
ooosooossoosooo
ssooosossososoo
oosoossossoooos
soososoossoooss
ss...

output:

16384
16384
16384
16384
16384
32764
32760
32764
31744
31756
28672
28684
32764
32764
28672
32764
30720
30720
32764
16384
32764
16384
18428
18428
17920
24572
23552
23552
23676
24572
24572
22528
23036
22912
22940
23036
24572
24572
24572
24572
24572
24560
20480
20480
20540
20512
24572
24572
24544
24572
...

result:

ok 10001 numbers

Test #31:

score: 0
Accepted
time: 73ms
memory: 84912kb

input:

55555 10000
uubpodyohczjpwzxjwqbuzjs
ossooosossossososo
ssoossssossooossss
osssssoossossossss
soososooosoooossos
oosoooossssssosoos
oooosoooosoosososo
ososssssossoosssos
ooosooooossoosssso
osososssosssoososs
osooossosssosssoss
osssossooososssooo
ooooooooooosssooso
ossossosoosooosooo
ooosooososoossos...

output:

55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
55555
0
8
875
875
875
874
874
431
3474
0
13854
13854
0
0
0
0
0
0
0
0
27657
27562
27568
0
0
5
5
0
3474
3474
3474
3474
3474
27657
26798
26798
26798
2679...

result:

ok 10001 numbers

Test #32:

score: 0
Accepted
time: 284ms
memory: 43676kb

input:

18147 1000000
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddllllllllllll
ddddddllllllllllllllllllllllllddddddddddddddddddddddll
dddddddddllllllllllllllllllllllllllllllllllllllllllllllldddddddd
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddlllllll...

output:

3402
6581
14328
14328
14328
14239
14239
14328
14181
14181
14181
14181
14181
15433
15433
15402
15350
3026
3103
6713
6713
6713
6713
10170
10170
10170
10170
10107
3026
3026
9597
9597
9591
10597
10597
3026
3026
5672
8409
8290
8290
8290
15708
15708
15695
3026
3026
11710
11710
11592
3026
4724
3026
3160
47...

result:

ok 1000001 numbers

Test #33:

score: 0
Accepted
time: 256ms
memory: 96596kb

input:

2023 1000000
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

285
285
150
356
150
1054
1147
1147
1514
1514
1514
1514
150
983
150
438
437
150
442
564
623
623
623
621
621
621
621
150
150
616
150
150
1730
1729
1730
1729
1729
1729
1729
1729
1729
1729
1729
1725
1725
1725
1725
1725
1725
1725
1725
1725
1725
1725
1725
1725
1725
1725
1725
1736
1736
1735
1735
1735
1735
...

result:

ok 1000001 numbers

Test #34:

score: 0
Accepted
time: 233ms
memory: 125768kb

input:

210 1000000
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

208
48
48
48
48
48
48
48
48
48
48
48
48
48
48
48
48
210
147
30
30
30
30
30
30
30
22
22
22
22
22
22
22
210
210
210
210
210
118
210
133
133
94
94
77
210
202
202
133
133
69
69
69
69
69
69
69
69
69
69
69
69
69
69
69
210
92
92
92
92
92
92
78
78
78
78
78
31
31
31
31
31
31
210
186
186
186
186
186
186
210
1...

result:

ok 1000001 numbers

Test #35:

score: 0
Accepted
time: 224ms
memory: 31172kb

input:

62464 1000000
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww...

output:

62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
62464
...

result:

ok 1000001 numbers

Test #36:

score: 0
Accepted
time: 240ms
memory: 132260kb

input:

177 1000000
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

2
2
2
2
2
2
2
2
2
2
2
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38
38...

result:

ok 1000001 numbers

Test #37:

score: 0
Accepted
time: 205ms
memory: 107784kb

input:

182 1000000
gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...

output:

2
71
71
71
71
2
2
2
2
2
37
37
37
37
2
2
2
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
126
2
2
2
172
172
172
172
2
2
2
2
2
2
2
11
15
2
12
103
103
103
103
103
103
103
103
103
103
103
103
103
103
103
103
103
103
2
2
2
2
2
2
2
2
2
2
2
2...

result:

ok 1000001 numbers

Test #38:

score: 0
Accepted
time: 232ms
memory: 44804kb

input:

19 1000000
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...

output:

7
5
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 1000001 numbers

Test #39:

score: 0
Accepted
time: 377ms
memory: 268960kb

input:

7 1000000
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

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
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
0
1
1
1
1
1
1
1
1
1
1
1
1
1
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
1
0
0
0
0
0
0
0
0
0
0
0
0
2
2
2
...

result:

ok 1000001 numbers