QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296688#4824. Bracket-and-bar Sequencesdefyers#AC ✓4ms3872kbC++172.6kb2024-01-03 13:37:412024-01-03 13:37:42

Judging History

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

  • [2024-01-03 13:37:42]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3872kb
  • [2024-01-03 13:37:41]
  • 提交

answer

#include "bits/stdc++.h"
#define all(a) begin(a), end(a)
using namespace std;

#define int long long 
using ll = long long;
using pii = pair<int, int>;

int n;

const int N = 26;
int dp[N][N][N];
int prefix(string s){
	int a0, a1, a2;
	a0 = count(all(s), '(');
	a1 = count(all(s), '|');
	a2 = count(all(s), ')');
#ifdef LOCAL
	printf("dp[%lld][%lld][%lld] = %lld\n", a0, a1, a2, dp[a0][a1][a2]);
#endif
	return dp[a0][a1][a2];
}

bool valid(int i, int j, int k){
	return i >= j && j >= k;
}

int f[N];
void precalc(){
	f[0] = 1; f[1] = 1;
	for(int n = 2; n < N; n++){
		for(int l = 0; l < n; l++){
			for(int m = 0; l + m < n; m++){
				int r = n - 1 - l - m;
				f[n] += f[l] * f[m] * f[r];
			}
		}
	}
	// cout << "HERE" << endl;
	// for(int n = 1; n < N; n++){
	// 	cout << n << ' ' << f[n] << endl;
	// }
}

int string_to_int(string s){
	// cout << s << endl;
	int n = s.size() / 3;
	if(n == 0) return 0;
	int tot = 0;
	int L = 0, M = 0;
	int net = 0;
	for(int i = 1; i < n * 3; i++){
		if(net == 0 && L == 0 && s[i] == '|'){
			L = i;
		}else if(net == 0 && M == 0 && s[i] == ')'){
			M = i;
		}
		if(s[i] == '(') net++;
		else if(s[i] == ')') net--;
	}
	// cout << L << ' ' << M << endl;
	for(int l = 0; l < n; l++){
		for(int m = 0; l + m < n; m++){
			int r = n - 1 - l - m;
			if(1 + l * 3 == L && 2 + (l + m) * 3 == M){
				int L = string_to_int(s.substr(1, l * 3));
				int M = string_to_int(s.substr(l * 3 + 2, m * 3));
				int R = string_to_int(s.substr((l + m) * 3 + 3, r * 3));
				tot += L * f[m] * f[r] + M * f[r] + R;
				return tot;
			}else{
				tot += f[l] * f[m] * f[r];
			}
		}
	}
	return 0;
}

string int_to_string(int n, int cnt){
	if(n == 0) return "";
	if(n == 1) return "(|)";
	for(int l = 0; l < n; l++){
		for(int m = 0; l + m < n; m++){
			int r = n - 1 - l - m;
			if(cnt < f[l] * f[m] * f[r]){
				string L = int_to_string(l, cnt / f[m] / f[r]); cnt %= (f[m] * f[r]);
				string M = int_to_string(m, cnt / f[r]); cnt %= f[r];
				string R = int_to_string(r, cnt);
				return "(" + L + "|" + M + ")" + R;
			}else{
				cnt -= f[l] * f[m] * f[r];
			}
		}
	}
	return "";
}

void encode() {
	cin >> n;
	string s; cin >> s;
	int cnt = string_to_int(s);
	cout << cnt << '\n';
}

void decode() {
	cin >> n;
	int cnt; cin >> cnt;
	string ans = int_to_string(n, cnt);
	cout << ans << '\n';
}
 
int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(10);
	precalc();
	string type; cin >> type;
	int t; cin >> t;

	while(t--){
		if(type == "encode") encode();
		else decode();
	}
	
}

詳細信息

Test #1:

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

input:

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

output:

0
54
65

input:

decode
3
1
0
4
54
5
65

output:

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

result:

ok 3 lines

Test #2:

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

input:

encode
1
1
(|)

output:

0

input:

decode
1
1
0

output:

(|)

