QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295742#4824. Bracket-and-bar Sequencesucup-team2307#AC ✓3ms3564kbC++202.4kb2023-12-31 20:52:292023-12-31 20:52:29

Judging History

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

  • [2023-12-31 20:52:29]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3564kb
  • [2023-12-31 20:52:29]
  • 提交

answer

#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using ll = long long;
using namespace std;
const int N = 26;
uint64_t dp[N];
void precalc() {
    dp[0] = 1;
    for(int i = 1; i < N; i++) {
        for(int l = 0; l < i; l++) {
            for(int r = 0; l + r < i; r++) {
                dp[i] += dp[l] * dp[r] * dp[i - l - r - 1];
            }
        }
    }
}

int find_pair(string s, char L, char R) {
    int cur = 0, bal = 0;
    do {
        bal += s[cur] == L;
        bal -= s[cur] == R;
        cur++;
    } while(bal);
    return cur - 1;
}

ll encode(ll n, string s) { 
    if(n == 0) return 0;
    int sep = find_pair(s, '(', '|');
    int clo = sep + find_pair(s.substr(sep), '|', ')');

    ll my_L = sep / 3;
    ll my_R = (clo - sep) / 3;

    ll base = 0, l = 0, r = 0;
    [&]() {
    for(l = 0; l < n; l++) {
        for(r = 0; l + r < n; r++) {
            if(l == my_L && r == my_R) return;
            base += dp[l] * dp[r] * dp[n - l - r - 1];
            
        }
    }
    }();

    // cout << s << " " << base << endl;

    base += encode(my_L, s.substr(1, my_L * 3));
    base += dp[my_L] * encode(my_R, s.substr(sep+1, my_R * 3));
    base += dp[my_L] * dp[my_R] * encode(n - 1 - my_L - my_R, s.substr(clo+1, 3*(n - 1 - my_L - my_R)));
    return base;
}
string decode(ll n, ll x) {
    if(n == 0) return "";
    ll my_L = -1, my_R = -1;

    [&]() {
    for(int l = 0; l < n; l++) {
        for(int r = 0; l + r < n; r++) {
            ll ways = dp[l] * dp[r] * dp[n - l - r - 1];
            if(x < ways) {
                my_L = l;
                my_R = r;
                return;
            }
            x -= ways;
        }
    }
    }();

    string res = "(";
    res += decode(my_L, x % dp[my_L]) + "|";
    x /= dp[my_L];
    res += decode(my_R, x % dp[my_R]) + ")";
    x /= dp[my_R];
    res += decode(n - 1 - my_L - my_R, x);

    return res;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    precalc();
    int T;
    // cout << dp[25] << endl;/
    string mode; cin >> mode >> T;
    if(mode == "encode") {
        string s;
        int n;
        while(T--) {
            cin >> n >> s;
            cout << encode(n, s) << '\n';
        }
    } else {
        ll x, n;
        while(T--) {
            cin >> n >> x;
            cout << decode(n, x) << '\n';
        }
    }
}

詳細信息

Test #1:

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

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: 3440kb

input:

encode
1
1
(|)

output:

0

input:

decode
1
1
0

output:

(|)

result:

ok single line: '(|)'

Test #3:

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

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: 3556kb

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: 3552kb

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: 3560kb

input:

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

output:

6073
6400
2826
4779
1250
7361
6555
322
4030
779
1922
4409
157
5119
2780
3304
2244
5090
3167
4603
3224
2398
6452
7680
6969
4044
399
1900
7098
1127
5555
2741
5886
1740
3828
6601
7708
2328
7191
645
1994
833
4252
3049
2640
2630
6022
3377
1676
3643
6313
4111
4482
1630
401
7656
5310
4380
3527
5282
7429
61...

input:

decode
1000
7
6073
7
6400
7
2826
7
4779
7
1250
7
7361
7
6555
8
322
7
4030
7
779
7
1922
7
4409
8
157
7
5119
7
2780
7
3304
7
2244
7
5090
7
3167
7
4603
7
3224
7
2398
7
6452
7
7680
7
6969
7
4044
7
399
7
1900
7
7098
7
1127
7
5555
7
2741
7
5886
7
1740
7
3828
7
6601
7
7708
7
2328
7
7191
7
645
7
1994
7
833
...

output:

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

result:

ok 1000 lines

Test #7:

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

input:

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

output:

