QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#294707#4824. Bracket-and-bar Sequencesucup-team1055#AC ✓41ms8272kbC++2022.5kb2023-12-30 16:01:182023-12-30 16:01:19

Judging History

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

  • [2023-12-30 16:01:19]
  • 评测
  • 测评结果:AC
  • 用时:41ms
  • 内存:8272kb
  • [2023-12-30 16:01:18]
  • 提交

answer

#line 2 "/Users/noya2/Desktop/Noya2_library/template/template.hpp"
using namespace std;

#include<bits/stdc++.h>
#line 1 "/Users/noya2/Desktop/Noya2_library/template/inout_old.hpp"
namespace noya2 {

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
    os << p.first << " " << p.second;
    return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p){
    is >> p.first >> p.second;
    return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
    int s = (int)v.size();
    for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v){
    for (auto &x : v) is >> x;
    return is;
}

void in() {}
template <typename T, class... U>
void in(T &t, U &...u){
    cin >> t;
    in(u...);
}

void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u){
    cout << t;
    if (sizeof...(u)) cout << sep;
    out(u...);
}

template<typename T>
void out(const vector<vector<T>> &vv){
    int s = (int)vv.size();
    for (int i = 0; i < s; i++) out(vv[i]);
}

struct IoSetup {
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(7);
    }
} iosetup_noya2;

} // namespace noya2
#line 1 "/Users/noya2/Desktop/Noya2_library/template/const.hpp"
namespace noya2{

const int iinf = 1'000'000'007;
const long long linf = 2'000'000'000'000'000'000LL;
const long long mod998 =  998244353;
const long long mod107 = 1000000007;
const long double pi = 3.14159265358979323;
const vector<int> dx = {0,1,0,-1,1,1,-1,-1};
const vector<int> dy = {1,0,-1,0,1,-1,-1,1};
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string NUM = "0123456789";

void yes(){ cout << "Yes\n"; }
void no(){ cout << "No\n"; }
void YES(){ cout << "YES\n"; }
void NO(){ cout << "NO\n"; }
void yn(bool t){ t ? yes() : no(); }
void YN(bool t){ t ? YES() : NO(); }

} // namespace noya2
#line 1 "/Users/noya2/Desktop/Noya2_library/template/utils.hpp"
namespace noya2{

unsigned long long inner_binary_gcd(unsigned long long a, unsigned long long b){
    if (a == 0 || b == 0) return a + b;
    int n = __builtin_ctzll(a); a >>= n;
    int m = __builtin_ctzll(b); b >>= m;
    while (a != b) {
        int mm = __builtin_ctzll(a - b);
        bool f = a > b;
        unsigned long long c = f ? a : b;
        b = f ? b : a;
        a = (c - b) >> mm;
    }
    return a << min(n, m);
}

template<typename T> T gcd_fast(T a, T b){ return static_cast<T>(inner_binary_gcd(abs(a),abs(b))); }

long long sqrt_fast(long long n) {
    if (n <= 0) return 0;
    long long x = sqrt(n);
    while ((x + 1) * (x + 1) <= n) x++;
    while (x * x > n) x--;
    return x;
}

template<typename T> T floor_div(const T n, const T d) {
    assert(d != 0);
    return n / d - static_cast<T>((n ^ d) < 0 && n % d != 0);
}

template<typename T> T ceil_div(const T n, const T d) {
    assert(d != 0);
    return n / d + static_cast<T>((n ^ d) >= 0 && n % d != 0);
}

template<typename T> void uniq(vector<T> &v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}

template <typename T, typename U> inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; }

template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; }

template<typename T> inline bool range(T l, T x, T r){ return l <= x && x < r; }

} // namespace noya2
#line 8 "/Users/noya2/Desktop/Noya2_library/template/template.hpp"

#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define repp(i,m,n) for (int i = (m); i < (int)(n); i++)
#define reb(i,n) for (int i = (int)(n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;

namespace noya2{

/* ~ (. _________ . /) */

}

using namespace noya2;


#line 2 "c.cpp"


#line 2 "/Users/noya2/Desktop/Noya2_library/utility/modint.hpp"

#line 2 "/Users/noya2/Desktop/Noya2_library/math/prime.hpp"

#line 4 "/Users/noya2/Desktop/Noya2_library/math/prime.hpp"

namespace noya2 {

constexpr ll safe_mod(ll x, ll m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

constexpr ll pow_mod_constexpr(ll x, ll n, int m) {
    if (m == 1) return 0;
    uint _m = (uint)(m);
    ull r = 1;
    ull y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;
        y = (y * y) % _m;
        n >>= 1;
    }
    return r;
}

constexpr bool is_prime_constexpr(int n) {
    if (n <= 1) return false;
    if (n == 2 || n == 7 || n == 61) return true;
    if (n % 2 == 0) return false;
    ll d = n - 1;
    while (d % 2 == 0) d /= 2;
    constexpr ll bases[3] = {2, 7, 61};
    for (ll a : bases) {
        ll t = d;
        ll y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;
            t <<= 1;
        }
        if (y != n - 1 && t % 2 == 0) {
            return false;
        }
    }
    return true;
}
template <int n> constexpr bool is_prime_flag = is_prime_constexpr(n);

constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};
    long long s = b, t = a;
    long long m0 = 0, m1 = 1;
    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u; 
        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (ll)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x > 1) {
        divs[cnt++] = x;
    }
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;
                break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root_flag = primitive_root_constexpr(m);

} // namespace noya2
#line 4 "/Users/noya2/Desktop/Noya2_library/utility/modint.hpp"

namespace noya2{

struct barrett {
    uint _m;
    ull  im;
    explicit barrett(uint m) : _m(m), im((ull)(-1) / m + 1) {}
    uint umod() const { return _m; }
    uint mul(uint a, uint b) const {
        ull z = a;
        z *= b;
        ull x = ull((__uint128_t(z) * im) >> 64);
        uint v = (uint)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};

template <int m>
struct static_modint {
    using mint = static_modint;
  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }
    constexpr static_modint() : _v(0) {}
    template<signed_integral T>
    constexpr static_modint(T v){
        ll x = (ll)(v % (ll)(umod()));
        if (x < 0) x += umod();
        _v = (uint)(x);
    }
    template<unsigned_integral T>
    constexpr static_modint(T v){
        _v = (uint)(v % umod());
    }
    constexpr unsigned int val() const { return _v; }
    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }
    constexpr mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    constexpr mint& operator-=(const mint& rhs) {
        _v -= rhs._v;
        if (_v >= umod()) _v += umod();
        return *this;
    }
    constexpr mint& operator*=(const mint& rhs) {
        ull z = _v;
        z *= rhs._v;
        _v = (uint)(z % umod());
        return *this;
    }
    constexpr mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    constexpr mint operator+() const { return *this; }
    constexpr mint operator-() const { return mint() - *this; }
    constexpr mint pow(ll n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    constexpr mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }
    friend constexpr mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend constexpr mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend constexpr mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend constexpr mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend constexpr bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend constexpr bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint& p) {
        return os << p.val();
    }
    friend std::istream &operator>>(std::istream &is, mint &a) {
        long long t; is >> t;
        a = mint(t);
        return (is);
    }

  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = is_prime_flag<m>;
};


template <int id> struct dynamic_modint {
    using mint = dynamic_modint;
  public:
    static int mod() { return (int)(bt.umod()); }
    static void set_mod(int m) {
        assert(1 <= m);
        bt = barrett(m);
    }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    dynamic_modint() : _v(0) {}
    template<signed_integral T>
    dynamic_modint(T v){
        ll x = (ll)(v % (ll)(mod()));
        if (x < 0) x += mod();
        _v = (uint)(x);
    }
    template<unsigned_integral T>
    dynamic_modint(T v){
        _v = (uint)(v % mod());
    }
    uint val() const { return _v; }
    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }
    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v += mod() - rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        _v = bt.mul(_v, rhs._v);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        auto eg = noya2::inv_gcd(_v, mod());
        assert(eg.first == 1);
        return eg.second;
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint& p) {
        return os << p.val();
    }
    friend std::istream &operator>>(std::istream &is, mint &a) {
        long long t; is >> t;
        a = mint(t);
        return (is);
    }

  private:
    unsigned int _v;
    static barrett bt;
    static unsigned int umod() { return bt.umod(); }
};
template <int id> noya2::barrett dynamic_modint<id>::bt(998244353);

using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;

template<typename T>
concept Modint = requires (T &a){
    T::mod();
    a.inv();
    a.val();
    a.pow(declval<int>());
};

} // namespace noya2
#line 5 "c.cpp"
using mint1 = static_modint<1100000017>;
using mint2 = static_modint<1100000009>;

/*

f = 1/(1-g)
g = x^3 f^2

f = 1/(1 - x^3 f^2)

f(1 - X f^2) = 1
f - 1 = X f^3
X = (f-1)/f^3

f <- f-1

X = f/(f+1)^3

F = x/(x+1)^3

1/n [x^{n-1}] (x/F)^n

1/n [x^{n-1}] (x+1)^3n

1/n 3nC{n-1}

{1, 3, 12, 55, 273, 1428, 7752, 43263, 246675, 1430715, 8414640, 50067108, 300830572, 1822766520, 11124755664}

{11124755664, 68328754959, 422030545335, 2619631042665, 16332922290300, 102240109897695, 642312451217745, 
4048514844039120, 25594403741131680, 162250238001816900, 1031147983159782228}

*/