result:

ok single line: '(|)'

Test #3:

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

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: 1ms
memory: 3856kb

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:

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

input:

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

output:

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

result:

ok 1000 lines

Test #5:

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

input:

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

output:

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...

input:

decode
1000
6
660
6
661
6
662
6
663
6
664
6
665
6
666
6
667
6
668
6
669
6
670
6
671
6
672
6
673
6
674
6
675
6
676
6
677
6
678
6
679
6
680
6
681
6
682
6
683
6
684
6
685
6
686
6
687
6
688
6
689
6
690
6
691
6
692
6
693
6
694
6
695
6
696
6
697
6
698
6
699
6
700
6
701
6
702
6
703
6
704
6
705
6
706
6
707
...

output:

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

result:

ok 1000 lines

Test #6:

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

input:

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

output:

6073
6400
2819
4784
1250
7347
6555
322
4030
779
1966
4409
157
5064
2789
3304
2248
5145
3167
4603
3224
2398
6452
7680
6971
4044
399
1988
7098
1127
5551
2741
5886
1714
3828
6601
7708
2328
7191
647
1972
833
4241
3049
2638
2630
6022
3386
1676
3643
6313
4111
4482
1630
401
7656
5266
4380
3527
5359
7429
61...

input:

decode
1000
7
6073
7
6400
7
2819
7
4784
7
1250
7
7347
7
6555
8
322
7
4030
7
779
7
1966
7
4409
8
157
7
5064
7
2789
7
3304
7
2248
7
5145
7
3167
7
4603
7
3224
7
2398
7
6452
7
7680
7
6971
7
4044
7
399
7
1988
7
7098
7
1127
7
5551
7
2741
7
5886
7
1714
7
3828
7
6601
7
7708
7
2328
7
7191
7
647
7
1972
7
833
...

output:

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

result:

ok 1000 lines

Test #7:

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

input:

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

output:

2477
7083
1614
701
3237
1232
5743
4690
583
5204
533
4910
379
62
3981
2163
1896
5965
314
448
5850
2836
6553
7320
5415
4309
3601
1537
1719
7692
4651
3441
232
7148
6326
5328
2919
4897
582
2108
618
4981
1817
2646
6316
3823
3553
5348
1364
1469
4530
577
1599
240
2615
5772
7175
5035
681
2712
4557
6453
288
...

input:

decode
1000
7
2477
7
7083
7
1614
7
701
7
3237
7
1232
7
5743
7
4690
7
583
7
5204
7
533
7
4910
8
379
8
62
7
3981
7
2163
7
1896
7
5965
8
314
8
448
7
5850
7
2836
7
6553
7
7320
7
5415
7
4309
7
3601
7
1537
7
1719
7
7692
7
4651
7
3441
7
232
7
7148
7
6326
7
5328
7
2919
7
4897
7
582
7
2108
7
618
7
4981
7
181...

output:

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

result:

ok 1000 lines

Test #8:

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

input:

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

output:

7140
350
3950
1804
5241
6105
3724
6585
63
2731
7655
1603
3927
7276
4740
1215
2749
5372
5647
6004
3842
3928
2117
2360
442
7734
508
4699
1414
3333
2544
4405
2031
5534
4094
347
4535
5253
5949
5977
2643
4350
6279
2812
7319
907
4133
2426
2923
4245
7037
1976
3323
3507
2219
7683
3262
5404
5599
4201
908
480...

input:

decode
1000
7
7140
7
350
7
3950
7
1804
7
5241
7
6105
7
3724
7
6585
8
63
7
2731
7
7655
7
1603
7
3927
7
7276
7
4740
7
1215
7
2749
7
5372
7
5647
7
6004
7
3842
7
3928
7
2117
7
2360
7
442
7
7734
7
508
7
4699
7
1414
7
3333
7
2544
7
4405
7
2031
7
5534
7
4094
8
347
7
4535
7
5253
7
5949
7
5977
7
2643
7
4350
...

output:

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

result:

ok 1000 lines

Test #9:

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

input:

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

output:

5452
1669
427
333
3819
5155
5657
7294
1516
7323
6734
1020
5981
1589
5313
5484
1112
5625
6845
434
2153
1097
2334
180
5662
2769
1044
5059
1158
993
454
2860
7744
1722
96
5132
1373
3415
1047
5086
5742
188
4606
4901
2673
6781
5350
6155
2390
5642
2880
3152
4632
2274
38
4555
2669
4727
189
1010
2502
1562
28...

input:

decode
1000
7
5452
7
1669
7
427
8
333
7
3819
7
5155
7
5657
7
7294
7
1516
7
7323
7
6734
7
1020
7
5981
7
1589
7
5313
7
5484
7
1112
7
5625
7
6845
8
434
7
2153
7
1097
7
2334
8
180
7
5662
7
2769
7
1044
7
5059
7
1158
7
993
8
454
7
2860
7
7744
7
1722
8
96
7
5132
7
1373
7
3415
7
1047
7
5086
7
5742
8
188
7
4...

output:

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

result:

ok 1000 lines

Test #10:

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

input:

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

output:

7403
7196
688
2632
942
5866
3623
5136
1141
1502
1725
5189
1142
3975
1604
2304
7326
2008
3137
4270
159
3944
6384
3348
89
1939
4086
5188
5300
5870
1524
7413
2335
6490
5959
3829
4269
563
5604
3429
814
686
2488
5988
6543
6934
3558
5021
289
6141
975
2651
3893
941
3693
1907
685
4498
1574
3494
2624
7332
50...

input:

decode
1000
7
7403
7
7196
7
688
7
2632
7
942
7
5866
7
3623
7
5136
7
1141
7
1502
7
1725
7
5189
7
1142
7
3975
7
1604
7
2304
7
7326
7
2008
7
3137
7
4270
8
159
7
3944
7
6384
7
3348
8
89
7
1939
7
4086
7
5188
7
5300
7
5870
7
1524
7
7413
7
2335
7
6490
7
5959
7
3829
7
4269
7
563
7
5604
7
3429
7
814
7
686
7
...

output:

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

result:

ok 1000 lines

Test #11:

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

input:

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

output:

3356
3752
967
1480
2289
5182
874
3583
6003
4146
5497
3485
5856
5416
187
5914
3115
5426
7489
7531
6435
6331
6028
3775
5822
266
233
7010
6509
7585
5327
5242
6647
3545
5056
4139
410
4761
2737
2781
2342
1900
2607
3256
959
3455
4462
1380
3185
1276
5061
2130
1106
5235
1067
7031
602
246
5399
6081
6946
2374...

input:

decode
1000
7
3356
7
3752
7
967
7
1480
7
2289
7
5182
7
874
7
3583
7
6003
7
4146
7
5497
7
3485
7
5856
7
5416
8
187
7
5914
7
3115
7
5426
7
7489
7
7531
7
6435
7
6331
7
6028
7
3775
7
5822
7
266
8
233
7
7010
7
6509
7
7585
7
5327
7
5242
7
6647
7
3545
7
5056
7
4139
7
410
7
4761
7
2737
7
2781
7
2342
7
1900
...

output:

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

result:

ok 1000 lines

Test #12:

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

input:

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

output:

2992
2279
3537
3624
936
6597
5163
6843
2527
3253
3265
4554
1378
6491
158
6639
6050
2690
6121
4470
1555
748
1412
3361
6083
6534
6226
5156
4513
4293
3038
367
6191
6445
2131
519
2542
7728
5392
3011
1430
3974
5649
5853
2268
3910
5157
4299
1807
5483
5943
4366
7370
207
5303
6012
1547
5370
5289
1297
297
38...

input:

decode
1000
7
2992
7
2279
7
3537
7
3624
7
936
7
6597
7
5163
7
6843
7
2527
7
3253
7
3265
7
4554
7
1378
7
6491
8
158
7
6639
7
6050
7
2690
7
6121
7
4470
7
1555
7
748
7
1412
7
3361
7
6083
7
6534
7
6226
7
5156
7
4513
7
4293
7
3038
7
367
7
6191
7
6445
7
2131
7
519
7
2542
7
7728
7
5392
7
3011
7
1430
7
3974...

