QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322281#4824. Bracket-and-bar Sequencesduongnc000AC ✓5ms3892kbC++204.3kb2024-02-06 18:38:242024-02-06 18:38:26

Judging History

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

  • [2024-02-06 18:38:26]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3892kb
  • [2024-02-06 18:38:24]
  • 提交

answer

/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define int long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;

int dp[30], dp2[30];

void precalc() {
    dp[0] = dp[1] = 1;
    for (int i = 2; i <= 25; ++i) {
        for (int j = 1; j <= i; ++j) {
            int res = 0;
            for (int l = 0; l < j; ++l) {
                res += dp[l] * dp[j - l - 1];
            }
            dp[i] += res * dp[i - j];
        }
    }
    for (int j = 1; j <= 25; ++j) {
        for (int l = 0; l < j; ++l) {
            dp2[j] += dp[l] * dp[j - l - 1];
        }
    }
}

string get(int n, int ord) {
    if (n == 0) return "";
    if (n == 1) {
        assert(ord == 1);
        return "(|)";
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int tmp = dp2[i];
        if (cnt + tmp * dp[n - i] >= ord) {
            int left = ord - cnt;
            int tt1 = (left + tmp - 1) / tmp, tt2 = left - (tt1 - 1) * tmp;
            assert(tt2 <= tmp);
            string res = get(n - i, tt1);
            res.push_back('(');
            for (int j = 0; j < i; ++j) {
                if (dp[j] * dp[i - j - 1] < tt2) tt2 -= dp[j] * dp[i - j - 1];
                else {
                    int ttt1 = (tt2 + dp[i - j - 1] - 1) / dp[i - j - 1];
                    int ttt2 = tt2 - (ttt1 - 1) * dp[i - j - 1];
                    res += get(j, ttt1);
                    res.push_back('|');
                    res += get(i - j - 1, ttt2);
                    res.push_back(')');
                    return res;
                }
            }
        }
        cnt += tmp * dp[n - i];
    }
    return "idiot";
}

pair<string, string> clean(string s) {
    s.erase(s.begin());
    s.pop_back();
    int sum = 0;
    string res = "";
    for (int i = 0; i < isz(s); ++i) {
        if (s[i] == '(') ++sum;
        if (s[i] == ')') --sum;
        if (sum == 0 and s[i] == '|') return {s.substr(0, i), s.substr(i + 1)};
    }
}

int get(string s);

int get2(string s) {
    if (s.empty()) return 1;
    auto [u, v] = clean(s);
    int res = 0;
    for (int i = 0; i < isz(u) / 3; ++i) res += dp[i] * dp[isz(u) / 3 + isz(v) / 3 - i];
    res += (get(u) - 1) * dp[isz(v) / 3] + get(v);
    return res;
}

int get(string s) {
    if (s.empty()) return 1;
    int n = isz(s) / 3, sum = 0, res = 0;
    for (int i = 3 * n - 1; i >= 0; --i) {
        if (s[i] == '(') sum--;
        if (s[i] == ')') sum++;
        if (sum == 0) {
            int clen = (3 * n - i) / 3;
            for (int j = 1; j < clen; ++j) {
                res += dp2[j] * dp[n - j];
            }
            res += (get(s.substr(0, i)) - 1) * dp2[clen];
            res += get2(s.substr(i, 3 * clen));
            return res;
        }
    }
    return res;
}

string name;

void encode() {
    int n; cin >> n;
    while (n--) {
        int len; string s;
        cin >> len >> s;
        cout << get(s) << "\n";
    }
}

void decode() {
    int n; cin >> n;
    while (n--) {
        int len, val;
        cin >> len >> val;
        cout << get(len, val) << "\n";
    }
}

void solve() {
    cin >> name;
    if (name == "encode") encode();
    else decode();
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    precalc();
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
   cout << "Check array size pls sir" << endl;
#endif

}

詳細信息

Test #1:

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

input:

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

output:

1
55
92

input:

decode
3
1
1
4
55
5
92

output:

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

result:

ok 3 lines

Test #2:

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

input:

encode
1
1
(|)

output:

1

input:

decode
1
1
1

output:

(|)

result:

ok single line: '(|)'

Test #3:

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

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

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:

1
4
5
2
6
7
8
3
9
10
11
12
1
13
14
4
19
20
21
5
22
23
24
25
2
15
16
6
7
8
26
29
30
27
31
32
33
28
34
35
36
37
3
17
18
9
38
39
40
10
11
12
41
42
43
44
47
48
45
49
50
51
46
52
53
54
55
1
56
57
13
80
81
82
14
83
84
85
86
4
62
63
19
20
21
101
104
105
102
106
107
108
103
109
110
111
112
5
64
65
22
113
11...

input:

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

output:

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

result:

ok 1000 lines

Test #5:

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

input:

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

output:

755
907
910
911
908
912
913
914
909
915
916
917
918
919
931
932
922
937
938
939
923
940
941
942
943
920
933
934
924
925
926
944
947
948
945
949
950
951
946
952
953
954
955
921
935
936
927
956
957
958
928
929
930
959
960
961
962
965
966
963
967
968
969
964
970
971
972
973
3
278
279
60
398
399
400
61
...

input:

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

output:

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

result:

ok 1000 lines

Test #6:

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

input:

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

output:

6157
6425
4208
356
3738
7406
6984
12905
2100
2506
2206
5334
8526
369
4162
4890
708
2339
4839
5577
4428
938
6922
7525
7229
3063
1652
1500
6871
3583
1970
4378
1315
1559
5254
6715
7722
799
7349
3353
2211
3429
1799
4593
4506
3992
1407
4920
2953
5147
6316
3101
5401
524
570
7555
5785
5430
4132
5855
7444
6...

input:

decode
1000
7
6157
7
6425
7
4208
7
356
7
3738
7
7406
7
6984
8
12905
7
2100
7
2506
7
2206
7
5334
8
8526
7
369
7
4162
7
4890
7
708
7
2339
7
4839
7
5577
7
4428
7
938
7
6922
7
7525
7
7229
7
3063
7
1652
7
1500
7
6871
7
3583
7
1970
7
4378
7
1315
7
1559
7
5254
7
6715
7
7722
7
799
7
7349
7
3353
7
2211
7
342...

output:

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

result:

ok 1000 lines

Test #7:

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

input:

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

output:

4355
6632
2931
3402
4318
3632
6017
1581
3319
216
3178
5620
474
1540
3013
182
2180
1355
12896
2769
1224
3910
6994
6707
1873
982
5030
2889
2510
7688
2653
4257
2823
7319
6599
5829
4596
5614
3290
1724
3338
5691
2026
4000
6318
5263
4996
5840
3811
2406
5354
3316
2928
2838
4496
6046
7336
1516
3388
4566
554...

input:

decode
1000
7
4355
7
6632
7
2931
7
3402
7
4318
7
3632
7
6017
7
1581
7
3319
7
216
7
3178
7
5620
8
474
8
1540
7
3013
7
182
7
2180
7
1355
8
12896
8
2769
7
1224
7
3910
7
6994
7
6707
7
1873
7
982
7
5030
7
2889
7
2510
7
7688
7
2653
7
4257
7
2823
7
7319
7
6599
7
5829
7
4596
7
5614
7
3290
7
1724
7
3338
7
56...

output:

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

result:

ok 1000 lines

Test #8:

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

input:

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

output:

7298
2113
1619
2564
1093
6181
5170
7013
10997
4272
7490
1610
2446
7378
2698
3691
4384
5864
5960
1395
5276
2447
1766
898
600
7707
3277
2675
3863
4171
4455
5374
135
267
3094
1590
5358
5748
1351
1205
3998
5408
6293
3902
6706
116
3105
927
4681
1806
7283
1498
4323
4110
822
7533
4072
1872
1142
2627
1659
3...

input:

decode
1000
7
7298
7
2113
7
1619
7
2564
7
1093
7
6181
7
5170
7
7013
8
10997
7
4272
7
7490
7
1610
7
2446
7
7378
7
2698
7
3691
7
4384
7
5864
7
5960
7
1395
7
5276
7
2447
7
1766
7
898
7
600
7
7707
7
3277
7
2675
7
3863
7
4171
7
4455
7
5374
7
135
7
267
7
3094
8
1590
7
5358
7
5748
7
1351
7
1205
7
3998
7
54...

