QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295091#4824. Bracket-and-bar Sequencesucup-team191#AC ✓12ms3620kbC++232.8kb2023-12-30 18:45:162023-12-30 18:45:17

Judging History

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

  • [2023-12-30 18:45:17]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:3620kb
  • [2023-12-30 18:45:16]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=300010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int n,q,maxn=25;
ll jed[N],sve[N];
string ti,h;

vl mul(vl a,vl b)
{
	assert(a.size()==b.size());
	int le=a.size();
	vl c(le);
	for (int i=0;i<le;++i) for (int j=0;i+j<le;++j) c[i+j]+=a[i]*b[j];
	return c;
}

int getN(string s)
{
	return s.size()/3;
}

ll getNum(string s,bool tip=0)
{
	if (tip==0)
	{
		if (s=="") return 0;
		ll an=0;
		int cupr=0;
		string cus;
		vector<string> v;
		for (auto x: s)
		{
			cus.pb(x);
			if (x=='(') ++cupr;
			if (x==')') --cupr;
			if (cupr==0)
			{
				v.pb(cus);
				cus="";
			}
		}
		int cun=getN(s),cn=v.size();
		vl je(jed,jed+cun+1),cu=je;
		for (int j=0;j<cn-1;++j)
		{
			an+=cu[cun];
			cu=mul(cu,je);
		}
		ll an2=0;
		int sz=cun;
		for (int j=cn-1;j>=1;--j)
		{
			cu=je;
			for (int k=0;k<j-1;++k) cu=mul(cu,je);
			for (int k=0;k<getN(v[j]);++k) an2+=je[k]*cu[sz-k];
			an2+=cu[sz-getN(v[j])]*getNum(v[j],1);
			sz-=getN(v[j]);
		}
		an2+=getNum(v[0],1);
		return an+an2;
	}
	else
	{
		int po=-1,cu=0;
		for (int i=0;i<(int)s.size();++i)
		{
			if (s[i]=='(') ++cu;
			if (s[i]==')') --cu;
			if (s[i]=='|' && cu==1) po=i;
		}
		string a=s.substr(1,po-1),b=s.substr(po+1);
		b.pop_back();
		ll an=0;
		for (int i=0;i<getN(a);++i) an+=sve[i]*sve[getN(s)-i-1];
		an+=getNum(a)*sve[getN(b)]+getNum(b);
		return an;
	}
}