output:

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

result:

ok 1000 lines

Test #13:

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

input:

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

output:

2063
4609
7668
127
6323
7599
2802
4896
2866
2620
7724
1496
6093
5215
2951
5962
3316
6414
7699
1991
901
1362
1405
5368
1050
4182
5656
601
2128
5686
5079
5106
1119
2030
3305
1507
4818
3487
469
933
2344
2800
1527
6527
544
6978
947
7422
3259
2584
133
263
765
7195
1664
466
2582
4717
4108
464
2667
5024
50...

input:

decode
1000
7
2063
7
4609
7
7668
8
127
7
6323
7
7599
7
2802
7
4896
7
2866
7
2620
7
7724
7
1496
7
6093
7
5215
7
2951
7
5962
7
3316
7
6414
7
7699
7
1991
7
901
7
1362
7
1405
7
5368
7
1050
7
4182
7
5656
7
601
7
2128
7
5686
7
5079
7
5106
7
1119
7
2030
7
3305
7
1507
7
4818
7
3487
8
469
7
933
7
2344
7
2800...

output:

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

result:

ok 1000 lines

Test #14:

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

input:

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

output:

10349
2642
6847
5865
19982
39686
36863
36276
21868
8374
42844
27311
19054
2286
19647
21674
1568
27317
10288
30886
30279
4487
13925
30058
14983
2387
4814
34171
34003
2959
16421
30099
15468
41287
38199
15560
20277
33168
11271
26121
7622
8451
19979
23536
4278
25896
4482
27418
19397
27580
795
22649
4075...

input:

decode
1000
8
10349
8
2642
8
6847
8
5865
8
19982
8
39686
8
36863
8
36276
8
21868
8
8374
8
42844
8
27311
8
19054
8
2286
8
19647
8
21674
8
1568
8
27317
8
10288
8
30886
8
30279
8
4487
8
13925
8
30058
8
14983
8
2387
8
4814
8
34171
8
34003
8
2959
8
16421
8
30099
8
15468
8
41287
8
38199
8
15560
8
20277
8
...

output:

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

result:

ok 1000 lines

Test #15:

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

input:

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

output:

210377
244195
111679
243674
35141
17444
234742
50515
105300
236559
111626
53861
240729
161348
110770
81295
63219
130644
11643
204111
112847
170292
42024
164612
26202
24164
152649
172482
41102
140116
236978
100344
115047
150388
979
118601
33689
102680
50941
15890
66360
97240
147306
154189
179103
6103...

input:

decode
1000
9
210377
9
244195
9
111679
9
243674
9
35141
9
17444
9
234742
9
50515
9
105300
9
236559
9
111626
9
53861
9
240729
9
161348
9
110770
9
81295
9
63219
9
130644
9
11643
9
204111
9
112847
9
170292
9
42024
9
164612
9
26202
9
24164
9
152649
9
172482
9
41102
9
140116
9
236978
9
100344
9
115047
9
...

output:

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

result:

ok 1000 lines

Test #16:

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

input:

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

output:

0
1430714
537507
715357
140744
225947
1193807
1429007
931168
286086
785996
1017557
351382
239737
354663
311192
312987
453662
790727
994491
463116
905894
1316532
1267151
24580
1063105
984871
786698
1382779
1413581
895685
79240
1137938
504731
187121
1401830
813221
554635
525121
300892
366856
870236
78...

input:

decode
1000
10
0
10
1430714
10
537507
10
715357
10
140744
10
225947
10
1193807
10
1429007
10
931168
10
286086
10
785996
10
1017557
10
351382
10
239737
10
354663
10
311192
10
312987
10
453662
10
790727
10
994491
10
463116
10
905894
10
1316532
10
1267151
10
24580
10
1063105
10
984871
10
786698
10
1382...

output:

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

result:

ok 1000 lines

Test #17:

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

input:

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

output:

0
8414639
3138807
4207320
3522475
4703863
4846786
5266804
5500361
4643860
1987995
4449675
6450787
972418
5509894
2543996
2224998
1259294
5683957
1413140
2877497
8128440
5157715
1486742
2192804
5823001
8073334
8394986
584238
4429229
6125916
5772486
2949582
3269057
8388305
457931
4635580
352581
207043...

input:

decode
1000
11
0
11
8414639
11
3138807
11
4207320
11
3522475
11
4703863
11
4846786
11
5266804
11
5500361
11
4643860
11
1987995
11
4449675
11
6450787
11
972418
11
5509894
11
2543996
11
2224998
11
1259294
11
5683957
11
1413140
11
2877497
11
8128440
11
5157715
11
1486742
11
2192804
11
5823001
11
807333...

output:

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

result:

ok 1000 lines

Test #18:

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

input:

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

output:

0
50067107
18565647
25033554
35028684
24323098
44825853
21477528
27289202
24577426
47564582
15937726
9946337
4501212
31300634
4999013
279153
20968361
33204334
14336744
38337322
38963489
18571663
8631867
30864812
37846762
30150501
45027409
49281210
24973307
9774746
38397479
7559984
26729117
1809900
1...

input:

decode
1000
12
0
12
50067107
12
18565647
12
25033554
12
35028684
12
24323098
12
44825853
12
21477528
12
27289202
12
24577426
12
47564582
12
15937726
12
9946337
12
4501212
12
31300634
12
4999013
12
279153
12
20968361
12
33204334
12
14336744
12
38337322
12
38963489
12
18571663
12
8631867
12
30864812
1...

output:

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

result:

ok 1000 lines

Test #19:

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

input:

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

output:

276760186
134809902
86865302
263865986
49462892
205673056
93583218
12212268
110223754
178158826
195352959
62437335
64227968
31655175
252916074
172059090
49489187
93065726
205226276
152429787
120524121
99764872
174099593
52192258
257494005
57163054
258238534
80887537
222773181
54370651
288251925
1005...

input:

decode
1000
13
276760186
13
134809902
13
86865302
13
263865986
13
49462892
13
205673056
13
93583218
13
12212268
13
110223754
13
178158826
13
195352959
13
62437335
13
64227968
13
31655175
13
252916074
13
172059090
13
49489187
13
93065726
13
205226276
13
152429787
13
120524121
13
99764872
13
174099593...

output:

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

result:

ok 1000 lines

Test #20:

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

input:

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

output:

0
1822766519
669682579
911383260
717606149
1097898903
12327981
1499648914
1377918540
1186758758
731217804
1499277309
520544541
1506477088
812380857
445973534
729613835
1380846779
646968531
536901802
70123125
924215437
36516911
1174050886
102977673
603306286
368085643
1001524429
1402074870
788545935
...

input:

decode
1000
14
0
14
1822766519
14
669682579
14
911383260
14
717606149
14
1097898903
14
12327981
14
1499648914
14
1377918540
14
1186758758
14
731217804
14
1499277309
14
520544541
14
1506477088
14
812380857
14
445973534
14
729613835
14
1380846779
14
646968531
14
536901802
14
70123125
14
924215437
14
3...

output:

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

result:

ok 1000 lines

Test #21:

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

input:

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

output:

6425124984
105210525
5454943576
2964749895
8134228987
920387118
986674272
2820643318
9506148457
10156164121
5285653115
10827774916
5224939986
5091892295
6511326032
9678212384
4484694386
9054161639
3047325936
10774632540
5287863062
1671186270
7171501936
8208250436
6131864634
8308390363
9151854076
870...

input:

decode
1000
15
6425124984
15
105210525
15
5454943576
15
2964749895
15
8134228987
15
920387118
15
986674272
15
2820643318
15
9506148457
15
10156164121
15
5285653115
15
10827774916
15
5224939986
15
5091892295
15
6511326032
15
9678212384
15
4484694386
15
9054161639
15
3047325936
15
10774632540
15
52878...

output:

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

result:

ok 1000 lines

