QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#323395#4824. Bracket-and-bar Sequenceshotboy2703AC ✓4ms3900kbC++144.3kb2024-02-09 15:11:272024-02-09 15:11:27

Judging History

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

  • [2024-02-09 15:11:27]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3900kb
  • [2024-02-09 15:11:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL << (i))
ull dp[60];
ll wow[61];
ll recursion_count = 0;
ll find_right(string s){
    assert(sz(s)>0);
    ll sum = 0;
    ll l = -1;
    for (ll i = sz(s) - 2;i >= 0;i --){
        sum += (s[i] == '|' ? 0 : (s[i] == '(' ? 1 : -1));
        if (sum == 0 && s[i] == '|'){l = i;break;}
    }
    return l;
}
ll normal_to_int(string s);
ll wow_to_int(string s){
    if ((recursion_count++)>1000){
        assert(0);
        return 0;
    }
    ll n=sz(s)/3;
    assert(n!=0);
    if (n < 2)return 0;
    ll l = find_right(s);
    ll right_sz = (sz(s) - 1 - (l + 1) + 1)/3;
    ll res = 0;
    for (ll i = 0;i < right_sz;i ++){
        res += dp[i] * dp[n-1-i];
    }
    string left_part(s,1,l-1),right_part(s,l+1,sz(s)-2-l);
    return res + normal_to_int(left_part) * dp[sz(right_part)/3] + normal_to_int(right_part);
}
ll normal_to_int(string s){
    if ((recursion_count++)>1000){
        assert(0);
        return 0;
    }
    ll n = sz(s)/3;
    if (n < 2)return 0;
    ll sum = 0;
    ll l = -1;
    for (ll i = sz(s) - 1;i >= 0;i --){
        sum += (s[i] == '|' ? 0 : (s[i] == '(' ? 1 : -1));
        if (sum == 0){l = i;break;}
    }
    ll right_sz = (sz(s)-l)/3;
    if (right_sz==n){
//        cout<<"SUS "<<s<<endl;
        return wow_to_int(s);
    }
    else{
        ll res = wow[n];
        for (ll i = 1;i < right_sz;i ++){
            res += wow[i] * dp[n-i];
        }
        string left_part(s,0,sz(s)-right_sz*3),right_part(s,sz(s)-right_sz*3,right_sz*3);
//        cout<<s<<' '<<left_part<<' '<<right_part<<endl;
        return res + normal_to_int(left_part) * wow[sz(right_part)/3] + wow_to_int(right_part);
    }
}
ll to_int(string s){
    recursion_count = 0;
    ll res = 0;
    ll n=sz(s)/3;
    for (ll i = 0;i < n;i++)res+=dp[i];
    res += normal_to_int(s);
    return res;
}
string pr_to_string(ll n,ll k){
    if (n == 1)return "(|)";
    if (n==0)return "";
    if (k < wow[n]){
        for (ll j = 0;j < n;j ++){
            if (dp[j] * dp[n-1-j]<=k)k-=dp[j] * dp[n-1-j];
            else{
                ll k1,k2;
                k1 = k / dp[j];
                k2 = k % dp[j];
                return "(" + pr_to_string(n-1-j,k1) + "|" +  pr_to_string(j,k2) + ")";
            }
        }
    }
    else{
        k -= wow[n];
        for (ll i = 1;i < n;i ++){
            if (wow[i] * dp[n-i]<=k)k-=wow[i] * dp[n-i];
            else{
                ll k1,k2;
                k1 = k / wow[i];
                k2 = k % wow[i];
                return pr_to_string(n-i,k1)+pr_to_string(i,k2);
            }
        }
    }

}
string too_string(ll x){
    recursion_count = 0;
    for (ll i = 0;i <= 25;i ++){
        if (x >= ll(dp[i]))x -= dp[i];
        else {return pr_to_string(i,x);}
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
    dp[0] = 1;
    for (ll i = 1;i <= 25;i ++){
        wow[i] = 0;
        for (ll j = 0;j < i;j ++){
            wow[i] += dp[j] * dp[i-1-j];
        }
        dp[i] = wow[i];
        for (ll j = 1;j < i;j ++){
            dp[i] += wow[j] * dp[i-j];
        }
//        cout<<i<<' '<<ld(dp[i])<<' '<<ld(wow[i])<<'\n';
    }
//    for (ll i = 0;i < dp[0] + dp[1] + dp[2] + dp[3] + dp[4] + dp[5];i ++){
//        cout<<i<<' '<<too_string(i)<<' '<<to_int(too_string(i))<<endl;
//        assert(to_int(too_string(i)) == i);
//    }
//    cout<<wow[4]<<'\n';
//    cout<<to_int("((|(|))|(|))")<<endl;
    string task;
    cin>>task;
    ll t;
    cin>>t;
    while (t--){
        ll n;
        cin>>n;
        if (task=="encode"){
            string s;
            cin>>s;
            cout<<to_int(s)<<'\n';
//            cout<<ld(to_int(s))<<'\n';
//            if (recursion_count > 1000){
//                cout<<s<<'\n';
//            }
//            cout<<pr_to_int(s)<<'\n';
        }
        else{
            ll x;
            cin>>x;
            cout<<too_string(x)<<'\n';
        }
    }
}
/*
encode
1
4
(|(|)(|)(|))
decode
3
1
1
4
17
5
302

1274049
1273964
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1
17
302

input:

decode
3
1
1
4
17
5
302

output:

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

result:

ok 3 lines

Test #2:

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

input:

encode
1
1
(|)

output:

1

input:

decode
1
1
1

output:

(|)

result:

ok single line: '(|)'

Test #3:

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

input:

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

output:

2
1
3

input:

decode
3
2
2
1
1
2
3

output:

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

result:

ok 3 lines

Test #4:

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

input:

encode
1000
3
(|)(|)(|)
3
(|)(|(|))
3
(|)((|)|)
3
(|(|))(|)
3
(|(|)(|))
3
(|(|(|)))
3
(|((|)|))
3
((|)|)(|)
3
((|)|(|))
3
((|)(|)|)
3
((|(|))|)
3
(((|)|)|)
4
(|)(|)(|)(|)
4
(|)(|)(|(|))
4
(|)(|)((|)|)
4
(|)(|(|))(|)
4
(|)(|(|)(|))
4
(|)(|(|(|)))
4
(|)(|((|)|))
4
(|)((|)|)(|)
4
(|)((|)|(|))
4
(|)((|)...

output:

14
16
15
13
11
10
9
12
8
7
6
5
56
64
63
58
71
70
69
57
68
67
66
65
55
62
61
53
52
51
44
46
45
43
41
40
39
42
38
37
36
35
54
60
59
50
34
33
32
49
48
47
31
30
29
26
28
27
25
23
22
21
24
20
19
18
17
254
289
288
262
314
313
312
261
311
310
309
308
256
293
292
269
268
267
342
344
343
341
339
338
337
340
...

input:

decode
1000
3
14
3
16
3
15
3
13
3
11
3
10
3
9
3
12
3
8
3
7
3
6
3
5
4
56
4
64
4
63
4
58
4
71
4
70
4
69
4
57
4
68
4
67
4
66
4
65
4
55
4
62
4
61
4
53
4
52
4
51
4
44
4
46
4
45
4
43
4
41
4
40
4
39
4
42
4
38
4
37
4
36
4
35
4
54
4
60
4
59
4
50
4
34
4
33
4
32
4
49
4
48
4
47
4
31
4
30
4
29
4
26
4
28
4
27
4
2...

output:

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

result:

ok 1000 lines

Test #5:

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

input:

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

output:

943
864
866
865
863
861
860
859
862
858
857
856
855
839
847
846
841
854
853
852
840
851
850
849
848
838
845
844
836
835
834
827
829
828
826
824
823
822
825
821
820
819
818
837
843
842
833
817
816
815
832
831
830
814
813
812
809
811
810
808
806
805
804
807
803
802
801
800
1253
1421
1420
1286
1511
151...

input:

decode
1000
6
943
6
864
6
866
6
865
6
863
6
861
6
860
6
859
6
862
6
858
6
857
6
856
6
855
6
839
6
847
6
846
6
841
6
854
6
853
6
852
6
840
6
851
6
850
6
849
6
848
6
838
6
845
6
844
6
836
6
835
6
834
6
827
6
829
6
828
6
826
6
824
6
823
6
822
6
825
6
821
6
820
6
819
6
818
6
837
6
843
6
842
6
833
6
817
...

output:

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

result:

ok 1000 lines

Test #6:

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

input:

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

output:

3468
2771
5279
6677
8925
2119
3103
44776
7917
8311
7776
4119
40949
6670
5293
4635
6281
7643
4684
3948
5421
6157
3160
1923
2296
8451
7599
7401
2976
9090
7081
5474
5765
7500
4261
2946
1821
6327
2176
9320
7771
9231
7248
4862
5576
5206
5670
4608
8548
4478
3212
8402
4173
6877
7069
1974
3776
4195
4966
367...

input:

decode
1000
7
3468
7
2771
7
5279
7
6677
7
8925
7
2119
7
3103
8
44776
7
7917
7
8311
7
7776
7
4119
8
40949
7
6670
7
5293
7
4635
7
6281
7
7643
7
4684
7
3948
7
5421
7
6157
7
3160
7
1923
7
2296
7
8451
7
7599
7
7401
7
2976
7
9090
7
7081
7
5474
7
5765
7
7500
7
4261
7
2946
7
1821
7
6327
7
2176
7
9320
7
7771...

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:

5494
2859
8585
9271
5357
8969
3502
7478
9354
6434
9423
3905
35997
36581
8490
6468
7823
5722
44785
37817
5857
5113
3106
2774
7158
6082
4495
8625
8215
1835
8074
5224
8698
2224
2852
3694
4872
3911
9370
7337
9338
3824
7865
5198
3207
4267
4547
3683
8860
8261
4096
9357
8588
8678
5586
3479
2189
7381
9303
5...

input:

decode
1000
7
5494
7
2859
7
8585
7
9271
7
5357
7
8969
7
3502
7
7478
7
9354
7
6434
7
9423
7
3905
8
35997
8
36581
7
8490
7
6468
7
7823
7
5722
8
44785
8
37817
7
5857
7
5113
7
3106
7
2774
7
7158
7
6082
7
4495
7
8625
7
8215
7
1835
7
8074
7
5224
7
8698
7
2224
7
2852
7
3694
7
4872
7
3911
7
9370
7
7337
7
93...

output:

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

result:

ok 1000 lines

Test #8:

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

input:

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

output:

2212
7995
7530
8163
5984
3444
4342
3067
42973
5389
1947
7539
8221
2145
8029
9031
5465
3659
3619
5700
4247
8220
7285
6179
7034
1805
9496
8052
8810
5284
5645
4155
6505
6383
8407
36629
4092
3753
5726
5797
5203
4220
3250
5119
2775
6634
8398
6137
4947
7251
2242
7403
5352
4993
6358
1917
5026
7159
5935
810...

input:

decode
1000
7
2212
7
7995
7
7530
7
8163
7
5984
7
3444
7
4342
7
3067
8
42973
7
5389
7
1947
7
7539
7
8221
7
2145
7
8029
7
9031
7
5465
7
3659
7
3619
7
5700
7
4247
7
8220
7
7285
7
6179
7
7034
7
1805
7
9496
7
8052
7
8810
7
5284
7
5645
7
4155
7
6505
7
6383
7
8407
8
36629
7
4092
7
3753
7
5726
7
5797
7
5203...

output:

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

result:

ok 1000 lines

Test #9:

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

input:

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

output:

7135
8534
7042
43150
4277
7365
3606
2652
8638
2566
2638
9149
5794
8596
3705
7152
9108
3638
2457
37829
7265
6936
6263
40944
3580
5451
9125
7383
8987
7565
37812
5075
1779
8214
46438
6657
8836
5102
6980
7670
3503
46371
7427
3926
5546
2444
3680
3324
6161
3624
5079
4719
8087
6240
36967
4000
5547
7476
463...

input:

decode
1000
7
7135
7
8534
7
7042
8
43150
7
4277
7
7365
7
3606
7
2652
7
8638
7
2566
7
2638
7
9149
7
5794
7
8596
7
3705
7
7152
7
9108
7
3638
7
2457
8
37829
7
7265
7
6936
7
6263
8
40944
7
3580
7
5451
7
9125
7
7383
7
8987
7
7565
8
37812
7
5075
7
1779
7
8214
8
46438
7
6657
7
8836
7
5102
7
6980
7
7670
7
3...

output:

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

result:

ok 1000 lines

Test #10:

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

input:

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

output:

2518
2839
9288
5204
9178
5776
4492
6656
9083
7544
8210
6438
9082
8504
6607
6205
2561
7750
4711
6454
37364
7534
2966
5337
46434
7408
8429
7203
3719
5791
8650
2512
6262
3139
5847
4272
7233
9368
5930
5230
7011
9297
5490
5710
3105
2404
4543
3792
37027
3335
7575
5194
6813
9179
4355
7810
9290
4028
6739
49...

input:

decode
1000
7
2518
7
2839
7
9288
7
5204
7
9178
7
5776
7
4492
7
6656
7
9083
7
7544
7
8210
7
6438
7
9082
7
8504
7
6607
7
6205
7
2561
7
7750
7
4711
7
6454
8
37364
7
7534
7
2966
7
5337
8
46434
7
7408
7
8429
7
7203
7
3719
7
5791
7
8650
7
2512
7
6262
7
3139
7
5847
7
4272
7
7233
7
9368
7
5930
7
5230
7
7011...

output:

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

result:

ok 1000 lines

Test #11:

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

input:

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

output:

5251
4447
6630
8250
6213
7209
6751
4510
5689
8370
7111
4556
5820
7157
46372
5742
4735
6425
2010
2018
3169
2717
5691
4297
5903
8659
46335
2273
3133
1888
3691
5983
3005
4951
7700
8378
7071
8014
5183
5379
6184
7820
5208
5031
9162
5005
4045
8837
5383
8918
7699
6479
9122
5999
6958
2245
9480
46318
6423
33...

input:

decode
1000
7
5251
7
4447
7
6630
7
8250
7
6213
7
7209
7
6751
7
4510
7
5689
7
8370
7
7111
7
4556
7
5820
7
7157
8
46372
7
5742
7
4735
7
6425
7
2010
7
2018
7
3169
7
2717
7
5691
7
4297
7
5903
7
8659
8
46335
7
2273
7
3133
7
1888
7
3691
7
5983
7
3005
7
4951
7
7700
7
8378
7
7071
7
8014
7
5183
7
5379
7
6184...

output:

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

result:

ok 1000 lines

Test #12:

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

input:

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

output:

4811
6227
4960
4490
9185
2682
7631
2459
5218
5036
4668
4001
8850
3138
37365
3010
5649
5528
3379
4039
8629
8336
8827
5104
3419
3119
3403
6653
4105
6083
4770
6649
3291
3179
7282
9483
5646
1816
3639
4792
7439
8505
3590
5855
6245
8235
7636
6072
8161
6414
5731
4207
2548
46365
3715
5684
8642
3662
3741
888...

input:

decode
1000
7
4811
7
6227
7
4960
7
4490
7
9185
7
2682
7
7631
7
2459
7
5218
7
5036
7
4668
7
4001
7
8850
7
3138
8
37365
7
3010
7
5649
7
5528
7
3379
7
4039
7
8629
7
8336
7
8827
7
5104
7
3419
7
3119
7
3403
7
6653
7
4105
7
6083
7
4770
7
6649
7
3291
7
3179
7
7282
7
9483
7
5646
7
1816
7
3639
7
4792
7
7439
...

output:

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

result:

ok 1000 lines

Test #13:

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

input:

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

output:

7321
7852
1844
46417
3201
1903
5290
3912
5064
5582
1793
7548
3456
6004
4924
5804
4623
3192
1819
7761
7963
8863
8839
3663
6987
6784
3607
9438
7314
3541
7680
7372
9099
7357
4634
6900
7220
4554
48859
9188
6183
5126
8647
2746
9387
2376
9174
2502
5032
5599
46397
46309
6832
2676
8538
48875
5602
6711
8412
...

input:

decode
1000
7
7321
7
7852
7
1844
8
46417
7
3201
7
1903
7
5290
7
3912
7
5064
7
5582
7
1793
7
7548
7
3456
7
6004
7
4924
7
5804
7
4623
7
3192
7
1819
7
7761
7
7963
7
8863
7
8839
7
3663
7
6987
7
6784
7
3607
7
9438
7
7314
7
3541
7
7680
7
7372
7
9099
7
7357
7
4634
7
6900
7
7220
7
4554
8
48859
7
9188
7
6183...

output:

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

result:

ok 1000 lines

Test #14:

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

input:

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

output:

44050
52340
49578
38028
24518
15871
16700
14584
47311
47991
9882
20908
28481
38433
24702
43039
46675
20903
40691
39094
19952
51292
28072
32569
30126
38381
36076
18689
30910
52030
26395
20096
27864
11227
13282
29077
24142
31486
35538
43753
49092
47932
24511
33270
38313
40824
51312
43646
27211
36751
3...

input:

decode
1000
8
44050
8
52340
8
49578
8
38028
8
24518
8
15871
8
16700
8
14584
8
47311
8
47991
8
9882
8
20908
8
28481
8
38433
8
24702
8
43039
8
46675
8
20903
8
40691
8
39094
8
19952
8
51292
8
28072
8
32569
8
30126
8
38381
8
36076
8
18689
8
30910
8
52030
8
26395
8
20096
8
27864
8
11227
8
13282
8
29077
8...

output:

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

result:

ok 1000 lines

Test #15:

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

input:

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

output:

92704
54786
137955
57777
286670
297375
82167
270789
152930
74754
138081
261431
59180
114854
151266
171507
235587
199743
201876
91923
134971
233477
279501
236880
199515
291321
118035
198195
282327
123206
75134
159604
133068
120481
200790
131246
212688
164456
270541
296268
222414
144113
234397
251103
...

input:

decode
1000
9
92704
9
54786
9
137955
9
57777
9
286670
9
297375
9
82167
9
270789
9
152930
9
74754
9
138081
9
261431
9
59180
9
114854
9
151266
9
171507
9
235587
9
199743
9
201876
9
91923
9
134971
9
233477
9
279501
9
236880
9
199515
9
291321
9
118035
9
198195
9
282327
9
123206
9
75134
9
159604
9
133068...

output:

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

result:

ok 1000 lines

Test #16:

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

input:

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

output:

1136432
299463
836970
1559302
1679670
1647393
494264
303344
1355689
1573834
719221
1254222
1394700
1615241
1393661
1516772
1515270
899089
734535
634329
987718
676817
432695
417417
1601628
1239331
1046034
719105
345803
332478
1296402
1715935
992283
935989
1661729
318269
1197255
842487
855767
1522581
...

input:

decode
1000
10
1136432
10
299463
10
836970
10
1559302
10
1679670
10
1647393
10
494264
10
303344
10
1355689
10
1573834
10
719221
10
1254222
10
1394700
10
1615241
10
1393661
10
1516772
10
1515270
10
899089
10
734535
10
634329
10
987718
10
676817
10
432695
10
417417
10
1601628
10
1239331
10
1046034
10
...

output:

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

result:

ok 1000 lines

Test #17:

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

input:

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

output:

6599162
1730178
4868985
9151076
4691944
4097543
8843364
3941501
3823024
4144951
8314491
6180077
3476812
8204235
3819849
6332874
6564802
9589549
3780932
9489799
5402650
2018782
6753923
6877952
7820444
7995774
2037913
1753778
9968291
7333872
3580933
7841721
5430627
4789889
1747218
10143288
4148772
755...

input:

decode
1000
11
6599162
11
1730178
11
4868985
11
9151076
11
4691944
11
4097543
11
8843364
11
3941501
11
3823024
11
4144951
11
8314491
11
6180077
11
3476812
11
8204235
11
3819849
11
6332874
11
6564802
11
9589549
11
3780932
11
9489799
11
5402650
11
2018782
11
6753923
11
6877952
11
7820444
11
7995774
11...

output:

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

result:

ok 1000 lines

Test #18:

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

input:

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

output:

38855282
10144818
28710465
54293428
47014605
54782734
13336569
30345094
25101517
39840442
12073949
33884080
53476931
58772040
22969084
58476903
52504553
27633961
36007432
37725825
20267851
35059712
28731192
53647631
36122936
35642921
51630929
13175221
10637691
41358798
54855412
20229879
56792027
254...

input:

decode
1000
12
38855282
12
10144818
12
28710465
12
54293428
12
47014605
12
54782734
12
13336569
12
30345094
12
25101517
12
39840442
12
12073949
12
33884080
12
53476931
12
58772040
12
22969084
12
58476903
12
52504553
12
27633961
12
36007432
12
37725825
12
20267851
12
35059712
12
28731192
12
53647631
...

output:

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

result:

ok 1000 lines

Test #19:

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

input:

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

output:

95853080
159972821
221746122
95941487
338346852
283307201
198267379
293112231
172735221
140208032
298901687
319873113
312987238
276612004
94338720
294780164
337601212
198556688
276252580
312355054
195423068
199541748
216011325
286230356
91784709
330532535
106911095
259635851
123792085
309345908
9260...

input:

decode
1000
13
95853080
13
159972821
13
221746122
13
95941487
13
338346852
13
283307201
13
198267379
13
293112231
13
172735221
13
140208032
13
298901687
13
319873113
13
312987238
13
276612004
13
94338720
13
294780164
13
337601212
13
198556688
13
276252580
13
312355054
13
195423068
13
199541748
13
21...

output:

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

result:

ok 1000 lines

Test #20:

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

input:

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

output:

1391767574
361042498
1030725077
1844386373
1011808603
1732303317
1439119036
676067708
1525997593
805971756
1141186388
676952499
1351665833
673439432
969504627
1736569832
1162354400
1369044431
1085046407
1350903784
1666909171
1860627352
1495257418
1765844989
2176780589
1200363224
1715983595
870697434...

input:

decode
1000
14
1391767574
14
361042498
14
1030725077
14
1844386373
14
1011808603
14
1732303317
14
1439119036
14
676067708
14
1525997593
14
805971756
14
1141186388
14
676952499
14
1351665833
14
673439432
14
969504627
14
1736569832
14
1162354400
14
1369044431
14
1085046407
14
1350903784
14
1666909171
...

output:

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

result:

ok 1000 lines

Test #21:

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

input:

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

output:

5221097239
12434935895
12082781457
9486740202
8575935527
11504372656
12994726163
10292165700
3935401762
2745701196
11482600954
2459549696
5587035174
5771580163
5135951273
3693910429
6693147504
4279240662
9491007792
2530424789
11481369204
12715616685
4914368692
9338074861
11789668629
4485723562
42717...

input:

decode
1000
15
5221097239
15
12434935895
15
12082781457
15
9486740202
15
8575935527
15
11504372656
15
12994726163
15
10292165700
15
3935401762
15
2745701196
15
11482600954
15
2459549696
15
5587035174
15
5771580163
15
5135951273
15
3693910429
15
6693147504
15
4279240662
15
9491007792
15
2530424789
15...

output:

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

result:

ok 1000 lines

Test #22:

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

input:

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

output:

51548226316
13308564682
38239661635
70353597391
25371487232
75342290268
34916327013
18711322876
54491602664
72137371785
51476035284
44252025568
17570310449
26684535500
68372924333
24034038144
30553747208
50295651950
79507812739
75190875446
61133804490
35988861371
50629703471
45105474190
46110519207
...

input:

decode
1000
16
51548226316
16
13308564682
16
38239661635
16
70353597391
16
25371487232
16
75342290268
16
34916327013
16
18711322876
16
54491602664
16
72137371785
16
51476035284
16
44252025568
16
17570310449
16
26684535500
16
68372924333
16
24034038144
16
30553747208
16
50295651950
16
79507812739
16
...

output:

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

result:

ok 1000 lines

Test #23:

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

input:

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

output:

83872346307
179784443384
442444322918
91493961752
194346836355
246828782769
181490645123
385624576759
355995230292
231682825914
279259902714
370344546262
231910105243
201096203713
275911383192
402947997225
452829044762
332029457833
264721693525
379502118996
394294158519
170733504134
410383064363
102...

input:

decode
1000
17
83872346307
17
179784443384
17
442444322918
17
91493961752
17
194346836355
17
246828782769
17
181490645123
17
385624576759
17
355995230292
17
231682825914
17
279259902714
17
370344546262
17
231910105243
17
201096203713
17
275911383192
17
402947997225
17
452829044762
17
332029457833
17...

output:

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

result:

ok 1000 lines

Test #24:

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

input:

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

output:

1958054467623
503667864976
1454386602648
2003062289894
914328652403
1203223500289
1916654528629
2023355211738
1883870411588
1627071583940
2431629053848
2600701111190
1679139375340
2452645796517
1436529092530
2062142591877
561559787260
1418519033713
2062596331391
1691453110380
2975849502487
123320419...

input:

decode
1000
18
1958054467623
18
503667864976
18
1454386602648
18
2003062289894
18
914328652403
18
1203223500289
18
1916654528629
18
2023355211738
18
1883870411588
18
1627071583940
18
2431629053848
18
2600701111190
18
1679139375340
18
2452645796517
18
1436529092530
18
2062142591877
18
561559787260
18...

output:

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

result:

ok 1000 lines

Test #25:

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

input:

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

output:

12160828002213
3123298907641
9037529094573
12775503356531
9518188035240
17397664290920
9103893936483
4839741569370
9969015907238
15152805411945
13455462209726
6432297507727
14125211380154
4162865639050
7007876331829
6091171190849
3714729522000
13250382209505
10028645386443
18363261695738
51546744425...

input:

decode
1000
19
12160828002213
19
3123298907641
19
9037529094573
19
12775503356531
19
9518188035240
19
17397664290920
19
9103893936483
19
4839741569370
19
9969015907238
19
15152805411945
19
13455462209726
19
6432297507727
19
14125211380154
19
4162865639050
19
7007876331829
19
6091171190849
19
3714729...

output:

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

result:

ok 1000 lines

Test #26:

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

input:

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

output:

81144825906637
110564950627872
19967120735675
20509630233141
70060399524437
100397386239216
85233190024055
83686029417083
99037823197997
110523975668845
69497171007278
83448693117360
57700230160985
84826139414560
104742834597329
109012023977412
101542437945753
34458402436321
90204557549998
977742038...

input:

decode
1000
20
81144825906637
20
110564950627872
20
19967120735675
20
20509630233141
20
70060399524437
20
100397386239216
20
85233190024055
20
83686029417083
20
99037823197997
20
110523975668845
20
69497171007278
20
83448693117360
20
57700230160985
20
84826139414560
20
104742834597329
20
10901202397...

output:

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

result:

ok 1000 lines

Test #27:

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

input:

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

output:

261660797971731
291118985689135
442924996113838
597004004212625
552594872106748
257271020862573
180069936052360
343165858962084
607770625410951
541079512603691
501116045192940
515615510294908
508854587666765
524257306348578
228602033851348
399886821900621
497673450380687
711693198428064
318028637967...

input:

decode
1000
21
261660797971731
21
291118985689135
21
442924996113838
21
597004004212625
21
552594872106748
21
257271020862573
21
180069936052360
21
343165858962084
21
607770625410951
21
541079512603691
21
501116045192940
21
515615510294908
21
508854587666765
21
524257306348578
21
228602033851348
21
...

output:

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

result:

ok 1000 lines

Test #28:

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

input:

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

output:

2444210979962509
3720131003406538
1147005702637085
1160919397470791
1725652552609268
3547329529106641
2745665517797036
2277337254712054
3655009230748431
3755289904802235
3481507526942215
3258408612581200
1191771990910236
3394020770298879
1176529997743347
3544525882479220
3668922812412605
30933514320...

input:

decode
1000
22
2444210979962509
22
3720131003406538
22
1147005702637085
22
1160919397470791
22
1725652552609268
22
3547329529106641
22
2745665517797036
22
2277337254712054
22
3655009230748431
22
3755289904802235
22
3481507526942215
22
3258408612581200
22
1191771990910236
22
3394020770298879
22
11765...

output:

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

result:

ok 1000 lines

Test #29:

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

input:

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

output:

8411910617322499
26499726931437478
28025764216746415
5272805935196343
8891028496914611
16892335358178093
5932242127057440
7405292171083170
10708913684574076
23352292007971722
27217738021951533
11175107255912673
8452014797525199
13286687867078356
14986330989868834
16548605952685578
6608974053226535
2...

input:

decode
1000
23
8411910617322499
23
26499726931437478
23
28025764216746415
23
5272805935196343
23
8891028496914611
23
16892335358178093
23
5932242127057440
23
7405292171083170
23
10708913684574076
23
23352292007971722
23
27217738021951533
23
11175107255912673
23
8452014797525199
23
13286687867078356
...

output:

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

result:

ok 1000 lines

Test #30:

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

input:

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

output:

99368832703245882
191618099731842638
93384534450566144
86412657388644016
161116999605294974
59609438305899174
113577326311869784
115915095552992650
42829906343370488
145523757608855637
135691224119320691
66210521375637943
132723609794670562
176876141332275875
58920949940869919
134817580810696768
680...

input:

decode
1000
24
99368832703245882
24
191618099731842638
24
93384534450566144
24
86412657388644016
24
161116999605294974
24
59609438305899174
24
113577326311869784
24
115915095552992650
24
42829906343370488
24
145523757608855637
24
135691224119320691
24
66210521375637943
24
132723609794670562
24
17687...

output:

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

result:

ok 1000 lines

Test #31:

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

input:

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

output:

755093635835383686
192657165369301081
562436470466082606
913621305778951432
217610044797268599
306701858498358656
1201478272806910324
1127601477949629457
445113752558062708
777526573269334589
568305906940213058
740669871695074600
356215200004970153
490091110173426321
883732839008658505
1095238378185...

input:

decode
1000
25
755093635835383686
25
192657165369301081
25
562436470466082606
25
913621305778951432
25
217610044797268599
25
306701858498358656
25
1201478272806910324
25
1127601477949629457
25
445113752558062708
25
777526573269334589
25
568305906940213058
25
740669871695074600
25
356215200004970153
...

output:

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

result:

ok 1000 lines

Test #32:

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

input:

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

output:

1184818730471759610
405894438591535520
2221345052089353
74567602336247957
63115179743879123
20509541137290303
221720139932944
58244929354704
46546075676738
13786428904273122
12184428465288922
97838591162238906
1104003679531355008
372367956395165051
25475989658994753
126145479617882582
4
418417957377...

input:

decode
1000
25
1184818730471759610
25
405894438591535520
22
2221345052089353
24
74567602336247957
24
63115179743879123
23
20509541137290303
21
221720139932944
20
58244929354704
20
46546075676738
23
13786428904273122
23
12184428465288922
24
97838591162238906
25
1104003679531355008
25
3723679563951650...

output:

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

result:

ok 1000 lines