// (rem, mod)
std::pair<long long, long long> crt(const std::vector<long long>& r,
                                    const std::vector<long long>& m) {
    assert(r.size() == m.size());
    int n = int(r.size());
    // Contracts: 0 <= r0 < m0
    long long r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++) {
        assert(1 <= m[i]);
        long long r1 = safe_mod(r[i], m[i]), m1 = m[i];
        if (m0 < m1) {
            std::swap(r0, r1);
            std::swap(m0, m1);
        }
        if (m0 % m1 == 0) {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        // assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1)

        // (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1));
        // r2 % m0 = r0
        // r2 % m1 = r1
        // -> (r0 + x*m0) % m1 = r1
        // -> x*u0*g = r1-r0 (mod u1*g) (u0*g = m0, u1*g = m1)
        // -> x = (r1 - r0) / g * inv(u0) (mod u1)

        // im = inv(u0) (mod u1) (0 <= im < u1)
        long long g, im;
        std::tie(g, im) = inv_gcd(m0, m1);

        long long u1 = (m1 / g);
        // |r1 - r0| < (m0 + m1) <= lcm(m0, m1)
        if ((r1 - r0) % g) return {0, 0};

        // u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1)
        long long x = (r1 - r0) / g % u1 * im % u1;

        // |r0| + |m0 * x|
        // < m0 + m0 * (u1 - 1)
        // = m0 + m0 * m1 / g - m0
        // = lcm(m0, m1)
        r0 += x * m0;
        m0 *= u1;  // -> lcm(m0, m1)
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}

#line 2 "/Users/noya2/Desktop/Noya2_library/math/binomial.hpp"

namespace noya2 {

template<typename mint>
struct binomial {
    binomial(int len = 300000){ extend(len); }
    static mint fact(int n){
        if (n < 0) return 0;
        while (n >= (int)_fact.size()) extend();
        return _fact[n];
    }
    static mint ifact(int n){
        if (n < 0) return 0;
        while (n >= (int)_fact.size()) extend();
        return _ifact[n];
    }
    static mint inv(int n){
        return ifact(n) * fact(n-1);
    }
    static mint C(int n, int r){
        if (!(0 <= r && r <= n)) return 0;
        return fact(n) * ifact(r) * ifact(n-r);
    }
    static mint P(int n, int r){
        if (!(0 <= r && r <= n)) return 0;
        return fact(n) * ifact(n-r);
    }
    inline mint operator()(int n, int r) { return C(n, r); }
    template<class... Cnts> static mint M(const Cnts&... cnts){
        return multinomial(0,1,cnts...);
    }
  private:
    static mint multinomial(const int& sum, const mint& div_prod){
        if (sum < 0) return 0;
        return fact(sum) * div_prod;
    }
    template<class... Tail> static mint multinomial(const int& sum, const mint& div_prod, const int& n1, const Tail&... tail){
        if (n1 < 0) return 0;
        return multinomial(sum+n1,div_prod*ifact(n1),tail...);
    }
    static vector<mint> _fact, _ifact;
    static void extend(int len = -1){
        if (_fact.empty()){
            _fact = _ifact = {1,1};
        }
        int siz = _fact.size();
        if (len == -1) len = siz * 2;
        len = min<int>(len, mint::mod()-1);
        if (len < siz) return ;
        _fact.resize(len+1), _ifact.resize(len+1);
        for (int i = siz; i <= len; i++) _fact[i] = _fact[i-1] * i;
        _ifact[len] = _fact[len].inv();
        for (int i = len; i > siz; i--) _ifact[i-1] = _ifact[i] * i;
    }
};
template<typename T>
std::vector<T>binomial<T>::_fact = vector<T>(2,T(1));
template<typename T>
std::vector<T>binomial<T>::_ifact = vector<T>(2,T(1));

} // namespace noya2
#line 88 "c.cpp"

const int mx = 200;

ll val(mint1 v1, mint2 v2){
    return crt({v1.val(),v2.val()},{mint1::mod(),mint2::mod()}).first;
}

template<typename T>
vector<T> conv(const vector<T> &f, const vector<T> &g){
    vector<T> fg(mx,0);
    rep(i,mx) rep(j,mx){
        if (i + j >= mx) break;
        fg[i+j] += f[i]*g[j];
    }
    return fg;
}

vector<vector<mint1>> f1;
vector<vector<mint2>> f2;
void init_f(){
    binomial<mint1> bnm1;
    binomial<mint2> bnm2;
    f1.resize(mx,vector<mint1>(mx,0));
    f2.resize(mx,vector<mint2>(mx,0));
    f1[0][0] = 1;
    f2[0][0] = 1;
    rep(i,mx){
        f1[1][0] = 1;
        f2[1][0] = 1;
        repp(j,1,mx){
            f1[1][j] = bnm1(3*j,j-1) * bnm1.inv(j);
            f2[1][j] = bnm2(3*j,j-1) * bnm2.inv(j);
        }
    }
    repp(i,2,mx){
        f1[i] = conv(f1[i-1],f1[1]);
        f2[i] = conv(f2[i-1],f2[1]);
    }
}

ll calc(int n, const string &s){ //cout << "called" << endl;
    int len = 0;
    stack<char> st;
    for (auto c : s){
        len++;
        if (c == '('){
            st.push(c);
        }
        else if (c == '|'){
            if (st.empty() || st.top() != '('){
                return 0;
            }
            st.pop();
            st.push(c);
        }
        else {
            assert(c == ')');
            if (st.empty() || st.top() != '|'){
                return 0;
            }
            st.pop();
        }
    }
    int add = 0;
    while (!st.empty()){
        if (st.top() == '('){
            st.pop();
            st.push('|');
            add++;
        }
        else {
            assert(st.top() == '|');
            st.pop();
            add++;
        }
    }
    if (len + add > n*3) return 0;
    // [x^{(n*3-len-add)/3}]f^{add+1}
    mint1 v1 = f1[add+1][(n*3-len-add)/3];
    mint2 v2 = f2[add+1][(n*3-len-add)/3];
    //cout << "return" << endl;
    return val(v1,v2);
}

ll encode(int n, string s){
    ll ans = 0;
    string cur = "";
    rep(i,n*3){
        if (s[i] == '('){
            // nothing
        }
        else if (s[i] == '|'){
            cur += '(';
            ans += calc(n,cur);
            cur.pop_back();
        }
        else if (s[i] == ')'){
            cur += '(';
            ans += calc(n,cur);
            cur.pop_back();
            cur += '|';
            ans += calc(n,cur);
            cur.pop_back();
        }
        cur += s[i];
    }
    return ans;
}

string decode(int n, ll cnt){
    string ans = "";
    rep(i,n*3){
        ans += '(';
        ll sum = calc(n,ans);
        if (sum > cnt) continue;
        ans.pop_back();
        ans += '|';
        cnt -= sum;
        sum = calc(n,ans);
        if (sum > cnt) continue;
        cnt -= sum;
        ans.pop_back();
        ans += ')';
    }
    return ans;
}

#line 2 "/Users/noya2/Desktop/Noya2_library/misc/rng.hpp"

#line 4 "/Users/noya2/Desktop/Noya2_library/misc/rng.hpp"

namespace noya2 {

// [0, 2^64 - 1)
ull rng() {
  static ull _x = 88172645463325252UL;
  return _x ^= _x << 7, _x ^= _x >> 9;
}

// [l, r]
ll rng(ll l, ll r) {
  assert(l <= r);
  return l + rng() % ull(r - l + 1);
}

// [l, r)
ll randint(ll l, ll r) {
  assert(l < r);
  return l + rng() % ull(r - l);
}

// [0.0, 1.0)
ld rnd() { return rng() * 5.42101086242752217004e-20; }
// [l, r)
ld rnd(ld l, ld r) {
  assert(l < r);
  return l + rnd() * (r - l);
}

} // namespace noya2
#line 216 "c.cpp"

void jikken(){
    int t; in(t);
    while (t--){
        int n = randint(15,25);
        ll cnt = randint(0,iinf);
        cout << n << ' ' << cnt << endl;
        string s = decode(n,cnt);
        cout << "decode ok" << endl;
        ll ans = encode(n,s);
        cout << "encode ok" << endl;
        if (ans != cnt){
            out(n);
            out(cnt);
            out(s);
            out(ans);
            cout << flush;
        }
        assert(ans == cnt);
        cout << "OK" << endl;
    }
}

void solve(){
    // jikken(); return ;
    string dore; in(dore);
    if (dore == "encode"){
        int t; in(t);
        while (t--){
            int n; in(n);
            string s; in(s);
            out(encode(n,s));
        }
    }
    if (dore == "decode"){
        int t; in(t);
        while (t--){
            int n; in(n);
            ll cnt; in(cnt);
            out(decode(n,cnt));
        }
    }
}



int main(){
    init_f();
    int t = 1; // in(t);
    while (t--) { solve(); }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 7996kb

input:

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

output:

0
0
207

input:

decode
3
1
0
4
0
5
207

output:

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

result:

ok 3 lines

Test #2:

score: 100
Accepted
time: 17ms
memory: 8272kb

input:

encode
1
1
(|)

output:

0

input:

decode
1
1
0

output:

(|)

result:

ok single line: '(|)'

Test #3:

score: 100
Accepted
time: 17ms
memory: 8204kb

input:

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

output:

0
0
1

input:

decode
3
2
0
1
0
2
1

output:

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

result:

ok 3 lines

Test #4:

score: 100
Accepted
time: 20ms
memory: 8240kb

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:

11
10
9
8
7
6
5
4
3
2
1
0
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
35
30
38
37
36
34
33
32
31
29
28
27
26
25
24
23
22
21
20
19
18
17
12
6
16
11
5
15
14
13
10
9
8
7
4
3
2
1
0
272
271
270
269
268
267
266
265
264
263
262
261
260
259
258
257
253
248
256
255
254
252
251
250
249
247
246
245
244
243...

input:

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

output:

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

result:

ok 1000 lines

Test #5:

score: 100
Accepted
time: 16ms
memory: 7992kb

input:

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

output:

708
812
806
799
779
773
766
758
737
731
724
716
707
811
810
809
805
804
803
802
798
797
796
795
794
778
777
776
772
765
757
771
770
769
764
763
762
761
756
755
754
753
752
736
735
734
730
729
728
727
723
715
706
722
714
705
721
720
719
713
712
711
710
704
703
702
701
700
699
698
697
696
695
694
693
...

input:

decode
1000
6
708
6
812
6
806
6
799
6
779
6
773
6
766
6
758
6
737
6
731
6
724
6
716
6
707
6
811
6
810
6
809
6
805
6
804
6
803
6
802
6
798
6
797
6
796
6
795
6
794
6
778
6
777
6
776
6
772
6
765
6
757
6
771
6
770
6
769
6
764
6
763
6
762
6
761
6
756
6
755
6
754
6
753
6
752
6
736
6
735
6
734
6
730
6
729
...

output:

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

result:

ok 1000 lines

Test #6:

score: 100
Accepted
time: 20ms
memory: 8200kb

input:

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

output:

2767
2805
5359
2389
6667
580
2539
42942
3721
6972
4748
3410
43105
2685
5305
4643
5125
968
4910
3148
4762
4509
2715
50
1479
3707
7073
4438
1167
6594
223
5499
1871
6037
4018
2259
163
4767
976
7065
4742
6919
3534
5096
5678
5714
449
4400
6083
4463
182
3650
3303
6080
7404
139
2852
3468
4088
954
806
2106
...

input:

decode
1000
7
2767
7
2805
7
5359
7
2389
7
6667
7
580
7
2539
8
42942
7
3721
7
6972
7
4748
7
3410
8
43105
7
2685
7
5305
7
4643
7
5125
7
968
7
4910
7
3148
7
4762
7
4509
7
2715
7
50
7
1479
7
3707
7
7073
7
4438
7
1167
7
6594
7
223
7
5499
7
1871
7
6037
7
4018
7
2259
7
163
7
4767
7
976
7
7065
7
4742
7
6919...

output:

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

result:

ok 1000 lines

Test #7:

score: 100
Accepted
time: 20ms
memory: 8140kb

input:

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

output:

5941
1186
6145
7077
4729
6675
879
2416
7226
960
7286
3010
42791
43200
3771
4107
5771
892
42946
42603
1944
5081
2563
76
2661
3296
3896
6224
6034
49
3102
4007
7542
1070
2963
1722
5377
3038
7212
4783
7164
1352
4889
5670
119
4033
4507
1134
6417
6280
3215
7232
6152
7531
5730
158
1001
3002
7121
5609
3245
...

input:

decode
1000
7
5941
7
1186
7
6145
7
7077
7
4729
7
6675
7
879
7
2416
7
7226
7
960
7
7286
7
3010
8
42791
8
43200
7
3771
7
4107
7
5771
7
892
8
42946
8
42603
7
1944
7
5081
7
2563
7
76
7
2661
7
3296
7
3896
7
6224
7
6034
7
49
7
3102
7
4007
7
7542
7
1070
7
2963
7
1722
7
5377
7
3038
7
7212
7
4783
7
7164
7
13...

output:

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

result:

ok 1000 lines

Test #8:

score: 100
Accepted
time: 22ms
memory: 8124kb

input:

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

output:

1084
7325
3764
5549
953
2457
4229
2471
43199
5512
140
6148
3824
331
1401
6704
5487
707
2505
765
3965
3823
4695
4585
7068
29
7337
2409
6339
4422
5856
3366
5765
597
3693
42839
3165
2983
991
538
5703
3507
747
5418
77
6868
3609
4095
5380
3515
1454
4620
4601
4359
5704
20
4638
2842
669
3550
6867
1365
4221...

input:

decode
1000
7
1084
7
7325
7
3764
7
5549
7
953
7
2457
7
4229
7
2471
8
43199
7
5512
7
140
7
6148
7
3824
7
331
7
1401
7
6704
7
5487
7
707
7
2505
7
765
7
3965
7
3823
7
4695
7
4585
7
7068
7
29
7
7337
7
2409
7
6339
7
4422
7
5856
7
3366
7
5765
7
597
7
3693
8
42839
7
3165
7
2983
7
991
7
538
7
5703
7
3507
7
...

output:

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

result:

ok 1000 lines

Test #9:

score: 100
Accepted
time: 20ms
memory: 8160kb

input:

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

output:

2084
6102
7229
42929
3894
725
2210
630
6252
776
2009
6714
218
6164
1971
1253
6712
2815
1905
42679
4350
6353
4694
43030
1957
5462
6380
2690
6836
6436
42544
5284
15
6030
43181
1151
6458
4488
6832
2169
880
43060
3145
3029
5694
2102
1132
1849
4058
2598
5091
4935
3119
5331
43220
3250
5701
1414
43059
6845...

input:

decode
1000
7
2084
7
6102
7
7229
8
42929
7
3894
7
725
7
2210
7
630
7
6252
7
776
7
2009
7
6714
7
218
7
6164
7
1971
7
1253
7
6712
7
2815
7
1905
8
42679
7
4350
7
6353
7
4694
8
43030
7
1957
7
5462
7
6380
7
2690
7
6836
7
6436
8
42544
7
5284
7
15
7
6030
8
43181
7
1151
7
6458
7
4488
7
6832
7
2169
7
880
8
4...

output:

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

result:

ok 1000 lines

Test #10:

score: 100
Accepted
time: 18ms
memory: 8128kb

input:

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

output:

250
932
7096
5639
6728
2107
4510
1147
6425
6212
6027
2162
6373
3791
6125
4998
531
4185
4973
3241
43100
3807
2828
4173
43190
5139
3664
2290
2154
2068
6242
181
4661
2614
359
4017
3272
7263
636
4252
6895
7101
5926
585
2581
1644
4457
1302
42970
2093
6693
5621
3851
6729
4328
5535
7102
3282
6177
4548
5685...

input:

decode
1000
7
250
7
932
7
7096
7
5639
7
6728
7
2107
7
4510
7
1147
7
6425
7
6212
7
6027
7
2162
7
6373
7
3791
7
6125
7
4998
7
531
7
4185
7
4973
7
3241
8
43100
7
3807
7
2828
7
4173
8
43190
7
5139
7
3664
7
2290
7
2154
7
2068
7
6242
7
181
7
4661
7
2614
7
359
7
4017
7
3272
7
7263
7
636
7
4252
7
6895
7
710...

output:

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

result:

ok 1000 lines

Test #11:

score: 100
Accepted
time: 22ms
memory: 8200kb

input:

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

output:

4587
4116
6792
6271
5174
2860
6877
4080
772
3605
1097
4055
2037
2660
43083
1523
4965
2510
844
730
2755
2954
286
4066
2579
7489
43050
1534
2589
506
1724
948
2179
3907
2863
3620
7350
1382
5497
5430
4672
5767
5734
4684
6540
4005
3349
6443
4813
6599
2688
4592
6799
1265
6644
1463
7184
43033
2916
2654
162...

input:

decode
1000
7
4587
7
4116
7
6792
7
6271
7
5174
7
2860
7
6877
7
4080
7
772
7
3605
7
1097
7
4055
7
2037
7
2660
8
43083
7
1523
7
4965
7
2510
7
844
7
730
7
2755
7
2954
7
286
7
4066
7
2579
7
7489
8
43050
7
1534
7
2589
7
506
7
1724
7
948
7
2179
7
3907
7
2863
7
3620
7
7350
7
1382
7
5497
7
5430
7
4672
7
576...

output:

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

result:

ok 1000 lines

Test #12:

score: 100
Accepted
time: 22ms
memory: 8140kb

input:

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

output:

5251
5227
4031
4505
6851
2265
717
1907
5844
4709
4712
3251
6449
2613
43104
2180
12
5657
1954
3333
6187
7005
6330
4161
2643
2534
923
724
3266
3368
5153
7393
1459
2723
4591
7308
5860
47
378
5210
6321
3792
2270
1699
5379
3841
723
3386
5544
1254
1048
3482
857
43076
2151
527
6208
710
2283
6569
7455
3888
...

input:

decode
1000
7
5251
7
5227
7
4031
7
4505
7
6851
7
2265
7
717
7
1907
7
5844
7
4709
7
4712
7
3251
7
6449
7
2613
8
43104
7
2180
7
12
7
5657
7
1954
7
3333
7
6187
7
7005
7
6330
7
4161
7
2643
7
2534
7
923
7
724
7
3266
7
3368
7
5153
7
7393
7
1459
7
2723
7
4591
7
7308
7
5860
7
47
7
378
7
5210
7
6321
7
3792
7...

output:

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

result:

ok 1000 lines

Test #13:

score: 100
Accepted
time: 20ms
memory: 8096kb

input:

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

output:

5126
3142
131
43126
11
450
5122
3039
5254
5723
90
6255
2497
2980
5333
345
4625
2802
184
4435
6562
6452
6362
943
6807
3569
2211
7185
4182
1805
2294
1746
6676
5817
4636
6235
2361
4004
42898
6854
4652
5124
6239
2475
7295
1520
6722
22
4656
5788
43135
43007
6986
933
6110
42905
5790
1424
3666
7396
5706
12...

input:

decode
1000
7
5126
7
3142
7
131
8
43126
7
11
7
450
7
5122
7
3039
7
5254
7
5723
7
90
7
6255
7
2497
7
2980
7
5333
7
345
7
4625
7
2802
7
184
7
4435
7
6562
7
6452
7
6362
7
943
7
6807
7
3569
7
2211
7
7185
7
4182
7
1805
7
2294
7
1746
7
6676
7
5817
7
4636
7
6235
7
2361
7
4004
8
42898
7
6854
7
4652
7
5124
7...

output:

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

result:

ok 1000 lines

Test #14:

score: 100
Accepted
time: 23ms
memory: 8104kb

input:

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

output:

29168
41220
37399
37006
25757
6723
14318
15369
21478
34917
1332
7763
23515
40720
25561
21394
41694
7709
30192
14789
11581
38805
32874
4028
31659
39762
37891
16299
454
40793
29789
17047
30047
100
11833
28460
24185
11371
23427
13866
35808
34838
25764
19903
39034
8222
38814
17302
25332
13427
42467
2062...

input:

decode
1000
8
29168
8
41220
8
37399
8
37006
8
25757
8
6723
8
14318
8
15369
8
21478
8
34917
8
1332
8
7763
8
23515
8
40720
8
25561
8
21394
8
41694
8
7709
8
30192
8
14789
8
11581
8
38805
8
32874
8
4028
8
31659
8
39762
8
37891
8
16299
8
454
8
40793
8
29789
8
17047
8
30047
8
100
8
11833
8
28460
8
24185
8...

output:

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

result:

ok 1000 lines

Test #15:

score: 100
Accepted
time: 24ms
memory: 8268kb

input:

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

output:

86026
8515
139351
3560
207321
230824
8598
196556
135563
22066
139232
180687
21133
27246
132515
186909
164185
110237
233215
98936
149011
87033
208046
13485
220934
222558
45981
24739
205174
109116
6744
153490
142847
81288
245543
129904
205203
137822
195766
232374
174717
162874
80796
79119
52739
149913...

input:

decode
1000
9
86026
9
8515
9
139351
9
3560
9
207321
9
230824
9
8598
9
196556
9
135563
9
22066
9
139232
9
180687
9
21133
9
27246
9
132515
9
186909
9
164185
9
110237
9
233215
9
98936
9
149011
9
87033
9
208046
9
13485
9
220934
9
222558
9
45981
9
24739
9
205174
9
109116
9
6744
9
153490
9
142847
9
81288
...

output:

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

result:

ok 1000 lines

Test #16:

score: 100
Accepted
time: 20ms
memory: 8176kb

input:

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

output:

1430714
0
1001833
715127
1291334
1226478
553654
215
230792
1148205
655691
593070
1005558
1213246
901030
930397
930211
1111092
648055
236633
1098395
574432
239621
418834
1406283
150916
173652
654712
121373
23378
540067
1373118
59408
964140
1216342
137798
616269
945286
1027297
1060902
992695
281947
66...

input:

decode
1000
10
1430714
10
0
10
1001833
10
715127
10
1291334
10
1226478
10
553654
10
215
10
230792
10
1148205
10
655691
10
593070
10
1005558
10
1213246
10
901030
10
930397
10
930211
10
1111092
10
648055
10
236633
10
1098395
10
574432
10
239621
10
418834
10
1406283
10
150916
10
173652
10
654712
10
121...

output:

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

result:

ok 1000 lines

Test #17:

score: 100
Accepted
time: 25ms
memory: 8204kb

input:

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

output:

8414639
0
5940067
4214412
4509906
3743504
1749871
3230241
2658600
3792737
6467602
3944307
693965
7103073
2166194
5053715
6682433
7318757
3296250
7029308
6181589
1145474
1330982
6924981
5030430
488438
360465
115587
7882778
3814855
2566383
2080769
6054019
5657522
216855
8097571
3803377
7954832
8260575...

input:

decode
1000
11
8414639
11
0
11
5940067
11
4214412
11
4509906
11
3743504
11
1749871
11
3230241
11
2658600
11
3792737
11
6467602
11
3944307
11
693965
11
7103073
11
2166194
11
5053715
11
6682433
11
7318757
11
3296250
11
7029308
11
6181589
11
1145474
11
1330982
11
6924981
11
5030430
11
488438
11
360465
...

output:

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

result:

ok 1000 lines

Test #18:

score: 100
Accepted
time: 26ms
memory: 8156kb

input:

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

output:

50067107
0
35574762
25366000
4790575
25873295
13895458
30964728
22877411
25488356
4158573
39163880
40129681
45694167
8077843
44547150
49778975
27480969
3515474
34550471
13711498
18141627
35527105
41478873
3696490
18028877
16353161
12858168
3814356
24970768
40336706
11849041
43744608
23992958
4834422...

input:

decode
1000
12
50067107
12
0
12
35574762
12
25366000
12
4790575
12
25873295
12
13895458
12
30964728
12
22877411
12
25488356
12
4158573
12
39163880
12
40129681
12
45694167
12
8077843
12
44547150
12
49778975
12
27480969
12
3515474
12
34550471
12
13711498
12
18141627
12
35527105
12
41478873
12
3696490
...

output:

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

result:

ok 1000 lines

Test #19:

score: 100
Accepted
time: 27ms
memory: 8132kb

input:

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

output:

53626931
187458523
217663898
70282857
251826536
76740378
238880385
280531824
216530870
62436496
6653819
199414821
218322639
259880919
122963067
132317038
253220325
239624811
79252312
148418313
191682470
230280485
62107534
247094306
108812259
245603488
113334282
212257233
37291302
246459635
16555734
...

input:

decode
1000
13
53626931
13
187458523
13
217663898
13
70282857
13
251826536
13
76740378
13
238880385
13
280531824
13
216530870
13
62436496
13
6653819
13
199414821
13
218322639
13
259880919
13
122963067
13
132317038
13
253220325
13
239624811
13
79252312
13
148418313
13
191682470
13
230280485
13
621075...

output:

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

result:

ok 1000 lines

Test #20:

score: 100
Accepted
time: 28ms
memory: 8204kb

input:

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

output:

1822766519
0
1308003241
910294071
1189013019
352244796
1812134744
315366299
234400626
454641456
1164876121
319635117
1349757399
67075710
1150325161
1264171267
1124254036
191454031
1278941079
1125136669
1688948477
861497415
1774808033
691230207
1732870524
1400434537
1220504761
821903686
553662866
114...

input:

decode
1000
14
1822766519
14
0
14
1308003241
14
910294071
14
1189013019
14
352244796
14
1812134744
14
315366299
14
234400626
14
454641456
14
1164876121
14
319635117
14
1349757399
14
67075710
14
1150325161
14
1264171267
14
1124254036
14
191454031
14
1278941079
14
1125136669
14
1688948477
14
861497415...

output:

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

result:

ok 1000 lines

Test #21:

score: 100
Accepted
time: 26ms
memory: 8132kb

input:

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

output:

3988340013
11044472167
5727152081
8653511446
3379282603
10190085426
10150857694
6355225926
4149265500
2580566175
5825217397
1805153284
5905868874
6343072977
2361924640
3720784094
6660797907
3863519998
6718505473
1797998252
5798321903
9663760474
3005191793
3138079541
4990445870
1873095831
2209127602
...

input:

decode
1000
15
3988340013
15
11044472167
15
5727152081
15
8653511446
15
3379282603
15
10190085426
15
10150857694
15
6355225926
15
4149265500
15
2580566175
15
5825217397
15
1805153284
15
5905868874
15
6343072977
15
2361924640
15
3720784094
15
6660797907
15
3863519998
15
6718505473
15
1797998252
15
57...

output:

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

result:

ok 1000 lines

Test #22:

score: 100
Accepted
time: 27ms
memory: 8264kb

input:

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

output:

68328754958
0
49382379192
33657730499
5132844146
56564711165
41750145863
9753219092
33605165631
15233671162
41435475436
51412826410
21062073062
298078344
68186152464
25503912949
18338063599
53425656430
62140328450
56028044162
26879600521
43563014750
19858527618
54090790797
20155113851
60641198991
41...

input:

decode
1000
16
68328754958
16
0
16
49382379192
16
33657730499
16
5132844146
16
56564711165
16
41750145863
16
9753219092
16
33605165631
16
15233671162
16
41435475436
16
51412826410
16
21062073062
16
298078344
16
68186152464
16
25503912949
16
18338063599
16
53425656430
16
62140328450
16
56028044162
16...

output:

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

result:

ok 1000 lines

Test #23:

score: 100
Accepted
time: 27ms
memory: 8128kb

input:

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

output:

7085031833
105611360449
192887213570
30644102135
93266535752
290494472289
25815039573
248554528175
323667033552
291288697890
44714816052
78690920251
291196583435
198648779371
322283759926
399723811944
352225442800
219889242500
334116113027
304686759237
323667082538
49086247862
159245316544
802925430...

input:

decode
1000
17
7085031833
17
105611360449
17
192887213570
17
30644102135
17
93266535752
17
290494472289
17
25815039573
17
248554528175
17
323667033552
17
291288697890
17
44714816052
17
78690920251
17
291196583435
17
198648779371
17
322283759926
17
399723811944
17
352225442800
17
219889242500
17
3341...

output:

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

result:

ok 1000 lines

Test #24:

score: 100
Accepted
time: 32ms
memory: 8196kb

input:

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

output:

2619631042664
0
1903451601372
1242015339803
1058673873501
584373466441
2044775228939
184151003633
1456468015079
1413729558570
2099218863509
2020735446422
1755384196141
2149670997501
1776551588181
1034970352023
181143508113
1711042696219
841098644142
2009271904409
2315779745035
1214492171032
19341238...

input:

decode
1000
18
2619631042664
18
0
18
1903451601372
18
1242015339803
18
1058673873501
18
584373466441
18
2044775228939
18
184151003633
18
1456468015079
18
1413729558570
18
2099218863509
18
2020735446422
18
1755384196141
18
2149670997501
18
1776551588181
18
1034970352023
18
181143508113
18
17110426962...

output:

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

result:

ok 1000 lines

Test #25:

score: 100
Accepted
time: 29ms
memory: 8248kb

input:

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

output:

16332922290299
0
11894060137054
7773311196834
8990321826133
11032458717571
11787652730268
1138791010588
9871155979679
10457745130071
6332508432036
5534519430265
14872388159831
4298158292538
372763879259
2344944937781
1585041779414
14982891085981
9153914256963
14224376823210
3146323946488
78642678277...

input:

decode
1000
19
16332922290299
19
0
19
11894060137054
19
7773311196834
19
8990321826133
19
11032458717571
19
11787652730268
19
1138791010588
19
9871155979679
19
10457745130071
19
6332508432036
19
5534519430265
19
14872388159831
19
4298158292538
19
372763879259
19
2344944937781
19
1585041779414
19
149...

output:

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

result:

ok 1000 lines

Test #26:

score: 100
Accepted
time: 31ms
memory: 8072kb

input:

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

output:

78176670308879
52443623071174
2595785509238
10870888327695
40958486957410
51904523860441
75844195367659
1482165854133
12343111632632
52255622391212
11648251860982
25844126769363
75240252453525
60961939846530
83878324948605
69397056964183
98886531593608
44677948905714
83480291002136
37668019357545
10...

input:

decode
1000
20
78176670308879
20
52443623071174
20
2595785509238
20
10870888327695
20
40958486957410
20
51904523860441
20
75844195367659
20
1482165854133
20
12343111632632
20
52255622391212
20
11648251860982
20
25844126769363
20
75240252453525
20
60961939846530
20
83878324948605
20
69397056964183
20...

output:

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

result:

ok 1000 lines

Test #27:

score: 100
Accepted
time: 36ms
memory: 8120kb

input:

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

output:

64783573423364
289588588756515
208768022229155
415875186690146
586522612655225
38377040511392
244091633545555
397732492933726
146860214358354
564858639663205
408873935244792
558669159679400
344659184676859
100617712588577
124551622226664
427101915541648
630255283135699
626206869407313
36560260728530...

input:

decode
1000
21
64783573423364
21
289588588756515
21
208768022229155
21
415875186690146
21
586522612655225
21
38377040511392
21
244091633545555
21
397732492933726
21
146860214358354
21
564858639663205
21
408873935244792
21
558669159679400
21
344659184676859
21
100617712588577
21
124551622226664
21
42...

output:

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

result:

ok 1000 lines

Test #28:

score: 100
Accepted
time: 34ms
memory: 8204kb

input:

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

output:

2691764364151599
1339734237384440
1226277258391286
1706169198226549
619614399678813
1309252305099402
639831781849814
2992123222168517
571986581967739
3124244931137264
631588188787865
3728697603062125
1176958612626771
3267443288065676
1226597060786976
1231396311596756
3508925849758980
297560511427946...

input:

decode
1000
22
2691764364151599
22
1339734237384440
22
1226277258391286
22
1706169198226549
22
619614399678813
22
1309252305099402
22
639831781849814
22
2992123222168517
22
571986581967739
22
3124244931137264
22
631588188787865
22
3728697603062125
22
1176958612626771
22
3267443288065676
22
122659706...

output:

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

result:

ok 1000 lines

Test #29:

score: 100
Accepted
time: 38ms
memory: 8208kb

input:

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

output:

10630538792047512
20212866465027295
20955927662322287
2698159523668406
1833432678008545
7395260010233421
4704105548371558
7379755491898460
1820332778552317
11051710396773862
11893885837794979
4190315643048270
5533248592416611
16613792329771153
16812383067091321
20434209097937834
8736569156081587
109...

input:

decode
1000
23
10630538792047512
23
20212866465027295
23
20955927662322287
23
2698159523668406
23
1833432678008545
23
7395260010233421
23
4704105548371558
23
7379755491898460
23
1820332778552317
23
11051710396773862
23
11893885837794979
23
4190315643048270
23
5533248592416611
23
16613792329771153
23...

output:

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

result:

ok 1000 lines

Test #30:

score: 100
Accepted
time: 31ms
memory: 8208kb

input:

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

output:

91181433699101186
157012261507079231
111793635919452313
102716790227361227
25424313490873259
71283900059309032
105210110089454457
113587515146313287
27122749131024178
102437747336111583
23912104370522122
56111953137597506
36331847882642981
86672630066076105
28150241690042335
98767143027438421
469124...

input:

decode
1000
24
91181433699101186
24
157012261507079231
24
111793635919452313
24
102716790227361227
24
25424313490873259
24
71283900059309032
24
105210110089454457
24
113587515146313287
24
27122749131024178
24
102437747336111583
24
23912104370522122
24
56111953137597506
24
36331847882642981
24
866726...

output:

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

result:

ok 1000 lines

Test #31:

score: 100
Accepted
time: 41ms
memory: 8244kb

input:

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

output:

1031147983159782227
0
757943959758769327
484298145910396275
173420909508003563
363972400169796461
964560541701013778
847394004052494478
75772233627392117
922747598342092285
712937363790487769
825292947614670480
107791392673206102
515990919034874235
355157687699412605
478702292574195293
2994840127390...

input:

decode
1000
25
1031147983159782227
25
0
25
757943959758769327
25
484298145910396275
25
173420909508003563
25
363972400169796461
25
964560541701013778
25
847394004052494478
25
75772233627392117
25
922747598342092285
25
712937363790487769
25
825292947614670480
25
107791392673206102
25
5159909190348742...

output:

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

result:

ok 1000 lines

Test #32:

score: 100
Accepted
time: 37ms
memory: 7992kb

input:

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

output:

888966543391789355
443599023590113681
2953038136549413
60762631220716602
62076443535058215
21568267217445236
270680990364538
62511025415314
44483622319720
17522918942417705
12686348072394060
100256162076160343
842118366109734493
23085576100733040
12527590447926195
121271559013694640
2
29990063811661...

input:

decode
1000
25
888966543391789355
25
443599023590113681
22
2953038136549413
24
60762631220716602
24
62076443535058215
23
21568267217445236
21
270680990364538
20
62511025415314
20
44483622319720
23
17522918942417705
23
12686348072394060
24
100256162076160343
25
842118366109734493
25
23085576100733040...

output:

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

result:

ok 1000 lines