string getStr(ll x,int n,bool tip=0)
{
	if (n==0) return "";
	if (tip==0)
	{
		int cn=1;
		vl je(jed,jed+n+1),cu=je;
		while (x>=cu[n])
		{
			x-=cu[n];
			cu=mul(cu,je);
			++cn;
		}
		vector<string> v;
		int sz=n;
		for (int j=cn-1;j>=1;--j)
		{
			cu=je;
			for (int k=0;k<j-1;++k) cu=mul(cu,je);
			for (int k=0;;++k)
			{
				if (x>=je[k]*cu[sz-k]) x-=je[k]*cu[sz-k];
				else
				{
					v.pb(getStr(x/cu[sz-k],k,1));
					x%=cu[sz-k];
					sz-=k;
					break;
				}
			}
		}
		v.pb(getStr(x,sz,1));
		reverse(all(v));
		string re;
		for (auto x: v) re+=x;
		return re;
	}
	else
	{
		int sa=0;
		while (x>=sve[sa]*sve[n-sa-1]) x-=sve[sa]*sve[n-sa-1],++sa;
		return "("+getStr(x/sve[n-sa-1],sa)+"|"+getStr(x%sve[n-sa-1],n-sa-1)+")";
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	sve[0]=1;
	for (int i=1;i<=maxn;++i)
	{
		for (int j=0;j<i;++j) jed[i]+=sve[j]*sve[i-j-1];
		vl je(jed,jed+i+1),cu=je;
		for (int j=0;j<i;++j)
		{
			sve[i]+=cu[i];
			cu=mul(cu,je);
		}
		//cout<<i<<' '<<sve[i]<<en;
	}
	cin>>ti>>q;
	while (q--)
	{
		if (ti=="encode")
		{
			cin>>n>>h;
			cout<<getNum(h)<<en;
		}
		else
		{
			ll x;
			cin>>n>>x;
			cout<<getStr(x,n)<<en;
		}
	}
}

详细

Test #1:

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

input:

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

output:

0
23
195

input:

decode
3
1
0
4
23
5
195

output:

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

result:

ok 3 lines

Test #2:

score: 100
Accepted
time: 1ms
memory: 3516kb

input:

encode
1
1
(|)

output:

0

input:

decode
1
1
0

output:

(|)

result:

ok single line: '(|)'

Test #3:

score: 100
Accepted
time: 1ms
memory: 3524kb

input:

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

output:

1
0
0

input:

decode
3
2
1
1
0
2
0

output:

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

result:

ok 3 lines

Test #4:

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

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:

11
9
10
7
2
0
1
8
3
6
4
5
54
52
53
50
43
41
42
51
44
47
45
46
48
37
39
32
30
31
11
9
10
7
2
0
1
8
3
6
4
5
49
38
40
33
14
12
13
36
34
35
17
15
16
29
27
28
25
20
18
19
26
21
24
22
23
272
270
271
268
259
257
258
269
260
263
261
262
266
251
255
244
242
243
212
210
211
208
203
201
202
209
204
207
205
206...

input:

decode
1000
3
11
3
9
3
10
3
7
3
2
3
0
3
1
3
8
3
3
3
6
3
4
3
5
4
54
4
52
4
53
4
50
4
43
4
41
4
42
4
51
4
44
4
47
4
45
4
46
4
48
4
37
4
39
4
32
4
30
4
31
4
11
4
9
4
10
4
7
4
2
4
0
4
1
4
8
4
3
4
6
4
4
4
5
4
49
4
38
4
40
4
33
4
14
4
12
4
13
4
36
4
34
4
35
4
17
4
15
4
16
4
29
4
27
4
28
4
25
4
20
4
18
4
1...

output:

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

result:

ok 1000 lines

Test #5:

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

input:

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

output:

166
87
85
86
83
78
76
77
84
79
82
80
81
142
140
141
138
131
129
130
139
132
135
133
134
136
125
127
120
118
119
99
97
98
95
90
88
89
96
91
94
92
93
137
126
128
121
102
100
101
124
122
123
105
103
104
117
115
116
113
108
106
107
114
109
112
110
111
1418
1399
1405
1384
1316
1308
1312
1388
1320
1332
13...

input:

decode
1000
6
166
6
87
6
85
6
86
6
83
6
78
6
76
6
77
6
84
6
79
6
82
6
80
6
81
6
142
6
140
6
141
6
138
6
131
6
129
6
130
6
139
6
132
6
135
6
133
6
134
6
136
6
125
6
127
6
120
6
118
6
119
6
99
6
97
6
98
6
95
6
90
6
88
6
89
6
96
6
91
6
94
6
92
6
93
6
137
6
126
6
128
6
121
6
102
6
100
6
101
6
124
6
122
...

output:

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

result:

ok 1000 lines

Test #6:

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

input:

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

output:

2378
3700
881
6482
6102
2819
3613
42431
7055
7168
4953
1581
43056
6525
1271
290
4108
4974
113
1539
1017
4005
3505
3072
2518
5437
6930
6871
3479
6002
4859
1000
4341
6811
594
3763
3037
4072
2742
5666
5013
5900
4670
239
1108
1258
4422
337
5584
673
2290
5549
1622
6618
6688
3080
1974
1648
830
1948
2889
2...

input:

decode
1000
7
2378
7
3700
7
881
7
6482
7
6102
7
2819
7
3613
8
42431
7
7055
7
7168
7
4953
7
1581
8
43056
7
6525
7
1271
7
290
7
4108
7
4974
7
113
7
1539
7
1017
7
4005
7
3505
7
3072
7
2518
7
5437
7
6930
7
6871
7
3479
7
6002
7
4859
7
1000
7
4341
7
6811
7
594
7
3763
7
3037
7
4072
7
2742
7
5666
7
5013
7
5...

output:

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

result:

ok 1000 lines

Test #7:

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

input:

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

output:

1340
3729
5456
5688
941
6203
2097
6820
5613
6406
5749
1827
42788
43212
5373
6345
4930
4405
42407
41593
4511
1186
3622
3372
4743
4182
422
5324
5179
2987
5246
923
7328
2765
3874
1886
242
1816
5631
4787
5661
1806
6974
1261
2283
596
441
1909
6134
7141
1589
5610
5428
7291
1096
2078
2733
6896
5728
1153
15...

input:

decode
1000
7
1340
7
3729
7
5456
7
5688
7
941
7
6203
7
2097
7
6820
7
5613
7
6406
7
5749
7
1827
8
42788
8
43212
7
5373
7
6345
7
4930
7
4405
8
42407
8
41593
7
4511
7
1186
7
3622
7
3372
7
4743
7
4182
7
422
7
5324
7
5179
7
2987
7
5246
7
923
7
7328
7
2765
7
3874
7
1886
7
242
7
1816
7
5631
7
4787
7
5661
7...

output:

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

result:

ok 1000 lines

Test #8:

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

input:

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

output:

2775
7038
6826
5226
4258
2399
488
3605
43090
1323
3138
6923
7166
2795
5126
6238
988
1921
2148
4463
550
7178
4759
3951
6652
3027
5819
5223
6154
1293
1084
1602
6375
6432
5595
42877
1593
2000
4390
4492
1268
1638
2308
1194
3342
7419
5557
3997
211
4811
2553
6873
951
855
4104
3068
787
4885
4291
5271
6854
...

input:

decode
1000
7
2775
7
7038
7
6826
7
5226
7
4258
7
2399
7
488
7
3605
8
43090
7
1323
7
3138
7
6923
7
7166
7
2795
7
5126
7
6238
7
988
7
1921
7
2148
7
4463
7
550
7
7178
7
4759
7
3951
7
6652
7
3027
7
5819
7
5223
7
6154
7
1293
7
1084
7
1602
7
6375
7
6432
7
5595
8
42877
7
1593
7
2000
7
4390
7
4492
7
1268
7
...

output:

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

result:

ok 1000 lines

Test #9:

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

input:

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

output:

4844
5486
6642
42110
535
6889
2128
3656
5418
3262
3221
5982
4498
5442
1868
4741
6044
2141
2645
41589
4767
6748
4031
43006
2100
1016
5976
6895
6319
6947
41598
776
3011
5151
42537
6488
6193
1211
6777
4910
2099
42562
7565
1844
1179
2719
1902
2205
3958
2152
768
126
5134
3922
43218
1558
1178
6814
42560
5...

input:

decode
1000
7
4844
7
5486
7
6642
8
42110
7
535
7
6889
7
2128
7
3656
7
5418
7
3262
7
3221
7
5982
7
4498
7
5442
7
1868
7
4741
7
6044
7
2141
7
2645
8
41589
7
4767
7
6748
7
4031
8
43006
7
2100
7
1016
7
5976
7
6895
7
6319
7
6947
8
41598
7
776
7
3011
7
5151
8
42537
7
6488
7
6193
7
1211
7
6777
7
4910
7
209...

output:

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

result:

ok 1000 lines

Test #10:

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

input:

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

output:

3278
3725
5716
1257
5924
4385
666
6518
6011
6825
5109
6402
6012
5403
7396
3891
3252
5015
118
6383
42938
6828
3757
936
42545
6780
5467
4830
1897
4374
5398
3291
4032
3543
4516
587
4808
5606
4301
920
6695
5721
1352
4409
3628
2682
445
1785
42888
2228
6945
1265
7473
5926
508
4897
5732
1484
7441
868
1380
...

input:

decode
1000
7
3278
7
3725
7
5716
7
1257
7
5924
7
4385
7
666
7
6518
7
6011
7
6825
7
5109
7
6402
7
6012
7
5403
7
7396
7
3891
7
3252
7
5015
7
118
7
6383
8
42938
7
6828
7
3757
7
936
8
42545
7
6780
7
5467
7
4830
7
1897
7
4374
7
5398
7
3291
7
4032
7
3543
7
4516
7
587
7
4808
7
5606
7
4301
7
920
7
6695
7
57...

output:

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

result:

ok 1000 lines

Test #11:

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

input:

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

output:

888
645
7430
7177
3879
4832
7449
412
4470
5535
4849
382
4484
4886
42567
4349
77
6458
3164
3128
3488
3872
4459
515
4559
7307
42613
2573
3563
2914
1879
4259
3480
840
5067
5543
6681
5245
1227
933
3932
5020
1253
785
5940
808
1457
6190
1332
6084
4978
6341
6038
4264
6726
2550
5788
42585
6465
2442
2504
403...

input:

decode
1000
7
888
7
645
7
7430
7
7177
7
3879
7
4832
7
7449
7
412
7
4470
7
5535
7
4849
7
382
7
4484
7
4886
8
42567
7
4349
7
77
7
6458
7
3164
7
3128
7
3488
7
3872
7
4459
7
515
7
4559
7
7307
8
42613
7
2573
7
3563
7
2914
7
1879
7
4259
7
3480
7
840
7
5067
7
5543
7
6681
7
5245
7
1227
7
933
7
3932
7
5020
7...

output:

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

result:

ok 1000 lines

Test #12:

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

input:

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

output:

52
3906
843
663
5953
3865
5032
2647
1248
792
325
1557
6180
3544
42940
3460
4442
1129
2406
1449
5380
7124
6174
1199
2431
3566
2361
6489
1588
4180
20
7411
2199
3521
4621
5795
1082
3029
1931
10
7724
5401
2156
4512
3917
7138
4972
4149
5247
6461
4388
1641
3316
42578
1891
4449
5386
1923
1952
6074
7087
562...

input:

decode
1000
7
52
7
3906
7
843
7
663
7
5953
7
3865
7
5032
7
2647
7
1248
7
792
7
325
7
1557
7
6180
7
3544
8
42940
7
3460
7
4442
7
1129
7
2406
7
1449
7
5380
7
7124
7
6174
7
1199
7
2431
7
3566
7
2361
7
6489
7
1588
7
4180
7
20
7
7411
7
2199
7
3521
7
4621
7
5795
7
1082
7
3029
7
1931
7
10
7
7724
7
5401
7
2...

output:

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

result:

ok 1000 lines

Test #13:

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

input:

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

output:

4778
6961
2970
42528
2286
2943
1290
1815
739
1100
2997
6827
2392
4274
219
4490
297
3541
3044
4894
6989
6136
6179
1943
6765
6551
2127
5835
4639
2013
5035
6798
6005
4789
288
6590
4671
378
40225
5951
3934
1366
5402
3713
5648
2609
5928
3286
791
1058
42521
42609
7495
3819
5508
40232
1065
7437
5565
5859
1...

input:

decode
1000
7
4778
7
6961
7
2970
8
42528
7
2286
7
2943
7
1290
7
1815
7
739
7
1100
7
2997
7
6827
7
2392
7
4274
7
219
7
4490
7
297
7
3541
7
3044
7
4894
7
6989
7
6136
7
6179
7
1943
7
6765
7
6551
7
2127
7
5835
7
4639
7
2013
7
5035
7
6798
7
6005
7
4789
7
288
7
6590
7
4671
7
378
8
40225
7
5951
7
3934
7
13...

output:

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

result:

ok 1000 lines

Test #14:

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

input:

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

output:

27952
32278
33631
37207
3531
18690
19785
21061
29655
29664
16413
9540
4873
36604
2442
38465
39496
9530
37930
25870
11026
32612
7462
23403
6166
36681
41079
13232
24292
31257
779
11290
7351
15645
14696
4984
3357
24004
40719
28326
34176
29734
3540
22976
36930
37561
32630
28190
4554
36103
42802
30933
17...

input:

decode
1000
8
27952
8
32278
8
33631
8
37207
8
3531
8
18690
8
19785
8
21061
8
29655
8
29664
8
16413
8
9540
8
4873
8
36604
8
2442
8
38465
8
39496
8
9530
8
37930
8
25870
8
11026
8
32612
8
7462
8
23403
8
6166
8
36681
8
41079
8
13232
8
24292
8
31257
8
779
8
11290
8
7351
8
15645
8
14696
8
4984
8
3357
8
24...

output:

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

result:

ok 1000 lines

Test #15:

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

input:

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

output:

110441
92457
12272
97052
188760
183494
102731
173631
23230
100926
12373
166918
95760
56639
24440
32661
152910
231665
232466
116973
20203
150649
192890
215663
242826
184397
52791
231327
193644
47067
101564
26209
14946
52067
246074
15776
209598
38935
174145
179835
145616
3210
153213
162436
200723
1560...

input:

decode
1000
9
110441
9
92457
9
12272
9
97052
9
188760
9
183494
9
102731
9
173631
9
23230
9
100926
9
12373
9
166918
9
95760
9
56639
9
24440
9
32661
9
152910
9
231665
9
232466
9
116973
9
20203
9
150649
9
192890
9
215663
9
242826
9
184397
9
52791
9
231327
9
193644
9
47067
9
101564
9
26209
9
14946
9
520...

output:

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

result:

ok 1000 lines

Test #16:

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

input:

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

output:

1430714
537507
0
989285
1060371
1122385
684386
538930
1383543
1013198
251492
845744
892288
1111703
880691
959428
966463
235243
274968
348487
180481
327196
573323
477386
1319266
827873
753900
251538
513410
559273
1229454
1051330
783007
157378
1081555
527621
1178752
24626
39376
951671
861400
297796
25...

input:

decode
1000
10
1430714
10
537507
10
0
10
989285
10
1060371
10
1122385
10
684386
10
538930
10
1383543
10
1013198
10
251492
10
845744
10
892288
10
1111703
10
880691
10
959428
10
966463
10
235243
10
274968
10
348487
10
180481
10
327196
10
573323
10
477386
10
1319266
10
827873
10
753900
10
251538
10
513...

output:

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

result:

ok 1000 lines

Test #17:

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

input:

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

output:

8414639
3138807
0
5831824
320794
1515541
5680566
1886685
1916807
1489873
5298694
4279660
2294880
7377413
1911850
4172885
6676454
6509220
2035508
6493073
1247727
3033535
8269297
7933087
5033808
5165770
2993547
3144977
5989591
4889768
2147821
7302621
882312
80105
3123114
6125432
1488166
8019003
779230...

input:

decode
1000
11
8414639
11
3138807
11
0
11
5831824
11
320794
11
1515541
11
5680566
11
1886685
11
1916807
11
1489873
11
5298694
11
4279660
11
2294880
11
7377413
11
1911850
11
4172885
11
6676454
11
6509220
11
2035508
11
6493073
11
1247727
11
3033535
11
8269297
11
7933087
11
5033808
11
5165770
11
299354...

output:

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

result:

ok 1000 lines

Test #18:

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

input:

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

output:

50067107
18565647
0
35233656
30453961
34242816
15672714
6708383
9234789
49163134
17483893
6139790
33076926
36851113
10861770
36950324
48731364
1928876
25863690
24753856
13261239
27683839
30487
45446086
25694818
26387913
32735590
15710691
18104103
41119033
34867087
13296991
37980684
9428790
44509083
...

input:

decode
1000
12
50067107
12
18565647
12
0
12
35233656
12
30453961
12
34242816
12
15672714
12
6708383
12
9234789
12
49163134
12
17483893
12
6139790
12
33076926
12
36851113
12
10861770
12
36950324
12
48731364
12
1928876
12
25863690
12
24753856
12
13261239
12
27683839
12
30487
12
45446086
12
25694818
12...

output:

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

result:

ok 1000 lines

Test #19:

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

input:

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

output:

121856772
23077272
143914902
122178277
230507391
259143585
46017405
262301591
4249746
60335308
188929803
200904957
196906836
297315461
140142529
188479907
229428583
45727675
255719698
195681800
33596435
39183448
152663447
260101377
134150982
210281432
130438342
167476076
77391265
267216285
121486014...

input:

decode
1000
13
121856772
13
23077272
13
143914902
13
122178277
13
230507391
13
259143585
13
46017405
13
262301591
13
4249746
13
60335308
13
188929803
13
200904957
13
196906836
13
297315461
13
140142529
13
188479907
13
229428583
13
45727675
13
255719698
13
195681800
13
33596435
13
39183448
13
1526634...

output:

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

result:

ok 1000 lines

Test #20:

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

input:

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

output:

1822766519
669682579
0
1612600237
56368063
1101222345
1785312871
517636395
1019148170
407770675
180614848
517917033
890396317
520677066
128573703
1108138194
265771221
1438715234
148407952
903172565
1740187534
1171916294
1716686749
1125581707
1309531700
227373014
1741577392
319737601
505848181
832975...

input:

decode
1000
14
1822766519
14
669682579
14
0
14
1612600237
14
56368063
14
1101222345
14
1785312871
14
517636395
14
1019148170
14
407770675
14
180614848
14
517917033
14
890396317
14
520677066
14
128573703
14
1108138194
14
265771221
14
1438715234
14
148407952
14
903172565
14
1740187534
14
1171916294
14...

output:

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

result:

ok 1000 lines

Test #21:

score: 100
Accepted
time: 6ms
memory: 3540kb

input:

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

output:

2153215119
10095001611
7650874203
6269961814
8785912203
9866016388
8099341170
6578219438
4749664763
3510564670
9852762067
4235040395
669943380
803346562
2191887952
5019272551
1707731654
3306530456
6257811760
3956985891
9886017973
8535029901
2457079432
6168894088
7461234007
2872115399
3311154753
6057...

input:

decode
1000
15
2153215119
15
10095001611
15
7650874203
15
6269961814
15
8785912203
15
9866016388
15
8099341170
15
6578219438
15
4749664763
15
3510564670
15
9852762067
15
4235040395
15
669943380
15
803346562
15
2191887952
15
5019272551
15
1707731654
15
3306530456
15
6257811760
15
3956985891
15
988601...

output:

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

result:

ok 1000 lines

Test #22:

score: 100
Accepted
time: 6ms
memory: 3548kb

input:

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

output:

68328754958
24931096953
0
60712695286
19960649614
46008991424
3651397163
26923590281
54789346503
45620361289
62597409096
7507640074
21076219963
18616334466
68287181503
29029346754
14508809978
33632675713
49876280100
46610019886
57376302986
4713952824
53405703063
7775511282
35588801370
59014309667
29...

input:

decode
1000
16
68328754958
16
24931096953
16
0
16
60712695286
16
19960649614
16
46008991424
16
3651397163
16
26923590281
16
54789346503
16
45620361289
16
62597409096
16
7507640074
16
21076219963
16
18616334466
16
68287181503
16
29029346754
16
14508809978
16
33632675713
16
49876280100
16
46610019886
...

output:

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

result:

ok 1000 lines

Test #23:

score: 100
Accepted
time: 7ms
memory: 3604kb

input:

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

output:

152519987134
97647215509
376737475892
157148192551
81305439004
33020461384
96148331012
246151733414
230435787202
3509151812
221236008484
241036395329
3692671950
71466494793
50294461986
416478864993
380236461768
392325911609
59597250725
399459517545
252922163789
106412120000
258803144814
141375085717...

input:

decode
1000
17
152519987134
17
97647215509
17
376737475892
17
157148192551
17
81305439004
17
33020461384
17
96148331012
17
246151733414
17
230435787202
17
3509151812
17
221236008484
17
241036395329
17
3692671950
17
71466494793
17
50294461986
17
416478864993
17
380236461768
17
392325911609
17
5959725...

output:

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

result:

ok 1000 lines

Test #24:

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

input:

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

output:

2619631042664
950718737672
0
2599881231817
1103101305028
501531981706
1270216705891
2067212209072
1255044922364
365342069220
1560480639040
1630788714470
283747506926
2227903232085
27046963260
2084440617109
970598837297
72573834523
2084530426546
317949596982
1988306961419
446325934014
52730230502
206...

input:

decode
1000
18
2619631042664
18
950718737672
18
0
18
2599881231817
18
1103101305028
18
501531981706
18
1270216705891
18
2067212209072
18
1255044922364
18
365342069220
18
1560480639040
18
1630788714470
18
283747506926
18
2227903232085
18
27046963260
18
2084440617109
18
970598837297
18
72573834523
18
...

output:

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

result:

ok 1000 lines

Test #25:

score: 100
Accepted
time: 8ms
memory: 3616kb

input:

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

output:

16332922290299
5914230186932
0
15146643269414
2033303527830
10920727465453
200274789000
7425497405680
2214530825551
13885073930192
8983619026400
4218401752223
13472094019708
5352959156715
3658910342966
4948387789893
5584417866388
13215689638493
2235918243254
12203654269909
6566356670986
977493994490...

input:

decode
1000
19
16332922290299
19
5914230186932
19
0
19
15146643269414
19
2033303527830
19
10920727465453
19
200274789000
19
7425497405680
19
2214530825551
19
13885073930192
19
8983619026400
19
4218401752223
19
13472094019708
19
5352959156715
19
3658910342966
19
4948387789893
19
5584417866388
19
1321...

output:

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

result:

ok 1000 lines

Test #26:

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

input:

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

output:

81538994327385
70142722870304
36718583287607
36335157030948
51852894572580
88604003681788
56589029368204
57203360397050
88179479930008
70213912348984
52078843244639
55759267184461
2336706013509
55145058829915
89876641910278
67158127040607
88744129141965
45836046238137
96508255691106
62013397117481
1...

input:

decode
1000
20
81538994327385
20
70142722870304
20
36718583287607
20
36335157030948
20
51852894572580
20
88604003681788
20
56589029368204
20
57203360397050
20
88179479930008
20
70213912348984
20
52078843244639
20
55759267184461
20
2336706013509
20
55145058829915
20
89876641910278
20
67158127040607
2...

output:

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

result:

ok 1000 lines

Test #27:

score: 100
Accepted
time: 10ms
memory: 3552kb

input:

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

output:

157548505877897
131102075125770
320139433425177
381662216362324
531987866999185
159906904602954
288883803088800
20263389216611
549415459093030
599651876504381
508064023083810
521868475268821
596953561376677
358330265002477
181109166719846
64655621214179
626289150655830
581334760527779
38094037571522...

input:

decode
1000
21
157548505877897
21
131102075125770
21
320139433425177
21
381662216362324
21
531987866999185
21
159906904602954
21
288883803088800
21
20263389216611
21
549415459093030
21
599651876504381
21
508064023083810
21
521868475268821
21
596953561376677
21
358330265002477
21
181109166719846
21
6...

output:

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

result:

ok 1000 lines

Test #28:

score: 100
Accepted
time: 11ms
memory: 3548kb

input:

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

output:

369108486720073
3424717196865203
1735917261161660
1742563602205196
900475343862716
3972761151730744
2060492684098580
70024171798565
3824011973054581
2386437087221866
2266377436745657
3260426447607594
1752280704483863
3773346881364946
1579585729630521
3968861001159428
3390229788202285
372569910920445...

input:

decode
1000
22
369108486720073
22
3424717196865203
22
1735917261161660
22
1742563602205196
22
900475343862716
22
3972761151730744
22
2060492684098580
22
70024171798565
22
3824011973054581
22
2386437087221866
22
2266377436745657
22
3260426447607594
22
1752280704483863
22
3773346881364946
22
157958572...

output:

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

result:

ok 1000 lines

Test #29:

score: 100
Accepted
time: 10ms
memory: 3504kb

input:

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

output:

11349179222261306
16379746962630043
17591781234905580
9511349698662870
7315841449875199
13089409017706627
8537738269917328
9970998746154735
5900092909827196
25143661215398796
16815296490164773
5393653934434320
10483597625379319
1214385663113908
3225651450799427
2812235720141007
8319801064116510
2116...

input:

decode
1000
23
11349179222261306
23
16379746962630043
23
17591781234905580
23
9511349698662870
23
7315841449875199
23
13089409017706627
23
8537738269917328
23
9970998746154735
23
5900092909827196
23
25143661215398796
23
16815296490164773
23
5393653934434320
23
10483597625379319
23
1214385663113908
2...

output:

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

result:

ok 1000 lines

Test #30:

score: 100
Accepted
time: 8ms
memory: 3540kb

input:

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

output:

24390452570459538
115894373713341502
19594057006626185
4741515032242260
100759287360108637
48613773036504105
75764937904180540
77097704342542932
62524073845785001
136118174638313732
133055984789829246
38864097279549265
87289665698992335
109218389425269481
47358453292342751
131479578445328262
3727629...

input:

decode
1000
24
24390452570459538
24
115894373713341502
24
19594057006626185
24
4741515032242260
24
100759287360108637
24
48613773036504105
24
75764937904180540
24
77097704342542932
24
62524073845785001
24
136118174638313732
24
133055984789829246
24
38864097279549265
24
87289665698992335
24
109218389...

output:

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

result:

ok 1000 lines

Test #31:

score: 100
Accepted
time: 12ms
memory: 3592kb

input:

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

output:

1031147983159782227
369779305096781525
0
591433345014040654
378477543521059781
405122397661198552
721898066483740527
706550128191081482
219133732306912755
1001126730993184394
20203424863113365
491448809319299787
293929002029342901
165287542298085274
573653048274888098
683580910575387809
899564258107...

input:

decode
1000
25
1031147983159782227
25
369779305096781525
25
0
25
591433345014040654
25
378477543521059781
25
405122397661198552
25
721898066483740527
25
706550128191081482
25
219133732306912755
25
1001126730993184394
25
20203424863113365
25
491448809319299787
25
293929002029342901
25
165287542298085...

output:

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

result:

ok 1000 lines

Test #32:

score: 100
Accepted
time: 10ms
memory: 3620kb

input:

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

output:

749370081207614796
264363815216568032
1079450299380
30006264593457032
42775118740590065
20611599525871171
266666839238691
8418432795413
20853383876616
230494903517142
4108308368207503
14903892651950949
674172187005728034
307241585941497196
22259774721057492
128030599263662616
2
2598397777761722
2125...

input:

decode
1000
25
749370081207614796
25
264363815216568032
22
1079450299380
24
30006264593457032
24
42775118740590065
23
20611599525871171
21
266666839238691
20
8418432795413
20
20853383876616
23
230494903517142
23
4108308368207503
24
14903892651950949
25
674172187005728034
25
307241585941497196
23
222...

output:

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

result:

ok 1000 lines