2477
7083
1616
701
3237
1232
5711
4698
583
5186
533
4994
369
62
3981
2061
1940
5969
314
448
5852
2820
6553
7320
5455
4309
3601
1537
1755
7692
4745
3443
232
7148
6326
5339
2919
4955
582
2152
618
4879
1721
2646
6316
3823
3553
5293
1364
1469
4530
577
1599
240
2615
5666
7175
5057
681
2712
4557
6453
288
...

input:

decode
1000
7
2477
7
7083
7
1616
7
701
7
3237
7
1232
7
5711
7
4698
7
583
7
5186
7
533
7
4994
8
369
8
62
7
3981
7
2061
7
1940
7
5969
8
314
8
448
7
5852
7
2820
7
6553
7
7320
7
5455
7
4309
7
3601
7
1537
7
1755
7
7692
7
4745
7
3443
7
232
7
7148
7
6326
7
5339
7
2919
7
4955
7
582
7
2152
7
618
7
4879
7
172...

output:

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

result:

ok 1000 lines

Test #8:

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

input:

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

output:

7140
359
3948
1846
5234
6105
3724
6585
63
2731
7653
1607
3927
7260
4684
1215
2749
5295
5679
6004
3842
3928
2155
2360
442
7734
508
4725
1414
3326
2544
4403
2017
5440
4094
350
4535
5297
5949
5977
2643
4350
6279
2812
7308
907
4133
2426
2923
4265
7037
1899
3331
3507
2219
7683
3262
5506
5599
4201
910
479...

input:

decode
1000
7
7140
7
359
7
3948
7
1846
7
5234
7
6105
7
3724
7
6585
8
63
7
2731
7
7653
7
1607
7
3927
7
7260
7
4684
7
1215
7
2749
7
5295
7
5679
7
6004
7
3842
7
3928
7
2155
7
2360
7
442
7
7734
7
508
7
4725
7
1414
7
3326
7
2544
7
4403
7
2017
7
5440
7
4094
8
350
7
4535
7
5297
7
5949
7
5977
7
2643
7
4350
...

output:

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

result:

ok 1000 lines

Test #9:

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

input:

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

output:

5522
1669
427
343
3819
5067
5737
7288
1516
7323
6734
1036
5981
1589
5302
5478
1112
5617
6845
434
2167
1097
2334
178
5684
2769
1044
5059
1158
995
454
2860
7744
1764
96
5077
1373
3411
1047
5097
5656
186
4610
4967
2673
6781
5317
6155
2390
5732
2880
3152
4688
2274
38
4555
2669
4645
189
1021
2502
1562
28...

input:

decode
1000
7
5522
7
1669
7
427
8
343
7
3819
7
5067
7
5737
7
7288
7
1516
7
7323
7
6734
7
1036
7
5981
7
1589
7
5302
7
5478
7
1112
7
5617
7
6845
8
434
7
2167
7
1097
7
2334
8
178
7
5684
7
2769
7
1044
7
5059
7
1158
7
995
8
454
7
2860
7
7744
7
1764
8
96
7
5077
7
1373
7
3411
7
1047
7
5097
7
5656
8
186
7
4...

output:

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

result:

ok 1000 lines

Test #10:

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

input:

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

output:

7403
7198
688
2632
941
5866
3623
5125
1141
1500
1773
5181
1142
3975
1602
2304
7326
1997
3137
4250
159
3946
6384
3336
89
1884
4086
5204
5289
5870
1524
7413
2335
6490
5959
3829
4273
563
5604
3439
814
686
2488
5988
6543
6934
3558
4999
289
6141
989
2651
3893
938
3693
1929
685
4498
1574
3494
2622
7332
50...

input:

decode
1000
7
7403
7
7198
7
688
7
2632
7
941
7
5866
7
3623
7
5125
7
1141
7
1500
7
1773
7
5181
7
1142
7
3975
7
1602
7
2304
7
7326
7
1997
7
3137
7
4250
8
159
7
3946
7
6384
7
3336
8
89
7
1884
7
4086
7
5204
7
5289
7
5870
7
1524
7
7413
7
2335
7
6490
7
5959
7
3829
7
4273
7
563
7
5604
7
3439
7
814
7
686
7
...

output:

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

result:

ok 1000 lines

Test #11:

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

input:

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

output:

3358
3752
963
1480
2289
5202
880
3583
6003
4146
5537
3478
5856
5510
191
5914
3115
5404
7489
7531
6435
6331
6028
3775
5822
266
233
7010
6509
7585
5327
5246
6647
3545
5166
4139
410
4747
2737
2791
2342
1988
2607
3256
957
3455
4462
1380
3185
1276
5083
2050
1106
5232
1067
7031
602
246
5395
6081
6946
2374...

input:

decode
1000
7
3358
7
3752
7
963
7
1480
7
2289
7
5202
7
880
7
3583
7
6003
7
4146
7
5537
7
3478
7
5856
7
5510
8
191
7
5914
7
3115
7
5404
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
5246
7
6647
7
3545
7
5166
7
4139
7
410
7
4747
7
2737
7
2791
7
2342
7
1988
...

output:

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

result:

ok 1000 lines

Test #12:

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

input:

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

output:

2992
2279
3537
3624
958
6597
5163
6843
2527
3253
3265
4554
1378
6491
158
6639
6050
2690
6119
4470
1555
748
1412
3357
6083
6534
6230
5079
4513
4293
3038
365
6191
6445
2105
519
2542
7728
5392
3011
1430
3974
5625
5853
2268
3910
5091
4299
1855
5423
5943
4366
7370
207
5325
6012
1547
5271
5300
1297
297
38...

input:

decode
1000
7
2992
7
2279
7
3537
7
3624
7
958
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
6119
7
4470
7
1555
7
748
7
1412
7
3357
7
6083
7
6534
7
6230
7
5079
7
4513
7
4293
7
3038
7
365
7
6191
7
6445
7
2105
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: 3496kb

input:

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

output:

2137
4619
7668
127
6323
7599
2784
4952
2866
2620
7724
1498
6093
5237
2951
5962
3316
6414
7699
1936
891
1362
1405
5390
1050
4182
5682
601
2104
5692
5156
5051
1119
2126
3305
1507
4818
3467
469
949
2344
2778
1527
6527
544
6978
956
7422
3259
2584
133
263
765
7195
1664
466
2582
4615
4108
464
2667
5008
49...

input:

decode
1000
7
2137
7
4619
7
7668
8
127
7
6323
7
7599
7
2784
7
4952
7
2866
7
2620
7
7724
7
1498
7
6093
7
5237
7
2951
7
5962
7
3316
7
6414
7
7699
7
1936
7
891
7
1362
7
1405
7
5390
7
1050
7
4182
7
5682
7
601
7
2104
7
5692
7
5156
7
5051
7
1119
7
2126
7
3305
7
1507
7
4818
7
3467
8
469
7
949
7
2344
7
2778...

output:

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

result:

ok 1000 lines

Test #14:

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

input:

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

output:

10245
2642
6849
5865
19982
39686
36863
36276
21868
8374
42844
27179
19100
2286
19647
21660
1568
27197
10172
31064
30265
4487
13917
30020
14983
2387
4806
34171
34003
2959
16421
30250
15435
41233
38199
15538
20285
33168
10710
26173
7622
8451
19979
23536
4278
25664
4482
27858
19397
27825
795
22647
4075...

input:

decode
1000
8
10245
8
2642
8
6849
8
5865
8
19982
8
39686
8
36863
8
36276
8
21868
8
8374
8
42844
8
27179
8
19100
8
2286
8
19647
8
21660
8
1568
8
27197
8
10172
8
31064
8
30265
8
4487
8
13917
8
30020
8
14983
8
2387
8
4806
8
34171
8
34003
8
2959
8
16421
8
30250
8
15435
8
41233
8
38199
8
15538
8
20285
8
...

output:

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

result:

ok 1000 lines

Test #15:

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

input:

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

output:

210379
244305
111679
243640
35141
17444
234624
50521
105234
236559
111624
55270
240775
159035
110770
81295
64737
130542
11427
204111
112847
171407
42024
162182
26184
24153
151683
169952
41102
140116
236978
100384
115045
149207
967
118601
33684
102192
50941
15890
68226
97240
147503
156112
178287
6054...

input:

decode
1000
9
210379
9
244305
9
111679
9
243640
9
35141
9
17444
9
234624
9
50521
9
105234
9
236559
9
111624
9
55270
9
240775
9
159035
9
110770
9
81295
9
64737
9
130542
9
11427
9
204111
9
112847
9
171407
9
42024
9
162182
9
26184
9
24153
9
151683
9
169952
9
41102
9
140116
9
236978
9
100384
9
115045
9
...