output:

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

result:

ok 1000 lines

Test #9:

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

input:

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

output:

1922
2982
592
11163
5248
1536
5934
6369
2863
6535
6478
3518
1208
2918
5820
1869
3550
5941
7117
2757
1786
698
739
8531
5906
4398
3548
1524
3616
1686
2774
4008
7746
2511
14191
376
3822
3924
659
2312
6016
14240
1448
5586
4526
7081
5845
6188
916
5955
4024
4811
2640
855
1980
5543
4525
1583
14241
3514
437...

input:

decode
1000
7
1922
7
2982
7
592
8
11163
7
5248
7
1536
7
5934
7
6369
7
2863
7
6535
7
6478
7
3518
7
1208
7
2918
7
5820
7
1869
7
3550
7
5941
7
7117
8
2757
7
1786
7
698
7
739
8
8531
7
5906
7
4398
7
3548
7
1524
7
3616
7
1686
8
2774
7
4008
7
7746
7
2511
8
14191
7
376
7
3822
7
3924
7
659
7
2312
7
6016
8
14...

output:

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

result:

ok 1000 lines

Test #10:

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

input:

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

output:

6580
6616
3372
3994
3495
1286
5136
377
3590
1605
2517
212
3591
3030
92
872
6537
2232
4801
196
2373
1615
6730
4338
14182
1493
3087
1844
5804
1304
2884
6589
740
6943
1234
5271
1818
3308
1145
4251
623
3381
4359
1367
6982
7033
5000
5731
2060
6195
1676
4004
400
3494
5175
2158
3368
5497
304
4107
3900
6542...

input:

decode
1000
7
6580
7
6616
7
3372
7
3994
7
3495
7
1286
7
5136
7
377
7
3590
7
1605
7
2517
7
212
7
3591
7
3030
7
92
7
872
7
6537
7
2232
7
4801
7
196
8
2373
7
1615
7
6730
7
4338
8
14182
7
1493
7
3087
7
1844
7
5804
7
1304
7
2884
7
6589
7
740
7
6943
7
1234
7
5271
7
1818
7
3308
7
1145
7
4251
7
623
7
3381
7...

output:

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

result:

ok 1000 lines

Test #11:

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

input:

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

output:

4230
5127
123
2417
864
1848
318
5015
1378
3146
1940
4969
1185
1874
14239
1335
4790
243
7564
7607
6913
6381
1391
5228
1277
2857
14263
7257
6949
7635
5834
1094
6842
4147
2303
3141
581
2713
3964
4296
893
2183
3990
4067
3511
4093
5478
3826
4278
3742
2304
171
3569
1072
676
7280
3242
14293
232
6056
7217
7...

input:

decode
1000
7
4230
7
5127
7
123
7
2417
7
864
7
1848
7
318
7
5015
7
1378
7
3146
7
1940
7
4969
7
1185
7
1874
8
14239
7
1335
7
4790
7
243
7
7564
7
7607
7
6913
7
6381
7
1391
7
5228
7
1277
7
2857
8
14263
7
7257
7
6949
7
7635
7
5834
7
1094
7
6842
7
4147
7
2303
7
3141
7
581
7
2713
7
3964
7
4296
7
893
7
218...

output:

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

result:

ok 1000 lines

Test #12:

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

input:

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

output:

4719
837
4141
5133
3488
6326
2351
7115
3978
4065
4862
5542
3841
6944
2372
6839
1428
4554
6058
5486
2874
2484
3833
3919
6116
6963
6126
380
5345
981
4755
104
6234
6890
1769
3239
4454
7714
5886
4736
1432
3029
5890
1226
850
2432
2346
1005
2566
221
1346
5418
6555
14249
5810
1380
2879
5866
5760
3788
2457
...

input:

decode
1000
7
4719
7
837
7
4141
7
5133
7
3488
7
6326
7
2351
7
7115
7
3978
7
4065
7
4862
7
5542
7
3841
7
6944
8
2372
7
6839
7
1428
7
4554
7
6058
7
5486
7
2874
7
2484
7
3833
7
3919
7
6116
7
6963
7
6126
7
380
7
5345
7
981
7
4755
7
104
7
6234
7
6890
7
1769
7
3239
7
4454
7
7714
7
5886
7
4736
7
1432
7
302...

output:

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

result:

ok 1000 lines

Test #13:

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

input:

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

output:

1704
2039
7681
14181
6324
7627
4165
5613
4032
4500
7732
1601
6169
1067
4701
1198
4902
6895
7711
2221
2145
3813
3839
5862
665
443
5933
3165
1711
5984
2288
1529
3577
1730
4891
499
1831
4971
15948
3485
894
3884
2887
6452
3291
7074
3499
6596
4064
4483
14217
14305
416
6334
2976
15971
4478
296
3109
3232
4...

input:

decode
1000
7
1704
7
2039
7
7681
8
14181
7
6324
7
7627
7
4165
7
5613
7
4032
7
4500
7
7732
7
1601
7
6169
7
1067
7
4701
7
1198
7
4902
7
6895
7
7711
7
2221
7
2145
7
3813
7
3839
7
5862
7
665
7
443
7
5933
7
3165
7
1711
7
5984
7
2288
7
1529
7
3577
7
1730
7
4891
7
499
7
1831
7
4971
8
15948
7
3485
7
894
7
3...

output:

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

result:

ok 1000 lines

Test #14:

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

input:

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

output:

13484
18188
21283
3640
28845
38119
39159
35927
17476
16806
42900
31878
23843
3310
28001
11274
14651
31885
8424
10309
32678
19569
22260
6020
25813
3362
628
34641
7685
18827
25956
32750
21972
41561
40063
24168
28598
7039
182
13778
21675
16865
28839
5423
3435
8679
19594
13825
23229
2287
480
17807
36602...

input:

decode
1000
8
13484
8
18188
8
21283
8
3640
8
28845
8
38119
8
39159
8
35927
8
17476
8
16806
8
42900
8
31878
8
23843
8
3310
8
28001
8
11274
8
14651
8
31885
8
8424
8
10309
8
32678
8
19569
8
22260
8
6020
8
25813
8
3362
8
628
8
34641
8
7685
8
18827
8
25956
8
32750
8
21972
8
41561
8
40063
8
24168
8
28598
...

output:

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

result:

ok 1000 lines

Test #15:

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

input:

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

output:

224828
244713
161526
239388
117553
106616
213567
100908
132343
210459
161294
89907
241483
184552
134104
146125
64892
1816
3308
219549
162601
67716
125701
60610
627
113280
181426
1375
119857
176581
210092
136274
165911
179539
2385
168204
21607
139360
101083
105978
52465
154910
66096
83350
6361
74057
...

input:

decode
1000
9
224828
9
244713
9
161526
9
239388
9
117553
9
106616
9
213567
9
100908
9
132343
9
210459
9
161294
9
89907
9
241483
9
184552
9
134104
9
146125
9
64892
9
1816
9
3308
9
219549
9
162601
9
67716
9
125701
9
60610
9
627
9
113280
9
181426
9
1375
9
119857
9
176581
9
210092
9
136274
9
165911
9
17...

output:

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

result:

ok 1000 lines

Test #16:

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

input:

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

output:

1
1430715
893208
606747
670376
714574
1253420
1424386
335005
593207
1010483
314953
413163
732896
414262
538670
540212
753133
1000386
1095847
847168
1058202
1213762
1330879
563844
331342
191010
1010605
1384287
1398357
266493
623097
244548
813015
688446
1410018
91449
873089
879697
533176
365479
105031...

input:

decode
1000
10
1
10
1430715
10
893208
10
606747
10
670376
10
714574
10
1253420
10
1424386
10
335005
10
593207
10
1010483
10
314953
10
413163
10
732896
10
414262
10
538670
10
540212
10
753133
10
1000386
10
1095847
10
847168
10
1058202
10
1213762
10
1330879
10
563844
10
331342
10
191010
10
1010605
10
...

