QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292982#4824. Bracket-and-bar Sequencesucup-team1447#AC ✓5ms3840kbC++143.1kb2023-12-28 18:44:302023-12-28 18:44:30

Judging History

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

  • [2023-12-28 18:44:30]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3840kb
  • [2023-12-28 18:44:30]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
	int x;cin>>x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
 
#define maxn 2000005
#define inf 0x3f3f3f3f

ull f[76],g[76];

void init(){
	f[0]=1;
	For(i,1,75){
		For(j,1,i-1) f[i]+=f[j]*g[i-j];
		For(j,0,i-3) f[i]+=f[j]*f[i-3-j],g[i]+=f[j]*f[i-3-j];
//		cout<<"i: "<<i<<" "<<f[i]<<" "<<g[i]<<"\n";
	}
}


int T,n;
char s[maxn];

ull solve(int l,int r){
	int n=r-l+1;
//	cout<<"l,r "<<l<<" "<<r<<"\n";
	assert(n%3==0);
	if(n<=3)return 0;
	int tp=0,pos=-1,mid=-1;
	Rep(i,r,l){
		if(s[i]==')')++tp;
		if(s[i]=='(')--tp;
		if(tp==0){
			pos=i;
			break;
		}
		if(tp==1 && s[i]=='|') mid=i;
	}
	ull res=0;
	assert(pos!=-1);
	if(pos==l){
		For(j,1,n-1) res+=f[j]*g[n-j];
		assert(mid!=-1);
		int lef=mid-l-1;
		For(j,0,lef-1) res+=f[j]*f[n-3-j];
		int fl=solve(l+1,mid-1),fr=solve(mid+1,r-1);
		res+=fl*f[r-mid-1]+fr;
//		cout<<"fl,fr "<<fl<<" "<<fr<<"\n";
//		cout<<"l,r,res "<<l<<" "<<r<<" "<<res<<"\n";
		assert(res<f[n]);
		return res;
	}
	mid=pos;
	int nl=mid-l,nr=n-nl;
	int fl=solve(l,mid-1),fr=solve(mid,r);
	For(j,1,nl-1) res+=f[j]*g[n-j];
	
	For(j,1,nr-1) fr-=f[j]*g[nr-j];
	
	res+=fl*g[n-nl]+(fr);
//	cout<<"ENC "<<fl<<" "<<fr<<" "<<g[n-nl]<<"\n";
//	cout<<"L,R,RES "<<l<<" "<<r<<" "<<res<<"\n";
	return res;
}

void enc(){
	cin>>T;
	while(T--){
		cin>>n>>(s+1);
		n*=3;
		ull res=solve(1,n);
		cout<<res<<"\n";
	}
}

void buildF(int l,int r,int res);
void buildG(int l,int r,int res){
	int n=r-l+1;
	assert(n%3==0);
//	cout<<"buildG "<<l<<" "<<r<<" "<<res<<"\n";
	if(n==0)return;
	if(n==3){
		s[l]='(';
		s[l+1]='|';
		s[l+2]=')';
		return;
	}
	
	For(j,0,n-3) if(j%3==0) {
		if(res<f[j]*f[n-3-j]){
			s[l]='(',s[r]=')';
			int mid=l+j+1;
			s[mid]='|';
			int fl=res/f[n-3-j],fr=res%f[n-3-j];
			buildF(l+1,mid-1,fl);
			buildF(mid+1,r-1,fr);
			return;
		}else{
			res-=f[j]*f[n-3-j];
			continue;
		}
	}
	assert(0);
}
void buildF(int l,int r,int res){
//	cout<<"buildF "<<l<<" "<<r<<" "<<res<<"\n";
	int n=r-l+1;
	assert(n%3==0);
	if(n==0)return;
	if(n==3){
		s[l]='(';
		s[l+1]='|';
		s[l+2]=')';
		return;
	}
	For(j,1,n-1)if(j%3==0){
		if(res<f[j]*g[n-j]){
			int mid=(l+j-1);
			int fl=res/g[n-j],fr=res%g[n-j];
			buildF(l,mid,fl);
			buildG(mid+1,r,fr);
			return;
		}
		else{
			res-=f[j]*g[n-j];
			continue;
		}
	}
	buildG(l,r,res);
}
void dec(){
	cin>>T;
	while(T--){
		cin>>n;
		int x;cin>>x;
		n*=3;
		buildF(1,n,x);
		For(i,1,n)cout<<s[i];cout<<endl;
	}
}