Test #22:

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

input:

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

output:

0
68328754958
24931096953
34164377479
56484756272
11843406352
30757520625
65936331392
34289423728
38090676859
18056661858
22808466940
61181409532
53381843764
142613790
58359972905
42577928527
19186841720
6387154105
12183669973
47175250026
30257325990
51794452586
21527235857
54179717019
7562000184
29...

input:

decode
1000
16
0
16
68328754958
16
24931096953
16
34164377479
16
56484756272
16
11843406352
16
30757520625
16
65936331392
16
34289423728
16
38090676859
16
18056661858
16
22808466940
16
61181409532
16
53381843764
16
142613790
16
58359972905
16
42577928527
16
19186841720
16
6387154105
16
12183669973
1...

output:

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

result:

ok 1000 lines

Test #23:

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

input:

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

output:

419555004680
284596155080
229196353103
416400814275
243472655583
148756179217
279879505376
107226106630
112746752719
159629875958
341445563820
311541957030
159527399261
226903091608
136318396218
13604651597
70002995580
199530114924
131168608668
89739398401
103686560480
309018771391
280639758845
3894...

input:

decode
1000
17
419555004680
17
284596155080
17
229196353103
17
416400814275
17
243472655583
17
148756179217
17
279879505376
17
107226106630
17
112746752719
17
159629875958
17
341445563820
17
311541957030
17
159527399261
17
226903091608
17
136318396218
17
13604651597
17
70002995580
17
199530114924
17...

output:

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

result:

ok 1000 lines

Test #24:

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

input:

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

output:

0
2619631042664
950718737672
1309815521332
2233361659204
1505032642391
737851554748
1861477178849
783709129260
1074001929814
643644602902
589714772125
998488374186
469882079934
991435548574
1662639265695
2585503205417
1025803677558
1636354141314
864520949062
370994078973
1414984319403
936109324514
6...

input:

decode
1000
18
0
18
2619631042664
18
950718737672
18
1309815521332
18
2233361659204
18
1505032642391
18
737851554748
18
1861477178849
18
783709129260
18
1074001929814
18
643644602902
18
589714772125
18
998488374186
18
469882079934
18
991435548574
18
1662639265695
18
2585503205417
18
1025803677558
18...

output:

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

result:

ok 1000 lines

Test #25:

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

input:

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

output:

0
16332922290299
5914230186932
8166461145150
6766237723048
3243151856316
5887216993805
15484310404536
6817834894177
3938504018754
12421424908456
12299564756520
1983229130302
14807285159731
10686436025187
13522162532556
15523643380832
1341503702238
6699342058884
2417411214980
15030934550328
822094358...

input:

decode
1000
19
0
19
16332922290299
19
5914230186932
19
8166461145150
19
6766237723048
19
3243151856316
19
5887216993805
19
15484310404536
19
6817834894177
19
3938504018754
19
12421424908456
19
12299564756520
19
1983229130302
19
14807285159731
19
10686436025187
19
13522162532556
19
15523643380832
19
...

output:

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

result:

ok 1000 lines

Test #26:

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

input:

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

output:

19498080322312
49817054838032
101664274656322
100627116401028
76711767305611
50256026942630
27446019662867
78685197898967
67824364564123
49916724087665
79348540861536
78218156553373
36488012498917
28254845242852
17787442696575
19988243920432
3638936792377
86225660310192
18197491624904
56793612832353...

input:

decode
1000
20
19498080322312
20
49817054838032
20
101664274656322
20
100627116401028
20
76711767305611
20
50256026942630
20
27446019662867
20
78685197898967
20
67824364564123
20
49916724087665
20
79348540861536
20
78218156553373
20
36488012498917
20
28254845242852
20
17787442696575
20
1998824392043...

output:

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

result:

ok 1000 lines

Test #27:

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

input:

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

output:

457891657785451
376852450991271
419156106614044
158275162968217
57044171408717
466511895075307
551982198129397
255248802071525
355189989867073
74725588658251
142851035009194
82087566090068
297733670379398
494786742857264
532337562653468
245616295633688
10890128472381
13698304438293
294857152286473
1...