output:

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

result:

ok 1000 lines

Test #17:

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

input:

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

output:

1
8414640
5275833
3633382
5452874
6047200
3325395
6226609
6318890
6000019
2562685
1012981
6625427
2336520
6322213
777939
139049
4164065
6391186
4355053
4736746
8144105
251364
402511
2088352
2454261
8108339
8376847
3868135
1784185
6565937
1968578
4794936
5354502
8397556
3799230
5995430
1530528
342765...

input:

decode
1000
11
1
11
8414640
11
5275833
11
3633382
11
5452874
11
6047200
11
3325395
11
6226609
11
6318890
11
6000019
11
2562685
11
1012981
11
6625427
11
2336520
11
6322213
11
777939
11
139049
11
4164065
11
6391186
11
4355053
11
4736746
11
8144105
11
251364
11
402511
11
2088352
11
2454261
11
8108339
1...

output:

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

result:

ok 1000 lines

Test #18:

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

input:

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

output:

1
50067108
31501461
22006137
14261973
21623428
46775409
26424725
34950260
1574023
48137995
29922351
19310319
23738679
37242415
23917589
17774731
32577963
6373031
4832878
39944075
7344029
31492743
18901299
6275176
6863197
18541594
47025658
49573611
3683402
21446105
39982056
25588892
35232494
16836407...

input:

decode
1000
12
1
12
50067108
12
31501461
12
22006137
12
14261973
12
21623428
12
46775409
12
26424725
12
34950260
12
1574023
12
48137995
12
29922351
12
19310319
12
23738679
12
37242415
12
23917589
12
17774731
12
32577963
12
6373031
12
4832878
12
39944075
12
7344029
12
31492743
12
18901299
12
6275176
...

output:

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

result:

ok 1000 lines

Test #19:

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

input:

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

output:

263238259
203157588
30880041
263154668
157333086
78129343
178865738
86931091
185360226
220819864
101627275
119338907
111325910
68750758
259391592
94559592
157934757
178489756
69151174
111945892
178191911
183171471
36766958
79871848
255141884
129682688
276397250
58884085
237244392
103581951
261901046...

input:

decode
1000
13
263238259
13
203157588
13
30880041
13
263154668
13
157333086
13
78129343
13
178865738
13
86931091
13
185360226
13
220819864
13
101627275
13
119338907
13
111325910
13
68750758
13
259391592
13
94559592
13
157934757
13
178489756
13
69151174
13
111945892
13
178191911
13
183171471
13
36766...

output:

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

result:

ok 1000 lines

Test #20:

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

input:

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

output:

1
1822766520
1153083941
609020879
1175687510
529107634
70804932
1507776298
396372403
1377842095
1045513784
1506932104
173254201
1510366956
1236658343
524845695
1060770542
43831032
993135174
171806326
417268633
652593767
124641697
562553779
840364251
1117916835
474107979
1313092330
1454682289
1201638...

input:

decode
1000
14
1
14
1822766520
14
1153083941
14
609020879
14
1175687510
14
529107634
14
70804932
14
1507776298
14
396372403
14
1377842095
14
1045513784
14
1506932104
14
173254201
14
1510366956
14
1236658343
14
524845695
14
1060770542
14
43831032
14
993135174
14
171806326
14
417268633
14
652593767
14...

output:

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

result:

ok 1000 lines

Test #21:

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

input:

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

output:

8085520708
4624769368
4977483463
2158936228
394556903
3994453971
5354987069
2914621495
10193284212
10562798294
3981104828
10947568891
7721048154
7441295105
8172721837
9935049478
6002239606
9128034647
2167415138
10794247494
3982148716
5731579883
8394231279
2318188589
4559006452
8822811466
9135517624
...

input:

decode
1000
15
8085520708
15
4624769368
15
4977483463
15
2158936228
15
394556903
15
3994453971
15
5354987069
15
2914621495
15
10193284212
15
10562798294
15
3981104828
15
10947568891
15
7721048154
15
7441295105
15
8172721837
15
9935049478
15
6002239606
15
9128034647
15
2167415138
15
10794247494
15
39...