output:

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

result:

ok 1000 lines

Test #16:

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

input:

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

output:

0
1430714
537507
715347
140744
225947
1193345
1429007
921862
286086
785996
1020405
356920
239737
351793
307244
312575
453778
790775
991293
463076
907448
1316528
1267151
24580
1057620
983440
786716
1382777
1413485
895761
79240
1138028
505433
187645
1401830
817933
554635
525121
299545
366613
861072
78...

input:

decode
1000
10
0
10
1430714
10
537507
10
715347
10
140744
10
225947
10
1193345
10
1429007
10
921862
10
286086
10
785996
10
1020405
10
356920
10
239737
10
351793
10
307244
10
312575
10
453778
10
790775
10
991293
10
463076
10
907448
10
1316528
10
1267151
10
24580
10
1057620
10
983440
10
786716
10
1382...

output:

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

result:

ok 1000 lines

Test #17:

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

input:

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

output:

0
8414639
3138807
4209163
3520770
4703863
4835468
5309756
5527384
4644562
2045115
4449686
6433995
974402
5501651
2543996
2224890
1259294
5716053
1413310
2877544
8128440
5138619
1488200
2198877
5803687
8071029
8394986
584238
4431587
6143822
5767051
2952704
3269057
8388303
457940
4636414
353939
207043...

input:

decode
1000
11
0
11
8414639
11
3138807
11
4209163
11
3520770
11
4703863
11
4835468
11
5309756
11
5527384
11
4644562
11
2045115
11
4449686
11
6433995
11
974402
11
5501651
11
2543996
11
2224890
11
1259294
11
5716053
11
1413310
11
2877544
11
8128440
11
5138619
11
1488200
11
2198877
11
5803687
11
807102...

output:

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

result:

ok 1000 lines

Test #18:

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

input:

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

output:

0
50067107
18565647
25033554
34990212
24323098
44825853
21475868
27289202
24577393
47536889
15936396
10148301
4501212
31381590
4960369
278725
20940118
33201070
14336722
38393140
38962352
18571663
8631867
30824108
37846762
30327793
45027409
49281122
24973307
9773981
38659851
7559890
26729117
1839831
...

input:

decode
1000
12
0
12
50067107
12
18565647
12
25033554
12
34990212
12
24323098
12
44825853
12
21475868
12
27289202
12
24577393
12
47536889
12
15936396
12
10148301
12
4501212
12
31381590
12
4960369
12
278725
12
20940118
12
33201070
12
14336722
12
38393140
12
38962352
12
18571663
12
8631867
12
30824108
...

output:

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

result:

ok 1000 lines

Test #19:

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

input:

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

output:

276785165
134809902
86865301
263963593
49447650
204901773
93583366
12260243
110224261
177604046
194239923
61724423
65422298
31604509
252912577
172234362
49491649
93065726
205838106
152601267
120962097
99761742
174010637
52190230
257493994
57163066
258238534
81536367
221603991
54370651
288462509
1005...

input:

decode
1000
13
276785165
13
134809902
13
86865301
13
263963593
13
49447650
13
204901773
13
93583366
13
12260243
13
110224261
13
177604046
13
194239923
13
61724423
13
65422298
13
31604509
13
252912577
13
172234362
13
49491649
13
93065726
13
205838106
13
152601267
13
120962097
13
99761742
13
174010637...

output:

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

result:

ok 1000 lines

Test #20:

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

input:

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

output:

0
1822766519
669682579
911369368
717604367
1097740180
12442684
1499650377
1376297325
1183772609
731264218
1499280713
520683228
1506205245
812388253
450105023
729466151
1368941975
646969031
536985638
68653165
924676608
36535741
1174874634
102899093
603308611
351957375
1001524785
1406789619
789830951
...

input:

decode
1000
14
0
14
1822766519
14
669682579
14
911369368
14
717604367
14
1097740180
14
12442684
14
1499650377
14
1376297325
14
1183772609
14
731264218
14
1499280713
14
520683228
14
1506205245
14
812388253
14
450105023
14
729466151
14
1368941975
14
646969031
14
536985638
14
68653165
14
924676608
14
3...

output:

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

result:

ok 1000 lines

Test #21:

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

input:

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

output:

6401385404
105561394
5456349304
3056031033
8125730459
920852382
986769435
2801294435
9504978317
10156164132
5285174103
10827773364
5224939986
5094129637
6509426058
9679109464
4476919042
9054170195
3083569082
10774632544
5287513354
1671186270
7157176086
8210094601
6226017820
8279096581
9151854006
870...

input:

decode
1000
15
6401385404
15
105561394
15
5456349304
15
3056031033
15
8125730459
15
920852382
15
986769435
15
2801294435
15
9504978317
15
10156164132
15
5285174103
15
10827773364
15
5224939986
15
5094129637
15
6509426058
15
9679109464
15
4476919042
15
9054170195
15
3083569082
15
10774632544
15
52875...

output:

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

result:

ok 1000 lines

Test #22:

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

input:

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

output:

0
68328754958
24931096953
34128392930
56483053974
11843396834
30757520589
65936324625
34337977249
38049834949
17576516288
22808543260
61181409532
53198757485
142613790
58350856211
42609399084
19186841729
6437304469
12179580693
47173496582
30257325990
51566583318
21527170830
54179300067
7590132557
29...

input:

decode
1000
16
0
16
68328754958
16
24931096953
16
34128392930
16
56483053974
16
11843396834
16
30757520589
16
65936324625
16
34337977249
16
38049834949
16
17576516288
16
22808543260
16
61181409532
16
53198757485
16
142613790
16
58350856211
16
42609399084
16
19186841729
16
6437304469
16
12179580693
1...

output:

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

result:

ok 1000 lines

Test #23:

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

input:

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

output:

419539025757
284227952380
229726546149
416400810903
241204969127
148756460193
279814327550
107142147299
114088935883
159629875958
341445563820
311628870674
159525196185
226903095136
136291057357
13113858092
70002995580
199508887313
131177808241
88861274921
105301468518
308855470443
281114299732
3894...

input:

decode
1000
17
419539025757
17
284227952380
17
229726546149
17
416400810903
17
241204969127
17
148756460193
17
279814327550
17
107142147299
17
114088935883
17
159629875958
17
341445563820
17
311628870674
17
159525196185
17
226903095136
17
136291057357
17
13113858092
17
70002995580
17
199508887313
17...

output:

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

result:

ok 1000 lines

Test #24:

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

input:

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

output:

0
2619631042664
950718737672
1309469366063
2233359359678
1490901809005
737851070550
1858177436558
783709199656
1073185370213
655846261315
594043466990
998488376026
469901396412
991422501602
1668042700920
2585540409113
1025803677558
1637234787444
864520933285
371061977016
1414984319079
936094191936
6...

input:

decode
1000
18
0
18
2619631042664
18
950718737672
18
1309469366063
18
2233359359678
18
1490901809005
18
737851070550
18
1858177436558
18
783709199656
18
1073185370213
18
655846261315
18
594043466990
18
998488376026
18
469901396412
18
991422501602
18
1668042700920
18
2585540409113
18
1025803677558
18...

output:

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

result:

ok 1000 lines

Test #25:

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

input:

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

output:

0
16332922290299
5914230186932
8159593790835
6765726589388
3236155748384
5887216993891
15483934193250
6813501735252
3917877906397
12469422972010
12260942883637
1994247597607
14808072755921
10645824627341
13520635355185
15520858465195
1341496224548
6696542825529
2417411247145
15031279132371
822580192...

input:

decode
1000
19
0
19
16332922290299
19
5914230186932
19
8159593790835
19
6765726589388
19
3236155748384
19
5887216993891
19
15483934193250
19
6813501735252
19
3917877906397
19
12469422972010
19
12260942883637
19
1994247597607
19
14808072755921
19
10645824627341
19
13520635355185
19
15520858465195
19
...

output:

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

result:

ok 1000 lines

Test #26:

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

input:

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

output:

19323039663790
49817528281409
101664581341978
100627116401028
76764788558618
50256353290287
28090302169117
78881823156981
67552878574360
49916724087651
79348554090418
78303374464345
36491192807424
27937873947886
17786491258252
19527441840971
3657192035585
86225260343828
18196096559644
56806932443809...

input:

decode
1000
20
19323039663790
20
49817528281409
20
101664581341978
20
100627116401028
20
76764788558618
20
50256353290287
20
28090302169117
20
78881823156981
20
67552878574360
20
49916724087651
20
79348554090418
20
78303374464345
20
36491192807424
20
27937873947886
20
17786491258252
20
1952744184097...

