QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#299148#4824. Bracket-and-bar SequencesKevin5307AC ✓5ms3576kbC++233.0kb2024-01-06 17:25:362024-01-06 17:25:37

Judging History

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

  • [2024-01-06 17:25:37]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3576kb
  • [2024-01-06 17:25:36]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
namespace solver
{
	ll dp[30],dp2[30];
	void init()
	{
		dp[0]=1;
		for(int i=1;i<=25;i++)
		{
			for(int j=0;j<i;j++)
				dp[i]+=dp[j]*dp[i-1-j];
			for(int j=0;j<i;j++)
				dp[i]+=dp[j]*dp2[i-j];
			for(int j=0;j<i;j++)
				dp2[i]+=dp[j]*dp[i-1-j];
		}
		ll sum=0;
		for(int i=0;i<=25;i++)
			sum+=dp[i];
		assert(sum<=2000000000000000000ll);
	}
	ll encode2(string s);
	ll encode(string s)
	{
		int n=sz(s)/3;
		if(!n) return 0;
		ll sum=0;
		for(int i=0;i<n;i++)
			sum+=dp[i];
		int split=-1,bar=-1;
		int c=0;
		for(int i=0;i<sz(s);i++)
			if(s[i]=='(')
				c++;
			else if(s[i]==')')
			{
				c--;
				if(!c)
				{
					split=i;
					break;
				}
			}
			else if(c==1)
				bar=i;
		if(split!=sz(s)-1)
		{
			for(int i=0;i<n;i++)
				sum+=dp[i]*dp[n-1-i];
			int l1=(split+1)/3,l2=n-l1;
			for(int i=0;i<l1;i++)
				sum+=dp2[i]*dp[n-i];
			ll val1=encode2(s.substr(0,l1*3)),val2=encode2(s.substr(l1*3));
			return sum+val1*dp[l2]+val2;
		}
		int l1=(bar-1)/3;
		int l2=n-1-l1;
		for(int i=0;i<l1;i++)
			sum+=dp[i]*dp[n-1-i];
		ll val1=encode2(s.substr(1,l1*3)),val2=encode2(s.substr(l1*3+2,l2*3));
		return sum+val1*dp[l2]+val2;
	}
	ll encode2(string s)
	{
		int n=sz(s)/3;
		ll ret=encode(s);
		for(int i=0;i<n;i++)
			ret-=dp[i];
		return ret;
	}
	string decode2(ll val,int len);
	string decode(ll val)
	{
		if(!val) return "";
		int n=0;
		while(dp[n]<=val)
		{
			val-=dp[n];
			n++;
		}
		int p=0;
		while(p<n&&dp[p]*dp[n-1-p]<=val)
		{
			val-=dp[p]*dp[n-1-p];
			p++;
		}
		if(p==n)
		{
			int p2=0;
			while(dp2[p2]*dp[n-p2]<=val)
			{
				val-=dp2[p2]*dp[n-p2];
				p2++;
			}
			int l1=p2,l2=n-p2;
			return decode2(val/dp[l2],l1)+decode2(val%dp[l2],l2);
		}
		else
		{
			int l1=p,l2=n-1-p;
			return "("+decode2(val/dp[l2],l1)+"|"+decode2(val%dp[l2],l2)+")";
		}
	}
	string decode2(ll val,int len)
	{
		for(int i=0;i<len;i++)
			val+=dp[i];
		return decode(val);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solver::init();
	string mode;
	cin>>mode;
	if(mode=="encode")
	{
		int t;
		cin>>t;
		while(t--)
		{
			int n;
			cin>>n;
			string s;
			cin>>s;
			cout<<solver::encode(s)<<'\n';
		}
	}
	else
	{
		int t;
		cin>>t;
		while(t--)
		{
			int n;
			cin>>n;
			ll x;
			cin>>x;
			cout<<solver::decode(x)<<'\n';
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1
40
274

input:

decode
3
1
1
4
40
5
274

output:

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

result:

ok 3 lines

Test #2:

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

input:

encode
1
1
(|)

output:

1

input:

decode
1
1
1

output:

(|)

result:

ok single line: '(|)'

Test #3:

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

input:

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

output:

3
1
2

input:

decode
3
2
3
1
1
2
2

output:

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

result:

ok 3 lines

Test #4:

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

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:

14
12
13
15
7
5
6
16
8
11
9
10
56
54
55
57
49
47
48
58
50
53
51
52
61
59
60
67
65
66
26
24
25
27
19
17
18
28
20
23
21
22
64
62
63
68
31
29
30
71
69
70
34
32
33
44
42
43
45
37
35
36
46
38
41
39
40
254
252
253
255
247
245
246
256
248
251
249
250
259
257
258
265
263
264
224
222
223
225
217
215
216
226
...

input:

decode
1000
3
14
3
12
3
13
3
15
3
7
3
5
3
6
3
16
3
8
3
11
3
9
3
10
4
56
4
54
4
55
4
57
4
49
4
47
4
48
4
58
4
50
4
53
4
51
4
52
4
61
4
59
4
60
4
67
4
65
4
66
4
26
4
24
4
25
4
27
4
19
4
17
4
18
4
28
4
20
4
23
4
21
4
22
4
64
4
62
4
63
4
68
4
31
4
29
4
30
4
71
4
69
4
70
4
34
4
32
4
33
4
44
4
42
4
43
4
4...

output:

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

result:

ok 1000 lines

Test #5:

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

input:

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

output:

611
430
428
429
431
423
421
422
432
424
427
425
426
472
470
471
473
465
463
464
474
466
469
467
468
477
475
476
483
481
482
442
440
441
443
435
433
434
444
436
439
437
438
480
478
479
484
447
445
446
487
485
486
450
448
449
460
458
459
461
453
451
452
462
454
457
455
456
1440
1438
1439
1441
1433
143...

input:

decode
1000
6
611
6
430
6
428
6
429
6
431
6
423
6
421
6
422
6
432
6
424
6
427
6
425
6
426
6
472
6
470
6
471
6
473
6
465
6
463
6
464
6
474
6
466
6
469
6
467
6
468
6
477
6
475
6
476
6
483
6
481
6
482
6
442
6
440
6
441
6
443
6
435
6
433
6
434
6
444
6
436
6
439
6
437
6
438
6
480
6
478
6
479
6
484
6
447
...

output:

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

result:

ok 1000 lines

Test #6:

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

input:

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

output:

4093
5201
2992
8198
6145
4592
5079
35739
7565
6726
8046
3452
35679
8331
2891
2063
9024
8298
1889
3312
2847
8915
4966
4948
4291
7416
6860
8064
5305
6055
8705
2782
9260
7775
2357
5254
4799
9011
4515
5719
8048
5971
8560
1993
2569
2761
9343
2108
7212
2388
4061
7487
3414
7341
6971
4910
3723
3363
3160
371...

input:

decode
1000
7
4093
7
5201
7
2992
7
8198
7
6145
7
4592
7
5079
8
35739
7
7565
7
6726
7
8046
7
3452
8
35679
7
8331
7
2891
7
2063
7
9024
7
8298
7
1889
7
3312
7
2847
7
8915
7
4966
7
4948
7
4291
7
7416
7
6860
7
8064
7
5305
7
6055
7
8705
7
2782
7
9260
7
7775
7
2357
7
5254
7
4799
7
9011
7
4515
7
5719
7
8048...

output:

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

result:

ok 1000 lines

Test #7:

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

input:

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

output:

2649
5322
7150
5741
2921
6354
3864
7888
5666
8616
5900
3600
35916
35656
7399
8433
8105
9326
35735
36022
9475
2979
5072
5486
8755
9121
2195
7087
7742
4763
7973
3035
6508
4527
5130
3662
1964
3589
5702
8507
5712
3569
7709
2764
4056
2354
2203
3685
6190
7235
3462
5663
7136
6467
2557
3851
4506
8340
5770
2...

input:

decode
1000
7
2649
7
5322
7
7150
7
5741
7
2921
7
6354
7
3864
7
7888
7
5666
7
8616
7
5900
7
3600
8
35916
8
35656
7
7399
7
8433
7
8105
7
9326
8
35735
8
36022
7
9475
7
2979
7
5072
7
5486
7
8755
7
9121
7
2195
7
7087
7
7742
7
4763
7
7973
7
3035
7
6508
7
4527
7
5130
7
3662
7
1964
7
3589
7
5702
7
8507
7
57...

output:

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

result:

ok 1000 lines

Test #8:

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

input:

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

output:

4533
6764
7575
7641
9179
4114
2279
5064
35648
2808
4912
7318
7514
4571
7901
6302
2778
3697
3888
9373
2326
7517
8405
8872
6950
4818
5814
7860
6207
2940
2534
3426
8493
8694
7477
35841
3466
3749
9311
9513
2769
3351
4070
2997
5485
6897
7491
8936
1924
8555
4326
8088
2958
3189
8965
4941
3117
8753
9212
781...

input:

decode
1000
7
4533
7
6764
7
7575
7
7641
7
9179
7
4114
7
2279
7
5064
8
35648
7
2808
7
4912
7
7318
7
7514
7
4571
7
7901
7
6302
7
2778
7
3697
7
3888
7
9373
7
2326
7
7517
7
8405
7
8872
7
6950
7
4818
7
5814
7
7860
7
6207
7
2940
7
2534
7
3426
7
8493
7
8694
7
7477
8
35841
7
3466
7
3749
7
9311
7
9513
7
2769...

output:

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

result:

ok 1000 lines

Test #9:

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

input:

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

output:

8654
7165
6940
35854
2308
8280
3913
5502
7116
5590
5540
6044
9519
7141
3641
8773
6093
3881
4424
36018
8429
7046
9052
35684
3927
2792
6029
8328
6287
6911
36027
3102
4784
7743
35480
8270
6231
3048
7060
8248
3866
35516
7991
3635
2630
4402
3675
3996
8879
3892
3104
1906
7957
8832
35642
3320
2629
7940
355...

input:

decode
1000
7
8654
7
7165
7
6940
8
35854
7
2308
7
8280
7
3913
7
5502
7
7116
7
5590
7
5540
7
6044
7
9519
7
7141
7
3641
7
8773
7
6093
7
3881
7
4424
8
36018
7
8429
7
7046
7
9052
8
35684
7
3927
7
2792
7
6029
7
8328
7
6287
7
6911
8
36027
7
3102
7
4784
7
7743
8
35480
7
8270
7
6231
7
3048
7
7060
7
8248
7
3...

output:

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

result:

ok 1000 lines

Test #10:

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

input:

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

output:

5608
5411
5787
2760
5977
9291
2379
8271
6064
7302
7734
8604
6065
7385
7313
8812
5582
8072
1909
8547
35702
7578
5147
2944
35484
8027
7428
8627
3673
9284
7110
5619
9053
5004
9490
2349
8552
5657
9225
3026
6993
5779
2661
9330
5074
4454
2207
3556
35768
3986
6905
2768
7542
5979
2266
8128
5781
3257
7297
31...

input:

decode
1000
7
5608
7
5411
7
5787
7
2760
7
5977
7
9291
7
2379
7
8271
7
6064
7
7302
7
7734
7
8604
7
6065
7
7385
7
7313
7
8812
7
5582
7
8072
7
1909
7
8547
8
35702
7
7578
7
5147
7
2944
8
35484
7
8027
7
7428
7
8627
7
3673
7
9284
7
7110
7
5619
7
9053
7
5004
7
9490
7
2349
7
8552
7
5657
7
9225
7
3026
7
6993...

output:

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

result:

ok 1000 lines

Test #11:

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

input:

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

output:

3019
2439
6924
7244
8800
8618
6842
2185
9381
7462
8675
2155
9503
8756
35521
9270
1850
8739
4853
4843
4949
5133
9386
2288
9420
6483
35585
4351
5024
4685
3652
9180
5251
3170
8313
7464
6968
7918
2822
2908
8853
8108
2756
3115
5993
3138
3228
6233
2865
6155
8322
8421
6080
9194
7024
4323
5861
35539
8748
41...

input:

decode
1000
7
3019
7
2439
7
6924
7
7244
7
8800
7
8618
7
6842
7
2185
7
9381
7
7462
7
8675
7
2155
7
9503
7
8756
8
35521
7
9270
7
1850
7
8739
7
4853
7
4843
7
4949
7
5133
7
9386
7
2288
7
9420
7
6483
8
35585
7
4351
7
5024
7
4685
7
3652
7
9180
7
5251
7
3170
7
8313
7
7464
7
6968
7
7918
7
2822
7
2908
7
8853...

output:

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

result:

ok 1000 lines

Test #12:

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

input:

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

output:

1810
8845
3171
2381
6006
5261
8276
4425
2754
3120
2083
3319
6222
5005
35704
5238
9363
2590
4172
3222
7130
6713
6245
3018
4137
5027
4189
8282
3461
9119
1793
6867
3972
5000
8419
5853
2532
4809
3704
1781
7258
7384
3917
9478
8827
7507
8274
9070
7644
8775
9309
3356
5631
35530
3664
9388
7122
3694
3761
612...

input:

decode
1000
7
1810
7
8845
7
3171
7
2381
7
6006
7
5261
7
8276
7
4425
7
2754
7
3120
7
2083
7
3319
7
6222
7
5005
8
35704
7
5238
7
9363
7
2590
7
4172
7
3222
7
7130
7
6713
7
6245
7
3018
7
4137
7
5027
7
4189
7
8282
7
3461
7
9119
7
1793
7
6867
7
3972
7
5000
7
8419
7
5853
7
2532
7
4809
7
3704
7
1781
7
7258
...

output:

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

result:

ok 1000 lines

Test #13:

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

input:

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

output:

8516
7983
4743
35500
4059
4722
2904
3588
3067
2561
4770
7305
4107
9189
1934
9511
2070
4987
4802
8056
6821
6187
6238
3716
7052
7839
3912
5869
8527
3786
8348
8243
6056
8462
2061
7330
8569
2151
34905
6004
8855
2905
7112
5216
5686
4482
5981
5616
3124
2519
35473
35561
6759
5413
7174
34897
2529
7938
7481
...

input:

decode
1000
7
8516
7
7983
7
4743
8
35500
7
4059
7
4722
7
2904
7
3588
7
3067
7
2561
7
4770
7
7305
7
4107
7
9189
7
1934
7
9511
7
2070
7
4987
7
4802
7
8056
7
6821
7
6187
7
6238
7
3716
7
7052
7
7839
7
3912
7
5869
7
8527
7
3786
7
8348
7
8243
7
6056
7
8462
7
2061
7
7330
7
8569
7
2151
8
34905
7
6004
7
8855...

output:

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

result:

ok 1000 lines

Test #14:

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

input:

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

output:

43425
31841
33519
38570
12733
29109
27693
28077
40064
38651
25932
19063
16520
37867
11890
41148
36171
19055
43405
48582
20770
32502
14535
51006
13969
37944
37647
22430
51886
31048
10851
20638
15889
25170
23909
15811
13202
51568
45273
44209
33965
38686
12738
50510
38178
43047
32484
44864
17169
44956
...

input:

decode
1000
8
43425
8
31841
8
33519
8
38570
8
12733
8
29109
8
27693
8
28077
8
40064
8
38651
8
25932
8
19063
8
16520
8
37867
8
11890
8
41148
8
36171
8
19055
8
43405
8
48582
8
20770
8
32502
8
14535
8
51006
8
13969
8
37944
8
37647
8
22430
8
51886
8
31048
8
10851
8
20638
8
15889
8
25170
8
23909
8
15811
...

output:

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

result:

ok 1000 lines

Test #15:

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

input:

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

output:

153539
145221
65049
149445
186516
178721
169072
219036
94085
171732
65162
232299
149145
109376
95239
75701
258122
253153
210192
154985
71516
265198
189772
256381
209347
181925
105582
264834
194004
99391
172775
90853
67318
104543
199411
68582
215171
86226
219390
180198
267106
56573
261722
249503
2774...

input:

decode
1000
9
153539
9
145221
9
65049
9
149445
9
186516
9
178721
9
169072
9
219036
9
94085
9
171732
9
65162
9
232299
9
149145
9
109376
9
95239
9
75701
9
258122
9
253153
9
210192
9
154985
9
71516
9
265198
9
189772
9
256381
9
209347
9
181925
9
105582
9
264834
9
194004
9
99391
9
172775
9
90853
9
67318
...

output:

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

result:

ok 1000 lines

Test #16:

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

input:

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

output:

1136432
836970
299463
1289015
1035983
1098227
896010
841541
1448210
1256115
552944
1585197
1460063
1085851
1462687
1333195
1334212
451834
580656
647953
426557
623491
977554
767181
1119424
1597124
1673081
553076
812874
855138
1480935
1018709
1702318
499472
1056926
825609
1377128
342704
326822
1324413...

input:

decode
1000
10
1136432
10
836970
10
299463
10
1289015
10
1035983
10
1098227
10
896010
10
841541
10
1448210
10
1256115
10
552944
10
1585197
10
1460063
10
1085851
10
1462687
10
1333195
10
1334212
10
451834
10
580656
10
647953
10
426557
10
623491
10
977554
10
767181
10
1119424
10
1597124
10
1673081
10
...

output:

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

result:

ok 1000 lines

Test #17:

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

input:

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

output:

6599162
4868985
1730178
7503673
2050972
3245819
7922839
3601335
3644512
3219959
8478924
9701967
4079265
6961682
3646254
9698510
9171869
6433910
3749816
6316266
2704233
4754023
8181312
7384290
8915574
8796110
4728579
4893224
5808889
9233326
3873319
8826107
2899289
1810840
4853648
5887359
3219143
6923...

input:

decode
1000
11
6599162
11
4868985
11
1730178
11
7503673
11
2050972
11
3245819
11
7922839
11
3601335
11
3644512
11
3219959
11
8478924
11
9701967
11
4079265
11
6961682
11
3646254
11
9698510
11
9171869
11
6433910
11
3749816
11
6316266
11
2704233
11
4754023
11
8181312
11
7384290
11
8915574
11
8796110
11...

output:

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

result:

ok 1000 lines

Test #18:

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

input:

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

output:

38855282
28710465
10144818
44425950
52447407
43972007
25755831
17728301
19833896
44885094
27628700
14390798
45764516
35545510
21007145
35692058
38967236
12073697
58229421
57315717
23406057
59683842
10175783
43173277
58031666
58670753
47866247
25847245
28248648
45232103
42907101
23441803
36806385
195...

input:

decode
1000
12
38855282
12
28710465
12
10144818
12
44425950
12
52447407
12
43972007
12
25755831
12
17728301
12
19833896
12
44885094
12
27628700
12
14390798
12
45764516
12
35545510
12
21007145
12
35692058
12
38967236
12
12073697
12
58229421
12
57315717
12
23406057
12
59683842
12
10175783
12
43173277
...

output:

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

result:

ok 1000 lines

Test #19:

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

input:

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

output:

195760090
80664966
338164775
195298861
221806029
308264549
88522237
243376373
68092022
120565849
297542533
271425605
279699423
241649267
183664679
301501873
221048783
88331536
309803238
283105949
96893062
87827265
347365461
259708913
184747688
256082219
179250299
328855942
137603717
258872736
198077...

input:

decode
1000
13
195760090
13
80664966
13
338164775
13
195298861
13
221806029
13
308264549
13
88522237
13
243376373
13
68092022
13
120565849
13
297542533
13
271425605
13
279699423
13
241649267
13
183664679
13
301501873
13
221048783
13
88331536
13
309803238
13
283105949
13
96893062
13
87827265
13
34736...

output:

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

result:

ok 1000 lines

Test #20:

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

input:

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

output:

1391767574
1030725077
361042498
1652785258
415500116
1865988460
1404675312
878715728
2021194687
768819300
614001654
879274246
2081840620
881716776
478446681
1851143324
584318559
2038132038
643856911
2077616903
1454360155
1739697996
1411444501
1837021874
1256026483
520168117
1635134794
681127090
8632...

input:

decode
1000
14
1391767574
14
1030725077
14
361042498
14
1652785258
14
415500116
14
1865988460
14
1404675312
14
878715728
14
2021194687
14
768819300
14
614001654
14
879274246
14
2081840620
14
881716776
14
478446681
14
1851143324
14
584318559
14
2038132038
14
643856911
14
2077616903
14
1454360155
14
1...

output:

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

result:

ok 1000 lines

Test #21:

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

input:

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

output:

4349959292
8311382555
9614949358
12115578318
11922388704
8745962269
7752238372
11574943704
6518076495
5694326509
9742197019
6311982132
2854371207
2961864092
4375639601
6919284321
3531293428
5479176531
12147357606
6123068939
9744166106
8171218850
4640914947
12273890687
10156141141
5055804768
54896324...

input:

decode
1000
15
4349959292
15
8311382555
15
9614949358
15
12115578318
15
11922388704
15
8745962269
15
7752238372
15
11574943704
15
6518076495
15
5694326509
15
9742197019
15
6311982132
15
2854371207
15
2961864092
15
4375639601
15
6919284321
15
3531293428
15
5479176531
15
12147357606
15
6123068939
15
9...

output:

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

result:

ok 1000 lines

Test #22:

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

input:

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

output:

51548226316
38239661635
13308564682
62796467859
34090618864
56473787960
16902127924
45177146534
64225554193
61669490931
72389721182
20368793062
34314301820
32328370132
51582734723
39799282339
27816031801
77475725551
47550280624
56775026417
71564209113
17594936582
75533908639
18539863802
80025957498
...

input:

decode
1000
16
51548226316
16
38239661635
16
13308564682
16
62796467859
16
34090618864
16
56473787960
16
16902127924
16
45177146534
16
64225554193
16
61669490931
16
72389721182
16
20368793062
16
34314301820
16
32328370132
16
51582734723
16
39799282339
16
27816031801
16
77475725551
16
47550280624
16
...

output:

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

result:

ok 1000 lines

Test #23:

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

input:

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

output:

234192521372
179284546961
381098885781
238557548779
162959508434
146382741246
177799043996
439868732590
459471179488
85146396131
495994790143
455630246171
85271498431
153092852294
116323931255
325838920915
352911847027
366699675236
122261191899
391028709750
432563638456
188066624574
419614076786
222...

input:

decode
1000
17
234192521372
17
179284546961
17
381098885781
17
238557548779
17
162959508434
17
146382741246
17
177799043996
17
439868732590
17
459471179488
17
85146396131
17
495994790143
17
455630246171
17
85271498431
17
153092852294
17
116323931255
17
325838920915
17
352911847027
17
366699675236
17...

output:

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

result:

ok 1000 lines

Test #24:

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

input:

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

output:

1958054467623
1454386602648
503667864976
2471588844286
1510181463268
1005182820500
2961614665213
2712763435644
2993322492421
836095799921
2689456040862
2532722971992
780376758930
2202021693610
534674295764
2522592486176
1478938015155
576132137658
2513765548275
724982525179
1909312024280
949992140495...

input:

decode
1000
18
1958054467623
18
1454386602648
18
503667864976
18
2471588844286
18
1510181463268
18
1005182820500
18
2961614665213
18
2712763435644
18
2993322492421
18
836095799921
18
2689456040862
18
2532722971992
18
780376758930
18
2202021693610
18
534674295764
18
2522592486176
18
1478938015155
18
...

output:

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

result:

ok 1000 lines

Test #25:

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

input:

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

output:

12160828002213
9037529094573
3123298907641
15730911325983
5500981208460
14269025753818
3516604392413
10328611190486
5328235590470
16379085153977
18141898729592
7336671335182
13114583110072
8442289414631
6782209193235
7960659122219
8707726611230
13197941191234
5198907905478
11579217418105
10180319531...

input:

decode
1000
19
12160828002213
19
9037529094573
19
3123298907641
19
15730911325983
19
5500981208460
19
14269025753818
19
3516604392413
19
10328611190486
19
5328235590470
19
16379085153977
19
18141898729592
19
7336671335182
19
13114583110072
19
8442289414631
19
6782209193235
19
7960659122219
19
870772...

output:

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

result:

ok 1000 lines

Test #26:

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

input:

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

output:

88786014612495
86657371837275
56170660787892
55747046507329
118553666063923
89986981714238
111474675726125
114008140062194
100354224479667
86692964276926
118835209853199
112887329164981
21262371190409
110999656668574
85040010277974
88838738570686
79387037412341
59401107767556
85401758508728
10197660...

input:

decode
1000
20
88786014612495
20
86657371837275
20
56170660787892
20
55747046507329
20
118553666063923
20
89986981714238
20
111474675726125
20
114008140062194
20
100354224479667
20
86692964276926
20
118835209853199
20
112887329164981
20
21262371190409
20
110999656668574
20
85040010277974
20
88838738...

output:

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

result:

ok 1000 lines

Test #27:

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

input:

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

output:

280180270436133
251956068329708
739949210684489
653286940614688
511246321666535
281773031787971
378188618911882
141964104854218
618598040698399
508849895024858
610545692860164
520145762242953
547263891221178
715932066149771
302800702028099
198997031569025
479041963514799
470734088898777
159502999180...

input:

decode
1000
21
280180270436133
21
251956068329708
21
739949210684489
21
653286940614688
21
511246321666535
21
281773031787971
21
378188618911882
21
141964104854218
21
618598040698399
21
508849895024858
21
610545692860164
21
520145762242953
21
547263891221178
21
715932066149771
21
302800702028099
21
...

output:

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

result:

ok 1000 lines

Test #28:

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

input:

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

output:

1315043592973561
3843776025353042
2453465686061386
2383013966515626
1664431803832912
3767164070659149
4706635522421881
828536070982918
3814540340037835
4124351603370584
4354638450641416
3245171429648594
2427146727451303
4010287230903423
2569460220531923
4073263676919490
3185329757594930
367262052766...

input:

decode
1000
22
1315043592973561
22
3843776025353042
22
2453465686061386
22
2383013966515626
22
1664431803832912
22
3767164070659149
22
4706635522421881
22
828536070982918
22
3814540340037835
22
4124351603370584
22
4354638450641416
22
3245171429648594
22
2427146727451303
22
4010287230903423
22
256946...

output:

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

result:

ok 1000 lines

Test #29:

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

input:

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

output:

14842408415784956
23231616149380781
20928865968144558
14272545310162440
12128175139638582
29831588938532928
13344341743400368
16200043770709280
10744567967401246
25686934352105627
22565395726400259
10201436451232433
15189344307888991
5995499829299215
7642150228767712
6692432705724278
129216034002973...

input:

decode
1000
23
14842408415784956
23
23231616149380781
23
20928865968144558
23
14272545310162440
23
12128175139638582
23
29831588938532928
23
13344341743400368
23
16200043770709280
23
10744567967401246
23
25686934352105627
23
22565395726400259
23
10201436451232433
23
15189344307888991
23
599549982929...

output:

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

result:

ok 1000 lines

Test #30:

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

input:

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

output:

48634528320635713
107377984050843394
53520446969305059
35195734290256114
154701033911008328
77684661819550563
181968861136114841
184105711878331580
104715982286754489
160029112565900437
170965462275022012
69485314561553127
177792977697986941
135097874298877984
78845511227160427
172032251166918920
67...

input:

decode
1000
24
48634528320635713
24
107377984050843394
24
53520446969305059
24
35195734290256114
24
154701033911008328
24
77684661819550563
24
181968861136114841
24
184105711878331580
24
104715982286754489
24
160029112565900437
24
170965462275022012
24
69485314561553127
24
177792977697986941
24
1350...

output:

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

result:

ok 1000 lines

Test #31:

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

input:

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

output:

755093635835383686
562436470466082606
192657165369301081
1081026385941110985
565258271508616244
643364733302506975
677035876262732730
840308490713162675
411790298276181425
804882193308727404
212163606291403542
1160964009609364654
486602241496583068
357015272085270913
1111511459569929361
905530409249...

input:

decode
1000
25
755093635835383686
25
562436470466082606
25
192657165369301081
25
1081026385941110985
25
565258271508616244
25
643364733302506975
25
677035876262732730
25
840308490713162675
25
411790298276181425
25
804882193308727404
25
212163606291403542
25
1160964009609364654
25
486602241496583068
...

output:

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

result:

ok 1000 lines

Test #32:

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

input:

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

output:

705157160891583452
455729714953052446
765103402728101
60609553326710776
72902975704914657
20501425220613074
364817124342658
35427797017125
40173007223345
5043002441616218
8946608807335847
52238420416385887
887991859848456233
500767205890055559
24178988068986859
150623560047906378
4
3676578478472613
...

input:

decode
1000
25
705157160891583452
25
455729714953052446
22
765103402728101
24
60609553326710776
24
72902975704914657
23
20501425220613074
21
364817124342658
20
35427797017125
20
40173007223345
23
5043002441616218
23
8946608807335847
24
52238420416385887
25
887991859848456233
25
500767205890055559
23...

output:

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

result:

ok 1000 lines