output:

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

result:

ok 1000 lines

Test #22:

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

input:

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

output:

1
68328754959
43397658006
24575352094
55602847906
29611779075
46634942155
58735711985
4045204022
28527408214
202553531
41138346249
64205176956
54627990149
22508132777
62640067948
51084718791
6620362313
33265431405
29762219501
15049206688
46491403364
1707622123
41571646280
10384747960
20095446293
452...

input:

decode
1000
16
1
16
68328754959
16
43397658006
16
24575352094
16
55602847906
16
29611779075
16
46634942155
16
58735711985
16
4045204022
16
28527408214
16
202553531
16
41138346249
16
64205176956
16
54627990149
16
22508132777
16
62640067948
16
51084718791
16
6620362313
16
33265431405
16
29762219501
16...

output:

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

result:

ok 1000 lines

Test #23:

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

input:

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

output:

419798779219
323883418015
160651628450
415926374614
309314495553
231357127014
322167575058
108186972729
80440867278
271985093218
67635956542
101273728858
271783974811
302593689827
258856032681
121345316928
168647790471
21021161177
247066729178
94799792548
116703453602
332920276264
135611912985
40183...

input:

decode
1000
17
419798779219
17
323883418015
17
160651628450
17
415926374614
17
309314495553
17
231357127014
17
322167575058
17
108186972729
17
80440867278
17
271985093218
17
67635956542
17
101273728858
17
271783974811
17
302593689827
17
258856032681
17
121345316928
17
168647790471
17
21021161177
17
...

output:

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

result:

ok 1000 lines

Test #24:

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

input:

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

output:

1
2619631042665
1668912304993
72195393021
2402556796650
1920073004413
259400663753
112194144555
235802447104
1527361776803
714177543327
881166993201
1589596377876
709819903828
1685117553703
146101610453
2577746474976
1704687716771
145877873989
1624944906773
1349812960827
1890110805719
1660145836032
...

input:

decode
1000
18
1
18
2619631042665
18
1668912304993
18
72195393021
18
2402556796650
18
1920073004413
18
259400663753
18
112194144555
18
235802447104
18
1527361776803
18
714177543327
18
881166993201
18
1589596377876
18
709819903828
18
1685117553703
18
146101610453
18
2577746474976
18
1704687716771
18
...

output:

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

result:

ok 1000 lines

Test #25:

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

input:

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

output:

1
16332922290300
10418692103368
837450771961
8802942981430
6802579574676
10195707550505
14138172486192
9394728892538
4328328460574
3397499618638
13033741328860
3055854977788
15125618344341
12448344974542
13439453375050
15741495220596
1279172854328
9453066400089
8624583876270
14538260552308
469235325...

input:

decode
1000
19
1
19
16332922290300
19
10418692103368
19
837450771961
19
8802942981430
19
6802579574676
19
10195707550505
19
14138172486192
19
9394728892538
19
4328328460574
19
3397499618638
19
13033741328860
19
3055854977788
19
15125618344341
19
12448344974542
19
13439453375050
19
15741495220596
19
...

output:

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

result:

ok 1000 lines

Test #26:

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

input:

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

output:

6755568751969
47182142642079
101718800370938
101048974152700
13187655468473
33114386749159
19156038620382
20908349302850
31895775876920
47223107943033
13668902496421
21278385789163
64626932555720
19842196325167
37299804855821
42714225032848
34164312698144
92958559749449
21781639260990
31436553149738...

input:

decode
1000
20
6755568751969
20
47182142642079
20
101718800370938
20
101048974152700
20
13187655468473
20
33114386749159
20
19156038620382
20
20908349302850
20
31895775876920
20
47223107943033
20
13668902496421
20
21278385789163
20
64626932555720
20
19842196325167
20
37299804855821
20
42714225032848...

output:

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

result:

ok 1000 lines

Test #27:

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

input:

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

output:

501971688574474
472047149374444
77876336654832
181144015446177
118282382334307
506666601628363
543117516521353
420858929561085
185823261126843
104884576482838
35403061172298
53347003464321
41705846280944
130730455933553
535402756547760
381858452575567
31102059321444
280164157287694
445121291118184
1...

input:

decode
1000
21
501971688574474
21
472047149374444
21
77876336654832
21
181144015446177
21
118282382334307
21
506666601628363
21
543117516521353
21
420858929561085
21
185823261126843
21
104884576482838
21
35403061172298
21
53347003464321
21
41705846280944
21
130730455933553
21
535402756547760
21
3818...

output:

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

result:

ok 1000 lines

Test #28:

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

input:

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

output:

2342081435031192
1059779567913881
3445150603749702
3455797245679035
3086961305134645
853082566677227
526641368976007
2571233052763760
985469277042850
1130799438106759
958924951816260
315625176305896
3522060262416899
651628296631990
3526970122907664
849945590680166
1000578981327356
157942058625369
89...

input:

decode
1000
22
2342081435031192
22
1059779567913881
22
3445150603749702
22
3455797245679035
22
3086961305134645
22
853082566677227
22
526641368976007
22
2571233052763760
22
985469277042850
22
1130799438106759
22
958924951816260
22
315625176305896
22
3522060262416899
22
651628296631990
22
35269701229...

output:

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

result:

ok 1000 lines

Test #29:

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

input:

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

output:

23228579409008381
9907344392570945
11567598352045936
25109532427836388
21515022177340599
3798248738810884
24474760775912560
22300331644419255
19672474425484340
6540024777479744
10904740104874547
19239606504601889
23398398244251845
17143499410092331
14073342244252898
15744863868434045
239920541301387...

input:

decode
1000
23
23228579409008381
23
9907344392570945
23
11567598352045936
23
25109532427836388
23
21515022177340599
23
3798248738810884
23
24474760775912560
23
22300331644419255
23
19672474425484340
23
6540024777479744
23
10904740104874547
23
19239606504601889
23
23398398244251845
23
171434994100923...

output:

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

result:

ok 1000 lines

Test #30:

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

input:

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

output:

95612629405865717
76923571062578425
87965615242462687
106205962190465799
57288172896212304
134280310710645910
17059481029602462
15056328616650568
140372833691982761
39059223135592537
27270180903790526
126272562565633680
31606829933772589
73992305674790342
133696760183680144
26449124051535321
1246293...

input:

decode
1000
24
95612629405865717
24
76923571062578425
24
87965615242462687
24
106205962190465799
24
57288172896212304
24
134280310710645910
24
17059481029602462
24
15056328616650568
24
140372833691982761
24
39059223135592537
24
27270180903790526
24
126272562565633680
24
31606829933772589
24
73992305...

output:

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

result:

ok 1000 lines

Test #31:

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

input:

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

output:

1
1031147983159782228
661368678063000703
255643918638974397
1018127481423689186
908736931615113506
505655136137281102
467363345029549431
778692598792541856
34063996074579830
646415071542907783
99934455155134879
867603594655132208
735595647730922160
239071869527301286
443459832554504922
3768278158096...

input:

decode
1000
25
1
25
1031147983159782228
25
661368678063000703
25
255643918638974397
25
1018127481423689186
25
908736931615113506
25
505655136137281102
25
467363345029549431
25
778692598792541856
25
34063996074579830
25
646415071542907783
25
99934455155134879
25
867603594655132208
25
7355956477309221...

output:

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

result:

ok 1000 lines

Test #32:

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

input:

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

output:

521713341013853792
820510107125022352
2591298026991174
118032495109535309
130107602479548588
2027979699871100
589773236289165
57310802935113
75355258161502
16620529601047926
18222367539260972
94468551820504020
434693995567841169
848748813611976978
8782209244521332
9344288707047471
1
1559886431266900...

input:

decode
1000
25
521713341013853792
25
820510107125022352
22
2591298026991174
24
118032495109535309
24
130107602479548588
23
2027979699871100
21
589773236289165
20
57310802935113
20
75355258161502
23
16620529601047926
23
18222367539260972
24
94468551820504020
25
434693995567841169
25
84874881361197697...

output:

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

result:

ok 1000 lines