QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129874#6507. Recover the StringSortingML 1221ms249460kbC++5.0kb2023-07-23 02:17:502023-07-23 02:17:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 02:17:52]
  • 评测
  • 测评结果:ML
  • 用时:1221ms
  • 内存:249460kb
  • [2023-07-23 02:17:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
const ll mod=998244353;
vector<int>in[N];
int out[N];
int n,m,k;


ll w[N];
bool vis[N];
void dfs(int id){
	vis[id]=true;
	for(auto c:in[id]){
		if(!vis[c]) dfs(c);
	}
	if(in[id].empty()) w[id]=id;
	else{
		w[id]=0;
		for(int j=0; j<2 ;j++){
			w[id]=(w[id]+w[in[id][j%in[id].size()]])%mod;
		}
	}
}

ll f[N],inf[N];
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
ll C(ll x,ll y){
	return f[x]*inf[y]%mod*inf[x-y]%mod;
}
int find(vector<int>&v,int c){
	for(int i=0; i<v.size() ;i++){
		if(c==v[i]) return i;
	}
	return -1;
}

vector<int>cyclic(vector<int>g,int p){
	if(p==1) return g;
	vector<int>head;
	{
		for(auto c:in[g[0]]){
			bool ok=true;
			int d=c;
			for(int i=0; i<g.size() ;i++){
				int p=find(in[g[i]],c);
				if(p==-1) ok=false;
				if(in[g[i]].size()==2){
					c^=in[g[i]][0];
					c^=in[g[i]][1];
				}
			}
			if(ok && d==c) head.push_back(c);
		}
	}
	int c=head[0];
	vector<int>ng;
	ng.push_back(c);
	for(int i=0; i<g.size() ;i++){
		if(in[g[i]].size()==2){
			c^=in[g[i]][0];
			c^=in[g[i]][1];
		}
		ng.push_back(c);
	}
	ng.pop_back();
	return cyclic(ng,p-1);
}
vector<int>karina(vector<int>g,int p){//not guarenteed that g is distinct
	/*cout << "karina " << p << endl;
	for(auto c:g) cout << c << ' ';
	cout << endl;*/
	if(p==1) return g;
	vector<int>head;
	{
		for(auto c:in[g[0]]){
			bool ok=true;
			int d=c;
			for(int i=0; i<g.size() ;i++){
				int p=find(in[g[i]],c);
				if(p==-1) ok=false;
				if(in[g[i]].size()==2){
					c^=in[g[i]][0];
					c^=in[g[i]][1];
				}
			}
			if(ok) head.push_back(d);
		}
	}
	int c=head[0];
	vector<int>ng;
	ng.push_back(c);
	for(int i=0; i<g.size() ;i++){
		if(in[g[i]].size()==2){
			c^=in[g[i]][0];
			c^=in[g[i]][1];
		}
		ng.push_back(c);
	}
	return karina(ng,p-1);
	
}
int mem[N];

ll jk[N];
vector<int>winter(vector<int>g,int p){//guarenteed that g is distinct
	if(g.size()+100>p) return karina(g,p);
	vector<int>head;
	{
		for(auto c:in[g[0]]){
			bool ok=true;
			int d=c;
			for(int i=0; i<g.size() ;i++){
				int p=find(in[g[i]],c);
				if(p==-1) ok=false;
				if(in[g[i]].size()==2){
					c^=in[g[i]][0];
					c^=in[g[i]][1];
				}
			}
			if(ok) head.push_back(d);
		}
	}
	int c=head[0];
	vector<int>ng;
	ng.push_back(c);
	for(int i=0; i<g.size() ;i++){
		if(in[g[i]].size()==2){
			c^=in[g[i]][0];
			c^=in[g[i]][1];
		}
		ng.push_back(c);
	}
	for(auto c:ng) mem[c]=0;
	int fl=-1,fr=-1;
	for(int i=1; i<ng.size() ;i++){
		if(ng[mem[ng[i]]]==ng[i]){
			fl=mem[ng[i]];
			fr=i;
			break;
		}
	}
	if(fl==-1){
		return winter(ng,p-1);
	}
	vector<int>nk,nc;
	for(int i=0; i<fl ;i++){
		nk.push_back(ng[i]);
	}
	for(int i=fl; i<fr ;i++) nc.push_back(ng[i]);
	for(int i=fr; i<ng.size() ;i++) nk.push_back(ng[i]);
	/*cout << "WINTER" << endl;
	cout << "NC: ";
	for(auto c:nc) cout << c << ' ';
	cout << endl;
	cout << "NK: ";
	for(auto c:nk) cout << c << ' ';
	cout << endl;*/
	
	p--;
	if(nc.size()==2 && nk.size()>2){
		vector<int>fn;
		auto v1=winter(nk,p);
		for(int i=0; i<fl+1 ;i++) fn.push_back(v1[i]);
		for(int i=fl; i<v1.size() ;i++) fn.push_back(v1[i]);
		return fn;
	}
	auto v2=cyclic(nc,p);
	int pr=v2.size();
	for(int i=0; i<p ;i++){
		v2.push_back(v2[i%pr]);
	}
	for(int i=0; i<v2.size() ;i++){
		jk[fl+i]=v2[i];
	}
	vector<int>v3;
	for(int i=fl-1; i>=0 ;i--){
		ll cur=w[ng[i]];
		for(int j=1; j<=p-1 ;j++){
			cur=(cur+(mod-C(p-1,j))*jk[i+j])%mod;
		}
	}
	for(int i=fr+1; i<ng.size() ;i++){
		ll cur=w[ng[i]];
		for(int j=0; j<p-1 ;j++){
			cur=(cur+(mod-C(p-1,j))*jk[i+j])%mod;
		}
		jk[i+p-1]=cur;
	}
	for(int i=0; i<ng.size()+p-1 ;i++){
		v3.push_back(jk[i]);
	}
	return v3;
}

int lb[N];
string greedy(vector<int>s){
	for(int i=1; i<=n ;i++) lb[i]=0;
	int ptr=0;
	string res;
	for(auto c:s){
		//cout << "haha " << c << endl;
		if(lb[c]==0){
			lb[c]=++ptr;
		}
		res+='a'+lb[c]-1;
	}
	return res;
}
void solve(){
	cin >> n >> m;
	for(int i=1; i<=n ;i++){
		in[i].clear();
		out[i]=0;
		vis[i]=false;
	}
	f[0]=1;
	for(int i=1; i<=n ;i++) f[i]=f[i-1]*i%mod;
	inf[n]=pw(f[n],mod-2);
	for(int i=n; i>=1 ;i--) inf[i-1]=inf[i]*i%mod;
	for(int i=1; i<=m ;i++){
		int u,v;cin >> u >> v;
		in[v].push_back(u);
		out[u]++;
	}
	if(n==1){
		cout << "a\n";
		return;
	}
	int boss=0;
	for(int i=1; i<=n ;i++){
		if(out[i]==0){
			boss=i;break;
		}
	}
	dfs(boss);
	{//compute length
		int x=boss;
		k=1;
		while(!in[x].empty()){
			k++;
			x=in[x][0];
		}
	}
	if(in[boss].size()==1){
		for(int i=1; i<=n ;i++) cout << "a";
		cout << '\n';
		return;
	}
	auto v1=winter({in[boss][0],in[boss][1]},k-1);
	string s1=greedy(v1);
	auto v2=winter({in[boss][1],in[boss][0]},k-1);
	string s2=greedy(v2);
	cout << min(s1,s2) << '\n';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t;cin >> t;while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 37372kb

input:

3
1 0
5 6
2 4
2 5
5 3
4 3
1 5
1 4
8 11
1 2
1 4
1 6
2 5
3 4
3 6
4 5
4 7
5 8
6 7
7 8

output:

a
aba
aaba

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 208ms
memory: 38900kb

input:

26837
1 0
2 1
2 1
3 2
1 3
2 3
3 2
3 1
1 2
5 5
4 3
5 1
1 2
3 2
5 3
5 6
2 4
2 5
5 3
4 3
1 5
1 4
5 5
1 5
2 1
2 4
4 5
3 4
6 6
1 4
5 3
2 4
4 6
3 6
2 3
4 3
1 3
3 4
2 1
7 8
2 5
1 3
7 1
3 5
7 6
1 2
4 6
6 3
8 11
2 6
2 7
3 7
8 1
6 4
4 5
7 4
7 1
3 8
2 8
1 5
8 10
8 1
4 5
7 8
3 5
3 1
7 3
1 2
5 2
6 4
6 3
9 11
5 2...

output:

a
aa
ab
aaa
aab
aba
aab
abc
aaaa
aaab
aaba
aabb
aabc
aaba
abab
abac
abba
aaab
abbc
abca
abac
aabc
abcd
aaaaa
aaaab
aaaba
aaabb
aaabc
aabaa
aabab
aabac
aabba
aaabb
aabbc
aabca
aabcb
aabcc
aabcd
aaaba
abaab
abaac
ababa
aabab
ababc
abaca
abacb
aabcb
abacd
aabba
abaab
abbac
abbba
aaaab
abbbc
abbca
abaac...

result:

ok 26837 lines

Test #3:

score: 0
Accepted
time: 221ms
memory: 38936kb

input:

6450
148 290
30 17
69 52
99 36
15 20
96 129
17 64
86 137
74 81
145 138
135 30
113 118
26 52
125 60
39 34
15 59
112 92
126 68
13 23
33 96
145 148
71 88
77 51
81 86
12 127
54 5
47 31
13 21
49 137
51 66
135 48
45 62
93 53
133 119
76 65
94 104
103 25
10 143
44 2
4 80
92 57
131 99
64 28
36 148
53 122
35 ...

output:

abbabaababbaabbabaab
abbcacababccababcbca
abcdefghijklmnopqrst
abaababaabaababaabab
abcabcabcabcabcabcab
abaabaabaabaabaabaab
ababaababaababaababa
abaabaabaabaababaaba
abababababababababab
abacabacabacabacabac
abacabadabacabaeabac
aabaabbabbbaabbaabba
aaababbcbbccaaaabcac
abcadefghijfklmkcbdf
aabaca...

result:

ok 6450 lines

Test #4:

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

input:

970
920 1834
730 734
56 197
114 794
161 101
228 454
791 135
423 9
877 886
875 387
840 727
730 643
587 823
112 816
672 87
911 365
251 329
478 863
76 580
869 898
906 598
222 116
523 621
349 645
601 897
109 271
26 594
877 691
409 891
245 286
146 591
289 95
786 850
576 8
131 507
6 285
71 695
853 713
265...

output:

ababbabaabbaababbaabbabaabbaababbabaababbaabbabaab
ababccababcbcaabcbcacabcababcbcaabcbcacabbcacababc
abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxz
abaababaabaababaababaabaababaabaababaababaabaababa
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab
abaabaabaabaabaabaabaabaabaabaabaabaabaabaaba...

result:

ok 970 lines

Test #5:

score: 0
Accepted
time: 227ms
memory: 37452kb

input:

237
3672 7338
128 799
1687 1156
3289 2676
17 11
10 2456
3634 1671
1180 2885
1838 3438
272 406
1704 2120
2612 2145
3172 1407
2717 3154
2801 1157
1377 2383
3458 3086
1633 3374
1922 869
958 248
2150 2186
1010 2998
370 1368
3407 2495
3644 987
1582 1701
2231 3541
1600 1620
2574 2836
3238 2131
1373 1548
2...

output:

abbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababba
aabcbcacabbcacababcbcacababccababcbcaabcbcacabcababcbcaabcbcacabbcacababcabcbcacabbcacababccababcbca
abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvzxyabcdefghijklmnopqrstuvzwyabcdefghijklmnopqrstuvz...

result:

ok 237 lines

Test #6:

score: 0
Accepted
time: 317ms
memory: 44212kb

input:

30
33368 66730
8076 11100
29514 11018
19224 28482
7851 20178
15965 14582
27252 7790
21764 13370
14476 32499
32535 26445
13036 10117
21957 8939
27288 2575
94 31016
28912 8162
11851 20676
1998 14167
23076 4834
13894 23588
4510 16856
4125 24548
7174 31028
20038 16939
13363 29338
27074 24233
14616 29951...

output:

abbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaab...

result:

ok 30 lines

Test #7:

score: 0
Accepted
time: 500ms
memory: 74684kb

input:

8
380248 760490
124441 243214
318264 317073
80812 184051
371269 92314
147997 324777
348208 151765
277437 22744
135856 228557
170049 232045
211622 83057
272356 232823
47448 177829
101380 373767
357788 184436
373026 30555
89629 377654
213780 51067
227975 39349
216809 210156
42077 295276
195939 221049
...

output:

abbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababba...

result:

ok 8 lines

Test #8:

score: 0
Accepted
time: 644ms
memory: 165296kb

input:

1
1000000 999999
486593 40134
567630 575732
673482 763704
372903 393266
657204 514133
677524 433408
258586 60505
668823 278755
406509 351060
877657 86847
393838 390004
323007 188430
833631 698149
362171 368078
725792 944166
810862 211037
579856 958663
293964 656704
398325 41189
393451 571249
585688 ...

output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

result:

ok single line: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

Test #9:

score: 0
Accepted
time: 826ms
memory: 107900kb

input:

1
999720 1999418
478960 367385
278842 195576
978938 976238
621173 945176
934972 578856
824323 381756
538870 587404
445290 681032
934823 385654
924723 412221
85667 342451
175667 376718
825906 546292
215330 897312
29111 214255
903178 224277
622872 949028
895275 674752
744266 238233
917807 485857
50574...

output:

ababbaaaabbaaababbbabaaababaabbaababbbabbbaababbaaaabbabbbbbababbbaababaababaabbaabbbbbaabaababbbbbbbaaabbabaaabbaabbbababaabaabbbaabbabababbababababbbaabbbbbbbabbbabbbbbaabbaaaaabbbbabbaaaaababaabbababaababababbababbaabbabaaaababaabbababbbbaaaabaaabbaababaaaabbbabaaaaabbbaaabbaababbbaaaabaabbbbaabb...

result:

ok single line: 'ababbaaaabbaaababbbabaaababaab...abbbaabaababbaaabbaabbbababbbba'

Test #10:

score: 0
Accepted
time: 794ms
memory: 105892kb

input:

1
999962 1999902
52152 909124
778034 197109
215551 980572
351009 284250
906426 112777
146723 864320
128930 437120
297457 358563
702334 350219
168315 3105
750352 326219
541338 400633
725295 147687
463415 95558
557045 884970
906696 895067
8701 56935
472957 784385
733678 464051
491501 368221
717902 907...

output:

aababbaaabbaaaabbabaabbbabbaabaaaabbabbabbbbabbbaaabbbbbbaabbaabbabbabbabaaaabaabbaaababbbbbaaababaaaababaabbababbbababbabaaaaaaabbaabbababbaabbaabaabababbaaabaaaaababababbbabbaabaaababbbaaaabaababbbbbaababbabbaaaabbbabbbbbaabaaabaaabbaaabbbbababbaabbbbbbbabababbbbaabaaaaabbbabbbbabaaaaabbaabbabbbaa...

result:

ok single line: 'aababbaaabbaaaabbabaabbbabbaab...aababaaaaaabbabaabbbbaabbaabbab'

Test #11:

score: 0
Accepted
time: 816ms
memory: 107956kb

input:

1
999932 1999842
994049 660788
387551 736624
508811 633488
317145 571345
906407 201785
430886 611119
183526 415265
720900 956714
207924 571189
781568 293026
258860 300050
29668 968606
711768 267147
140099 193742
353070 17072
117128 701452
842704 198461
918561 757129
879182 813948
245889 282501
46994...

output:

aabaaabababbabbababbbaaabbababaabaabaabbababbbababababbbabbbaabbabaabbaaaaaabababbaaababbabbabbabaaabaabbabaaabbbabbaabaaaaaaaabaabbaababbaaababababbbabaaaaaababbbabbbabbabbbabbaaaababbbbabbbabbaababaabbbabaaabbabaaabbaaabababbbabaaabbaaababbbaaababbaabbbabbbbbabbbabbbabbbbabaaaaaaabaababbaaabababaa...

result:

ok single line: 'aabaaabababbabbababbbaaabbabab...baabaaababbaaaaabaaabbbaaaabbaa'

Test #12:

score: 0
Accepted
time: 810ms
memory: 105948kb

input:

1
999960 1999898
696875 9265
618298 741593
334125 932167
316155 284255
923880 106712
771194 353262
31998 417868
845589 256875
591867 976859
220019 209003
829310 14740
460460 37659
538159 801865
462765 878326
602060 979546
157850 511382
761195 500165
433201 295913
87888 947492
306572 761401
978020 91...

output:

aaaaabbabaabbbabababbaaaabbaaaabaabaababbabbbaabbaaabbbbaaaaabababbaabaabbbabbaaabbabbaabbaabaaabbaaaababbababaabbbaabaababaabbbbabbbbbbaabbaababbabbbbbabbaabbaabaaababbaaaaaabbbaaaaaabbababaabaaababbabaaaabbbbbababbabaabbabbabbaaabaaaaabaaaabbabaaababbabbbbbbaaaabaabbaababbaaaaaaaababbaababaaabbbab...

result:

ok single line: 'aaaaabbabaabbbabababbaaaabbaaa...bbbbbbbbabaaaaaaaaabbabbaaaabbb'

Test #13:

score: 0
Accepted
time: 827ms
memory: 107980kb

input:

1
999286 1998549
332293 847900
781086 328251
89438 882788
175083 14440
572430 574257
809569 484269
663930 438265
122446 76616
651689 649277
10930 366807
865522 459778
415599 426786
191310 197100
747014 674992
395012 954730
372947 143720
681954 55327
377093 403183
960062 910427
919504 396335
314041 2...

output:

aabbacbacbccccabcacccabbbabcccacbaaaaaaccacbccaacbbaaacbcbaccbbacaacabcaccccaabcabccaaccbaaabbabbccbbbcbcbbbccababbbbbcaabbacaaacaabbaacbaabbbbbcbccaccbbcbabcbacccabcbbcbcaaabbbabbaccacacbaacaabbaacccacbaabbccbbcabacabbcbababccbbcbaacacbaccaaabbabbbbbaacbbbaaabacaabcacaaaccaaccbcababacbbabbababacbcc...

result:

ok single line: 'aabbacbacbccccabcacccabbbabccc...acbacbbabaaacaccbccaabbbbaaaaba'

Test #14:

score: 0
Accepted
time: 832ms
memory: 105856kb

input:

1
999331 1998641
729147 538731
921253 798894
885546 677818
298747 97157
180087 234737
418721 783414
901052 913813
595106 405323
295245 567060
70011 388501
377766 19230
874327 848890
928988 650497
238183 939267
593826 388828
573609 454635
81052 5415
661081 742732
500902 266652
996206 520864
328011 14...

output:

aabacbaaccbabbabbacaccbbabcbccabcabbbacbccacbabccbbcacbabbcbbabbacacccaaccccbaaccbaabcbcaaaaaacacbccbbcaabcbaabaccbcabacaccbbbabccabaaabbbbbcbacacacaabcacaabccccabcaabaacacbccabaaccabaccaabcacbccbbabbacbbcbabccaabbbcbacbbbcabaabcabacbaaccaccacabcacbaccaabacacccbabaacbbbcbcabcbabcababbaabacaacacccacb...

result:

ok single line: 'aabacbaaccbabbabbacaccbbabcbcc...cacacacaaaaacbbaaaccbaacbccaaca'

Test #15:

score: 0
Accepted
time: 858ms
memory: 105908kb

input:

1
999390 1998754
371866 116100
905495 392764
44483 862055
894183 603825
297556 557791
204825 860195
258135 783387
213801 233286
733327 526541
291442 435626
497561 467258
125745 889357
162794 595141
727020 316815
329022 931460
658882 219351
855248 963142
453518 646179
49612 456747
168958 167848
23953...

output:

aabbbccaaddebdeebadbabadcdddbacaacababeeabbeebddadedaddaadedcdebccabeaebcdbaabceaceebabeeeddeecaecccddabdbbacadaedceddbecaecdcbdaebbdbaacaaebddaeaaabaddbecaacacacedccdabbaaacdeaccacdbaeeecaecbeddcdaecabceaebdebaeceebbbcdbdeacdcbacceaaebeecbecdaadcabbdbcadbaaeabcdaeabcdcaabdbcebecacebcdceeeacebbabada...

result:

ok single line: 'aabbbccaaddebdeebadbabadcdddba...eeccdaabdcbadbdcbaecedbdccdaeba'

Test #16:

score: 0
Accepted
time: 826ms
memory: 105956kb

input:

1
999332 1998641
340224 312609
496357 621563
282231 31016
9727 518497
345711 368257
231510 162608
370656 157276
520228 905900
444817 419597
284400 368374
619796 817878
542290 224955
388559 105743
824688 371866
837389 734221
600626 944539
93565 550551
676681 298291
663021 283487
761202 315067
748929 ...

output:

aaaabbcaddcacaecdedaadbcbeadddbebbedeededceddedcadadacadceddbddbcadcdabedaabdbccededaccedabecacbacdcacebaecaabbdeedcdaacaacaceaeeedeecbbbeedacdeaaebcadaddcdecaadebabbcbcbbddcadcbeabeaededbcacdbbdcabeaaeaaedabdbcbeadaddadedddaebcacacbdbdedcccaabbbdaebdadecbecabaedadcbceecbdadacdbbdabeaaddebcbacdcbaca...

result:

ok single line: 'aaaabbcaddcacaecdedaadbcbeaddd...eacabbeddaaebbabcadcccbccbacdaa'

Test #17:

score: 0
Accepted
time: 790ms
memory: 108068kb

input:

1
999739 1999440
205098 344014
307300 441050
151960 549625
675401 498542
254496 388186
804623 686320
449469 974202
149674 935006
81205 629864
388824 158142
4307 138602
862844 464387
337179 904964
437580 558766
679226 445604
698011 971021
661578 367602
698306 240195
179735 321954
638187 260543
541268...

output:

ababcdefdgfcdafhhceahiifjgafafcigfgfagjdjigccjgfcjifaegcghjiadafegiaajfbjjbajdddjjjfggggjgaccdchcafcddbhcfchbjjcjfjbihebdjbbcfafbfhdfhibdjhcgajahjibfgicfibadjacggejebbgjijaafdidgbajgidffahebabbghecffcfgiaficgichiffadidjfheaibhfbhjegeghjbecdjdjjhadjaieieeebagcehdicjdgbdadgceaaefahgfjjaebiajdjdibeheeb...

result:

ok single line: 'ababcdefdgfcdafhhceahiifjgafaf...cfhdacdjbjjddfgcabahhcdeiicjjce'

Test #18:

score: 0
Accepted
time: 827ms
memory: 107932kb

input:

1
999710 1999383
937916 289472
397745 223193
993084 450771
753199 164546
143627 180490
834071 338355
930758 765524
949290 91931
660057 139978
516021 518052
871186 290530
170047 970212
327356 621467
28958 564133
69866 550611
793613 404090
468057 410337
75929 627503
834050 483273
545988 569261
672096 ...

output:

aabcdefgfbhhccdeigdgjbffiadhbfiidghdehbddedajggcahedibjegediaeeafjbiedbgaagfehgigbghdgbjjfcbggfgcdghahahijjiagaiihbeiiefchhhgdjchecefccfhdadfeffibffhebdbjicccgehhchdcfjibbjbajbcigefgiahjhahgdahfjjifjgcjbggjbbhhhahbebbaeeajabcgahjiaajaaejcjgffhcadeggjhdibddggjibajejdbaahiigbdcdafbcdebjiedbgjbidfhddgg...

result:

ok single line: 'aabcdefgfbhhccdeigdgjbffiadhbf...jgaagcajigbaejchgeebccacidafbfd'

Test #19:

score: 0
Accepted
time: 659ms
memory: 164920kb

input:

1
1000000 999999
278296 106049
911981 972246
893106 498127
783362 841190
100615 892567
336171 546759
879578 798806
821558 165334
240626 948176
766870 782719
698585 659818
433374 475363
210776 45956
160561 881213
929083 451179
276955 528871
172610 1150
945837 980812
612046 510874
516551 688101
401500...

output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

result:

ok single line: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

Test #20:

score: 0
Accepted
time: 1221ms
memory: 249460kb

input:

1
999999 1999994
581178 432299
504497 15192
717769 924100
36894 56780
350786 794293
246364 706614
179777 929163
22940 704272
114548 224999
620984 147378
124534 370669
505076 273968
57565 156162
541654 824947
916216 571797
789038 941852
350195 648312
405505 10481
468099 554657
404064 883737
532801 98...

output:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

result:

ok single line: 'ababababababababababababababab...bababababababababababababababab'

Test #21:

score: 0
Accepted
time: 1006ms
memory: 199560kb

input:

1
999998 1999991
502440 225432
907870 129550
370548 895535
620827 138519
897488 833709
258967 197331
89186 611424
230243 115052
954916 685415
382575 991163
444881 168318
477042 695931
194483 310115
507944 516190
212825 890287
912499 452579
963934 970547
834795 353372
605876 302159
822307 403587
8405...

output:

abbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabb...

result:

ok single line: 'abbabbabbabbabbabbabbabbabbabb...abbabbabbabbabbabbabbabbabbabba'

Test #22:

score: 0
Accepted
time: 952ms
memory: 161836kb

input:

1
999998 1999989
595730 310210
908053 394407
461180 848797
672792 775917
456419 134484
715782 940107
711822 990066
783823 505433
358475 383299
798906 799596
4778 559674
386597 918032
282719 688058
607254 369671
418402 146760
860019 606201
702960 835553
465554 416276
659508 639592
630598 289700
66072...

output:

abbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbacabbac...

result:

ok single line: 'abbacabbacabbacabbacabbacabbac...bbacabbacabbacabbacabbacabbacab'

Test #23:

score: 0
Accepted
time: 835ms
memory: 132648kb

input:

1
999995 1999984
985741 202112
113452 812649
354353 812277
914828 794156
237877 784099
83225 363810
460713 920418
882028 800901
100788 205903
159925 413984
967001 483208
331627 948744
570437 582893
13328 86930
767339 632074
18502 997818
406585 599919
467701 341607
864711 804632
818010 362731
824254 ...

output:

aaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaababaaabaaabab...

result:

ok single line: 'aaabaaababaaabaaababaaabaaabab...ababaaabaaababaaabaaababaaabaaa'

Test #24:

score: 0
Accepted
time: 793ms
memory: 109744kb

input:

1
999928 1999843
780792 443802
738669 482072
537914 842795
629514 977885
89155 978805
453095 46839
277560 840110
720578 751856
364055 148013
864991 290855
773216 943671
870509 856883
849463 758421
599401 354294
524399 488376
232309 297812
740639 386214
453935 356707
625717 765634
728871 222854
36708...

output:

aaabcbaabccacabbaababababaaacccbbcbbabbbbcbaacbcbbacbbcccaaabbbccbbcbabcabbcbabcbcbbacacaacaabbcacbcaaabcbaabccacabbaababababaaacccbbcbbabbbbcbaacbcbbacbbcccaaabbbccbbcbabcabbcbabcbcbbacacaacaabbcacbcaaabcbaabccacabbaababababaaacccbbcbbabbbbcbaacbcbbacbbcccaaabbbccbbcbabcabbcbabcbcbbacacaacaabbcacbc...

result:

ok single line: 'aaabcbaabccacabbaababababaaacc...ababaaacccbbcbbabbbbcbaacbcbbac'

Test #25:

score: -100
Memory Limit Exceeded

input:

1
999999 1499996
543259 17410
19444 340297
23045 521300
220491 517443
277358 699622
73281 353606
236580 492358
61489 960056
25447 699120
947866 294363
416423 700035
663938 203930
587798 626412
119412 932504
356124 522705
998857 821629
431645 781068
770294 779724
460263 352045
492971 437971
713950 27...

output:


result: