QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#440399#5014. 复读程度Kevin5307100 ✓2129ms194984kbC++2312.0kb2024-06-13 17:39:472024-06-13 17:39:48

Judging History

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

  • [2024-06-13 17:39:48]
  • 评测
  • 测评结果:100
  • 用时:2129ms
  • 内存:194984kb
  • [2024-06-13 17:39:47]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
class SuffixAutomaton
{
	#define MAXN 200000+5
	#define MAXLG 20
	public:
		SuffixAutomaton():last(1),tot(1){}
		int trans[MAXN][26],fail[MAXN],len[MAXN],occ[MAXN],last,tot,dfn,in[MAXN],out[MAXN],id[MAXN],rep[MAXN];
		int anc[MAXLG][MAXN];
		ull weight[MAXN];
		vector<int> G[MAXN];
		int extend(int x,ull w=0,int pos=0)
		{
			int p=last;
			int np=++tot;
			len[np]=len[p]+1;
			while(p&&!trans[p][x])
			{
				trans[p][x]=np;
				p=fail[p];
			}
			if(!p)
				fail[np]=1;
			else
			{
				int q=trans[p][x];
				if(len[p]+1==len[q])
					fail[np]=q;
				else
				{
					int nq=++tot;
					memcpy(trans[nq],trans[q],sizeof(int)*26);
					len[nq]=len[p]+1;
					fail[nq]=fail[q];
					fail[q]=fail[np]=nq;
					while(p&&trans[p][x]==q)
					{
						trans[p][x]=nq;
						p=fail[p];
					}
				}
			}
			last=np;
			occ[last]++;
			weight[last]+=w;
			rep[last]=pos;
			return last;
		}
		void dfs(int u)
		{
			in[u]=++dfn;
			id[dfn]=u;
			for(auto v:G[u])
			{
				dfs(v);
				occ[u]+=occ[v];
				weight[u]+=weight[v];
				rep[u]=max(rep[u],rep[v]);
			}
			out[u]=dfn;
		}
		void init()
		{
			for(int i=1;i<=tot;i++)
				if(fail[i])
					G[fail[i]].pb(i);
			dfs(1);
			for(int i=1;i<=tot;i++)
				anc[0][i]=fail[i];
			for(int i=1;i<20;i++)
				for(int j=1;j<=tot;j++)
					anc[i][j]=anc[i-1][anc[i-1][j]];
		}
		int locate(int node,int length)
		{
			for(int i=MAXLG-1;i>=0;i--)
				if(len[anc[i][node]]>=length)
					node=anc[i][node];
			return node;
		}
	#undef MAXN
	#undef MAXLG
};
class BasicSubstringStructure
{
	#define MAXN 100000+5
	public:
		BasicSubstringStructure(string _s):s(_s){build();}
		BasicSubstringStructure(){}
		string s;
		SuffixAutomaton S1,S2;
		int node1[MAXN],node2[MAXN],n;
		ull wl[MAXN],wr[MAXN];
		void build()
		{
			n=sz(s);
			for(int i=1;i<=n;i++)
				node1[i]=S1.extend(s[i-1]-'a',wr[i],i);
			for(int i=n;i>=1;i--)
				node2[i]=S2.extend(s[i-1]-'a',wl[i],i);
			S1.init();
			S2.init();
		}
		int locate1(pii str)
		{
			int nd1=S1.locate(node1[str.second],str.second-str.first+1);
			return nd1;
		}
		int locate2(pii str)
		{
			int nd2=S2.locate(node2[str.first],str.second-str.first+1);
			return nd2;
		}
		pii rep(pii str)
		{
			int nd1=S1.locate(node1[str.second],str.second-str.first+1);
			str=mp(str.second-S1.len[nd1]+1,str.second);
			int nd2=S2.locate(node2[str.first],str.second-str.first+1);
			str=mp(str.first,str.first+S2.len[nd2]-1);
			int pos=S1.rep[locate1(str)];
			str.first+=pos-str.second;
			str.second=pos;
			return str;
		}
		int occ(pii str)
		{
			int nd1=S1.locate(node1[str.second],str.second-str.first+1);
			return S1.occ[nd1];
		}
		ull weight(pii str)
		{
			int nd1=S1.locate(node1[str.second],str.second-str.first+1);
			int nd2=S2.locate(node2[str.first],str.second-str.first+1);
			return S1.weight[nd1]*S2.weight[nd2];
		}
		vector<int> order1()
		{
			int s1=S1.tot;
			vector<pair<pii,pii>> vec;
			for(int i=2;i<=s1;i++)
			{
				pii pos(S1.rep[i]-S1.len[i]+1,S1.rep[i]);
				vec.pb(rep(pos),pii(S1.len[i]-S1.len[S1.fail[i]],i));
			}
			srt(vec);
			vector<int> ret;
			for(int i=0;i<sz(vec);i++)
				ret.pb(vec[i].second.second);
			return ret;
		}
		vector<int> order2()
		{
			int s2=S2.tot;
			vector<pair<pii,pii>> vec;
			for(int i=2;i<=s2;i++)
			{
				pii pos(S2.rep[i],S2.rep[i]+S2.len[i]-1);
				vec.pb(rep(pos),pii(S2.len[i]-S2.len[S2.fail[i]],i));
			}
			srt(vec);
			vector<int> ret;
			for(int i=0;i<sz(vec);i++)
				ret.pb(vec[i].second.second);
			return ret;
		}
	#undef MAXN
}BSS;
int n,q;
string s;
ull wl[100100],wr[100100];
ull ans[400400];
int ql[400400],qr[400400];
int l1[100100],r1[100100],l2[100100],r2[100100],nd1[100100],nd2[100100];
const int B1=630,B2=450;
int qx[400400],qly[400400],qry[400400];
int qy[400400],qlx[400400],qrx[400400];
ull ans1[400400],ans2[400400];
vector<int> vqx[400400],vqy[400400];
int s1,s2;
int label1[200200],label2[200200];
ull tag[200200/B2+5],rval[200200];
ull W[200200];
ull res[100100];
vector<pii> pool;
struct query
{
	int pos,ind,ql,qr;
	ull coef;
	friend bool operator <(const query &a,const query &b){return a.pos<b.pos;}
};
vector<query> vq1[200200],vq2[200200];
vector<int> vnode1[200200],vnode2[200200];
namespace BIT
{
	#define MAXN 200200
	ull bit[MAXN];
	void update(int p,ull v)
	{
		while(p<MAXN)
		{
			bit[p]+=v;
			p+=(p&(-p));
		}
	}
	ull query(int p)
	{
		ull ret=0;
		while(p)
		{
			ret+=bit[p];
			p-=(p&(-p));
		}
		return ret;
	}
	void clear()
	{
		memset(bit,0,sizeof(bit));
	}
	#undef MAXN
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q>>s;
	for(int i=1;i<=n;i++)
		cin>>wl[i];
	for(int i=1;i<=n;i++)
		cin>>wr[i];
	BSS.s=s;
	for(int i=1;i<=n;i++)
		BSS.wl[i]=wl[i];
	for(int i=1;i<=n;i++)
		BSS.wr[i]=wr[i];
	BSS.build();
	for(int i=2;i<=BSS.S1.tot;i++)
	{
		pii str(BSS.S1.rep[i]-BSS.S1.len[i]+1,BSS.S1.rep[i]);
		pool.pb(BSS.rep(str));
	}
	srt(pool);
	uni(pool);
	for(int i=1;i<=q;i++)
	{
		cin>>l2[i]>>r2[i]>>l1[i]>>r1[i];
		nd1[i]=BSS.locate1({l1[i],r1[i]});
		nd2[i]=BSS.locate2({l2[i],r2[i]});
		if(BSS.rep({l1[i],r1[i]})==BSS.rep({l2[i],r2[i]}))
		{
			pii rep=BSS.rep({l1[i],r1[i]});
			int len=BSS.S1.len[nd1[i]]+BSS.S2.len[nd2[i]]-(rep.second-rep.first+1);
			if(len<max(r1[i]-l1[i]+1,r2[i]-l2[i]+1))
			{
				int d1=BSS.S2.len[nd2[i]]-(rep.second-rep.first+1);
				int d2=BSS.S1.len[nd1[i]]-(rep.second-rep.first+1);
				rep.first-=d1;
				rep.second+=d2;
				if(rep.second>=rep.first&&BSS.rep(rep)==BSS.rep({l1[i],r1[i]}))
					res[i]-=BSS.occ(rep)*BSS.S2.weight[BSS.locate2(rep)]*BSS.S1.weight[BSS.locate1(rep)];
			}
		}
		else
		{
			int len=max(r1[i]-l1[i]+1,r2[i]-l2[i]+1);
			int block1=ub(pool,BSS.rep({BSS.S1.rep[nd1[i]]-BSS.S1.len[nd1[i]]+1,BSS.S1.rep[nd1[i]]}));
			int block2=ub(pool,BSS.rep({BSS.S2.rep[nd2[i]],BSS.S2.rep[nd2[i]]+BSS.S2.len[nd2[i]]-1}));
			query q1{BSS.S1.len[nd1[i]]-BSS.S1.len[BSS.S1.fail[nd1[i]]],i,BSS.S2.in[nd2[i]],BSS.S2.out[nd2[i]],-BSS.S1.weight[nd1[i]]};
			query q2{max(BSS.S1.len[nd1[i]]-max(len-1,BSS.S1.len[BSS.S1.fail[nd1[i]]]),0),i,BSS.S2.in[nd2[i]],BSS.S2.out[nd2[i]],BSS.S1.weight[nd1[i]]};
			query q3{BSS.S2.len[nd2[i]]-BSS.S2.len[BSS.S2.fail[nd2[i]]],i,BSS.S1.in[nd1[i]],BSS.S1.out[nd1[i]],-BSS.S2.weight[nd2[i]]};
			query q4{max(BSS.S2.len[nd2[i]]-max(len-1,BSS.S2.len[BSS.S2.fail[nd2[i]]]),0),i,BSS.S1.in[nd1[i]],BSS.S1.out[nd1[i]],BSS.S2.weight[nd2[i]]};
			vq1[block1].pb(q1);
			vq1[block1].pb(q2);
			vq2[block2].pb(q3);
			vq2[block2].pb(q4);
		}
		ql[i*4-3]=BSS.S1.in[nd1[i]]-1;
		qr[i*4-3]=BSS.S2.in[nd2[i]]-1;
		ql[i*4-2]=BSS.S1.out[nd1[i]];
		qr[i*4-2]=BSS.S2.in[nd2[i]]-1;
		ql[i*4-1]=BSS.S1.in[nd1[i]]-1;
		qr[i*4-1]=BSS.S2.out[nd2[i]];
		ql[i*4-0]=BSS.S1.out[nd1[i]];
		qr[i*4-0]=BSS.S2.out[nd2[i]];
	}
	vector<pii> vn1,vn2;
	for(int i=2;i<=BSS.S1.tot;i++)
		vn1.pb(BSS.S1.rep[i],i);
	for(int i=2;i<=BSS.S2.tot;i++)
		vn2.pb(BSS.S2.rep[i],i);
	rsrt(vn1);
	srt(vn2);
	for(auto pr:vn1)
	{
		int nd=pr.second;
		int block=ub(pool,BSS.rep({BSS.S1.rep[nd]-BSS.S1.len[nd]+1,BSS.S1.rep[nd]}));
		vnode1[block].pb(nd);
	}
	for(auto pr:vn2)
	{
		int nd=pr.second;
		int block=ub(pool,BSS.rep({BSS.S2.rep[nd],BSS.S2.rep[nd]+BSS.S2.len[nd]-1}));
		vnode2[block].pb(nd);
	}
	for(int i=1;i<=sz(pool);i++)
	{
		srt(vq1[i]);
		int p=0;
		while(p<sz(vq1[i])&&vq1[i][p].pos==0) p++;
		for(int j=1;j<=sz(vnode2[i]);j++)
		{
			int nd=vnode2[i][j-1];
			BIT::update(BSS.S2.in[nd],BSS.S2.occ[nd]*BSS.S2.weight[nd]);
			while(p<sz(vq1[i])&&vq1[i][p].pos==j)
			{
				res[vq1[i][p].ind]+=vq1[i][p].coef*(BIT::query(vq1[i][p].qr)-BIT::query(vq1[i][p].ql-1));
				p++;
			}
		}
		for(int j=1;j<=sz(vnode2[i]);j++)
		{
			int nd=vnode2[i][j-1];
			BIT::update(BSS.S2.in[nd],(ull)-BSS.S2.occ[nd]*BSS.S2.weight[nd]);
		}
	}
	for(int i=1;i<=sz(pool);i++)
	{
		srt(vq2[i]);
		int p=0;
		while(p<sz(vq2[i])&&vq2[i][p].pos==0) p++;
		for(int j=1;j<=sz(vnode1[i]);j++)
		{
			int nd=vnode1[i][j-1];
			BIT::update(BSS.S1.in[nd],BSS.S1.occ[nd]*BSS.S1.weight[nd]);
			while(p<sz(vq2[i])&&vq2[i][p].pos==j)
			{
				res[vq2[i][p].ind]+=vq2[i][p].coef*(BIT::query(vq2[i][p].qr)-BIT::query(vq2[i][p].ql-1));
				p++;
			}
		}
		for(int j=1;j<=sz(vnode1[i]);j++)
		{
			int nd=vnode1[i][j-1];
			BIT::update(BSS.S1.in[nd],(ull)-BSS.S1.occ[nd]*BSS.S1.weight[nd]);
		}
	}
	vector<int> vq;
	for(int i=1;i<=q*4;i++)
		vq.pb(i);
	sort(ALL(vq),[&](int u,int v)
	{
		if(ql[u]/B1==ql[v]/B1) return qr[u]<qr[v];
		return ql[u]<ql[v];
	});
	int cl=1,cr=1;
	for(int i=1;i<=q*4;i++)
	{
		int ind=vq[i-1];
		int l=ql[ind],r=qr[ind];
		if(cl<=l)
		{
			qy[i]=cr;
			qlx[i]=cl+1;
			qrx[i]=l;
			cl=l;
		}
		else
		{
			qy[i]=cr;
			qlx[i]=l+1;
			qrx[i]=cl;
			cl=l;
		}
		if(cr<=r)
		{
			qx[i]=cl;
			qly[i]=cr+1;
			qry[i]=r;
			cr=r;
		}
		else
		{
			qx[i]=cl;
			qly[i]=r+1;
			qry[i]=cr;
			cr=r;
		}
	}
	for(int i=1;i<=q*4;i++)
	{
		vqx[qx[i]].pb(i);
		vqy[qy[i]].pb(i);
	}
	s1=BSS.S1.tot;
	s2=BSS.S2.tot;
	vector<int> order1=BSS.order1(),order2=BSS.order2();
	for(int i=1;i<=sz(order1);i++)
		label1[order1[i-1]]=i;
	for(int i=1;i<=sz(order2);i++)
		label2[order2[i-1]]=i;
	for(int i=1;i<=s2;i++)
		W[label2[i]]=BSS.S2.weight[i];
	for(int i=2;i<=s1;i++)
	{
		int node=BSS.S1.id[i];
		int pos=BSS.S1.rep[node];
		int ndl=BSS.locate2(pii(pos-BSS.S1.len[BSS.S1.fail[node]],pos));
		int ndr=BSS.locate2(pii(pos-BSS.S1.len[node]+1,pos));
		int cl=label2[ndl],cr=label2[ndr];
		int lb=cl/B2,rb=cr/B2;
		ull val=BSS.S1.weight[node]*BSS.S1.occ[node];
		for(int i=lb+1;i<rb;i++)
			tag[i]+=val;
		if(lb<rb)
		{
			for(int i=cl;i/B2==lb;i++)
				rval[i]+=val*W[i];
			for(int i=cr;i/B2==rb;i--)
				rval[i]+=val*W[i];
		}
		else
		{
			for(int i=cl;i<=cr;i++)
				rval[i]+=val*W[i];
		}
		for(auto qind:vqx[i])
			for(int ydfn=qly[qind];ydfn<=qry[qind];ydfn++)
			{
				int yind=label2[BSS.S2.id[ydfn]];
				ans1[qind]+=tag[yind/B2]*W[yind]+rval[yind];
			}
	}
	memset(tag,0,sizeof(tag));
	memset(rval,0,sizeof(rval));
	for(int i=1;i<=s1;i++)
		W[label1[i]]=BSS.S1.weight[i];
	for(int i=2;i<=s2;i++)
	{
		int node=BSS.S2.id[i];
		int pos=BSS.S2.rep[node];
		int ndl=BSS.locate1(pii(pos,pos+BSS.S2.len[BSS.S2.fail[node]]));
		int ndr=BSS.locate1(pii(pos,pos+BSS.S2.len[node]-1));
		int cl=label1[ndl],cr=label1[ndr];
		int lb=cl/B2,rb=cr/B2;
		ull val=BSS.S2.weight[node]*BSS.S2.occ[node];
		for(int i=lb+1;i<rb;i++)
			tag[i]+=val;
		if(lb<rb)
		{
			for(int i=cl;i/B2==lb;i++)
				rval[i]+=val*W[i];
			for(int i=cr;i/B2==rb;i--)
				rval[i]+=val*W[i];
		}
		else
		{
			for(int i=cl;i<=cr;i++)
				rval[i]+=val*W[i];
		}
		for(auto qind:vqy[i])
			for(int xdfn=qlx[qind];xdfn<=qrx[qind];xdfn++)
			{
				int xind=label1[BSS.S1.id[xdfn]];
				ans2[qind]+=tag[xind/B2]*W[xind]+rval[xind];
			}
	}
	cl=1;
	cr=1;
	ull tot=0;
	for(int i=1;i<=q*4;i++)
	{
		int ind=vq[i-1];
		int l=ql[ind],r=qr[ind];
		if(cl<=l)
		{
			tot+=ans2[i];
			cl=l;
		}
		else
		{
			tot-=ans2[i];
			cl=l;
		}
		if(cr<=r)
		{
			tot+=ans1[i];
			cr=r;
		}
		else
		{
			tot-=ans1[i];
			cr=r;
		}
		ans[ind]=tot;
	}
	for(int i=1;i<=q;i++)
		res[i]+=ans[i*4-0]-ans[i*4-1]-ans[i*4-2]+ans[i*4-3];
	for(int i=1;i<=q;i++)
		cout<<res[i]<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 3ms
memory: 81980kb

input:

500 500
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

15720454042420499810
4058077030882532408
14651762045124606089
4030024243931986061
18033423360813892607
9470601111824364484
3883374861354698625
16650831689368240202
8339028189650687576
2683289915379600554
13133811958066776394
14181220923901262251
18173739360450512256
13142314545999179754
148925491596...

result:

ok 500 lines

Test #2:

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

input:

500 500
zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszz...

output:

4843650749197240262
7777110205341291111
533576317536031175
16712994243500559204
9988085877723856684
9644193924482321332
3247342125341043527
18152622312040037224
13045121434804725850
10593529771756855740
13316626648976199221
6181092693273210423
9148547538129213975
9376364571107435561
2140403332478526...

result:

ok 500 lines

Test #3:

score: 0
Accepted
time: 8ms
memory: 86000kb

input:

500 500
aaaaabbaabbabbbaabaabbabbabbbaaabaaaabbbbbbaaabaabbbbbbaabbaaaaababbaaaaabbbbababbabaabbbbbbbbaaaaaaabaabbabbbbaabbaabaaabbbabbaabbbabaabaaaaababbaabbabbbabbababbbaabbabaaabbbbaaabbbabbabaabbabbaaabbaabbabbbbaaaaaababaaaabaababbaabbabbabbbabbaabbbaabbaaababaaabbababbbabaababaabbbbbabbababaab...

output:

841375054012212333
13406426787139944226
6541986259052503362
10583258635957015782
11582649090627508617
4747829250201069768
11571422754704651998
14603866222879735665
8438246043626601023
16155298152184479844
9052925087624568857
18388444310571976215
13304308468056840286
18125780089857220122
363421144082...

result:

ok 500 lines

Test #4:

score: 0
Accepted
time: 6ms
memory: 81976kb

input:

500 500
sulasusulasusulasulasulsulasusulasususulasulasulsulasulasulsulasulasulsulasususulasulasulsulasulasulsulasulasulsulasusulasulasulsulasulasulsulasulasulsulasusulasulasulsulasulasulsulasulasulsulasulasulsulasususulasulasulsulasulasulsulasulasulsulasusulasulasulsulasulasulsulasusulasusulasusulas...

output:

2320755102639148175
17108462705447992416
6030359132551843296
889683039894413148
10901851555398837076
1991544941914879425
9087724446342520941
5134546535199286414
12947484109492427089
5962550827492657739
4877066450610765849
6699323319072695780
11167645157062070624
13985172887966350800
8075429763917070...

result:

ok 500 lines

Test #5:

score: 0
Accepted
time: 4ms
memory: 81976kb

input:

500 500
bbbbbbqouvtudkzorrxinacvncytgmtbbbbbbfyfzxjdqlcaadccvsbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbfyfzxjdqlcaadccvsbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbfyfzxjdqlcaadccvsbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbbbbbbbqouvtudkzorrx...

output:

18295637548117042088
6105463594888898313
15681140870484623884
17957090271580958329
11763132903578154240
17769627666201366836
16493946443969420940
12712093409624537595
2436698665645215125
8863273927617841787
5065586857868462806
8771649105206144878
6715985691821336097
8851433094837196039
7055234226266...

result:

ok 500 lines

Test #6:

score: 0
Accepted
time: 7ms
memory: 82104kb

input:

500 500
yyyayyayyyayyayyyayyayyyayyyayyyayyayyyyayyayyyayyyayyayyyayyyayyayyayyyyayyyayyyayyayyayyyayyayyayyyayyayyayyyayyyyyayyayyyyayyayyyayyayyyayyyayyyayyayyyayyayyyyayyyayyayyayyyayyayyyayyyyayyyyayyayyyayyayyayyyayyayyayyyyayyayyyayyayyayyyayyyyayyayyayyyayyayyayyyayyayyayyyyayyyayyyayyyyayyay...

output:

6159560444195180556
5294852391541430076
6195718271241091926
7959984071139675340
1598729415848168155
4879964117998052348
2279721248493220290
2026655128556749470
9803272548967597498
1028236064772678471
5410852487707111065
3600180224455323043
60239358603452318
2179897463397058094
16626503365867372202
3...

result:

ok 500 lines

Test #7:

score: 0
Accepted
time: 15ms
memory: 82016kb

input:

500 500
fffffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqiffffffxfqifffnmogfffxfqifffffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqifffffffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqifffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfff...

output:

6263422992304461664
10533199195660359295
11930245273187149005
380050211417129795
8399013088311259527
7005867409130681392
6872331929648615383
11661502418569897193
18027795221888639599
8932010711134684820
6331436398298306214
14599171184201697655
16632037523890780117
10373998601812781913
16089838760431...

result:

ok 500 lines

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #8:

score: 15
Accepted
time: 39ms
memory: 83116kb

input:

5000 5000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

12046186417900804485
3907200386448639860
16785470842023310270
13867397394972404837
17085398553187209926
11495532885795119226
12151570815045120790
4174337022608077877
6326694597133262496
5169007805286709535
14463367619086789683
627371028328452442
16378439470252322552
8286285259552634235
4646456254657...

result:

ok 5000 lines

Test #9:

score: 0
Accepted
time: 40ms
memory: 84000kb

input:

5000 5000
zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzs...

output:

735272585091871492
2425556370857741242
8489901764977622765
9888756352722135114
3110111362923242403
9113727892967247055
13146817111311386931
5955980702194075793
11763307103994511020
11636340521260903139
13880517640770645879
18280247001976771986
9041182678245966519
902847942097731925
17037540142883387...

result:

ok 5000 lines

Test #10:

score: 0
Accepted
time: 43ms
memory: 86848kb

input:

5000 5000
bababbaabbbbbabbabaababbbaabababbbbaaabbaabbbbaaabaaaaabbababaababbbabbabbaaabbaaaaaababbababbbbbabbbbbaaabbabababaaababbababaabaaaaaabaaabbabaaaabaabaaaaaabbaaaaaaabbbbbabbabababbbabababaabaabbbbbabaabbbaaabbaaababbabaabaabbababaaaaaaabaaaabaabbbabbaaaababbabbaaabbbbabbabbaabbabbbbabaabbb...

output:

14997976760389310587
15623438489514479805
3150343034406864174
3816221098639928267
9378704101760633024
7513129444188437491
13447233088170491140
9761793475353455477
14533020333667464089
3755460369265761557
1017346093533703703
13617526768501762999
3768834851789866303
6158131626925412903
362975187944345...

result:

ok 5000 lines

Test #11:

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

input:

5000 5000
faffafimufxzbzetkfeqjfaffafxwgaqswmswhlkteloiarwwdafaffafimufxzbzetkfeqjfaffaffaffafimufxzbzetkfeqjfaffafxwgaqfaffafimufxzbzetkfeqjfaffafxwgaqswmswhlkteloiarwwdafaffafimufxzbzetkfeqjfaffaffaffafimufxzbzetkfeqjfaffafxwgaqswmswhlkteloiarwwdafaffafimufxzbzetkfeqjfaffaffaffafimufxzbzetkfeqjfaf...

output:

1845388242333177970
9831947454379400267
1031368185674017505
7263197708536716267
14239370791222150808
146482920919415220
17250529541921412624
16073012951843647214
14426094333257632462
9475986787147068259
17618123199330645299
7007181348027660953
7868744985222980634
24008326611725469
109704767314001231...

result:

ok 5000 lines

Test #12:

score: 0
Accepted
time: 44ms
memory: 85220kb

input:

5000 5000
rreurrrrkodwxsvtckttkrreurrrrtvjqcbspphhcmqjjadnkvdhavzhasjorreurrrrkodwxsvtckttkrreurrrrdhzorreurrrrkodwxsvtckttkrreurrrrtvjqcbspphhcmqjjadnkvdhavzhasjorreurrrrkodwxsvtckttkrreurrrrxgpkocctymfhcjougjsvimxuwczjxyhasapncenwpvkvtrmcdhkfjmndumgccngxginwyjhwexjeujrnvfaznvonweytryeeoocesoxavgaw...

output:

11585208823777493396
6508373161762025375
8952030838195753202
1744593196955201879
7361869313836500243
4211703722346758091
11507326811546869387
12152026172660216436
6502452509264613488
16456537462830488502
7769483154726766332
5049920983662723085
6208254085958990276
1561961237223372279
2581189727041718...

result:

ok 5000 lines

Test #13:

score: 0
Accepted
time: 33ms
memory: 86860kb

input:

5000 5000
bdybdbdybdbdybbdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdybdbdybdybdbdybdbdybbdybdbdybdybdbdybdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdybdb...

output:

15484750028865001809
11154229346905269019
17415778058314228645
12967502341758445430
14197547387946783600
16593119823307221414
3430123628603013461
15944735630911629097
3372966924712269006
16370170534370111687
7776152546511005126
10081736260495879969
3361043444817366723
14159037165445633566
4790222378...

result:

ok 5000 lines

Test #14:

score: 0
Accepted
time: 44ms
memory: 90308kb

input:

5000 5000
gskozovzgkcfxgrjipkmaurpgskozovzgkcfxuetjsdskistgkrkxbvpwljcjmnamkcdqmeteslgskozovzgkcfxgrjipkmaurpgskozovzgkcfxgskozovzgkcfxgrjipkmaurpgskozovzgkcfxuetjsdskistgkrkgskozovzgkcfxgrjipkmaurpgskozovzgkcfxuetjsdskistgkrkxbvpwljcjmnamkcdqmeteslgskozovzgkcfxgrjipkmaurpgskozovzgkcfxgskozovzgkcfxg...

output:

5804930040756324744
15650208817097681461
11355021187259627510
6741010156229702848
11225541410427015147
1272653894362217625
8025793205090026227
17985669688971641284
17805739950886098400
15447039299473890938
13822612697353510946
16409494890413019301
10397340813113479673
11748441386197961568
1796390231...

result:

ok 5000 lines

Subtask #3:

score: 12
Accepted

Dependency #2:

100%
Accepted

Test #15:

score: 12
Accepted
time: 339ms
memory: 111768kb

input:

5000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

5845120425902525283
8990351971173725430
14941690660751686216
784971306663465014
14729108738538674226
9552307739797797498
3551599368844499432
3212787150504387790
8594382131237834529
16887368685328314652
5586192237324217034
12381470524748547090
1961055982585971300
13257376816999825159
3385756250295802...

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 369ms
memory: 108488kb

input:

5000 100000
zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszsz...

output:

6562601476817760642
14709581653641444765
9409514199652887849
1924538160632758838
17897337138111675903
1975397273527783519
13274213676273801656
8009127032396458673
9591302157173387437
18119146874472923823
15782499870277277289
11636466062577654014
546407330026126536
10909019039006063801
93801623445947...

result:

ok 100000 lines

Test #17:

score: 0
Accepted
time: 402ms
memory: 112280kb

input:

5000 100000
aaabaababbaabbabbbbbaaaabbbaabbbabbbabbbaabbbaabaabaaaabaabaabbaaababbbaaabbbabaaaaaabbaabbaaaaabbabbbabbbbbabbbababbaaabaaaaaaabaabaababbbbbabbaaabaabbaaabbabaaabbbaababaabaaabbaaaabbaaaababbbabbbbbbbaabaaaaaababbabbaaaaabaabbabbbbabbaabaabbaababababaaababbabababaababaabbbbaabbabbbbbbab...

output:

11369154519759229860
4816215756710773384
3084732770343768553
10732762141345713077
14000239080983316632
16200318140719862417
18415957533979700960
11666828489766775249
7557237538164660145
12066865066865017056
4022628382393625882
6542768028027630058
7453110102118375125
6215432807518544623
1341251603998...

result:

ok 100000 lines

Test #18:

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

input:

5000 100000
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

12902464409189323146
2112106874663835270
17874290669032515261
17889078556270410717
1153359439408633103
17496184927378147549
4218582814297155576
12182030755254116397
2311499738865929178
12069095198538404628
11646473706806926093
13424856046086967932
13546170125890126237
9125301078493922531
68650470543...

result:

ok 100000 lines

Test #19:

score: 0
Accepted
time: 327ms
memory: 106592kb

input:

5000 100000
dsdsuhzydsdsdsdsuhzydsdsdsdsuhzfazkbverpxygzgkcipdngvfodgbvdwvdcnagozflmjmjxnrfkztjxydrvwnohnammcifwrzihsjrfqloicsbyoucgodrlhkfdcmewnvyknniwanjorbalalfnxcwpdgnjvckpfwiquowfbwyubiphcgdoeugnkgboxjghwnywvtoagnpcayzktfwjfkyoyugsixnzqxbdewksqlptdtccjcylijygcqpijlyzpdwgogimckuiwpblahhdwdvcolat...

output:

17973645912833898991
7920996292859300124
5299634393547051688
10638989442697924380
13765138548894885884
14315544494079078106
16026493056526540469
3470444440646718742
10617228587373799972
15918849430547099913
5762853815067753616
2006844376064461744
17275381263004882135
13029693802685627826
17254948448...

result:

ok 100000 lines

Test #20:

score: 0
Accepted
time: 411ms
memory: 111336kb

input:

5000 100000
juptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjujuptjujuptjujuptjjuptjup...

output:

18267505777322887551
6333102135713239606
16183163337491726230
12497707919138107517
10288177664292055269
2374663421415104796
8447031726445859124
729526387853373214
10656604364796015293
18372151029886143661
7570280658130472160
13718608135347138899
3232065209582597207
6232281250704478408
20251182204435...

result:

ok 100000 lines

Test #21:

score: 0
Accepted
time: 387ms
memory: 110228kb

input:

5000 100000
mkubtkmkubmkubtkmkubmmkubtkmkubmkubtkmkubmmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubtkmkubmkubtkmkubmkubtkmkumkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubtkmkubmkubtkmkubmmkubtkmkubmkubtkmkubmmkubtkm...

output:

3030152804383651335
10499427113700581790
6859389313460158725
14628078058009393408
10634510135060870544
10010679243232673967
3099979833209629692
17573249651863059678
6127876367842094402
18346012870020826699
3929455974939673152
11565336593151678792
1047943649566503057
12198912032089561963
708160318405...

result:

ok 100000 lines

Subtask #4:

score: 6
Accepted

Test #22:

score: 6
Accepted
time: 988ms
memory: 173692kb

input:

100000 100000
zbbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaabab...

output:

16102224067619618967
2409962914769200003
427496158535942638
17668679206267169316
9612725428377010375
16283030984784184667
14966758574838045581
8108029333542434517
5821899279772898061
7354415533246368927
15016230232022193055
9072126619623269970
5490256818353051548
432088324301719512
13681741566473101...

result:

ok 100000 lines

Test #23:

score: 0
Accepted
time: 879ms
memory: 169512kb

input:

100000 100000
zsyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysy...

output:

4559870725517531243
7294838067589907718
11611591353940805930
6570123277626119382
7422995984298182834
5907659314847245750
16910510485299347733
4264602948914788684
13190214217087942183
6600183534290302450
18342681242733610030
11565497126186922166
17128453730139037795
1670830382187028213
18164994643596...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 1081ms
memory: 175396kb

input:

100000 100000
zoooooooollexlwockjmmpcsmrmxbcsxiopbhrsgmuffubpextcneqsmtouhuovwmosufyvtciwaiqfgxdjgebcnwbeyyyascjixpskyeyoecigpydkqrssvcwcuirkwyxxbcfgjdorrrgdghdooooooooofnkxriqwewxjgitnhfrykdhcrpbgmcnqujvlugcougvywjyjknbcfqdohyxidpswedsqodaqavibkmrykeiqfmoyavdcctpjvqomwmhjysbynqskjvprebydvglxmnqsvxy...

output:

812998614822431625
1250302312590066903
0
17068288240276554944
8822011249064016718
5154878686056167322
16634251694703169315
7627132526351165031
17489820411768677459
1612901206518396247
9557606214238964493
8125053178366415794
6923591044772654970
16010694286126551160
0
11810757301219826743
180907391938...

result:

ok 100000 lines

Subtask #5:

score: 16
Accepted

Dependency #4:

100%
Accepted

Test #25:

score: 16
Accepted
time: 601ms
memory: 165088kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

15893638524428831028
10131593916133042820
10131593916133042820
1813611689029665142
15893638524428831028
10131593916133042820
1813611689029665142
10131593916133042820
9834492063345021236
9834492063345021236
15893638524428831028
9834492063345021236
9834492063345021236
10131593916133042820
158936385244...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 1071ms
memory: 153480kb

input:

100000 100000
zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzsz...

output:

14439422629921813482
7264444986505301195
8399425172162457504
17048555139745491862
16735123042057153971
12928309510252812093
16135471956121714472
17826672489979253119
16258051235616677222
8446479705050496657
7223602662161126632
1971470682186795478
8333561403870758533
863416755415237407
70175023211500...

result:

ok 100000 lines

Test #27:

score: 0
Accepted
time: 2120ms
memory: 194984kb

input:

100000 100000
abaabbbbabbbbabaabaaabbbaabbbabbabbbbbbbbbbbbbbbbbaabbaaaabbabbbbaaaabbbbbabbbabaaabbabbbbabababaabbabbaaaaaabbababaaaabbaaaaaaababaabaabbaaaaaabbaababbbbbabbaababbaaaabaaaabbabaaaaabababbaabababbbbbbbaabaabaaaabbbbbbbbabbbaaabababaaaabbbabbaaabbbbaaaabbaabaaaabababaaabbbabbababaaaabaa...

output:

10348496775022677298
12511671250199152445
13872505305538169853
16611708808942759173
11535776221933150702
16263435910894651648
10120655890750471139
12260508507784435643
1339500102427367364
4902372664266247810
1170842149015283078
16881711901865165778
16676861468327607676
14417665981067338986
102127466...

result:

ok 100000 lines

Test #28:

score: 0
Accepted
time: 1615ms
memory: 181516kb

input:

100000 100000
lillillihhkfizgepwynrylillillikkirovrdzfhpzlillillihhkfizgepwynrylillillilillillihhkfizgepwynrylillillikkirovrdzfhpzlillillihhkfizgepwynrylillillilillillihhkfizgepwynrylillillikkirovrdzfhpzlillillihhkfizgepwynrylillillilillillihhkfizgepwynrylillillikkirovrdzfhpzlillillihhkfizgepwynryli...

output:

2112665416168259268
18183038600342895680
13496966969913038858
8154126208909124618
16581409824991085770
10655339270320451046
1977020901569718806
15705817383532880856
1695950320333203980
5234818620184067040
3238449889140837400
13706176062802348859
4300409394832772695
11241971664447517011
1750563877984...

result:

ok 100000 lines

Test #29:

score: 0
Accepted
time: 1154ms
memory: 158676kb

input:

100000 100000
hryjkyemhhryjkyemhhryjkdhryjkyemhhryjkyemhhryjkhryjkyemhhryjkyemhhryjkdhryjkyemhhryjkyemhhryjkhryjkyemhhryjkyemhhryjkdhryjkyemhhryjkyemhhryjkhryjkyemhryjkyemhhryjkyemhhryjkdhryjkyemhhryjkyemhhryjkhryjkyemhhryjkyemhhryjkdhryjkyemhhryjkyemhhryjkhryjkyemhhryjkyemhhryjkdhryjkyemhhryjkyemhh...

output:

1939695913384962354
17781155715789077633
14249444338467462290
1732409044902774072
2456898424726847211
18174619427157967553
7805178411137067093
11839052306862933521
13792974201094165147
11225111816170182422
17974776061151883708
909790747551645956
2096851641726456436
7000387766636378371
91470084202943...

result:

ok 100000 lines

Test #30:

score: 0
Accepted
time: 1987ms
memory: 185164kb

input:

100000 100000
zczclzczclzczclzczclzczclzczclzczczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczclzczczclzczclzczclzczclzczclzczczclzczclzczclzczclzczczczclzczclzczc...

output:

15142314166577095386
14927680296391616636
4687871239826074213
10226656332404147438
16726518734590309113
3474385564785489282
6891956214543571385
18395149788637100899
8113398196263223132
3196273168945986346
18020475312376886048
14838565852674759204
13261449460509250692
10945505788793492627
50098028674...

result:

ok 100000 lines

Test #31:

score: 0
Accepted
time: 1795ms
memory: 182408kb

input:

100000 100000
fpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffphzflqvunyzgfpkvppamsbvdbbkaqgywfrvrnsneqjuxhdzxqdsswfpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpfpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilffpilf...

output:

303900597936489797
13155897641283878663
16562352308377160248
6544378102354430764
6176503777418422340
15851367915778395879
11844030414264234218
14338390011399563138
8190352458917263516
9925258023055873953
6138593044877745812
18181207298814038977
14877393532041837353
10193877411997854093
1952813602044...

result:

ok 100000 lines

Subtask #6:

score: 21
Accepted

Dependency #2:

100%
Accepted

Test #32:

score: 21
Accepted
time: 464ms
memory: 132072kb

input:

50000 50000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

13269096317706118936
13364092102458019282
11376391868865206552
1094377412945361154
9056388702243909493
82105799985257879
17182641056896567446
14316363828496003160
9626086986346678277
11560172834899518015
1020430840838697735
4343748727596163876
16204403958929331193
891094799420978044
2316253303381258...

result:

ok 50000 lines

Test #33:

score: 0
Accepted
time: 471ms
memory: 119492kb

input:

50000 50000
zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszsz...

output:

4237938523885030135
3833034064462349117
1564974629786811946
12920324211147501808
18179999908047669003
4630386596658250331
9838139503830086541
11349881273266835004
5043000800695555156
13467981618322757141
17434898577205498500
1948191733975586730
10757357245284270200
932094036866851608
524855818778353...

result:

ok 50000 lines

Test #34:

score: 0
Accepted
time: 761ms
memory: 140712kb

input:

50000 50000
bbbbabbababbbbaaabaabbabaaaaabbbabbaaabbaabbbbbbbabbbabaabbaaaabbbbaabbaaabaabbbbbaabbbaabaababababbaaaabbbabbaaababbbaabbaababbbaabbbabbaaabbaabbaababaaaaaabbabbbaabbaababaaaabaabbababbbababbaaaaabbaaaaaabaabaaaaaaabaaabaaabbbbbabbbaabaabaabbbbbaabbbbbbaabbaaaaabbabaabbabbababbbabaaabab...

output:

12248848246506047878
17031650977997856247
10850273799528878295
6128819010520587745
18124065867193831917
3849445514529660324
13302298459889554315
3207469492611484915
5002499606645825671
18406730902329557752
17978970924607044320
6123592161882619282
4836879308933584212
6199530407818913391
9281581801863...

result:

ok 50000 lines

Test #35:

score: 0
Accepted
time: 683ms
memory: 135336kb

input:

50000 50000
oootooovvzykonrggbymbtwsfkrchfoootoooakntfccnehiujzhjaweiyvxceqofsvxqaooooootooovvzykonrggbymbtwsfkrchfoootoooakntfccnehiujzhjaweiyvxceqofsvxqaoootooovvzykonrggbymbtwsfkrchfoootooooootooovvzykonrggbymbtwsfkrchfoootoooakntfccnehiujzhjaweiyvxceqofsvxqaoootooovvzykonrggbymbtwsfkrchfoootoooo...

output:

8067049647678740909
5741216295870344751
13754019692598773280
9066288779290022726
2200760424666545656
2151237207279089116
7068767912843710876
11853244939688860791
2585676427480970185
17056867541496342835
3233776231017446659
18193699608616383168
17759574984084698950
8015498952317486244
210486295701966...

result:

ok 50000 lines

Test #36:

score: 0
Accepted
time: 517ms
memory: 121256kb

input:

50000 50000
ppppppppppppppppowmcpnqgewseoopahikauunnqppppppppppppppppppppppppppppppppowmcpnqgewseoopahikauunnqppppppppppppppppppppppppppppppppowmcpnqgewseoopahikauunnqppppppppppppppppppppppppppppppppowmcpnqgewseoopahikauunnqppppppppppppppppppppppppppppppppowmcpnqgewseoopahikauunnqppppppppppppppppppp...

output:

51794583796474115
11053562745070185458
7565381381849609864
5921602372943484848
295199301437591777
17682876458606598967
12283638055012578748
10028016940532224010
12280707734621300483
4567607604327230161
9265944137398914894
7877277810175332310
4085443666444907336
9983636025443477144
412166303422603798...

result:

ok 50000 lines

Test #37:

score: 0
Accepted
time: 798ms
memory: 136204kb

input:

50000 50000
kbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkfkbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkfkbaqkkbaqkfkbaqkkbaqkfkbaqkkbaqkfkb...

output:

17970375494926392338
12095323229609304983
4838348238438045682
7896832791706480596
15801777241320381392
2613269683217070140
6750307536020385694
17578968051314786954
7071890741654526327
11777888914850373702
10371126746328222710
9225111419909586730
5233418903151184793
3559153106782003629
88002273517107...

result:

ok 50000 lines

Test #38:

score: 0
Accepted
time: 716ms
memory: 133708kb

input:

50000 50000
wczchwlmikhbatynoykqnlpvgrvcmhwwczchwwczchwlmikhbatynoykqnlpvgrvcmhwwczchwwczchwlmikhbatynoykqnlpvgrvcmhwwczchwwczchwlwczchwlmikhbatynoykqnlpvgrvcmhwwczchwwczchwlmikhbatynoykqnlpvgrvcmhwwczchwwczchwlmikhbatynoykqnlpvgrvcmhwwczchwwczchwlwczchwlmikhbatynoykqnlpvgrvcwczchwlmikhbatynoykqnlpv...

output:

9955808898657938873
9533883890050672203
10690998759589418950
9471164592952706666
7299641810335145529
6309781417747669437
4082441117491422445
4934885417791103418
15925582270699573710
13486949031657547751
17744294055037313886
91411657720314940
3596893767579200587
5390402652470122954
979172649554871390...

result:

ok 50000 lines

Test #39:

score: 0
Accepted
time: 743ms
memory: 135020kb

input:

50000 50000
liltqjsijecxwfcrdrkybnfbfhmhjuogkofjslilliltqjsijecxwfcrdrkybnfbfhmhjuogkofjslilliltqjsijecxwfcrdrkyliltqjsijecxwfcrdrkybnfbfhmhjuogkofjslilliltqjsijecxwfcrdrkybnfbfhmhjuogkofjslilliltqjsijecxwfcrdrkyliltqjsijecxwfcrdrkybnfbfhmhjuogkofjslilliltqjsijecxwfcrdrkybnfbfhmhjuogkofjslilliltqjsi...

output:

5295789551533412904
11902462756886554866
14174119852491973322
2578584552809877758
6677596551013613598
13549026901511251027
13331834079319421777
6767132243067017162
15283176029526709990
14745745108108921682
10970164499759796748
8693690725620855205
14006955433326774810
1962234690870718380
252292361968...

result:

ok 50000 lines

Test #40:

score: 0
Accepted
time: 635ms
memory: 135416kb

input:

50000 50000
kfiyzelyfkfkfiyzelyfkfkfiyzelyfkkfiyzelyfkfkfiyzelyfkfkfiyzelyfkkfiyzelyfkfkfiyzelyfkfkfiykfiyzelyfkfkfiyzelyfkfkfiyzelyfkkfiyzelyfkfkfiyzelyfkfkfiyzelyfkkfiyzelyfkfkfiyzelyfkfkfiykfiyzelyfkfkfiyzelyfkfkfiyzelyfkkfiyzelyfkfkfiyzelyfkfkfiyzelyfkkfiyzelyfkfkfiyzelyfkfkfidfsnttbzbzhdzbsefmy...

output:

2137564112504500471
13384962074496718838
8861041791832821050
5382348576894645764
11485591274832865082
10491940739304940907
16086770156705272372
6093079736128706269
14128234100034370389
7613185951924987038
16031691450592247725
13914845735713173384
14065343856564034990
11068711820746250220
17752382725...

result:

ok 50000 lines

Test #41:

score: 0
Accepted
time: 563ms
memory: 129168kb

input:

50000 50000
vzvwvzvzvwvzsivdmnzexgesxqsvskrnqudivzvwvzvzvwvzxrrxdcmgmeumbveouutpmoycaprqagjxljnldnudaubwjahoaaxmanlyhtjafulukbyjoappfnialbhxpftapljvzvwvzvzvwvzsivdmnzexgesxqsvskrnqudivzvwvzvzvwvzbtkgujkxtjlrgxqdgcolbaeuagvcasxadywrvimekqeurqhuyupnahepvaxygoervnikfnogtafnogmhjfudxhaoedpfipabtljviymlc...

output:

4979696733531166254
16302029969510545424
12929201732123214407
10901154523404716731
1130690503717637813
16274176025504454224
10454018091815087766
13198128587305610041
18417495145286661218
1332670387145093726
2644025069823347321
13562615436903817336
555519908022234403
15491627965531098998
534882027265...

result:

ok 50000 lines

Subtask #7:

score: 23
Accepted

Dependency #3:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #42:

score: 23
Accepted
time: 1069ms
memory: 166444kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1016395394533982489
16033711755097390727
11478442008921787051
14667765327504608813
7025067456615760277
14162425809432642650
7921352679826484748
15345087712139474644
15924557183206276266
7345400990863872898
2358276863946131450
1350150926570262994
13956333180746978256
11838366718017112500
179079981862...

result:

ok 100000 lines

Test #43:

score: 0
Accepted
time: 1114ms
memory: 154344kb

input:

100000 100000
zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzsz...

output:

10572099593376075199
9988758982686831779
5085408683026789799
824575656560973491
8815626032833177099
357631889691028789
6535776756273280846
8076157238003931370
11418057517479797827
99992339931906068
2595900725574754954
1730421005298664674
9760105626805751661
12079993317091535880
13557208030375017858
...

result:

ok 100000 lines

Test #44:

score: 0
Accepted
time: 2129ms
memory: 194212kb

input:

100000 100000
baabbabaaabbabbabaabaabaabbbbbbbaaaabbaabaaabbbababbababbbbbbabbbbbbbbaabababbbbabababababbbbbbaaabaaaaabbababbabbaabbbaababbbabbbabbbbbbabbbbabaabbbaaabbaabbbaaaaaaabbabbababbbbbbbbbababaaabaabbbbbbaabbbbbaababaaababbaaaaabaaabaababbbbbaabbbbaaabbbbbbaabaabbabbaabaaaabbabaabaaaabbabab...

output:

14176700672144789890
10817294471222993843
7785514598912378254
14964739329511417559
5147139062694097037
4830694357487280059
8616170817751677901
10639145812506512636
11472847379983983048
4899263505597537607
9021900809446053569
5279833005369086566
10908280484350309699
11875206169496589737
1015659753368...

result:

ok 100000 lines

Test #45:

score: 0
Accepted
time: 1819ms
memory: 182840kb

input:

100000 100000
eueueueueueueueueueueuhqvmierftfytglyzmhveytpakcaewarjtldifgyhalxgluponppxotzomvbnlftlmtyzojpzqagarqcxznvtfnlzszaevbkccvppzyeenngkkraaawtpapltvgtuoiqhoeueueueueueueueueueueueueueueueueueueueueueuhqvmierftfytglyzmhveytpakcaewarjtldifgyhalxgluponppxotzomvbnlftlmtyzojpzqagarqcxznvtfnlzsza...

output:

1588855275291796321
15943085510893868478
8406259817788156459
3535965475445776248
2813509710731034897
11499429150664161387
5904701572312013892
6563822606122544936
13763986965878192821
9470691435506277649
11567891291738794721
17585339693393601654
8794442202581095514
15437400692461950019
73484786838386...

result:

ok 100000 lines

Test #46:

score: 0
Accepted
time: 1165ms
memory: 159292kb

input:

100000 100000
zzzzzzzzxlogxubjgxndwahfinbrjrnqnccoxnqskkzzzzzzzzxyppcuxzqlnvjdlpcyfypeaoffaxvnsplyoxzzzzzzzzxlogxubjgxndwahfinbrjrnqnccoxnqskkzzzzzzzzzzzzzzzzxlogxubjgxndwahfinbrjrnqnccoxnqskkzzzzzzzzxyppcuxzqlnvjdlpcyfypeaoffaxvnsplyoxzzzzzzzzxlogxubjgxndwahfinbrjrnqnccoxnqskkzzzzzzzzzzzzzzzzxlogxu...

output:

12324070073594512565
6137979528943677014
7262875029855684308
11925589373364576705
14302152247337960862
11480048275252525951
1578141428586965080
13008331864704099955
3307343370544393033
5925463374232913789
5033937466691121825
10803771093222412877
11515241783106835072
17390498692373381651
532534903113...

result:

ok 100000 lines

Test #47:

score: 0
Accepted
time: 2102ms
memory: 184160kb

input:

100000 100000
zzafzzzzafzzzzafzzzzzafzzzzafzzzzafzzzzzafzzzzafzzzzafzzzzafzzzzafzzzzzafzzzzafzzzzafzzzzafzzzzafzzzzzafzzzzafzzzzafzzzzafzzzzafzzzzzafzzzzafzzzzafzzzzzafzzzzafzzzzafzzzzafzzzzafzzzzafzzzzafzzzzzafzzzzafzzzzzzafzzzzafzzzzzafzzzzafzzzzzafzzzzafzzzzzzzzzafzzzzafzzzzafzzzzzafzzzzafzzzzafz...

output:

17410315216501377669
15222637845444406879
14552324631549682249
10214730636973445525
7819297749800205942
15165942077526663279
10499046491441327318
15354710404216170446
11474320882508158324
18306984697026370734
818497615152767402
6048416276359744395
18092230200880041189
2025893546987889294
11578718095...

result:

ok 100000 lines

Test #48:

score: 0
Accepted
time: 1857ms
memory: 182532kb

input:

100000 100000
iiiiiievbtngaiiiiiizcbjsnsxwfbjnveqdqplnizwbzablyasaeksfiqbijvudsxqcmjmqvgftyhmuxkupmgcjkehbjqoehhqljqtekawaaelemvwqmcwyhuzbmgnhxtynbuckmldvtujyyahmnvbeiiiiiievbtngaiiiiiizcbjsnsxwfbjnveqdqplnizwbzablyasaeksfiqbijvudsxqcmjmqvgftyhmuxkupmgcjkehbjqoehhqljqtekawaaelemvwqmcwyhuzbmgnhxtynbu...

output:

15646426410510001159
8888085953827132922
158999884706368577
12058622663660437351
15147045293011642820
6737780543472573818
12421093832346036661
9760987055019174601
16086193560916732551
15768521267407614023
15248377391365790540
5454709149560508926
15725036823348138051
11771347483515039415
956703873456...

result:

ok 100000 lines

Test #49:

score: 0
Accepted
time: 2004ms
memory: 183844kb

input:

100000 100000
bqbqbqbgbdekynvtbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbbqbqbqbgbdekynvtbqbqbqbg...

output:

11865920330057413789
3376009358396511182
4303032469663092020
1720355408600252446
9521530762989655795
4466212886374444204
13786836384812945390
15030704860059809390
10183804211580163210
11081238405991306813
13909604236840927179
17926418657832249352
4985723755440501301
15621531314481808023
126202061863...

result:

ok 100000 lines

Test #50:

score: 0
Accepted
time: 1749ms
memory: 181584kb

input:

100000 100000
mimimmimimmimimmimimmiaefzgnmqgcmbporxdlgqunmkehmpwvqdvcpynhbphugvwimacczafstdcsjbqlixttxuauysmsrpffwlobshyhdrowlpiymbnhoqvmcmndmtrkchgpglapjomttorxmimimmimimmimimmimimmimimimmimimmimimmimimmiaefzgnmqgcmbporxdlgqunmkehmpwvqdvcpynhbphugvwimacczafstdcsjbqlixttxuauysmsrpffwlobshyhdrowlpiy...

output:

835575853237910975
17653371528123446093
2374036918263056564
6095433427826342465
12690976452983159085
9989895972079602
1653734870205200276
9188294739868904522
8873549259778148545
16554000159628060899
899169586016112083
13830925928078401556
295149222613782645
12747326293143444736
7838272218862100257
7...

result:

ok 100000 lines

Test #51:

score: 0
Accepted
time: 1673ms
memory: 180572kb

input:

100000 100000
ttttrrsdaaxtttteuibjerwhoomutkatknjcxlgbxgmxmugzxcgctihaxoexdkwoqbzruszxbslkneyugjnpgoupuauvkbkhqmnyaqtjvnuepqqebmriaquakqeiynfvkrcxqtibtwhttahbpqauzownmnhzexapdvbrwzcwddzfwoagoqpduttwhvvvnotwzqjowxatkqohzjygrtahpemromntgoemqpoewdiuhnrfszidorppysjmpcioolaqwaawkxftzttttrrsdaaxttttoehpjs...

output:

1961545821800948166
4357282015979021106
17766594773478244120
2798440387169394448
10336203062285988628
4025867987763702423
10779686098011860566
17526585533603228856
13633223423976957025
16710062896951368091
2239899710620647223
15941986347011209077
148115499152761710
2234768332766177800
11866553342153...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed