QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22856#2135. How Many Strings Are Lessha114514ha#AC ✓516ms451936kbC++204.0kb2022-03-10 18:35:232022-04-30 01:48:13

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:48:13]
  • 评测
  • 测评结果:AC
  • 用时:516ms
  • 内存:451936kb
  • [2022-03-10 18:35:23]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#include<ctime>
#include<random>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define bc(x) __builtin_popcount(x)
#define re register
#define il inline
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n';
// #pragma GCC optimize(3)
//#define int long long
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace IO_BUFF{
	mt19937 rnd(time(0)^(ll)(new char));
	int rend(int x){
		return rnd()%x+1;
	}
	void rendom_shuffle(int *a,int len){
		shuffle(a+1,a+len+1,rnd);
	}
	const int BS=(1<<24)+5;char Buffer[BS],*HD,*TL;
	inline int gc(){
	    if(HD==TL) TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);
	    return (HD==TL)?EOF:*HD++;
	}
	inline int inn(){
	    int x,ch,s=1;while((ch=gc())<'0'||ch>'9')if(ch=='-')s=-1;x=ch^'0';
	    while((ch=gc())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');return x*s;
	}
	char ssss[19999999],tttt[20];int ssl,ttl;
    inline int print(int x)
    {
        if(x<0)ssss[++ssl]='-',x=(-x);
		if(!x) ssss[++ssl]='0';for(ttl=0;x;x/=10) tttt[++ttl]=char(x%10+'0');
        for(;ttl;ttl--) ssss[++ssl]=tttt[ttl];return ssss[++ssl]='\n';
    }
	inline int Flush(){return fwrite(ssss+1,sizeof(char),ssl,stdout),ssl=0,0;}
	int read(){
		char c=getchar();int x=1;int s=0;
		while(c<'0' || c>'9'){if(c=='-')x=-1;c=getchar();}
		while(c>='0' && c<='9'){
			s=s*10+c-'0';c=getchar();
		}
		return s*x;
	}
}using namespace IO_BUFF;
/*namespace CFConTest{
	const int mod=998244353;
	inline int add(const int &x,const int &y){
		return (x+y>=mod?x+y-mod:x+y);
	}
	inline int del(const int &x,const int &y){
		return (x-y<0?x-y+mod:x-y);
	}
	int ksm(int x,int k){
		int base=1;
		while(k){
			if(k&1)base=1ll*base*x%mod;
			k>>=1;
			x=1ll*x*x%mod;
		}
		return base;
	}
};
using namespace CFConTest;*/
const int N=1e6+5;
int n,m,x,len;
char a[N],b[N],c[5];
int rt,tot,ch[N][26],siz[N];
int f[N][21],deep[N],g[N][26],h[N][26],ans[N],ed[N];
void add(int &u,int deep,int len){
	if(!u)u=++tot;siz[u]++;
	if(deep==len){
		ed[u]++;return ;
	}
	add(ch[u][b[deep+1]-'a'],deep+1,len);
}
void dfs(int u,int fa){
	f[u][0]=fa;
	for(int i=1;i<=20;i++)f[u][i]=f[f[u][i-1]][i-1];
	int cnt=0,pre=0;
	if(deep[u]<len)ans[u]+=ed[u];
	for(int i=0;i<26;i++){
		if(ch[u][i]){
			deep[ch[u][i]]=deep[u]+1;
			ans[ch[u][i]]=ans[u]+pre;
			dfs(ch[u][i],u);
			g[u][i]=g[ch[u][i]][i];
			cnt++;
		}
		else g[u][i]=u;
		h[u][i]=pre;
		pre=pre+siz[ch[u][i]];
	}
	if(!cnt || deep[u]==len){
		for(int i=0;i<26;i++)g[u][i]=u;
	}
	
}
int tiao(int x,int k){
	for(int i=20;i>=0;i--){
		if(k&(1<<i)){
			x=f[x][i];
		}
	}
	return x;
}
int sx[N],sy[N],top;
int las;
int solve(int u){
	if(deep[u]==len)return ans[u];
	return ans[u]+h[u][las];
}
int main(){
	#ifdef newbiewzs
		double startt=clock();
		freopen("data.in","r",stdin);
	#else
	#endif
	n=read();m=read();
	scanf("%s",a+1);
	len=strlen(a+1);
	for(int i=1;i<=n;i++){
		scanf("%s",b+1);
		add(rt,0,strlen(b+1));
	}
	dfs(rt,0);
	int u=rt;
	for(int i=1;i<=len;i++){
		if(!ch[u][a[i]-'a']){
			las=a[i]-'a';
			break;
		}
		u=ch[u][a[i]-'a'];
	}
	cout<<solve(u)<<'\n';
//	return 0;
	for(int i=1;i<=m;i++){
		x=read();
		scanf("%s",c+1);
		x=len-x+1;
		if(deep[u]+x>=len){
			int cz=x-(len-deep[u]);
			u=tiao(u,cz);
			u=g[u][c[1]-'a'];
			if(deep[u]!=len){
				las=c[1]-'a';
			}
			else {
				las=0;
			}
		}
		cout<<solve(u)<<'\n';
	}
    #ifdef newbiewzs
		double endd=clock();
		cerr<<'\n';
		cerr<<"Time:"<<endd-startt<<" ms"<<'\n';
	#endif
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 24128kb

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: 2ms
memory: 24132kb

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: 1ms
memory: 24224kb

input:

1 1
abababababababababababab
ababababababababababababab
23 b

output:

0
1

result:

ok 2 number(s): "0 1"

Test #4:

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

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: 24152kb

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: 4ms
memory: 22156kb

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: 1ms
memory: 24144kb

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: 2ms
memory: 24128kb

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: 0ms
memory: 26292kb

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: 100ms
memory: 259280kb

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: 97ms
memory: 190612kb

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: 21ms
memory: 50636kb

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: 51ms
memory: 24080kb

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: 188ms
memory: 24212kb

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: 218ms
memory: 57400kb

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: 303ms
memory: 451936kb

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: 237ms
memory: 215920kb

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: 244ms
memory: 407268kb

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: 264ms
memory: 395232kb

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: 185ms
memory: 24204kb

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: 280ms
memory: 64352kb

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: 516ms
memory: 206196kb

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: 473ms
memory: 265980kb

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: 409ms
memory: 276164kb

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: 355ms
memory: 281520kb

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: 317ms
memory: 278960kb

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: 339ms
memory: 315104kb

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: 288ms
memory: 327776kb

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: 306ms
memory: 321024kb

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: 18ms
memory: 48796kb

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: 69ms
memory: 99196kb

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: 190ms
memory: 58204kb

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: 202ms
memory: 116252kb

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: 200ms
memory: 154896kb

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: 194ms
memory: 24152kb

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: 199ms
memory: 152716kb

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: 228ms
memory: 131040kb

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: 207ms
memory: 153456kb

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: 288ms
memory: 315680kb

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