signed main()
{
	init();
	string str;cin>>str;
	if(str=="encode")enc();
	else dec();
	return 0;
}
/*
encode
3
4
((((|)|)|)|)
5
(|(|))((|(|))|)

7 15 (kmax-n+4)
9 27
11 50-11
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

encode
3
1
(|)
4
((((|)|)|)|)
5
(|(|))((|(|))|)

output:

0
54
42

input:

decode
3
1
0
4
54
5
42

output:

(|)
((((|)|)|)|)
(|(|))((|(|))|)

result:

ok 3 lines

Test #2:

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

input:

encode
1
1
(|)

output:

0

input:

decode
1
1
0

output:

(|)

result:

ok single line: '(|)'

Test #3:

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

input:

encode
3
2
((|)|)
1
(|)
2
(|(|))

output:

2
0
1

input:

decode
3
2
2
1
0
2
1

output:

((|)|)
(|)
(|(|))

result:

ok 3 lines

Test #4:

score: 100
Accepted
time: 2ms
memory: 3840kb

input:

encode
1000
3
(|)(|)(|)
3
(|)(|(|))
3
(|)((|)|)
3
(|(|))(|)
3
(|(|)(|))
3
(|(|(|)))
3
(|((|)|))
3
((|)|)(|)
3
((|)|(|))
3
((|)(|)|)
3
((|(|))|)
3
(((|)|)|)
4
(|)(|)(|)(|)
4
(|)(|)(|(|))
4
(|)(|)((|)|)
4
(|)(|(|))(|)
4
(|)(|(|)(|))
4
(|)(|(|(|)))
4
(|)(|((|)|))
4
(|)((|)|)(|)
4
(|)((|)|(|))
4
(|)((|)...

output:

2
0
1
3
5
6
7
4
8
9
10
11
15
7
8
13
0
1
2
14
3
4
5
6
16
9
10
18
19
20
27
25
26
28
30
31
32
29
33
34
35
36
17
11
12
21
37
38
39
22
23
24
40
41
42
45
43
44
46
48
49
50
47
51
52
53
54
90
55
56
82
30
31
32
83
33
34
35
36
88
51
52
75
76
77
2
0
1
3
5
6
7
4
8
9
10
11
89
53
54
78
12
13
14
79
80
81
15
16
17
...

input:

decode
1000
3
2
3
0
3
1
3
3
3
5
3
6
3
7
3
4
3
8
3
9
3
10
3
11
4
15
4
7
4
8
4
13
4
0
4
1
4
2
4
14
4
3
4
4
4
5
4
6
4
16
4
9
4
10
4
18
4
19
4
20
4
27
4
25
4
26
4
28
4
30
4
31
4
32
4
29
4
33
4
34
4
35
4
36
4
17
4
11
4
12
4
21
4
37
4
38
4
39
4
22
4
23
4
24
4
40
4
41
4
42
4
45
4
43
4
44
4
46
4
48
4
49
4
5...

output:

(|)(|)(|)
(|)(|(|))
(|)((|)|)
(|(|))(|)
(|(|)(|))
(|(|(|)))
(|((|)|))
((|)|)(|)
((|)|(|))
((|)(|)|)
((|(|))|)
(((|)|)|)
(|)(|)(|)(|)
(|)(|)(|(|))
(|)(|)((|)|)
(|)(|(|))(|)
(|)(|(|)(|))
(|)(|(|(|)))
(|)(|((|)|))
(|)((|)|)(|)
(|)((|)|(|))
(|)((|)(|)|)
(|)((|(|))|)
(|)(((|)|)|)
(|(|))(|)(|)
(|(|))(|(|)...

result:

ok 1000 lines

Test #5:

score: 100
Accepted
time: 2ms
memory: 3584kb

input:

encode
1000
6
(|((((|)|)|)|)(|))
6
(|((|)(|)(|)|(|)))
6
(|((|)(|(|))|(|)))
6
(|((|)((|)|)|(|)))
6
(|((|(|))(|)|(|)))
6
(|((|(|)(|))|(|)))
6
(|((|(|(|)))|(|)))
6
(|((|((|)|))|(|)))
6
(|(((|)|)(|)|(|)))
6
(|(((|)|(|))|(|)))
6
(|(((|)(|)|)|(|)))
6
(|(((|(|))|)|(|)))
6
(|((((|)|)|)|(|)))
6
(|((|)(|)(|)(...

output:

829
908
906
907
909
911
912
913
910
914
915
916
917
933
925
926
931
918
919
920
932
921
922
923
924
934
927
928
936
937
938
945
943
944
946
948
949
950
947
951
952
953
954
935
929
930
939
955
956
957
940
941
942
958
959
960
963
961
962
964
966
967
968
965
969
970
971
972
519
351
352
486
261
262
263
...

input:

decode
1000
6
829
6
908
6
906
6
907
6
909
6
911
6
912
6
913
6
910
6
914
6
915
6
916
6
917
6
933
6
925
6
926
6
931
6
918
6
919
6
920
6
932
6
921
6
922
6
923
6
924
6
934
6
927
6
928
6
936
6
937
6
938
6
945
6
943
6
944
6
946
6
948
6
949
6
950
6
947
6
951
6
952
6
953
6
954
6
935
6
929
6
930
6
939
6
955
...

output:

(|((((|)|)|)|)(|))
(|((|)(|)(|)|(|)))
(|((|)(|(|))|(|)))
(|((|)((|)|)|(|)))
(|((|(|))(|)|(|)))
(|((|(|)(|))|(|)))
(|((|(|(|)))|(|)))
(|((|((|)|))|(|)))
(|(((|)|)(|)|(|)))
(|(((|)|(|))|(|)))
(|(((|)(|)|)|(|)))
(|(((|(|))|)|(|)))
(|((((|)|)|)|(|)))
(|((|)(|)(|)(|)|))
(|((|)(|)(|(|))|))
(|((|)(|)((|)|)...

result:

ok 1000 lines

Test #6:

score: 100
Accepted
time: 2ms
memory: 3564kb

input:

encode
1000
7
((|)(|(|(|)(|)))|(|))
7
((|)(|(|)(|)(|))(|)|)
7
(|(|(|)((|)|))(|(|)))
7
((|(|))|(|))(|(|))(|)
7
(|)((|(|)((|)|)(|))|)
7
(((|(|)(|))|((|)|))|)
7
((|)((|(|))(|(|))|)|)
8
(|)(|)(|(|))((|((|)|))|)
7
((|)|)((|)|)(((|)|)|)
7
(|)((|)|)(((|)|(|))|)
7
(|((|)|(|)))(|(|)(|))
7
((|)|(|(|)((|)|))(|...

output:

6056
6753
4245
2847
599
7405
6421
8011
1607
1213
1748
5405
11838
2854
4231
4889
3243
1881
4840
5576
4103
3367
6364
7601
7228
1073
1925
2123
6548
434
2443
4050
3759
2024
5263
6578
7703
3197
7348
204
1753
293
2276
4662
3948
4318
3854
4916
976
5046
6312
1122
5351
2647
2455
7550
5748
5329
4558
5851
7425...

input:

decode
1000
7
6056
7
6753
7
4245
7
2847
7
599
7
7405
7
6421
8
8011
7
1607
7
1213
7
1748
7
5405
8
11838
7
2854
7
4231
7
4889
7
3243
7
1881
7
4840
7
5576
7
4103
7
3367
7
6364
7
7601
7
7228
7
1073
7
1925
7
2123
7
6548
7
434
7
2443
7
4050
7
3759
7
2024
7
5263
7
6578
7
7703
7
3197
7
7348
7
204
7
1753
7
2...

output:

((|)(|(|(|)(|)))|(|))
((|)(|(|)(|)(|))(|)|)
(|(|(|)((|)|))(|(|)))
((|(|))|(|))(|(|))(|)
(|)((|(|)((|)|)(|))|)
(((|(|)(|))|((|)|))|)
((|)((|(|))(|(|))|)|)
(|)(|)(|(|))((|((|)|))|)
((|)|)((|)|)(((|)|)|)
(|)((|)|)(((|)|(|))|)
(|((|)|(|)))(|(|)(|))
((|)|(|(|)((|)|))(|))
(|)(|)(|)((|)|(|))((|)|)
((|)((|)...

result:

ok 1000 lines

Test #7:

score: 100
Accepted
time: 2ms
memory: 3840kb

input:

encode
1000
7
(|(|)(|)(|(((|)|)|)))
7
(((|)|)((|)|)(|(|))|)
7
(|(|))((|)(|)|(|(|)))
7
(|)(|((|((|(|))|))|))
7
(|((|)|(|))(|((|)|)))
7
(|)((|(|)(|(|)))(|)|)
7
(((|)(|)(|)|)|(|(|)))
7
((|(|))|)((|)|)(|(|))
7
(|)(|(|((|)(|)|(|))))
7
(((|)(|)|)|(|))(|)(|)
7
(|)(|(|(|)((|)|))(|))
7
((|)(|)|(((|)|)|(|)))
...

output:

4030
6665
939
253
4167
555
6022
2046
170
3090
101
5619
16790
16206
1034
3056
1701
3802
8002
14970
3667
4411
6418
6750
2366
3442
5029
899
1309
7689
1450
4300
826
7300
6672
5830
4652
5613
154
2187
186
5700
1659
4326
6317
5257
4977
5841
664
1263
5428
167
936
846
3938
6045
7335
2143
221
4010
5525
6365
2...

input:

decode
1000
7
4030
7
6665
7
939
7
253
7
4167
7
555
7
6022
7
2046
7
170
7
3090
7
101
7
5619
8
16790
8
16206
7
1034
7
3056
7
1701
7
3802
8
8002
8
14970
7
3667
7
4411
7
6418
7
6750
7
2366
7
3442
7
5029
7
899
7
1309
7
7689
7
1450
7
4300
7
826
7
7300
7
6672
7
5830
7
4652
7
5613
7
154
7
2187
7
186
7
5700
...

output:

(|(|)(|)(|(((|)|)|)))
(((|)|)((|)|)(|(|))|)
(|(|))((|)(|)|(|(|)))
(|)(|((|((|(|))|))|))
(|((|)|(|))(|((|)|)))
(|)((|(|)(|(|)))(|)|)
(((|)(|)(|)|)|(|(|)))
((|(|))|)((|)|)(|(|))
(|)(|(|((|)(|)|(|))))
(((|)(|)|)|(|))(|)(|)
(|)(|(|(|)((|)|))(|))
((|)(|)|(((|)|)|(|)))
(|)(|)(|(|(|(|))))(|)(|)
(|)(|)(|)(|...

result:

ok 1000 lines

Test #8:

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

input:

encode
1000
7
(((|)|(|)(|)(|)(|))|)
7
(|)(|(|(|)))((|(|))|)
7
((|)|)(|((|)|))(|(|))
7
(|(|(|)))((|(|(|)))|)
7
(((|)(|)|)|(|(|)))(|)
7
((|)((((|)|)|)|)|(|))
7
(|((|((|)|(|))(|))|))
7
((|)(((|)(|)(|)|)|)|)
8
(|)(|)(|)(|(|))((|)|(|))
7
(|(|(|))(|)((|(|))|))
7
((((|(|))|)(|)(|)|)|)
7
(|(|))((|)(|)|)((|)...

output:

7312
1529
1994
1361
3540
6080
5182
6457
9814
4135
7577
1985
1303
7379
1495
493
4059
5865
5905
3824
5277
1304
2239
3345
2490
7719
28
1472
714
4240
3879
5369
3019
3141
1117
16158
5432
5771
3798
3727
4321
5304
6274
4405
6749
2890
1126
3387
4577
2273
7282
2121
4172
4531
3166
7607
4498
2365
3589
1424
193...

input:

decode
1000
7
7312
7
1529
7
1994
7
1361
7
3540
7
6080
7
5182
7
6457
8
9814
7
4135
7
7577
7
1985
7
1303
7
7379
7
1495
7
493
7
4059
7
5865
7
5905
7
3824
7
5277
7
1304
7
2239
7
3345
7
2490
7
7719
7
28
7
1472
7
714
7
4240
7
3879
7
5369
7
3019
7
3141
7
1117
8
16158
7
5432
7
5771
7
3798
7
3727
7
4321
7
53...

output:

(((|)|(|)(|)(|)(|))|)
(|)(|(|(|)))((|(|))|)
((|)|)(|((|)|))(|(|))
(|(|(|)))((|(|(|)))|)
(((|)(|)|)|(|(|)))(|)
((|)((((|)|)|)|)|(|))
(|((|((|)|(|))(|))|))
((|)(((|)(|)(|)|)|)|)
(|)(|)(|)(|(|))((|)|(|))
(|(|(|))(|)((|(|))|))
((((|(|))|)(|)(|)|)|)
(|(|))((|)(|)|)((|)|)
((|)|)(|)(((|)|(|))|)
((((|)|)|(|...

result:

ok 1000 lines

Test #9:

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

input:

encode
1000
7
((|(|)(|(|)))|)((|)|)
7
(|(|))((|(|(|(|))))|)
7
(|)(|(|((|)(|)|)))(|)
8
(|)(|)(|(|)(|))(|(|(|)))
7
(|((((|(|))|)|(|))|))
7
(((|(|))|)|)(|)((|)|)
7
((|(|))((|)|)|((|)|))
7
(((|(|))(|)|)(|)(|)|)
7
(|(|))(|(|)(|)(|)(|))
7
(((|)((|)|)|(|))(|)|)
7
((|(|)((|(|))|))(|)|)
7
(|)((|(|))(|)|((|)|...

output:

2389
990
2482
9637
5247
2159
5918
6872
886
6958
6886
375
3730
928
5819
2372
416
5886
7067
14958
2259
2588
3261
11843
5944
4073
399
2141
537
1959
14975
4449
7745
1310
6349
2867
688
4422
2544
1854
6021
6416
2097
5598
3978
7080
5844
6200
3363
5900
4445
4805
1437
3284
15820
5524
3977
2048
6417
371
4048
...

input:

decode
1000
7
2389
7
990
7
2482
8
9637
7
5247
7
2159
7
5918
7
6872
7
886
7
6958
7
6886
7
375
7
3730
7
928
7
5819
7
2372
7
416
7
5886
7
7067
8
14958
7
2259
7
2588
7
3261
8
11843
7
5944
7
4073
7
399
7
2141
7
537
7
1959
8
14975
7
4449
7
7745
7
1310
8
6349
7
2867
7
688
7
4422
7
2544
7
1854
7
6021
8
6416...

output:

((|(|)(|(|)))|)((|)|)
(|(|))((|(|(|(|))))|)
(|)(|(|((|)(|)|)))(|)
(|)(|)(|(|)(|))(|(|(|)))
(|((((|(|))|)|(|))|))
(((|(|))|)|)(|)((|)|)
((|(|))((|)|)|((|)|))
(((|(|))(|)|)(|)(|)|)
(|(|))(|(|)(|)(|)(|))
(((|)((|)|)|(|))(|)|)
((|(|)((|(|))|))(|)|)
(|)((|(|))(|)|((|)|))
((((|)(|)|)|)(|)|)(|)
(|(|))((|)|...

result:

ok 1000 lines

Test #10:

score: 100
Accepted
time: 2ms
memory: 3568kb

input:

encode
1000
7
((((|)|(|)(|))|)(|)|)
7
(((|)(|)|)(|)(|(|))|)
7
(|)(|((|(|)(|))(|)|))
7
(|(|)(((|)|)|(|))(|))
7
(|)((|(|))|(|(|(|))))
7
((|(|)(|)(|)(|))|)(|)
7
(|((|)(|(|)((|)|))|))
7
(((|)|(|))|)((|)|)(|)
7
(|)(((|(|))|(|))|(|))
7
(|(|))(|((|)|))(|(|))
7
(|(|)(|))(|(|((|)|)))
7
((|(|)(|))|(|))(|)(|)
...

output:

7006
6685
236
4320
346
3748
5032
2868
441
1980
1314
3086
442
1020
2917
3319
6963
1774
4813
3070
15423
1990
6558
4187
6353
2116
1095
2321
5805
3733
874
7012
3262
6385
3677
5252
2291
156
3594
4294
2513
227
4034
3814
6419
7120
4981
5732
15760
6189
1949
4330
2711
345
5169
1714
234
5496
2785
4528
4383
69...

input:

decode
1000
7
7006
7
6685
7
236
7
4320
7
346
7
3748
7
5032
7
2868
7
441
7
1980
7
1314
7
3086
7
442
7
1020
7
2917
7
3319
7
6963
7
1774
7
4813
7
3070
8
15423
7
1990
7
6558
7
4187
8
6353
7
2116
7
1095
7
2321
7
5805
7
3733
7
874
7
7012
7
3262
7
6385
7
3677
7
5252
7
2291
7
156
7
3594
7
4294
7
2513
7
227
...

output:

((((|)|(|)(|))|)(|)|)
(((|)(|)|)(|)(|(|))|)
(|)(|((|(|)(|))(|)|))
(|(|)(((|)|)|(|))(|))
(|)((|(|))|(|(|(|))))
((|(|)(|)(|)(|))|)(|)
(|((|)(|(|)((|)|))|))
(((|)|(|))|)((|)|)(|)
(|)(((|(|))|(|))|(|))
(|(|))(|((|)|))(|(|))
(|(|)(|))(|(|((|)|)))
((|(|)(|))|(|))(|)(|)
(|)((((|)|)|(|))|(|))
((|)|)(|(|)(((...

result:

ok 1000 lines

Test #11:

score: 100
Accepted
time: 2ms
memory: 3584kb

input:

encode
1000
7
(|((|)(|)|(|))(|(|)))
7
(|(((|)|)(|((|)|))|))
7
(|)((|)((|)|)|)(|)(|)
7
(|(|))(|)(((|)(|)|)|)
7
(|(|(|((|)|(|)))))(|)
7
((|)(|(|))|(|))((|)|)
7
(|)((|)(|)|)(|(|))(|)
7
(|(((|)|(|(|)))|(|)))
7
(((|)((|)|)(|)|)|)(|)
7
((|)|)((((|)(|)|)|)|)
7
(((|)|(|)(|))|)((|)|)
7
(|(((|)(|)|)|(|(|))))
...

output:

4273
5077
2894
1274
3311
2315
2773
5014
3835
1154
2413
4968
3704
2367
6415
3782
4789
3099
7514
7506
6355
6807
3833
5227
3621
865
6452
7251
6391
7636
5833
3541
6519
4573
1824
1146
2453
1510
4341
4145
3340
1704
4316
4493
362
4519
5479
687
4141
606
1825
3045
402
3525
2566
7279
44
6469
3101
6140
7216
32...

input:

decode
1000
7
4273
7
5077
7
2894
7
1274
7
3311
7
2315
7
2773
7
5014
7
3835
7
1154
7
2413
7
4968
7
3704
7
2367
8
6415
7
3782
7
4789
7
3099
7
7514
7
7506
7
6355
7
6807
7
3833
7
5227
7
3621
7
865
8
6452
7
7251
7
6391
7
7636
7
5833
7
3541
7
6519
7
4573
7
1824
7
1146
7
2453
7
1510
7
4341
7
4145
7
3340
7
...

output:

(|((|)(|)|(|))(|(|)))
(|(((|)|)(|((|)|))|))
(|)((|)((|)|)|)(|)(|)
(|(|))(|)(((|)(|)|)|)
(|(|(|((|)|(|)))))(|)
((|)(|(|))|(|))((|)|)
(|)((|)(|)|)(|(|))(|)
(|(((|)|(|(|)))|(|)))
(((|)((|)|)(|)|)|)(|)
((|)|)((((|)(|)|)|)|)
(((|)|(|)(|))|)((|)|)
(|(((|)(|)|)|(|(|))))
((|(|)((|)|))(|)|)(|)
((|)((|)|)(|)|...

result:

ok 1000 lines

Test #12:

score: 100
Accepted
time: 2ms
memory: 3784kb

input:

encode
1000
7
(|(|(|(|)(|)(|(|)))))
7
(|(|(|(|(|)))(|)))(|)
7
(|(((|)(|(|))|)|)(|))
7
(|((|)(|(|(|))(|))|))
7
(|)((|)(|)|(((|)|)|))
7
((|(|))(|)(|)(|)(|)|)
7
(((|(|))|)|)((|(|))|)
7
((|(|(|))((|)(|)|))|)
7
(|(|)(|(|(|))(|))(|))
7
(|((|)|(|)(|(|)))(|))
7
(|((|)|(|)(|)(|(|))))
7
((|)|((|)(|(|(|)))|))
...

output:

4713
3297
4564
5034
339
6842
1893
7065
4306
4488
4856
5523
674
6386
15422
6514
3875
3996
6145
5485
895
1188
697
4420
6105
6405
6121
2871
5419
3441
4754
2875
6233
6345
2242
41
3878
7708
5885
4732
2085
1019
5934
3669
3279
1289
1888
3452
1363
3110
3793
5317
6976
6422
5809
3840
882
5862
5783
639
1164
52...

input:

decode
1000
7
4713
7
3297
7
4564
7
5034
7
339
7
6842
7
1893
7
7065
7
4306
7
4488
7
4856
7
5523
7
674
7
6386
8
15422
7
6514
7
3875
7
3996
7
6145
7
5485
7
895
7
1188
7
697
7
4420
7
6105
7
6405
7
6121
7
2871
7
5419
7
3441
7
4754
7
2875
7
6233
7
6345
7
2242
7
41
7
3878
7
7708
7
5885
7
4732
7
2085
7
1019...

output:

(|(|(|(|)(|)(|(|)))))
(|(|(|(|(|)))(|)))(|)
(|(((|)(|(|))|)|)(|))
(|((|)(|(|(|))(|))|))
(|)((|)(|)|(((|)|)|))
((|(|))(|)(|)(|)(|)|)
(((|(|))|)|)((|(|))|)
((|(|(|))((|)(|)|))|)
(|(|)(|(|(|))(|))(|))
(|((|)|(|)(|(|)))(|))
(|((|)|(|)(|)(|(|))))
((|)|((|)(|(|(|)))|))
(|)(((|)(|(|(|)))|)|)
((|)((|)|(|((|...

result:

ok 1000 lines

Test #13:

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

input:

encode
1000
7
(|(|((|)|))(|))((|)|)
7
((|)(|)|)(|)(|(|(|)))
7
((((|(|))|(|(|)))|)|)
8
(|)(|)(|)(|(((|)|)|)(|))
7
((((((|)|)|)|)|)|(|))
7
(((|((|)|)((|)|))|)|)
7
(|(|((|)|))(|)((|)|))
7
((|)(|)|(|((|(|))|)))
7
(|(|(|(|)(|)(|)))(|))
7
(|(|)((|)|(((|)|)|)))
7
((((|((|)(|)|))|)|)|)
7
(|(|))(|(|)(|))(|(|...

output:

2203
1672
7680
6370
6323
7621
4234
5612
4460
3942
7731
1976
6068
3520
4600
3720
4901
6332
7705
1763
1561
661
685
5861
2537
2740
5917
86
2210
5983
1844
2152
425
2167
4890
2624
2304
4970
3928
336
3341
4398
877
6778
137
7148
350
7022
4492
3925
6390
6478
2692
6848
986
3912
3922
2813
1112
34
3971
5733
57...

input:

decode
1000
7
2203
7
1672
7
7680
8
6370
7
6323
7
7621
7
4234
7
5612
7
4460
7
3942
7
7731
7
1976
7
6068
7
3520
7
4600
7
3720
7
4901
7
6332
7
7705
7
1763
7
1561
7
661
7
685
7
5861
7
2537
7
2740
7
5917
7
86
7
2210
7
5983
7
1844
7
2152
7
425
7
2167
7
4890
7
2624
7
2304
7
4970
8
3928
7
336
7
3341
7
4398
...

output:

(|(|((|)|))(|))((|)|)
((|)(|)|)(|)(|(|(|)))
((((|(|))|(|(|)))|)|)
(|)(|)(|)(|(((|)|)|)(|))
((((((|)|)|)|)|)|(|))
(((|((|)|)((|)|))|)|)
(|(|((|)|))(|)((|)|))
((|)(|)|(|((|(|))|)))
(|(|(|(|)(|)(|)))(|))
(|(|)((|)|(((|)|)|)))
((((|((|)(|)|))|)|)|)
(|(|))(|(|)(|))(|(|))
((|)(((|)|)|(|))|(|))
((|)(|)(|)|...

result:

ok 1000 lines

Test #14:

score: 100
Accepted
time: 2ms
memory: 3784kb

input:

encode
1000
8
(|(|((|)|)))(|(|)((|)|))
8
(|)(|(|)((|)(|)(|)|)(|))
8
(|)((|(|(|)(|))(|(|)))|)
8
(|)((|(((|)|)|))(|)|)(|)
8
(|((|)(|(|)(|(|)(|)))|))
8
(((|)|(|))(|((|)|(|)))|)
8
((|)(((|(|))(|)|)(|)|)|)
8
((|)((|)|)((|)(|)|)(|)|)
8
((|)|)(|(|(|)((|)|)(|)))
8
(|(|))(|((|)|(|((|)|))))
8
((((|)(|)(|)|(|)...

output:

8737
447
3209
14759
28269
36916
36087
38203
5476
4796
42905
31879
24306
14354
28085
9748
6112
31884
12096
13693
32835
1495
24715
20218
22661
14406
16711
34098
21877
757
26392
32691
24923
41560
39505
23710
28645
21301
17249
9034
3695
4855
28276
19517
14474
11963
1475
9141
25576
16036
16796
5885
39049...

input:

decode
1000
8
8737
8
447
8
3209
8
14759
8
28269
8
36916
8
36087
8
38203
8
5476
8
4796
8
42905
8
31879
8
24306
8
14354
8
28085
8
9748
8
6112
8
31884
8
12096
8
13693
8
32835
8
1495
8
24715
8
20218
8
22661
8
14406
8
16711
8
34098
8
21877
8
757
8
26392
8
32691
8
24923
8
41560
8
39505
8
23710
8
28645
8
2...

output:

(|(|((|)|)))(|(|)((|)|))
(|)(|(|)((|)(|)(|)|)(|))
(|)((|(|(|)(|))(|(|)))|)
(|)((|(((|)|)|))(|)|)(|)
(|((|)(|(|)(|(|)(|)))|))
(((|)|(|))(|((|)|(|)))|)
((|)(((|(|))(|)|)(|)|)|)
((|)((|)|)((|)(|)|)(|)|)
((|)|)(|(|(|)((|)|)(|)))
(|(|))(|((|)|(|((|)|))))
((((|)(|)(|)|(|)(|))|)|)
(((|)|)|((|)(|)(|)|(|)))
...

result:

ok 1000 lines

Test #15:

score: 100
Accepted
time: 2ms
memory: 3832kb

input:

encode
1000
9
((|)((|((|)(|)|(|(|))))|)|)
9
((((|)(|(|))|(((|)|)|))|)|)
9
(|((|((|)(((|)|)|)|))|(|)))
9
(((((|)|)|)((|)(|)|)(|)|)|)
9
(|)(((|(|))(|(|))|)(|)|(|))
9
(|)(|((|)|)(|)(|)(|)((|)|))
9
((((|)(|(|))|)(|)|)(|(|))|)
9
(|(|))(((|)(|)|(|(|))(|))|)
9
(|(((|)|(|))|(|)((|)|))(|))
9
(((|(|)((|)(|)|)...

output:

206758
244676
161507
241685
12792
2087
217295
28673
146532
224708
161381
38031
240282
184608
148196
127955
63875
99719
97586
207539
164491
65985
19961
62582
99947
8141
181427
101267
17135
176256
224328
139858
166394
178981
98672
168216
86774
135006
28921
3194
77048
155349
65065
48359
104292
54750
15...

input:

decode
1000
9
206758
9
244676
9
161507
9
241685
9
12792
9
2087
9
217295
9
28673
9
146532
9
224708
9
161381
9
38031
9
240282
9
184608
9
148196
9
127955
9
63875
9
99719
9
97586
9
207539
9
164491
9
65985
9
19961
9
62582
9
99947
9
8141
9
181427
9
101267
9
17135
9
176256
9
224328
9
139858
9
166394
9
1789...

output:

((|)((|((|)(|)|(|(|))))|)|)
((((|)(|(|))|(((|)|)|))|)|)
(|((|((|)(((|)|)|)|))|(|)))
(((((|)|)|)((|)(|)|)(|)|)|)
(|)(((|(|))(|(|))|)(|)|(|))
(|)(|((|)|)(|)(|)(|)((|)|))
((((|)(|(|))|)(|)|)(|(|))|)
(|(|))(((|)(|)|(|(|))(|))|)
(|(((|)|(|))|(|)((|)|))(|))
(((|(|)((|)(|)|)(|))|)(|)|)
(|((|((|(|))|)(|)(|)...

result:

ok 1000 lines

Test #16:

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

input:

encode
1000
10
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
10
((((((((((|)|)|)|)|)|)|)|)|)|)
10
(|(|(|(|(|(|(|(|(|(|))))))))))
10
((|)|)((|)|(((|)|)|)(|((|)|)))
10
(|)((|)|((|((|)(|((|)|))|))|))
10
(|)(((|)|)((|(|))((|)|)(|)|)|)
10
((|)(|((|)|))(|)((|(|))|(|))|)
10
(((((((|(|(|)))|)|)|)(|)|)|)|)
10
(((|)|((|)|))...

output:

593745
1430714
893207
170875
50507
82784
1235913
1426833
374488
156343
1010956
475955
335477
114936
336516
213405
214907
831088
995642
1095848
742459
1053360
1297482
1312760
128549
490846
684143
1011072
1384374
1397699
433775
14242
737894
794188
68448
1411908
532922
887690
874410
207596
385362
10503...

input:

decode
1000
10
593745
10
1430714
10
893207
10
170875
10
50507
10
82784
10
1235913
10
1426833
10
374488
10
156343
10
1010956
10
475955
10
335477
10
114936
10
336516
10
213405
10
214907
10
831088
10
995642
10
1095848
10
742459
10
1053360
10
1297482
10
1312760
10
128549
10
490846
10
684143
10
1011072
1...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|))))))))))
((|)|)((|)|(((|)|)|)(|((|)|)))
(|)((|)|((|((|)(|((|)|))|))|))
(|)(((|)|)((|(|))((|)|)(|)|)|)
((|)(|((|)|))(|)((|(|))|(|))|)
(((((((|(|(|)))|)|)|)(|)|)|)|)
(((|)|((|)|))|)(|)(|)((|)(|)|)
(|(|))(((|)|)(|)(|(|(...

result:

ok 1000 lines

Test #17:

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

input:

encode
1000
11
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
11
(((((((((((|)|)|)|)|)|)|)|)|)|)|)
11
(|(|(|(|(|(|(|(|(|(|(|)))))))))))
11
((|)|)((|(|))(|)(|)(|)|((|)(|)|))
11
(|((((|)|)|)|((|(|(((|)|)|)))|)))
11
((|)|(((|)|(|((|((|)|))|)(|)))|))
11
(((|)|)|)((|(|)(((|)|)|))(|(|))|)
11
((|)((|)|)|((|)((|)|)|(|(|...

output:

3545655
8414639
5275832
993741
5452873
6047274
1301453
6203316
6321793
5999866
1830326
3964740
6668005
1940582
6324968
3811943
3580015
555268
6363885
655018
4742167
8126035
3390894
3266865
2324373
2149043
8106904
8391039
176526
2810945
6563884
2303096
4714190
5354928
8397599
1529
5996045
2594728
768...

input:

decode
1000
11
3545655
11
8414639
11
5275832
11
993741
11
5452873
11
6047274
11
1301453
11
6203316
11
6321793
11
5999866
11
1830326
11
3964740
11
6668005
11
1940582
11
6324968
11
3811943
11
3580015
11
555268
11
6363885
11
655018
11
4742167
11
8126035
11
3390894
11
3266865
11
2324373
11
2149043
11
81...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
(((((((((((|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|)))))))))))
((|)|)((|(|))(|)(|)(|)|((|)(|)|))
(|((((|)|)|)|((|(|(((|)|)|)))|)))
((|)|(((|)|(|((|((|)|))|)(|)))|))
(((|)|)|)((|(|)(((|)|)|))(|(|))|)
((|)((|)|)|((|)((|)|)|(|(|(|)))))
((|(|)(|)(|))|((|(|))(|)|)(|...

result:

ok 1000 lines

Test #18:

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

input:

encode
1000
12
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
12
((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)
12
(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))
12
((|)|)((|)(|(|))(|(|))(|)((|)(|)|)|)
12
(((|(|((|)|))(|))(|)|)|)(((|)|)|(|))
12
((|)|)(|(|)((|(|((|)(|)|)))(|(|))|))
12
((|(|((|)|(|))(|)((|)|)(|)(|)(|)))|)
12
(|((|...

output:

21356643
50067107
31501460
5918497
13197320
5429191
46875356
29866831
35110408
20371483
48137976
26327845
6734994
1439885
37242841
1735022
7707372
32577964
24204493
22486100
39944074
25152213
31480733
6564294
24088989
24569004
8580996
47036704
49574234
18853127
5356513
39982046
3419898
34797422
8726...

input:

decode
1000
12
21356643
12
50067107
12
31501460
12
5918497
12
13197320
12
5429191
12
46875356
12
29866831
12
35110408
12
20371483
12
48137976
12
26327845
12
6734994
12
1439885
12
37242841
12
1735022
12
7707372
12
32577964
12
24204493
12
22486100
12
39944074
12
25152213
12
31480733
12
6564294
12
2408...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))
((|)|)((|)(|(|))(|(|))(|)((|)(|)|)|)
(((|(|((|)|))(|))(|)|)|)(((|)|)|(|))
((|)|)(|(|)((|(|((|)(|)|)))(|(|))|))
((|(|((|)|(|))(|)((|)|)(|)(|)(|)))|)
(|((|)((|)|(|(|))((|)|))|(|))(|)(|))
((|)...

result:

ok 1000 lines

Test #19:

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

input:

encode
1000
13
(((|)|(|((|)|)(|))(|)((|)|))(|((|)|))|)
13
(|((|)((|)|)((((|)|)((|)|)|)(|)|(|))|))
13
(|(|(|(|))(|)(|)(|(|((|)|)))(|(|))))(|)
13
((|(((|)|)(|(|))|((|)|(|))))((|(|))|)|)
13
(|)(((((|)|)|)(|)(|)(|(((|)|)|(|)))|)|)
13
((|((|)(|)(|)((|)|)|))|)(|)(|((|)(|)|))
13
(|(|)(|)((|(|(|(|)))(|))(|(...

output:

265189417
201069676
139296375
265101010
22695645
77735296
162775118
67930266
188307276
220834465
62140810
41169384
48055259
84430493
266703777
66262333
23441285
162485809
84789917
48687443
165619429
161500749
145031172
74812141
269257788
30509962
254131402
101406646
237250412
51696589
268435957
1616...

input:

decode
1000
13
265189417
13
201069676
13
139296375
13
265101010
13
22695645
13
77735296
13
162775118
13
67930266
13
188307276
13
220834465
13
62140810
13
41169384
13
48055259
13
84430493
13
266703777
13
66262333
13
23441285
13
162485809
13
84789917
13
48687443
13
165619429
13
161500749
13
145031172
...

output:

(((|)|(|((|)|)(|))(|)((|)|))(|((|)|))|)
(|((|)((|)|)((((|)|)((|)|)|)(|)|(|))|))
(|(|(|(|))(|)(|)(|(|((|)|)))(|(|))))(|)
((|(((|)|)(|(|))|((|)|(|))))((|(|))|)|)
(|)(((((|)|)|)(|)(|)(|(((|)|)|(|)))|)|)
((|((|)(|)(|)((|)|)|))|)(|)(|((|)(|)|))
(|(|)(|)((|(|(|(|)))(|))(|((|)|))|(|)))
(|)(|((|(|(|)(|)))|)...

result:

ok 1000 lines

Test #20:

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

input:

encode
1000
14
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
14
((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)
14
(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))
14
((|)|(|))(|((|)|))((|)((|)|(|)(|(|)))(|)|)
14
(|((|)|(|)((((|)|)|)(|)(|)|(|(((|)|)|)))))
14
(((|)|(|))|(|(|)(|))(|(|)))(|(((|)|(|))|))
14
(|)(|)(|(...

output:

792041443
1822766519
1153083940
339422644
1172000414
451505700
744689981
1507741309
657811424
1377837261
1042622629
1506856518
832143184
1510369585
1214304390
447239185
1021454617
814764586
1098762610
832905233
516899846
323181665
688551599
417964028
7028428
983445793
467825422
1313111583
1451415750...

input:

decode
1000
14
792041443
14
1822766519
14
1153083940
14
339422644
14
1172000414
14
451505700
14
744689981
14
1507741309
14
657811424
14
1377837261
14
1042622629
14
1506856518
14
832143184
14
1510369585
14
1214304390
14
447239185
14
1021454617
14
814764586
14
1098762610
14
832905233
14
516899846
14
3...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))
((|)|(|))(|((|)|))((|)((|)|(|)(|(|)))(|)|)
(|((|)|(|)((((|)|)|)(|)(|)|(|(((|)|)|)))))
(((|)|(|))|(|(|)(|))(|(|)))(|(((|)|(|))|))
(|)(|)(|(|)(|(|))((|)(|)(|)|))(|((|)|))(|)...

result:

ok 1000 lines

Test #21:

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

input:

encode
1000
15
((|(|))|(|(|((|((|)(|)|)(|(|)))|)))((|)|(|)))
15
(|)(|)(|(|(|)(|((|)(|((|)|))|)(|)))((|)(|)|))
15
((|)|)((|)(|)(|(|(|)(|)(|))((|)|))(|)|(|(|)))
15
(|(|)((|)|(((|)|)(|)(|)(|)|(|)))((|)|))((|)|)
15
((|(|(|)((|)|)((|)|((|(|))(|)|))))|)(|(|))(|)
15
(|)((|)|(|(|)))(((|)((|)|)|)|(|(|)(|((|)...

output:

8087467442
873628786
1225783224
3821824479
4732629154
1804192025
313838518
3016398981
9373162919
10562863485
1825963727
10849014985
7721529507
7536984518
8172613408
9614654252
6615417177
9029324019
3817556889
10778139892
1827195477
592947996
8394195989
3970489820
1518896052
8822841119
9036859676
562...

input:

decode
1000
15
8087467442
15
873628786
15
1225783224
15
3821824479
15
4732629154
15
1804192025
15
313838518
15
3016398981
15
9373162919
15
10562863485
15
1825963727
15
10849014985
15
7721529507
15
7536984518
15
8172613408
15
9614654252
15
6615417177
15
9029324019
15
3817556889
15
10778139892
15
1827...

output:

((|(|))|(|(|((|((|)(|)|)(|(|)))|)))((|)|(|)))
(|)(|)(|(|(|)(|((|)(|((|)|))|)(|)))((|)(|)|))
((|)|)((|)(|)(|(|(|)(|)(|))((|)|))(|)|(|(|)))
(|(|)((|)|(((|)|)(|)(|)(|)|(|)))((|)|))((|)|)
((|(|(|)((|)|)((|)|((|(|))(|)|))))|)(|(|))(|)
(|)((|)|(|(|)))(((|)((|)|)|)|(|(|)(|((|)|))))
(|)((|)|((|)((|(|)((|)(|...

result:

ok 1000 lines

Test #22:

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

input:

encode
1000
16
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
16
((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
16
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))))
16
((|)|(|(|)))(|)((|)(|(|(|(|))))((|)|(|))(|(|))|)
16
((((|)|)(|)|(|)(|)(|(|)((|)((|)|)|))(|))(|)|(|))
16
(|(|))(|((|)|(|((|)(|(|(|...

output:

30089093324
68328754958
43397658005
11283722249
56265832408
6295029372
46720992627
62925996764
27145716976
9499947855
30161284356
37385294072
64067009191
54952784140
13264395307
57603281496
51083572432
31341667690
2129506901
6446444194
20503515150
45648458269
31007616169
36531845450
35526800433
1578...

input:

decode
1000
16
30089093324
16
68328754958
16
43397658005
16
11283722249
16
56265832408
16
6295029372
16
46720992627
16
62925996764
16
27145716976
16
9499947855
16
30161284356
16
37385294072
16
64067009191
16
54952784140
16
13264395307
16
57603281496
16
51083572432
16
31341667690
16
2129506901
16
644...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))))
((|)|(|(|)))(|)((|)(|(|(|(|))))((|)|(|))(|(|))|)
((((|)|)(|)|(|)(|)(|(|)((|)((|)|)|))(|))(|)|(|))
(|(|))(|((|)|(|((|)(|(|(|)))|))((|)(|)|(|(|)))))
(|((|(...

result:

ok 1000 lines

Test #23:

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

input:

encode
1000
17
(((((|)(|(((|)|)|))|((|)|))(|(|(|))(|))|(|(|)))|)|)
17
((|((|((|((|)|))|(|)))|))|(|(((|)|)|)((|)|))((|)|))
17
((|)(|)|)(|)((|(|(|)((|(|))|))(|(|)((|)(|)|)))(|)|)
17
((((|)|)((|(|((|(((|)|)(|)|))|)(|(|)(|))(|)))|)|)|)
17
(((|)|)|(|(|((|(|(|(|))(|)(|)))((|)(|)|)|)((|)|))))
17
(|(|(((|)|...

output:

419795518668
323883421591
61223542057
412173903223
309321028620
256839082206
322177219852
118043288216
147672634683
271985039061
224407962261
133323318713
271757759732
302571661262
227756481783
100719867750
50838820213
171638407142
238946171450
124165745979
109373706456
332934360841
93284800612
4014...

input:

decode
1000
17
419795518668
17
323883421591
17
61223542057
17
412173903223
17
309321028620
17
256839082206
17
322177219852
17
118043288216
17
147672634683
17
271985039061
17
224407962261
17
133323318713
17
271757759732
17
302571661262
17
227756481783
17
100719867750
17
50838820213
17
171638407142
17...

output:

(((((|)(|(((|)|)|))|((|)|))(|(|(|))(|))|(|(|)))|)|)
((|((|((|((|)|))|(|)))|))|(|(((|)|)|)((|)|))((|)|))
((|)(|)|)(|)((|(|(|)((|(|))|))(|(|)((|)(|)|)))(|)|)
((((|)|)((|(|((|(((|)|)(|)|))|)(|(|)(|))(|)))|)|)|)
(((|)|)|(|(|((|(|(|(|))(|)(|)))((|)(|)|)|)((|)|))))
(|(|(((|)|)(|)|(|(|((|)|(|))(|)(|(|)))))...

result:

ok 1000 lines

Test #24:

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

input:

encode
1000
18
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
18
((((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
18
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))))))
18
((|)|((|(|))|(|)))(((|)|)((|)|)|)((|)|)(|(|))((|)|)(|)
18
((|)((|)|(|((|)|))((|(|))((|)(((|)|)|((|)|))|(|))|))|...

output:

1165244440017
2619631042664
1668912304992
1120236617746
2208970255237
1920075407351
1206644379011
1099943695902
1239428496052
1496227323700
691669853792
522597796450
1444159532300
670653111123
1686769815110
1061156315763
2561739120380
1704779873927
1060702576249
1431845797260
147449405153
1890094716...

input:

decode
1000
18
1165244440017
18
2619631042664
18
1668912304992
18
1120236617746
18
2208970255237
18
1920075407351
18
1206644379011
18
1099943695902
18
1239428496052
18
1496227323700
18
691669853792
18
522597796450
18
1444159532300
18
670653111123
18
1686769815110
18
1061156315763
18
2561739120380
18...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))))))
((|)|((|(|))|(|)))(((|)|)((|)|)|)((|)|)(|(|))((|)|)(|)
((|)((|)|(|((|)|))((|(|))((|)(((|)|)|((|)|))|(|))|))|)
(((|)|)|(|(|(|(|)(((((|)|...

result:

ok 1000 lines

Test #25:

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

input:

encode
1000
19
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
19
(((((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
19
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|)))))))))))))))))))
19
((|)|((|(|))|)((|)|(|)))(|)(|(((|)(|)(|)|(|(|))(|))|))(|)
19
(|((((|)(|)|)|)((|(((|)|)(|)|))|)|((|)|)(...

output:

7295393195727
16332922290299
10418692103367
6680717841409
9938033162700
2058556907020
10352327261457
14616479628570
9487205290702
4303415785995
6000758988214
13023923690213
5331009817786
15293355558890
12448344866111
13365050007091
15741491675940
6205838988435
9427575811497
1092959502202
14301546755...

input:

decode
1000
19
7295393195727
19
16332922290299
19
10418692103367
19
6680717841409
19
9938033162700
19
2058556907020
19
10352327261457
19
14616479628570
19
9487205290702
19
4303415785995
19
6000758988214
19
13023923690213
19
5331009817786
19
15293355558890
19
12448344866111
19
13365050007091
19
15741...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
(((((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|)))))))))))))))))))
((|)|((|(|))|)((|)|(|)))(|)(|(((|)(|)(|)|(|(|))(|))|))(|)
(|((((|)(|)|)|)((|(((|)|)(|)|))|)|((|)|)((|)|(|)))(|)(|))
(|((|)|))(...

result:

ok 1000 lines

Test #26:

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

input:

encode
1000
20
(|(|(|)))(|((|)|(((|(|(|)))|(|(|))(|(|)))(|)|)(|(|))(|)))(|)
20
((|)|)((((|)|(|))|((|((|)(|)|))(((|)|)(|)(((|(|))|)|)|)|))|)
20
(((((|)|)((((|)|)|)|((((|(|)(|(|)))|)|(|))|))(|)|(|(|)))|)|)
20
(((|((|)|(|))((((|(|)((|(|))(|)((|(|))|)|))|)|)|(|))(|))|)|)
20
((|)((|)(((|(|(|((|)|))))|)|)...

output:

40551505188998
11131380467763
101729210359960
101186700862494
51635931571198
21298944856419
36463141071580
38010301678552
22658507897638
11172355426790
52199160088357
38247637978275
63996100934650
36870191681075
16953496498306
12684307118223
20153893149882
87237928659314
31491773545637
2392212728761...

input:

decode
1000
20
40551505188998
20
11131380467763
20
101729210359960
20
101186700862494
20
51635931571198
20
21298944856419
20
36463141071580
20
38010301678552
20
22658507897638
20
11172355426790
20
52199160088357
20
38247637978275
20
63996100934650
20
36870191681075
20
16953496498306
20
1268430711822...

output:

(|(|(|)))(|((|)|(((|(|(|)))|(|(|))(|(|)))(|)|)(|(|))(|)))(|)
((|)|)((((|)|(|))|((|((|)(|)|))(((|)|)(|)(((|(|))|)|)|)|))|)
(((((|)|)((((|)|)|)|((((|(|)(|(|)))|)|(|))|))(|)|(|(|)))|)|)
(((|((|)|(|))((((|(|)((|(|))(|)((|(|))|)|))|)|)|(|))(|))|)|)
((|)((|)(((|(|(|((|)|))))|)|)|(|((|)(|)|((|)|))))|(|(|))...

result:

ok 1000 lines

Test #27:

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

input:

encode
1000
21
(((|((|(|)(|)(|(|)(|))(|))|))(|(|))|)(|(|))|(((|)|)|(|((|)|))))
21
((|)(|)(|)|(|((|(|)(|((|)|))(|)(|))(|(|)(|)(((|)|(|))(|)|))|)))
21
((|(|(|))(|)((|)|(|)))(|)|(((|)|)|(|(|(|)(|)(((|)(|)|)|)))))(|)
21
(|((|)(|(|))((|)|)(|)(|)((((|)|)|(|)(|))|)|))((|(|((|)|)))(|)|)
21
(|)((|)(|)|(|((((...

output:

502347984341649
472889796624245
321083786199542
167004778100755
211413910206632
506737761450807
583938846261020
420842923351296
156238156902429
222929269709689
262892737120440
248393272018472
255154194646615
239751475964802
535406748462032
364121960412759
266335331932693
52315583885316
4459801443462...

input:

decode
1000
21
502347984341649
21
472889796624245
21
321083786199542
21
167004778100755
21
211413910206632
21
506737761450807
21
583938846261020
21
420842923351296
21
156238156902429
21
222929269709689
21
262892737120440
21
248393272018472
21
255154194646615
21
239751475964802
21
535406748462032
21
...

output:

(((|((|(|)(|)(|(|)(|))(|))|))(|(|))|)(|(|))|(((|)|)|(|((|)|))))
((|)(|)(|)|(|((|(|)(|((|)|))(|)(|))(|(|)(|)(((|)|(|))(|)|))|)))
((|(|(|))(|)((|)|(|)))(|)|(((|)|)|(|(|(|)(|)(((|)(|)|)|)))))(|)
(|((|)(|(|))((|)|)(|)(|)((((|)|)|(|)(|))|)|))((|(|((|)|)))(|)|)
(|)((|)(|)|(|(((((|)|(|))|)|)|((|)|(|))(|)((...

result:

ok 1000 lines

Test #28:

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

input:

encode
1000
22
(|((|)|(|(|(((|)(|)(|)|)((|)(((|)|)|)|)(|)|)))(|(|)))(|(((|)|)|)))
22
((|(|(|)))|(|)(|)((|)|))(((|)|)(|((((|)|)|)|))|(|))((((|)(|)|)|)|)
22
((|(|((|(|))|)))(|(|(|)((|((|((((|)|)|(|))|(|)(|)))|)(|))|)))(|)|)
22
((|)(|((|(|(|(|(|)(|(|)))))(|)(|))(((|)|)|(|))(|((|)|)(|))|))(|)|)
22
(((|)...

output:

2368312646389991
1092392622945962
3665517923715415
3651604228881709
3086871073743232
1265194097245859
2066858108555464
2535186371640446
1157514395604069
1057233721550265
1331016099410285
1554115013771300
3620751635442264
1418502856053621
3635993628609153
1267997743873280
1143600813939895
17191721942...

input:

decode
1000
22
2368312646389991
22
1092392622945962
22
3665517923715415
22
3651604228881709
22
3086871073743232
22
1265194097245859
22
2066858108555464
22
2535186371640446
22
1157514395604069
22
1057233721550265
22
1331016099410285
22
1554115013771300
22
3620751635442264
22
1418502856053621
22
36359...

output:

(|((|)|(|(|(((|)(|)(|)|)((|)(((|)|)|)|)(|)|)))(|(|)))(|(((|)|)|)))
((|(|(|)))|(|)(|)((|)|))(((|)|)(|((((|)|)|)|))|(|))((((|)(|)|)|)|)
((|(|((|(|))|)))(|(|(|)((|((|((((|)|)|(|))|(|)(|)))|)(|))|)))(|)|)
((|)(|((|(|(|(|(|)(|(|)))))(|)(|))(((|)|)|(|))(|((|)|)(|))|))(|)|)
(((|)(((|(|))|)|)|((|)|))|(((|)(...

result:

ok 1000 lines

Test #29:

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

input:

encode
1000
23
((|)((|)|)(|((|(|(|(|(|))((|)((|)((|)|(|))(|((|(|))(|)|))|)|))))|))|)
23
(|(|)((|)|(|)))(|((|(|(((|((|)|)(|))|)|)))|)((|(|))(|)|(|(|)(|)(|))))
23
(|(|))((((|)|)(|)|(((|(|))|)(|)|))(|((|(|)(|))(|)|(|((|)|)(|))(|)))|)
23
(((|((|)((|(|))(|)|(|))|))((|)|(|(|)(|(|)((|)|(|)))))((|)|(|)(|))|...

output:

21995016750161681
3907200436046702
2381163150737765
25134121432287837
21515898870569569
13514592009306087
24474685240426740
23001635196401010
19698013682910104
7054635359512458
3189189345532647
19231820111571507
21954912569958981
17120239500405824
15420596377615346
13858321414798602
2379795331425764...

input:

decode
1000
23
21995016750161681
23
3907200436046702
23
2381163150737765
23
25134121432287837
23
21515898870569569
23
13514592009306087
23
24474685240426740
23
23001635196401010
23
19698013682910104
23
7054635359512458
23
3189189345532647
23
19231820111571507
23
21954912569958981
23
1712023950040582...

output:

((|)((|)|)(|((|(|(|(|(|))((|)((|)((|)|(|))(|((|(|))(|)|))|)|))))|))|)
(|(|)((|)|(|)))(|((|(|(((|((|)|)(|))|)|)))|)((|(|))(|)|(|(|)(|)(|))))
(|(|))((((|)|)(|)|(((|(|))|)(|)|))(|((|(|)(|))(|)|(|((|)|)(|))(|)))|)
(((|((|)((|(|))(|)|(|))|))((|)|(|(|)(|(|)((|)|(|)))))((|)|(|)(|))|)|)
((((|)|((|)(|(|))|)(...

result:

ok 1000 lines

Test #30:

score: 100
Accepted
time: 5ms
memory: 3596kb

input:

encode
1000
24
(|((((|)|)|)|)(|)(((|)|((|)(|(|))|))|(|))((|(|)(|))|(|(((|)|)|))((|)|)))
24
(|)(|(|)(|((|(|))|))(|)(|((|)((|)|)((|)|)|(((|)|)|)))(|((|)|(|(|))(|))))
24
(|(|((((|)|)(|)(|)((|(|))(|)|)|(|))|((((|(|(|))(|))|)|)|))(|(|)))(|)(|))
24
(|((|(|))|(((|)(|)|)|((|(|(|)((|(|))(|)(|)|(|))))|)((|)((...

output:

93288332666055198
1039065637458442
99272630918734936
106244507980657064
31540165764006106
133047727063401906
79079839057431296
76742069816308430
149827259025930592
47133407760445443
56965941249980389
126446643993663137
59933555574630518
15781024037025205
133736215428431161
57839584558604312
12459257...

input:

decode
1000
24
93288332666055198
24
1039065637458442
24
99272630918734936
24
106244507980657064
24
31540165764006106
24
133047727063401906
24
79079839057431296
24
76742069816308430
24
149827259025930592
24
47133407760445443
24
56965941249980389
24
126446643993663137
24
59933555574630518
24
157810240...

output:

(|((((|)|)|)|)(|)(((|)|((|)(|(|))|))|(|))((|(|)(|))|(|(((|)|)|))((|)|)))
(|)(|(|)(|((|(|))|))(|)(|((|)((|)|)((|)|)|(((|)|)|)))(|((|)|(|(|))(|))))
(|(|((((|)|)(|)(|)((|(|))(|)|)|(|))|((((|(|(|))(|))|)|)|))(|(|)))(|)(|))
(|((|(|))|(((|)(|)|)|((|(|(|)((|(|))(|)(|)|(|))))|)((|)((|)|)|)(|))(|)))
(((|)(((...

result:

ok 1000 lines

Test #31:

score: 100
Accepted
time: 5ms
memory: 3600kb

input:

encode
1000
25
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
25
(((((((((((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
25
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|)))))))))))))))))))))))))
25
((|)|((((|(|((|)|(|)(|))))|)|)(((|)(|)((|)|)|(|)...

output:

468711512693699622
1031147983159782227
661368678063000702
310183842750131876
1006195103731814709
917103290030724652
22326875722172984
96203670579453851
778691395971020600
446278575259748719
655499241588870250
483135276834008708
867589948524113155
733714038355656987
340072309520424803
128566770343900...

input:

decode
1000
25
468711512693699622
25
1031147983159782227
25
661368678063000702
25
310183842750131876
25
1006195103731814709
25
917103290030724652
25
22326875722172984
25
96203670579453851
25
778691395971020600
25
446278575259748719
25
655499241588870250
25
483135276834008708
25
867589948524113155
25...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
(((((((((((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|)))))))))))))))))))))))))
((|)|((((|(|((|)|(|)(|))))|)|)(((|)(|)((|)|)|(|))(|(|))(|)|)|))(((|)|(|)...

result:

ok 1000 lines

Test #32:

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

input:

encode
1000
25
(|)(((|(|(|(|))))|(|((|)(|)|)(|(|(|(|(|))))))(|))|(|((|)|)(|((|)|)((|)|))))
25
((|)(|(|((((|)|)|)|((|)|)(|))((((|(|))|)|)((|)|)|)(|(|(|)))))|(|(|)(|(|))))
22
(|(|(|(|((((|)|)|)(((|(((|)|)|))|(((|)|)|)(|))(|(|(|(|))))|)|)))))
24
((|(|))|(|(((|)(|)|(|))(((|)(|)|)(((|)|)(|)|((|)(|)|))(|)...

output:

38986418057323698
817910709937547788
2591178574263147
118089563033053123
129541985625421957
9897386230193877
542288642380436
63451401740931
75150255418897
16620498463211058
18222498902195258
94818574207062174
119801468997728300
851437192133918257
4930937708489427
66511685751418498
0
628344052574710
...

input:

decode
1000
25
38986418057323698
25
817910709937547788
22
2591178574263147
24
118089563033053123
24
129541985625421957
23
9897386230193877
21
542288642380436
20
63451401740931
20
75150255418897
23
16620498463211058
23
18222498902195258
24
94818574207062174
25
119801468997728300
25
851437192133918257...

output:

(|)(((|(|(|(|))))|(|((|)(|)|)(|(|(|(|(|))))))(|))|(|((|)|)(|((|)|)((|)|))))
((|)(|(|((((|)|)|)|((|)|)(|))((((|(|))|)|)((|)|)|)(|(|(|)))))|(|(|)(|(|))))
(|(|(|(|((((|)|)|)(((|(((|)|)|))|(((|)|)|)(|))(|(|(|(|))))|)|)))))
((|(|))|(|(((|)(|)|(|))(((|)(|)|)(((|)|)(|)|((|)(|)|))(|)|)|))((|)|(|)))
((|)((((...

result:

ok 1000 lines