input:

decode
1000
21
457891657785451
21
376852450991271
21
419156106614044
21
158275162968217
21
57044171408717
21
466511895075307
21
551982198129397
21
255248802071525
21
355189989867073
21
74725588658251
21
142851035009194
21
82087566090068
21
297733670379398
21
494786742857264
21
532337562653468
21
245...

output:

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

result:

ok 1000 lines

Test #28:

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

input:

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

output:

1549097233741186
2348692793632826
3539631530026522
3436910956185405
2639420574812570
2472724399429845
3146903190436062
1439701099158869
2531818215527352
988367601083649
3035761471386140
325743632807257
3532017874273882
946552538232122
3578925811281953
2783843672188547
448236778303291
834991227263706...

input:

decode
1000
22
1549097233741186
22
2348692793632826
22
3539631530026522
22
3436910956185405
22
2639420574812570
22
2472724399429845
22
3146903190436062
22
1439701099158869
22
2531818215527352
22
988367601083649
22
3035761471386140
22
325743632807257
22
3532017874273882
22
946552538232122
22
35789258...

output:

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

result:

ok 1000 lines

Test #29:

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

input:

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

output:

21850186409345843
5215578042248567
4648307064245093
25094951113259628
21497492218013557
20505248210446940
23805105670257707
22644577498608479
17227980640920599
16274088926465054
13702651481497479
15851516884272699
23468778544596256
11052226650931347
9923598486847783
7979643823692265
2282163605755833...

input:

decode
1000
23
21850186409345843
23
5215578042248567
23
4648307064245093
23
25094951113259628
23
21497492218013557
23
20505248210446940
23
23805105670257707
23
22644577498608479
23
17227980640920599
23
16274088926465054
23
13702651481497479
23
15851516884272699
23
23468778544596256
23
11052226650931...

output:

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

result:

ok 1000 lines

Test #30:

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

input:

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

output:

63790271477917970
7875653726956630
56059133815323939
63464578894025141
103962890367517895
132716543580994061
48162392032595261
45962235375606494
156959900974691634
38117855316278179
119169323762669047
113313660983140780
97145595630610384
75959640918800102
135478952447653365
42810060404146462
1083301...

input:

decode
1000
24
63790271477917970
24
7875653726956630
24
56059133815323939
24
63464578894025141
24
103962890367517895
24
132716543580994061
24
48162392032595261
24
45962235375606494
24
156959900974691634
24
38117855316278179
24
119169323762669047
24
113313660983140780
24
97145595630610384
24
75959640...

output:

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

result:

ok 1000 lines

Test #31:

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

input:

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

output:

0
1031147983159782227
369779305096781525
515573991579891114
1007420886973509245
909859217597655978
72592873114887391
186235565842963260
646048257753452041
116890148228024437
376789860363694149
287388683121576457
866638559791364036
531209011855622833
771631836125358467
552254694266089123
623931182193...

input:

decode
1000
25
0
25
1031147983159782227
25
369779305096781525
25
515573991579891114
25
1007420886973509245
25
909859217597655978
25
72592873114887391
25
186235565842963260
25
646048257753452041
25
116890148228024437
25
376789860363694149
25
287388683121576457
25
866638559791364036
25
531209011855622...

output:

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

result:

ok 1000 lines

Test #32:

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

input:

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

output:

113480751545553069
764807304235497872
1459403880951015
90935044243478675
123030570427359292
2629403081742910
547286440910027
44049032839508
60274947363693
9610845870469214
13240032997381447
67458825325057259
189345174887628401
862119653664762569
12668430214802447
34623028159682157
0
834118310619454
...

input:

decode
1000
25
113480751545553069
25
764807304235497872
22
1459403880951015
24
90935044243478675
24
123030570427359292
23
2629403081742910
21
547286440910027
20
44049032839508
20
60274947363693
23
9610845870469214
23
13240032997381447
24
67458825325057259
25
189345174887628401
25
862119653664762569
...

output:

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

result:

ok 1000 lines