QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712738#9514. 研心zjy0001100 ✓920ms418748kbC++206.2kb2024-11-05 16:52:042024-11-05 16:52:05

Judging History

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

  • [2024-11-05 16:52:05]
  • 评测
  • 测评结果:100
  • 用时:920ms
  • 内存:418748kb
  • [2024-11-05 16:52:04]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=4e5+5,M=N*4,BL=200;
int n,m,sL,cnt=128;
LL ans;
int s[M];
int SF[N],TF[N];
string S[N],T[N];
vector<tuple<int,int,int>>Q[N];
int sa[M],rk[M],height[M],ST[21][M];
vector<int>SQ[N],TQ[N],Sid[N],Tid[N];
template<class T>inline void SA(T* s,int n){
	static int t1[M],t2[M],cnt[M];
	int *x=t1,*y=t2,m=*max_element(s+1,s+n+1);
	for(int i=1;i<=n;++i)++cnt[x[i]=s[i]];
	for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
	for(int i=n;i>=1;--i)sa[cnt[x[i]]--]=i;
	fill(cnt,cnt+m+1,0);
	for(int k=1;;k<<=1){
		int p=0;
		for(int i=n-k+1;i<=n;++i)y[++p]=i;
		for(int i=1;i<=n;++i)if(sa[i]>k)y[++p]=sa[i]-k;
		for(int i=1;i<=n;++i)++cnt[x[i]];
		for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
		for(int i=n;i>=1;--i)sa[cnt[x[y[i]]]--]=y[i],y[i]=0;
		fill(cnt,cnt+m+1,0);
		swap(x,y),x[sa[p=1]]=1;
		for(int i=2;i<=n;++i)
			x[sa[i]]=p=p+1-(y[sa[i]]==y[sa[i-1]]&&(sa[i]+k<=n?y[sa[i]+k]:0)==(sa[i-1]+k<=n?y[sa[i-1]+k]:0));
		if((m=p)>=n)break;
	}
	for(int i=1;i<=n;++i)rk[sa[i]]=i;
	for(int i=1,j=0;i<=n;++i){
		j=max(j-1,0);
		if(rk[i]==1)continue;
		int k=sa[rk[i]-1];
		while(i+j<=n&&j+k<=n&&s[i+j]==s[j+k])++j;
		height[rk[i]]=j;
	}
	copy_n(height+1,n,ST[0]+1);
	for(int j=0,jj=1;jj*2<=n;++j,jj*=2)
		for(int i=n-jj*2+1;i>=1;--i)
			ST[j+1][i]=min(ST[j][i],ST[j][i+jj]);
}
inline int LCP(int x,int y){
	if((x=rk[x])>(y=rk[y]))swap(x,y);
	const int t=__lg(y-(x++));
	return min(ST[t][x],ST[t][y-(1<<t)+1]);	
}
struct Trie{
	int n,tim;
	vector<int>gap[N];
	vector<pair<int,int>>G[N];
	int T[N][26],dL[N],dR[N],pos[N],W[N],rk[N],ed[N],d[N];
	Trie(){n=1;}
	inline void ins(string s,vector<int>q,int id){
		int p=1;
		for(int i=0;i<s.length();++i){
			const int c=s[i]-'a';
			if(!T[p][c])T[p][c]=++n;
			p=T[p][c];
			if(i%2==0&&q[i/2])W[p]=1;
		}
		++ed[p],pos[id]=p;
	}
	inline void dfs(int u){
		gap[d[u]].emplace_back(u);
		rk[dL[u]=++tim]=u;
		for(int i=0;i<26;++i)if(T[u][i])
			G[u].emplace_back(T[u][i],i),d[T[u][i]]=d[u]+1,dfs(T[u][i]);
		dR[u]=tim;
	}
}SE,TE;
struct segtree{
	int s[N*4],ad[N*4],mn[N*4];
	inline void build(int p,int l,int r){
		mn[p]=0,ad[p]=0;
		if(l==r)return s[p]=SE.ed[SE.rk[l]],void();
		const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
		build(ls,l,mid),build(rs,mid+1,r);
		s[p]=s[ls]+s[rs];
	}
	inline void upd(int p,int l,int r,int x,int y,int z){
		if(x<=l&&r<=y)return ad[p]+=z,mn[p]+=z,void();
		const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
		if(ad[p])ad[ls]+=ad[p],mn[ls]+=ad[p],ad[rs]+=ad[p],mn[rs]+=ad[p],ad[p]=0;
		if(x<=mid)upd(ls,l,mid,x,y,z);
		if(mid<y)upd(rs,mid+1,r,x,y,z);
		mn[p]=min(mn[ls],mn[rs]),s[p]=(mn[ls]==mn[p]?s[ls]:0)+(mn[rs]==mn[p]?s[rs]:0);
	}
}tr;
inline int solve(string s){
	int n=s.length();
	s=" "+s+"$";
	vector<int>p(n+2);
	for(int i=2,j=1,k=2;i<=n;++i){
        p[i]=min(k-i,(j+j>=i?p[j+j-i]:0));
        for(;s[i-p[i]]==s[i+p[i]];++p[i]);
        if(i+p[i]>k)k=i+p[i],j=i;
    }
	return *max_element(p.begin(),p.end());
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
	cin>>n>>m;
	for(int i=0;i<n;++i)cin>>S[i];
	for(int i=0;i<m;++i)cin>>T[i];
	for(int i=0;i<n;++i){
		SQ[i].resize(S[i].length());
		vector<int>p(S[i].length());
		for(int j=0,k=0,r=0;j<S[i].length();++j){
			if(j<r)p[j]=min(r-j,p[k+k-j]);
			for(;j-p[j]>=0&&j+p[j]<S[i].length()&&S[i][j-p[j]]==S[i][j+p[j]];++p[j]);
			if(j+p[j]>r)k=j,r=j+p[j];
			SF[i]=max(SF[i],p[j]);
			if(p[j]==S[i].length()-j)SQ[i][j]=1;
		}
	}
	for(int i=0;i<m;++i){
		TQ[i].resize(T[i].length());
		vector<int>p(T[i].length());
		for(int j=0,k=0,r=0;j<T[i].length();++j){
			if(j<r)p[j]=min(r-j,p[k+k-j]);
			for(;j-p[j]>=0&&j+p[j]<T[i].length()&&T[i][j-p[j]]==T[i][j+p[j]];++p[j]);
			if(j+p[j]>r)k=j,r=j+p[j];
			TF[i]=max(TF[i],p[j]);
			if(p[j]==j+1)TQ[i][j]=1;
		}
	}
	for(int i=0;i<n;++i)
		SE.ins(string(S[i].rbegin(),S[i].rend()),vector<int>(SQ[i].rbegin(),SQ[i].rend()),i);
	for(int i=0;i<m;++i)
		TE.ins(T[i],TQ[i],i);
	SE.dfs(1),TE.dfs(1);
	vector<pair<int,int>>cur;
	for(int i=1;i<=BL;++i){
		for(int j=0;j<n;++j)if(SF[j]>=i)
			Q[TE.dL[1]].emplace_back(SE.dL[SE.pos[j]],SE.dL[SE.pos[j]],1),
			Q[TE.dR[1]+1].emplace_back(SE.dL[SE.pos[j]],SE.dL[SE.pos[j]],1);
		for(int j=0;j<m;++j)if(TF[j]>=i)
			Q[TE.dL[TE.pos[j]]].emplace_back(SE.dL[1],SE.dR[1],1),
			Q[TE.dL[TE.pos[j]]+1].emplace_back(SE.dL[1],SE.dR[1],-1);
		vector<pair<int,int>>nxt;
		for(auto [x,y]:cur)for(auto [z,c]:SE.G[x])if(TE.T[y][c])nxt.emplace_back(z,TE.T[y][c]);
		if(i>1){
			for(auto u:SE.gap[i+i-3])if(SE.W[u])for(auto [v,c]:SE.G[u])if(TE.T[1][c])nxt.emplace_back(v,TE.T[1][c]);
			for(auto u:TE.gap[i+i-3])if(TE.W[u])for(auto [v,c]:TE.G[u])if(SE.T[1][c])nxt.emplace_back(SE.T[1][c],v);
		}
		sort(nxt.begin(),nxt.end()),nxt.erase(unique(nxt.begin(),nxt.end()),nxt.end());
		for(auto [x,y]:nxt)Q[TE.dL[y]].emplace_back(SE.dL[x],SE.dR[x],1),Q[TE.dR[y]+1].emplace_back(SE.dL[x],SE.dR[x],-1);
		tr.build(1,1,SE.n);
		for(int j=1;j<=TE.n;++j){
			for(auto [l,r,v]:Q[j])tr.upd(1,1,SE.n,l,r,v);
			ans+=TE.ed[TE.rk[j]]*(n-(tr.mn[1]?0:tr.s[1])),Q[j].clear();
		}
		cur=nxt;
	}
	for(int i=0;i<n;++i){
		Sid[i].resize(S[i].length());
		for(int j=S[i].length();j--;)s[Sid[i][j]=++sL]=S[i][j];
		s[++sL]=cnt++;
	}
	for(int i=0;i<m;++i){
		Tid[i].resize(T[i].length());
		for(int j=0;j<T[i].length();++j)s[Tid[i][j]=++sL]=T[i][j];
		s[++sL]=cnt++;
	}
	SA(s,sL);
	for(int i=0;i<n;++i)if(S[i].length()>BL)
		for(int j=0;j<m;++j){
			int z=max(SF[i],TF[j]),r=T[j].length();
			for(int k=z;k>=max(1,z-r);--k)if(SQ[i][S[i].length()-k])
				z=max(z,k+(k+k<=S[i].length()?LCP(Sid[i][S[i].length()-k-k],Tid[j][0]):0));
			if(T[j].length()>BL)
				for(int k=1;k+k-2<T[j].length();++k)if(TQ[j][k-1])
					z=max(z,k+(k+k<=T[j].length()?LCP(Sid[i][S[i].length()-1],Tid[j][k+k-1]):0));
			if(z>BL)ans+=z-BL;
		}
	for(int j=0;j<m;++j)if(T[j].length()>BL)
		for(int i=0;i<n;++i)if(S[i].length()<=BL){
			int z=max(SF[i],TF[j]),r=S[i].length();
			for(int k=z;k>=max(1,z-r);--k)if(TQ[j][k-1])
				z=max(z,k+(k+k<=T[j].length()?LCP(Sid[i][S[i].length()-1],Tid[j][k+k-1]):0));
			if(z>BL)ans+=z-BL;
		}
	cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 16ms
memory: 137948kb

input:

10 100
aabaababaaaababbabaaaababaababbbaabbbaabaabaabbbaababaaababbaababababbbaababbbbbbbbaabbbbaabbbbbbbbaabaabbbaabbbbbabbbbbaabbbaabaa
bbaaabaabbbbaaabaaaaabbbbbabaabbabbaabbaabbaabbabbababaabaabbaabbbbbbaaaabbbbabaaaabaaabbbabaaaaaabbaaaabbbabbbbbaaaabbabaababbaabbaaabbbbbbaaaabbbababaabbaaaba
b...

output:

10468

result:

ok single line: '10468'

Test #2:

score: 20
Accepted
time: 11ms
memory: 139700kb

input:

10 100
abbacbbaabababcaabbaabbbabcaccabcabbabbbccaacabaabacccbacaaabbaaabbbaacaabbabcabbbcbacaaaaabaaaabaaacbbccbacacbbaaccacbabcbccacbaaacaaacccbabbaccacaaacaabbbccaaccbbabaabcbbcbcbb
bccabcacbacccbcababaccccaaabbccacaccccabbaabbcacabaccabacbbbaaaabaabccbcaacaaccbcacabcbbbcccccabccbaababccccabcabab...

output:

6384

result:

ok single line: '6384'

Test #3:

score: 20
Accepted
time: 11ms
memory: 137768kb

input:

50 50
aaaaabbabbbbbaababbaaaababaababababbbbaabaaaaaaaabaabbaaabaaaabaaabaabbbabbbababbbbabbbabbaaababbabaabbabbabbabbaaababaaaaabbbbbbaabaabaabbbbbabaaababb
abbabbbaabaaaaabababaabbabaabbbbab
bababbbbaabaabbaabbbbaabaabbbaabbbbaaabbabbbaaabbbbaaabaabbaaaaaabbbabaaaaabbaabaabaaabaaababbbbbaaabbbbbba...

output:

21362

result:

ok single line: '21362'

Test #4:

score: 20
Accepted
time: 12ms
memory: 137476kb

input:

50 50
aababcabbbcbaacaaaaccababbacbbaaabcbaaccabbababbcccaacaaaacacbcbaaabaacabbbbbbaccaaacbbacaacacbcccbbacabbcbcbacababcbbacaccaacacbcccbababaccabccccbabaccababccccbcbabcabcabccaaccababcbccacbbaaaacc
cbaccababccbaaacbccabbcccacacacaaaabaaababcacabaccbccacbcbaaaaabbacbbaccabba
ccbcbcacbcaccabbbccaa...

output:

13421

result:

ok single line: '13421'

Test #5:

score: 20
Accepted
time: 16ms
memory: 139520kb

input:

1000 1000
a
aabbab
bbbbababbbba
bb
baaaaa
ba
a
baa
a
bbaaaabaaaba
ba
a
a
a
bbababbbbbb
b
aaabb
bbbbbaabbabab
bbaaa
aaaa
aa
aaaaaababb
a
bbaba
baaa
aabbab
babaab
b
aab
bbbabb
aaaabbbbbaaaaaa
bbbbbbbaabab
bb
ab
aaa
aaababb
babaaaabab
aa
aaabaaababa
abbabaaaaabb
bbaa
abaabb
baa
abba
aaaa
abbbb
aab
b
aa...

output:

3159935

result:

ok single line: '3159935'

Subtask #2:

score: 30
Accepted

Test #6:

score: 30
Accepted
time: 752ms
memory: 418720kb

input:

1 10000
bcacacbcdadbcbccbdddaaddabcaccccbaabbcdcdaabdacccadacbbbabdaaacadacdccadcbdadadcaaabdbdbdcdcccbacbdbccacbdadcaaaacbabdadcacdcacadcadaabdaaabccccdcbcdbcadcaabbbaacaadaccdaccadbddcdbccbcddcaadcaadaadbbaadbcdbddbcbadbccbaddaacabcdccbadaddcadcbababccabcaadbcbdbcbbcdcbdbcdbdaaddbacddcabbbdccbddba...

output:

1160913325

result:

ok single line: '1160913325'

Test #7:

score: 30
Accepted
time: 719ms
memory: 412644kb

input:

1 1000
caaadbacdaaccbdcaccbdbddcdaccaaaaaccdccaadbadbcdccaacdadcccaddadcbacbbdcaadbbcdaddcadddccdbabccdadcaacabcabbbdbbbbdbbaaccddcdddcddddddbdbbadbddcbacdcdbdabcbbdbbaaadbdacaccdbaaabacbacabdaccaabaadddccbabacdbdddbdcadadcdccabaabbccbacddddcbcdbabaadaddbbdabadaccbdbaaabdadadaadabbdbadacacbdcbcbdccc...

output:

134272327

result:

ok single line: '134272327'

Test #8:

score: 30
Accepted
time: 723ms
memory: 417088kb

input:

1 10000
bbcbcaacaaaacacbacacbaacbacbaababaacacbacbacbccaacbbacbbccababcaaaccabaaccbbbaaaabbababaacbbccabcaccaaccbacccaacabcaacacaccababbbbbcbacaaabbcbaccacaaaaabbacbbcbbcabccaabcabcabaabbbabbababbabcacbcaccabacaababbacccabbcaaacacccbcbcccbbbbaababbabcaaabaccccbbbabccabacbcbabccccaccbcccccbcccccccbbc...

output:

1375114968

result:

ok single line: '1375114968'

Test #9:

score: 30
Accepted
time: 737ms
memory: 418748kb

input:

1 10000
cbaacaaaaccacaacbbcacabccbbabbababbababbacbababbcabcbacabbaaaacccacbbaaacacbacccbababaabccbbcabbbcaacbcbbbcbcbccccbabcacccccaabbbccacccacabccbcccbaaaccbbbacbaabbcbaabccccaabacabccaaccbbbaccbbcbcaabcaacbcbbcacbcbcabbacbababcbcabcbaabbbbbcccccbcacbabbcccccaacccbaccbaacbccbcababbabcbbccbbbbacab...

output:

1363955024

result:

ok single line: '1363955024'

Test #10:

score: 30
Accepted
time: 752ms
memory: 418572kb

input:

1 10000
aacbabccacabcccbccbbcacbbcbcacbbcacbbcbcacacbaaabbbbccaabcbbccccaccccbbcbbcacbbcbbcacbbcbcacacbaaabbbbccaabcbbccccaccccbbcbcbbccccaccccbbbccccaccccbbcbcbbccccaccccbbcbaaccbbbbaaaaabbbbccaabcbbccccaccccbbcbcbbccccaccccbbbccccaccccbbcbcbbccccaccccbbcbaaccbbbbaaabcacacbcbbcacbbcacacbaaabbbbccaa...

output:

1951994915

result:

ok single line: '1951994915'

Test #11:

score: 30
Accepted
time: 714ms
memory: 415420kb

input:

1 10000
bbaabbaaaabbbaaabbbaabaabaababbbbbabaabbababaaabbbbbbabbaaaabbbbbbaabababbbbabbaababbbbabaabaabaaabbabababbbbbaabababbaabbabbbababbbabaaaaabaaaaaaabaabaaabababbbabbabbaaaabababbbbabaabbaaababbaabbbbabbabbabbabbabaababaaaabbbaabbaababbabbbbaaaaaaaaaababbbbabbbabbaabbbbaaabaabbbbbaabbaababbaba...

output:

424739578

result:

ok single line: '424739578'

Subtask #3:

score: 20
Accepted

Test #12:

score: 20
Accepted
time: 625ms
memory: 369196kb

input:

100 1000
abbabbbbabbbbabaabaabbbbabaaabbbaabaabbabaabaabbaabbaabbababbabbababbbaabaabbaabbbabaabbbaaaabaaaabaababbaaaaaaaaabaabbaababbbbbbabbbabbbbababbbaaaaaabaaaabaaabbabbaaaaabbbabbabaabbabababbaaababbbaaaabbabbbabbabbabbbbbbabaabaabbbaabaaabbaabbabbbbaabbabaaabaabaabbbabbbbbabaababbbabababaabbba...

output:

1289287

result:

ok single line: '1289287'

Test #13:

score: 20
Accepted
time: 744ms
memory: 365552kb

input:

1000 1000
babbbabaabaaaabbbbbababaaabbaabbbbbabbaababbbbaaabbbbaaabbbababbaaaabaaabbbbbbbbaabbabbbabbabbaaabaabbbbbbbababaabbbbabaaabbaaaaabbbaababbaaaaabbbbaaaabbbaabaaababaaabbabbbabbabbbabbaabbabbbabaaaaaabaabbabbababbbbbabaaabbbbababbbaabbbaaabbababaababbbbbaaabbbabbabaaaababbbaabaaaabbbabaaabbb...

output:

10431998

result:

ok single line: '10431998'

Test #14:

score: 20
Accepted
time: 920ms
memory: 360176kb

input:

1000 10000
babbababbbaaaaaaaaababbabbbababbbbbbbbabaaaaaabbaababbbbbbbaaaabbaaaaabbbbbbbababbabaaaaabbaaabaaaaaaabbbabbabbaaabbbabbbbababababbabbababbabbbbaabbbbaababbaababbababbbaaabbbbaaabaaaabababbbbaabaababbabbbaabbbbbabbbaaabaabaabbaabaaaaabbabbbbaaabbabbbaababbbaabaaaabbbababbbbbbbabababbaabab...

output:

94347164

result:

ok single line: '94347164'

Test #15:

score: 20
Accepted
time: 693ms
memory: 348728kb

input:

10000 10000
bbbabbaababbbbbababbbbaabbabaaaababbabbbabababaaaaaababbbaabaabbababbbbbaa
b
aaabbbbbbabbaabbbbbbaabaaababbbabbabaaabababbababaaabbaabaabaabbbbabb
abbaabbaababbbabaabababaaaaaaaabaabbbb
bbbbbabbaabbaaaabaabaababbbababbbbbaaaabbabbbabbaabbbabaaababababaabbaaaabaabbaaabbbaaaaaababababbbabb...

output:

694099162

result:

ok single line: '694099162'

Test #16:

score: 20
Accepted
time: 596ms
memory: 366132kb

input:

100 100
ababababbbababbabbaabbbbbaabaaaaabbabaaaaabbbaabbbabababbbaaaaababbaabbbababaababbaabbaaababaabbaabbbbbbaaababbbaabaaaababbaababbbaaaabbbbaababaabaabaaabaaaabaababaaababbbbabbaabbbbababbaaabaaabaabaabaaaabaaaabbbbbabaaaabababaaababbbbbabbaaaabbbaaaaaaabababbaaababbbabbbbbaaaaaaaaaabbaabababa...

output:

138444

result:

ok single line: '138444'

Subtask #4:

score: 30
Accepted

Test #17:

score: 30
Accepted
time: 580ms
memory: 370172kb

input:

100 1000
bcbccabbbabacabaabbccbaaabbbbcbbbaaaacaaabbccbababbacbbabbbaccccccccbccabcaacbbccbbbbcaaacabcccaccbaacccbcbaaaccbcaaaaaaaabccaaaacccbabacbcababbacbbbcaabaaacbbcaccbaccccbbcbacabaacbcaccacbcbcbbcbccccbbcacccaabbabcaabbacabaaacccbbcbccbabbcbccbcbbbabbaabacbccbacababbacbababbbaacccacbabcabcaba...

output:

833103

result:

ok single line: '833103'

Test #18:

score: 30
Accepted
time: 728ms
memory: 365924kb

input:

1000 1000
cacccababcaaccbaaabcbcabcbbccbcbcbbcacbbcabcaaccabcccaacabccaacaaaababbbbbcbbcbcbbbcacbaabccaccbaacaaacabbbcbcbaabbcccacaababbbabcaabbaabaabaabaabccaacccbabcbaacccbbbccaacbbacacacaacccbcbcbaccbccaaacabaacbcbaacbcbacaccbacbbcaccbabbbabbbaccccbbbcacccccaacbbaaaccacabaaacaccabacacbaaaaacbacab...

output:

6757759

result:

ok single line: '6757759'

Test #19:

score: 30
Accepted
time: 857ms
memory: 359156kb

input:

1000 10000
cbacbccbcbbcccbbcccaacccbbbacbccaaaccabacaabacccbbbcbabcaacabbabbabcaaaabccbabcaaacaaabbbacccacabcacccaaababcacbaacaccbccbcaaaaaaaaccabbcaaaaabccacaacbccabacabcccaabbcaccbcabbccbabbbccaacbabcbacacabbaaaababbccbcbacbbbcaccaabacbcaabbaaacaacccaaabbbcabbbcccacacaccaacbccabccbcacbbbbbabcbabbc...

output:

61388196

result:

ok single line: '61388196'

Test #20:

score: 30
Accepted
time: 724ms
memory: 360212kb

input:

10000 10000
aababaaccbcbabaccbaccbcaaabbcbbbbacbcbababbccbccbbac
cbcccccacaccabcbbbaaabcaaccabccccccbabacbbabbaaacbabccbcaacacbbbabbbbcbbcbcbaaccaccbabccabbbbbabcabcbcccababbcabaccbbccbaaacaabacbcbcbbabbcbaabcaccaaaccbbcacaaabcabacabccbaabbacabccacbabbaababb
cacbcbabc
caacccaabaaccbbbabaababbbbcbcac...

output:

462062051

result:

ok single line: '462062051'

Test #21:

score: 30
Accepted
time: 589ms
memory: 368724kb

input:

100 100
abcababbbbbcaccccbcacacabbccccbbccacbbabacabbbbacacaacaaabbcaabcaaaaabaaccbaaacbbcbbcabbaaababacabcccaabbcbbbbaaaacaabbbacbcabacbbccbbacacbaaabacabbcbbcaabaccababccaaababbcbcacbabababcbcccccccababcbbbaaabbacbaabbaababcabaacbccacbbaccbbbbcbbabbccaacbaccaaabaccbaacaaaaabbcaccbbbaaccaaccccbbbaa...

output:

90325

result:

ok single line: '90325'

Test #22:

score: 30
Accepted
time: 669ms
memory: 322468kb

input:

430 800
aaaccaccaacbcccbccbccaaaaaabccabbcbccabcacbcaabcbacbccbbacccaccabccacbbcccccbacaacbabbbaaaaacbbbcabacbccaabcabcbacccacbabaacacbcaacbabbabbbbbaacacabbaccaabcccbacbbabccccccbabbaaaaababcababaabcaabbcbbaaccaccabbaabcabccbbcbacacaaabcbaaccccbcbacbccacaaacbbaabaabccabaacbccccbbbbcabccbbcbbcbccaba...

output:

157989035

result:

ok single line: '157989035'

Test #23:

score: 30
Accepted
time: 142ms
memory: 170744kb

input:

400 400
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

40039936

result:

ok single line: '40039936'

Test #24:

score: 30
Accepted
time: 863ms
memory: 293112kb

input:

400 400
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabaaaaabbbbaabbb...

output:

108484268

result:

ok single line: '108484268'