output:

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

result:

ok 1000 lines

Test #27:

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

input:

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

output:

457659306389021
378924464604600
419267986150853
158345127327768
57110717751414
465390735799619
551982959711305
255066091033334
355085539185671
74699388488265
141597443396977
82094553344048
297733670378671
496214808066177
532337562600710
245666104711452
10879314037514
13697847124241
294863647610856
1...

input:

decode
1000
21
457659306389021
21
378924464604600
21
419267986150853
21
158345127327768
21
57110717751414
21
465390735799619
21
551982959711305
21
255066091033334
21
355085539185671
21
74699388488265
21
141597443396977
21
82094553344048
21
297733670378671
21
496214808066177
21
532337562600710
21
245...

output:

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

result:

ok 1000 lines

Test #28:

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

input:

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

output:

1549256703582290
2349002628442214
3538778896022468
3436911581321033
2642124767299399
2467837129388853
3146911015855452
1439701098977405
2522627857388722
990981635547768
3024147494526832
325743632872122
3530778101082323
949410562677774
3582709025204024
2787212870621677
448172226714475
841327066094108...

input:

decode
1000
22
1549256703582290
22
2349002628442214
22
3538778896022468
22
3436911581321033
22
2642124767299399
22
2467837129388853
22
3146911015855452
22
1439701098977405
22
2522627857388722
22
990981635547768
22
3024147494526832
22
325743632872122
22
3530778101082323
22
949410562677774
22
35827090...

output:

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

result:

ok 1000 lines

Test #29:

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

input:

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

output:

21850186409345843
5252876020436683
4648300463296594
25094187776597831
21497496159273735
20505250758665344
23806286556491178
22661446644348104
17195754904405602
16273914677535831
13783872541200270
15771848404983799
23468768149839467
11052320458745411
9949768012275678
7979600725412229
2282163605755593...

input:

decode
1000
23
21850186409345843
23
5252876020436683
23
4648300463296594
23
25094187776597831
23
21497496159273735
23
20505250758665344
23
23806286556491178
23
22661446644348104
23
17195754904405602
23
16273914677535831
23
13783872541200270
23
15771848404983799
23
23468768149839467
23
11052320458745...

output:

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

result:

ok 1000 lines

Test #30:

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

input:

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

output:

63629026598075756
7871614605313828
55920968140627753
63482542632056767
103761273913335171
132716543580993845
48193562112144273
45961205562524327
156959862561778132
37972613039276575
119191670259945030
113371084878114800
97152650473145015
75959640917691161
135480097271748679
42035770870796521
1084086...

input:

decode
1000
24
63629026598075756
24
7871614605313828
24
55920968140627753
24
63482542632056767
24
103761273913335171
24
132716543580993845
24
48193562112144273
24
45961205562524327
24
156959862561778132
24
37972613039276575
24
119191670259945030
24
113371084878114800
24
97152650473145015
24
75959640...

output:

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

result:

ok 1000 lines

Test #31:

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

input:

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

output:

0
1031147983159782227
369779305096781525
515574389035186496
1007420886973524931
910588135037667517
72592864169275858
186237409754597290
643177647939966668
116795125091498485
376791060580770988
287388682423293268
866638631091992110
531209023056011222
773442518469643187
559916647666462461
622847405852...

input:

decode
1000
25
0
25
1031147983159782227
25
369779305096781525
25
515574389035186496
25
1007420886973524931
25
910588135037667517
25
72592864169275858
25
186237409754597290
25
643177647939966668
25
116795125091498485
25
376791060580770988
25
287388682423293268
25
866638631091992110
25
531209023056011...

output:

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

result:

ok 1000 lines

Test #32:

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

input:

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

output:

113374381658214657
766425326220818077
1459403659307471
90630307836700903
123567653059156905
2629469995515452
547286821458605
44049302597656
60833371457206
9610845870561541
13239920366132269
67508718481094047
192348461911165524
862015606088799834
12662563386003018
34578006862057848
0
839762310694041
...

input:

decode
1000
25
113374381658214657
25
766425326220818077
22
1459403659307471
24
90630307836700903
24
123567653059156905
23
2629469995515452
21
547286821458605
20
44049302597656
20
60833371457206
23
9610845870561541
23
13239920366132269
24
67508718481094047
25
192348461911165524
25
862015606088799834
...

output:

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

result:

ok 1000 lines