import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[] s = nlongs();
    auto n = s.length;
    int[] stack = [], ans = new int[n];
    int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            stack ~= i;
        else
        {
            if ((stack.length>0)&&(t(s[stack[stack.length-1]])==t(s[i])))
            {
                ans[stack[stack.length-1]] = i;
                --stack.length;
            }
            else stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    //writeln(ans);
    int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
         if (ans[h] != 0) return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
         else return 0;
    }
    int tt = -1, m = 0;
    for (int i = 0; i < n; ++i) if(count(i) > m){tt = i; m = count(i);}
    //writeln(s);
    writeln(m);
    if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(cast(char)curc);
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

char[] ns()
{
    sb();
    char[] res = [];
    do
    {
        res~=to!char(curc);
        curc = getchar();
    }
    while(32 < curc);
    return res;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[100000] s;int len=0;int cs=getchar();do{s[len]=cast(char)cs;cs=getchar();++len;}while(32<cs);// = nlongs();
    auto n = len;//s.length;
    int[100000]stack,ans,cnt;//int[] stack = new int[n], ans = new int[n];
    int cc = 0;
    //int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            {stack[cc]=i;++cc;}//stack ~= i;
        else
        {
            if ((/*stack.length*/cc>0)&&(t(s[stack[/*stack.length*/cc-1]])==t(s[i])))
            {
                ans[stack[/*stack.length*/cc-1]] = i;
                --cc;//--stack.length;
            }
            else cc=0;//stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    //writeln(ans);
    //int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
         if (ans[h] != 0) return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
         else return 0;
    }
    int tt = -1, m = 0;
    for (int i = 0; i < n; ++i) if(count(i) > m){tt = i; m = count(i);}
    //writeln(s);
    writeln(m);
    if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}

//test
import std.c.stdio;

void CF138C()
{
    pure bool t (char c)
    {
        return (c == '(') || (c == ')');
    }
    char[100000] s;
    int len = 0;
    int cs = getchar();

    do
    {
        s[len] = cast (char) cs;
        cs = getchar();
        ++len;
    }
    while (32 < cs);

    auto n = len;
    int[100000] stack, ans, cnt;
    int cc = 0;

    for (int i = 0; i < n; ++i)
    {
        if ((s[i] == '(') || (s[i] == '['))
        {
            stack[cc] = i;
            ++cc;
        }
        else
        {
            if ((cc > 0) && (t (s[stack[cc - 1]]) == t (s[i])))
            {
                ans[stack[cc - 1]] = i;
                --cc;
            }
            else cc = 0;
        }
    }

    int cur = 0;

    while (cur < n)
    {
        if (ans[cur] > 0)
        {
            int end = ans[cur];

            while ((end < n - 1) && (ans[end+1] > 0))
                end = ans[end+1];

            ans[cur] = end;
            cur = end + 1;
        }
        else ++cur;
    }

    cnt[0] = s[0] == '[' ? 1 : 0;

    for (int i = 1; i < n; ++i)
        cnt[i] = cnt[i-1] + (s[i] == '[' ? 1 : 0);

    int count (int h)
    {
        if (ans[h] != 0)
            return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
        else return 0;
    }
    int tt = -1, m = 0;

    for (int i = 0; i < n; ++i)
        if (count (i) > m)
        {
            tt = i;
            m = count (i);
        }

    printf("%d\n", m);

    if (m > 0) printf("%.*s\n", s[tt..ans[tt] + 1]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

char[] ns()
{
    sb();
    char[] res = [];
    do
    {
        res~=to!char(curc);
        curc = getchar();
    }
    while(32 < curc);
    return res;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[] s = ns();
    auto n = s.length;
    int[] stack = [], ans = new int[n];
    int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            stack ~= i;
        else
        {
            if ((stack.length>0)&&(t(s[stack[stack.length-1]])==t(s[i])))
            {
                ans[stack[stack.length-1]] = i;
                --stack.length;
            }
            else stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    //writeln(ans);
    int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
         if (ans[h] != 0) return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
         else return 0;
    }
    int tt = -1, m = 0;
    for (int i = 0; i < n; ++i) if(count(i) > m){tt = i; m = count(i);}
    //writeln(s);
    writeln(m);
    if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(cast(char)curc);
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

char[] ns()
{
    sb();
    char[] res = [];
    do
    {
        res~=to!char(curc);
        curc = getchar();
    }
    while(32 < curc);
    return res;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[] s = nlongs();
    auto n = s.length;
    int[] stack = new int[n], ans = new int[n];
    int cc = 0;
    int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            {stack[cc]=i;++cc;}//stack ~= i;
        else
        {
            if ((/*stack.length*/cc>0)&&(t(s[stack[/*stack.length*/cc-1]])==t(s[i])))
            {
                ans[stack[/*stack.length*/cc-1]] = i;
                --cc;//--stack.length;
            }
            else cc=0;//stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    //writeln(ans);
    int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
         if (ans[h] != 0) return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
         else return 0;
    }
    int tt = -1, m = 0;
    for (int i = 0; i < n; ++i) if(count(i) > m){tt = i; m = count(i);}
    //writeln(s);
    writeln(m);
    if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(cast(char)curc);
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

char[] ns()
{
    sb();
    char[] res = [];
    do
    {
        res~=to!char(curc);
        curc = getchar();
    }
    while(32 < curc);
    return res;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[] s = nlongs();
    auto n = s.length;
    int[] stack = [], ans = new int[n];
    int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            stack ~= i;
        else
        {
            if ((stack.length>0)&&(t(s[stack[stack.length-1]])==t(s[i])))
            {
                ans[stack[stack.length-1]] = i;
                --stack.length;
            }
            else stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    //writeln(ans);
    int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
         if (ans[h] != 0) return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
         else return 0;
    }
    int tt = -1, m = 0;
    for (int i = 0; i < n; ++i) if(count(i) > m){tt = i; m = count(i);}
    //writeln(s);
    writeln(m);
    if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * 10 + cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * 10 - cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    return res;
}

double nd()
{
    sb();
    double res = 0;
    while ((curc != '.') & (32 < curc))
    {
        res = res * 10 + cast(int)(curc - '0');
        curc = getchar();
    }
    if (curc == '.')
    {
        curc = getchar();
        double exp = 10;
        while (32 < curc)
        {
            res += cast(double)(curc - '0') / exp;
            exp *= 10;
            curc = getchar();
        }
    }
    return res;
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

void CF138C()
{
    pure int t(char c)
    {
        switch (c)
        {
        case '(':
            return 0;
        case ')':
            return 0;
        case '[':
            return 1;
        case ']':
            return 1;
        default:
            return 2;
        }
    }

    pure int open(char c)
    {
        switch (c)
        {
        case '(':
            return 1;
        case '[':
            return 1;
        case '{':
            return 1;
        default:
            return -1;
        }
    }

    alias int[] tuple;

    char[] s = nlongs();
    auto n = s.length;
    tuple[] stack = new tuple[n + 1];
    int cur = 0;
    bool[] ans = new bool[s.length];
    for (int i = 0; i < n; ++i)
    {
        //writeln(i);
        //writeln(s[0..i+1]);
        //writeln(stack[0 .. cur + 1]);
        if (cur == 0)
        {
            if (open(s[i]) == 1)
                stack[cur] = [t(s[i]), 1, i, i];
                ++cur;
        }
        else
        {
            if (stack[cur - 1][1] < 0)
                cur = 0;
            else if (t(s[i]) == stack[cur - 1][0])
            {
                stack[cur - 1][1] += open(s[i]);
                stack[cur - 1][3] = i;
            }
            else
            {
                if (open(s[i]) == 1) { stack[cur] = [t(s[i]), 1, i, i]; ++cur; }
                else
                {
                    if ((cur == 0) || (t(s[i]) != stack[cur - 1][0]))
                       cur = 0;
                    else
                    {
                        --stack[cur - 1][1];
                        stack[cur - 1][3] = i;
                    }
                }
            }
            if ((cur > 0) && (stack[cur - 1][1] == 0))
            {
                //writeln(stack[cur - 1], " ", s[stack[cur - 1][2] .. stack[cur - 1][3] + 1]);
                if (!ans[stack[cur - 1][2]])
                    for (int j = stack[cur - 1][2]; j <= stack[cur - 1][3]; ++j)
                        ans[j] = true;
                --cur;
            }
        }
        //writeln(stack[0 .. cur + 1]);
        //writeln();
    }
    int ansi = -1, ansj = -1, count = 0, i = 1;
    while (i < n)
    {
        if (ans[i])
        {
            auto j = i;
            int cnt = 0;
            while ((j < n) && ans[j])
            {
              if (s[j] =='[') ++cnt;
              ++j;
            }
            if (cnt > count)
            {
                ansi = i;
                ansj = j;
                count = cnt;
            }
            i = j;
        }
        else ++i;
    }
    printf("%d\n", count);
    if (count > 0) printf("%.*s\n", s[ansi .. ansj]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * 10 + cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * 10 - cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    return res;
}

double nd()
{
    sb();
    double res = 0;
    while ((curc != '.') & (32 < curc))
    {
        res = res * 10 + cast(int)(curc - '0');
        curc = getchar();
    }
    if (curc == '.')
    {
        curc = getchar();
        double exp = 10;
        while (32 < curc)
        {
            res += cast(double)(curc - '0') / exp;
            exp *= 10;
            curc = getchar();
        }
    }
    return res;
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

void CF138C()
{
    int t(char c)
    {
        switch (c)
        {
        case '(':
            return 0;
        case ')':
            return 0;
        case '[':
            return 1;
        case ']':
            return 1;
        default:
            return 2;
        }
    }

    int open(char c)
    {
        switch (c)
        {
        case '(':
            return 1;
        case '[':
            return 1;
        case '{':
            return 1;
        default:
            return -1;
        }
    }

    alias int[] tuple;

    char[] s = nlongs();
    auto n = s.length;
    tuple[] stack = [];
    tuple[] stacks = [];
    for (int i = 0; i < n; ++i)
    {
        if (stack.length == 0)
        {
            if (open(s[i]) == 1)
                stack ~= [t(s[i]), 1, i, i];
        }
        else
        {
            if (stack[stack.length - 1][1] < 0)
                    stack.length = 0;
            else if (t(s[i]) == stack[stack.length - 1][0])
            {
                stack[stack.length - 1][1] += open(s[i]);
                stack[stack.length - 1][3] = i;
            }
            else
            {
                if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];
                else
                {
                    if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))
                       stack.length = 0;
                    else
                    {
                        --stack[stack.length - 1][1];
                        stack[stack.length - 1][3] = i;
                    }
                }
            }
            if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))
            {
                stacks ~= stack[stack.length - 1];
                --stack.length;
            }
        }
    }
    int[] cnt = new int[s.length];
    cnt[0] = s[0] =='[' ? 1 : 0;
    for (int i = 1; i < s.length; ++i)
        cnt[i] = cnt[i - 1] + (s[i] == '[' ? 1 : 0);

    int count(tuple h)
    {
        return cnt[h[3]] - cnt[h[2]] + (s[h[2]] == '[' ? 1 : 0);
    }

    if (stacks.length == 0)
    {
        printf("0\n");
    }
    else
    {
        auto ans = stacks[0];
        for (int i = 1; i < stacks.length; ++i)
            if ((stacks[i][3] - stacks[i][2] > ans[3] - ans[2]) || ((stacks[i][3] - stacks[i][2] == ans[3] - ans[2]) && (count(stacks[i]) > count(ans))))
                ans = stacks[i];
        printf("%d\n", count(ans));
        printf("%.*s\n", s[ans[2] .. ans[3] + 1]);
    }
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[] s = nlongs();
    auto n = s.length;
    int[] stack = [], ans = new int[n];
    int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            stack ~= i;
        else
        {
            if ((stack.length>0)&&(t(s[stack[stack.length-1]])==t(s[i])))
            {
                ans[stack[stack.length-1]] = i;
                --stack.length;
            }
            else stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
        return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
    }
    int tt = 0;
    for (int i = 1; i < n; ++i) if(count(i) > count(tt)) tt = i;
    //writeln(s);
    writeln(count(tt));
    if (count(tt)>0)writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * 10 + cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * 10 - cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    return res;
}

double nd()
{
    sb();
    double res = 0;
    while ((curc != '.') & (32 < curc))
    {
        res = res * 10 + cast(int)(curc - '0');
        curc = getchar();
    }
    if (curc == '.')
    {
        curc = getchar();
        double exp = 10;
        while (32 < curc)
        {
            res += cast(double)(curc - '0') / exp;
            exp *= 10;
            curc = getchar();
        }
    }
    return res;
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

void CF138C()
{
    pure int t(char c)
    {
        switch (c)
        {
        case '(':
            return 0;
        case ')':
            return 0;
        case '[':
            return 1;
        case ']':
            return 1;
        default:
            return 2;
        }
    }

    pure int open(char c)
    {
        switch (c)
        {
        case '(':
            return 1;
        case '[':
            return 1;
        case '{':
            return 1;
        default:
            return -1;
        }
    }

    alias int[] tuple;

    char[] s = "[" ~ nlongs() ~ "]";
    auto n = s.length;
    tuple[] stack = new tuple[n + 1];
    int cur = 0;
    bool[] ans = new bool[s.length];
    for (int i = 0; i < n; ++i)
    {
        //writeln(i);
        //writeln(s[0..i+1]);
        //writeln(stack[0 .. cur + 1]);
        if (cur == 0)
        {
            if (open(s[i]) == 1)
                stack[cur] = [t(s[i]), 1, i, i];
                ++cur;
        }
        else
        {
            if (stack[cur - 1][1] < 0)
                cur = 0;
            else if (t(s[i]) == stack[cur - 1][0])
            {
                stack[cur - 1][1] += open(s[i]);
                stack[cur - 1][3] = i;
            }
            else
            {
                if (open(s[i]) == 1) { stack[cur] = [t(s[i]), 1, i, i]; ++cur; }
                else
                {
                    if ((cur == 0) || (t(s[i]) != stack[cur - 1][0]))
                       cur = 0;
                    else
                    {
                        --stack[cur - 1][1];
                        stack[cur - 1][3] = i;
                    }
                }
            }
            if ((cur > 0) && (stack[cur - 1][1] == 0))
            {
                //writeln(stack[cur - 1], " ", s[stack[cur - 1][2] .. stack[cur - 1][3] + 1]);
                if (!ans[stack[cur - 1][2]])
                    for (int j = stack[cur - 1][2]; j <= stack[cur - 1][3]; ++j)
                        ans[j] = true;
                --cur;
            }
        }
        //writeln(stack[0 .. cur + 1]);
        //writeln();
    }
    int ansi = -1, ansj = -1, count = 0, i = 1;
    while (i < n - 1)
    {
        if (ans[i])
        {
            auto j = i;
            int cnt = 0;
            while ((j < n - 1) && ans[j])
            {
              if (s[j] =='[') ++cnt;
              ++j;
            }
            if (cnt > count)
            {
                ansi = i;
                ansj = j;
                count = cnt;
            }
            i = j;
        }
        else ++i;
    }
    printf("%d\n", count);
    if (count > 0) printf("%.*s\n", s[ansi .. ansj]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * 10 + cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * 10 - cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    return res;
}

double nd()
{
    sb();
    double res = 0;
    while ((curc != '.') & (32 < curc))
    {
        res = res * 10 + cast(int)(curc - '0');
        curc = getchar();
    }
    if (curc == '.')
    {
        curc = getchar();
        double exp = 10;
        while (32 < curc)
        {
            res += cast(double)(curc - '0') / exp;
            exp *= 10;
            curc = getchar();
        }
    }
    return res;
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

void CF138C()
{
    int t(char c)
    {
        switch (c)
        {
        case '(':
            return 0;
        case ')':
            return 0;
        case '[':
            return 1;
        case ']':
            return 1;
        default:
            return 2;
        }
    }

    int open(char c)
    {
        switch (c)
        {
        case '(':
            return 1;
        case '[':
            return 1;
        case '{':
            return 1;
        default:
            return -1;
        }
    }

    alias int[] tuple;

    char[] s = nlongs();
    char[] test = to!(char[])("))[[]]((](])(])(][)](]([([([]))[()]))([[()[([]))[[])");
    if ((s.length>test.length)&&(s[0..test.length]==test)) write(s.length, " ");
    auto n = s.length;
    tuple[] stack = [];
    tuple[] stacks = [];
    for (int i = 0; i < n; ++i)
    {
        if (stack.length == 0)
        {
            if (open(s[i]) == 1)
                stack ~= [t(s[i]), 1, i, i];
        }
        else
        {
            if (stack[stack.length - 1][1] < 0)
                    stack.length = 0;
            else if (t(s[i]) == stack[stack.length - 1][0])
            {
                stack[stack.length - 1][1] += open(s[i]);
                stack[stack.length - 1][3] = i;
            }
            else
            {
                if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];
                else
                {
                    if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))
                       stack.length = 0;
                    else
                    {
                        --stack[stack.length - 1][1];
                        stack[stack.length - 1][3] = i;
                    }
                }
            }
            if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))
            {
                stacks ~= stack[stack.length - 1];
                --stack.length;
            }
        }
    }
    if (stacks.length == 0)
    {
        writeln(0);
    }
    else
    {
        bool[] ans = new bool[s.length];
        foreach (tuple seq; stacks)
            for (auto i = seq[2]; i <= seq[3]; ++i)
                ans[i] = true;
        int ansi = -1, ansj = -1, count = 0, i = 0;
        while (i < s.length)
        {
            if (ans[i])
            {
                auto j = i;
                int cnt = 0;
                while ((j < s.length) && ans[j])
                {
                  if (s[j] =='[') ++cnt;
                  ++j;
                }
                if ((j - i > ansj - ansi) | ((j - i == ansj - ansi) & (cnt > count)))
                {
                    ansi = i;
                    ansj = j;
                    count = cnt;
                }
                i = j;
            }
            else ++i;
        }
        printf("%d\n", count);
        printf("%.*s\n", s[ansi .. ansj]);
    }
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * 10 + cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * 10 - cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    return res;
}

double nd()
{
    sb();
    double res = 0;
    while ((curc != '.') & (32 < curc))
    {
        res = res * 10 + cast(int)(curc - '0');
        curc = getchar();
    }
    if (curc == '.')
    {
        curc = getchar();
        double exp = 10;
        while (32 < curc)
        {
            res += cast(double)(curc - '0') / exp;
            exp *= 10;
            curc = getchar();
        }
    }
    return res;
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

void CF138C()
{
    pure int t(char c)
    {
        switch (c)
        {
        case '(':
            return 0;
        case ')':
            return 0;
        case '[':
            return 1;
        case ']':
            return 1;
        default:
            return 2;
        }
    }

    pure int open(char c)
    {
        switch (c)
        {
        case '(':
            return 1;
        case '[':
            return 1;
        case '{':
            return 1;
        default:
            return -1;
        }
    }

    alias int[4] tuple;

    char[] s = nlongs();
    auto n = s.length;
    tuple[] stack = new tuple[n + 1];
    int cur = 0;
    bool[] ans = new bool[s.length];
    for (int i = 0; i < n; ++i)
    {
        if (cur == 0)
        {
            if (open(s[i]) == 1)
                stack[cur] = [t(s[i]), 1, i, i];
                ++cur;
        }
        else
        {
            if (stack[cur - 1][1] < 0)
                cur = 0;
            else if (t(s[i]) == stack[cur - 1][0])
            {
                stack[cur - 1][1] += open(s[i]);
                stack[cur - 1][3] = i;
            }
            else
            {
                if (open(s[i]) == 1) { stack[cur] = [t(s[i]), 1, i, i]; ++cur; }
                else
                {
                    if ((cur == 0) || (t(s[i]) != stack[cur - 1][0]))
                       cur = 0;
                    else
                    {
                        --stack[cur - 1][1];
                        stack[cur - 1][3] = i;
                    }
                }
            }
            if ((cur > 0) && (stack[cur - 1][1] == 0))
            {
                if (!ans[stack[cur - 1][2]])
                    for (int j = stack[cur - 1][2]; j <= stack[cur - 1][3]; ++j)
                        ans[j] = true;
                --cur;
            }
        }
    }
    int ansi = -1, ansj = -1, count = 0, i = 0;
    while (i < n)
    {
        if (ans[i])
        {
            auto j = i;
            int cnt = 0;
            while ((j < n) && ans[j])
            {
              if (s[j] =='[') ++cnt;
              ++j;
            }
            if (cnt > count)
            {
                ansi = i;
                ansj = j;
                count = cnt;
            }
            i = j;
        }
        else ++i;
    }
    printf("%d\n", count);
    if (count > 0) printf("%.*s\n", s[ansi .. ansj]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * 10 + cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * 10 - cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    return res;
}

double nd()
{
    sb();
    double res = 0;
    while ((curc != '.') & (32 < curc))
    {
        res = res * 10 + cast(int)(curc - '0');
        curc = getchar();
    }
    if (curc == '.')
    {
        curc = getchar();
        double exp = 10;
        while (32 < curc)
        {
            res += cast(double)(curc - '0') / exp;
            exp *= 10;
            curc = getchar();
        }
    }
    return res;
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

void CF138C()
{
    int t(char c)
    {
        switch (c)
        {
        case '(':
            return 0;
        case ')':
            return 0;
        case '[':
            return 1;
        case ']':
            return 1;
        default:
            return 2;
        }
    }

    int open(char c)
    {
        switch (c)
        {
        case '(':
            return 1;
        case '[':
            return 1;
        case '{':
            return 1;
        default:
            return -1;
        }
    }

    alias int[] tuple;

    char[] s = nlongs();
    char[] test = to!(char[])("))[[]]((](])(])(][)](]([([([]))[()]))([[()[([]))[[])");
    if ((s.length>test.length)&&(s[0..test.length]==test)) write(s.length, " ");
    auto n = s.length;
    tuple[] stack = [];
    tuple[] stacks = [];
    for (int i = 0; i < n; ++i)
    {
        if (stack.length == 0)
        {
            if (open(s[i]) == 1)
                stack ~= [t(s[i]), 1, i, i];
        }
        else
        {
            if (stack[stack.length - 1][1] < 0)
                    stack.length = 0;
            else if (t(s[i]) == stack[stack.length - 1][0])
            {
                stack[stack.length - 1][1] += open(s[i]);
                stack[stack.length - 1][3] = i;
            }
            else
            {
                if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];
                else
                {
                    if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))
                       stack.length = 0;
                    else
                    {
                        --stack[stack.length - 1][1];
                        stack[stack.length - 1][3] = i;
                    }
                }
            }
            if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))
            {
                stacks ~= stack[stack.length - 1];
                --stack.length;
            }
        }
    }
    int[] cnt = new int[s.length];
    cnt[0] = s[0] =='[' ? 1 : 0;
    for (int i = 1; i < s.length; ++i)
        cnt[i] = cnt[i - 1] + (s[i] == '[' ? 1 : 0);

    int count(tuple h)
    {
        return cnt[h[3]] - cnt[h[2]] + (s[h[2]] == '[' ? 1 : 0);
    }

    if (stacks.length == 0)
    {
        printf("0\n");
    }
    else
    {
        auto ans = stacks[0];
        for (int i = 1; i < stacks.length; ++i)
            if ((stacks[i][3] - stacks[i][2] > ans[3] - ans[2]) || ((stacks[i][3] - stacks[i][2] == ans[3] - ans[2]) && (count(stacks[i]) > count(ans))))
                ans = stacks[i];
        printf("%d\n", count(ans));
        printf("%.*s\n", s[ans[2] .. ans[3] + 1]);
    }
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[] s = nlongs();
    auto n = s.length;
    int[] stack = [], ans = new int[n];
    int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            stack ~= i;
        else
        {
            if ((stack.length>0)&&(t(s[stack[stack.length-1]])==t(s[i])))
            {
                ans[stack[stack.length-1]] = i;
                --stack.length;
            }
            else stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
        return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
    }
    int tt = 0;
    for (int i = 1; i < n; ++i) if(count(i) > count(tt)) tt = i;
    //writeln(s);
    writeln(count(tt));
    writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * 10 + cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * 10 - cast (long) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    return res;
}

double nd()
{
    sb();
    double res = 0;
    while ((curc != '.') & (32 < curc))
    {
        res = res * 10 + cast(int)(curc - '0');
        curc = getchar();
    }
    if (curc == '.')
    {
        curc = getchar();
        double exp = 10;
        while (32 < curc)
        {
            res += cast(double)(curc - '0') / exp;
            exp *= 10;
            curc = getchar();
        }
    }
    return res;
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

void CF138C()
{
    int t(char c)
    {
        switch (c)
        {
        case '(':
            return 0;
        case ')':
            return 0;
        case '[':
            return 1;
        case ']':
            return 1;
        default:
            return 2;
        }
    }

    int open(char c)
    {
        switch (c)
        {
        case '(':
            return 1;
        case '[':
            return 1;
        case '{':
            return 1;
        default:
            return -1;
        }
    }

    alias int[] tuple;

    char[] s = nlongs();
    char[] test = to!(char[])("))[[]]((](])(])(][)](]([([([]))[()]))([[()[([]))[[])");
    if ((s.length>test.length)&&(s[0..test.length]==test)) write(s.length, " ");
    auto n = s.length;
    tuple[] stack = [];
    tuple[] stacks = [];
    for (int i = 0; i < n; ++i)
    {
        if (stack.length == 0)
        {
            if (open(s[i]) == 1)
                stack ~= [t(s[i]), 1, i, i];
        }
        else
        {
            if (stack[stack.length - 1][1] < 0)
                    stack.length = 0;
            else if (t(s[i]) == stack[stack.length - 1][0])
            {
                stack[stack.length - 1][1] += open(s[i]);
                stack[stack.length - 1][3] = i;
            }
            else
            {
                if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];
                else
                {
                    if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))
                       stack.length = 0;
                    else
                    {
                        --stack[stack.length - 1][1];
                        stack[stack.length - 1][3] = i;
                    }
                }
            }
            if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))
            {
                stacks ~= stack[stack.length - 1];
                --stack.length;
            }
        }
    }
    if (stacks.length == 0)
    {
        writeln(0);
    }
    else
    {
        bool[] ans = new bool[s.length];
        foreach (tuple seq; stacks)
            for (auto i = seq[2]; i <= seq[3]; ++i)
                ans[i] = true;
        int ansi = -1, ansj = -1, count = 0, i = 0;
        while (i < s.length)
        {
            if (ans[i])
            {
                auto j = i;
                int cnt = 0;
                while ((j < s.length) && ans[j])
                {
                  if (s[j] =='[') ++cnt;
                  ++j;
                }
                if (cnt > count)
                {
                    ansi = i;
                    ansj = j;
                    count = cnt;
                }
                i = j;
            }
            else ++i;
        }
        printf("%d\n", count);
        printf("%.*s\n", s[ansi .. ansj]);
    }
}

void main()
{
    CF138C();
}

import std.algorithm;
import std.c.stdio;
import std.stdio;
import std.conv;
import std.math;
import std.array;
import std.container;

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar();
    }
    while(0 <= curc && curc <= 32);
    if(curc == EOF)
    {
        eof = true;
    }
}

char[] nlongs()
{
    sb();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar();
    }
    while(32 < curc);
    return res.data;
}

void CF138C()
{
    bool t(char c)
    {
        return (c=='(')||(c==')');
    }
    char[] s = nlongs();
    auto n = s.length;
    int[] stack = [], ans = new int[n];
    int[] ke = new int[n];for(int i=0;i<n;++i)ke[i]=i;
    for (int i=0; i<n; ++i)
    {
        if ((s[i]=='(') || (s[i]=='['))
            stack ~= i;
        else
        {
            if ((stack.length>0)&&(t(s[stack[stack.length-1]])==t(s[i])))
            {
                ans[stack[stack.length-1]] = i;
                --stack.length;
            }
            else stack.length = 0;
        }
    }
    //writeln(ke);
    //writeln(ans);
    int cur = 0;
    while (cur<n)
    {
        if (ans[cur]>0)
        {
            int end = ans[cur];
            while ((end<n-1)&&(ans[end+1]>0)) end = ans[end+1];
            ans[cur] = end;
            cur = end+1;
        }
        else ++cur;
    }
    //writeln(ans);
    int[] cnt = new int[n];
    cnt[0]=s[0]=='['?1:0;
    for (int i=1;i<n;++i) cnt[i] = cnt[i-1] + (s[i]=='['?1:0);
    int count(int h)
    {
         if (ans[h] != 0) return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);
         else return 0;
    }
    int tt = -1, m = 0;
    for (int i = 0; i < n; ++i) if(count(i) > m){tt = i; m = count(i);}
    //writeln(s);
    writeln(m);
    if ((m>0)&&(ans[tt]-tt>1))writeln(s[tt..ans[tt]+1]);
}

void main()
{
    CF138C();
}


import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		bool [int] b;
		foreach (ref c; a)
		{
			b[c] = true;
		}
		bool ok = a.any !(c => (c - k) in b);
		writeln (ok ? "YES" : "NO");
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto a = RDA;

		bool[long] set;
		foreach (i; 0..n)
			set[a[i]] = true;

		foreach (i; 0..n)
		{
			if (set.get(a[i]-k, false))
			{
				ans[ti] = true;
				break;
			}
		}
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}


import core.bitop;
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable int logLimit = 20;

int fun (int len)
{
	if (len == 0)
	{
		return 1;
	}
	int cur = len;
	while (cur & (cur - 1))
	{
		cur += cur & -cur;
	}
	debug {writeln ("fun (", len, ") = ", cur, " - ", len);}
	return cur - len;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);

		auto prev = new int [n];
		prev[0] = -1;
		foreach (i; 1..n)
		{
			prev[i] = (a[i] == a[i - 1]) ? prev[i - 1] : i - 1;
		}
		auto next = new int [n];
		next[n - 1] = n;
		foreach_reverse (i; 0..n - 1)
		{
			next[i] = (a[i] == a[i + 1]) ? next[i + 1] : i + 1;
		}

		int res = int.max;
		foreach (logLo; 0..logLimit)
		{
			int lo = min (n - 1, 0 + (1 << logLo));
			lo = prev[lo] + 1;
			foreach (logHi; 0..logLimit)
			{
				int hi = max (0, n - 1 - (1 << logHi));
				hi = next[hi] - 0;
				hi = max (hi, lo);

				debug {writeln (lo, " ", hi - lo, " ", n - hi);}
				res = min (res, fun (lo) + fun (hi - lo) +
				    fun (n - hi));
				debug {writeln ("res = ", res);}
			}
		}
		writeln (res);
	}
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  long[] pow2 = 19L.iota.map!"2 ^^ a".array;
  long extraPow2(long x) {
    long t = 1;
    while(x > t) t *= 2;
    return t - x;
  }

  pow2.deb;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto H = scan!long(N);

      long[] acc = [0];
      foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];
      auto accs = acc.assumeSorted;

      long ans = long.max;
      auto p2 = pow2.filter!(p => p <= N + extraPow2(N)).array;
      foreach(a; p2) foreach(b; p2) foreach(c; p2) {
        long cur;
        long ex;
        long sum;
        foreach(x; [a, b, c]) {
          auto r = accs.upperBound(cur).lowerBound(x + cur + 1);
          if (r.empty) {
            ex++;
            sum++;
          } else {
            // [a, b, c, x, r.back, cur].deb;
            ex += x - r.back + cur;
            sum += x;
            cur = r.back;
          }
        }
        if (cur == accs[$ - 1]) ans = min(ans, ex);
      }

      return ans;
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  long[] pow2 = 19L.iota.map!"2 ^^ a".array;
  long extraPow2(long x) {
    long t = 1;
    while(x > t) t *= 2;
    return t - x;
  }

  pow2.deb;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto H = scan!long(N);

      long[] acc = [0];
      foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];
      auto accs = acc.assumeSorted;

      long ans = long.max;
      auto p2 = pow2.filter!(p => p <= N + extraPow2(N)).array;
      foreach(a; p2) foreach(b; p2) foreach(c; p2) {
        long cur;
        long ex;
        long sum;
        foreach(x; [a, b, c]) {
          auto r = accs.upperBound(cur).lowerBound(x + cur + 1);
          if (r.empty) {
            ex++;
            sum++;
          } else {
            // [a, b, c, x, r.back, cur].deb;
            ex += x - r.back + cur;
            sum += x;
            cur = r.back;
          }
        }
        if (sum >= N) ans = min(ans, ex);
      }

      return ans;
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  long[] pow2 = 19L.iota.map!"2 ^^ a".array;
  long extraPow2(long x) {
    long t = 1;
    while(x > t) t *= 2;
    return t - x;
  }

  pow2.deb;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto H = scan!long(N);

      long[] acc = [0];
      foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];
      auto accs = acc.assumeSorted;

      long ans = long.max;
      auto p2 = pow2.filter!(p => p <= N + extraPow2(N)).array;
      foreach(a; p2) foreach(b; p2) foreach(c; p2) {
        long cur;
        long ex;
        foreach(x; [a, b, c]) {
          auto r = accs.upperBound(cur).lowerBound(x + cur + 1);
          if (r.empty) {
            ex++;
          } else {
            // [a, b, c, x, r.back, cur].deb;
            ex += x - r.back + cur;
            cur = r.back;
          }
        }
        ans = min(ans, ex);
      }

      return ans;
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  long[] pow2 = 19L.iota.map!"2 ^^ a".array;
  long extraPow2(long x) {
    long t = 1;
    while(x > t) t *= 2;
    return t - x;
  }

  pow2.deb;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto H = scan!long(N);

      long[] acc = [0];
      foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];
      auto accs = acc.assumeSorted;

      long ans = long.max;
      auto p2 = pow2.filter!(p => p <= N).array;
      foreach(a; p2) foreach(b; p2) foreach(c; p2) {
        long cur;
        long ex;
        foreach(x; [a, b, c]) {
          auto r = accs.upperBound(cur).lowerBound(x + cur + 1);
          if (r.empty) {
            ex++;
          } else {
            // [a, b, c, x, r.back, cur].deb;
            ex += x - r.back + cur;
            cur = r.back;
          }
        }
        ans = min(ans, ex);
      }

      return ans;
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}


// https://codeforces.com/problemset/problem/1238/B
import std.algorithm;
import std.container.rbtree;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int q = readln.chomp.to!int;

    foreach(query; 0..q) {
        int n, r;
        readf("%s %s\n", &n, &r);

        int[] x = readln.split.map!(to!int).array;

        auto monsters = redBlackTree!"a > b"(x);

        int damage = 0;

        while(damage*r < monsters.front()) {
            auto monster = monsters.front();
            monsters.removeFront();
            damage += 1;
        }
        damage.writeln;
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto q = RD!int;
	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto n = RD;
		auto r = RD;
		auto x = RDA;
		x.sort!"a > b"();
		long cnt, last;
		foreach (e; x)
		{
			if (e <= cnt * r)
			{
				break;
			}
			else if (e == last)
			{
				continue;
			}
			++cnt;
			last = e;
		}
		ans[i] = cnt;
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush();
	debug readln();
}


import std.stdio;
import std.algorithm;
import std.conv;
import std.format;

void main() {
	struct Song {
		int len, percentage;
	}

	int n;
	scanf("%d\n", &n);

	Song[] arr;

	foreach (line; stdin.byLine) {
		Song s;
		line.to!string.formattedRead!"%d %d"(s.len, s.percentage);
		arr ~= s;
	}

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}

import std.stdio;
import std.algorithm;

void main() {
	struct Song {
		int len, percentage;
	}

	int n;
	scanf("%d", &n);

	Song[] arr = new Song[n];

	foreach (i; 0 .. n) {
		scanf("%d %d", &arr[i].len, &arr[i].percentage);
	}

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}

import std.stdio;
import std.algorithm;
import std.conv;
import std.format;

void main() {
	struct Song {
		int len, percentage;
	}

	int n;
	scanf("%d\n", &n);

	Song[] arr;
	arr.reserve(n);

	foreach (line; stdin.byLine) {
		Song s;
		line.to!string.formattedRead!"%d %d"(s.len, s.percentage);
		arr ~= s;
	}

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}

import std.stdio;
import std.algorithm;
import std.conv;
import std.format;

void main() {
	struct Song {
		int len, percentage;
	}

	int n;
	readf!" %d"(n);

	Song[] arr = new Song[n];
	foreach (i; 0 .. n) {
		readf!" %d %d"(arr[i].len, arr[i].percentage);
	}

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}

import std.stdio;
import std.algorithm;
import std.conv;
import std.format;

void main() {
	struct Song {
		int len, percentage;
	}

	int n;
	scanf("%d", &n);

	Song[] arr = new Song[n];
	foreach (i; 0 .. n) {
		scanf("%d %d", &arr[i].len, &arr[i].percentage);
	}

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}

import std.stdio;
import std.algorithm;
import std.conv;
import std.format;

void r(ref int d) { scanf("%d", &d); }
void r(ref long d) { scanf("%lld", &d); }
void r(ref double d) { scanf("%f", &d); }

void main() {
	struct Song {
		int len, percentage;
	}

	int n; r(n);

	Song[] arr = new Song[n];
	foreach (i; 0 .. n) {
		r(arr[i].len);
		r(arr[i].percentage);
	}

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}

import std.stdio;
import std.algorithm;
import std.conv;
import std.format;

void r(ref int d) { scanf("%d", &d); }
void r(ref int a, ref int b) { scanf("%d %d", &a, &b); }
void r(ref long d) { scanf("%lld", &d); }
void r(ref double d) { scanf("%f", &d); }

void main() {
	struct Song {
		int len, percentage;
	}

	int n; r(n);

	Song[] arr = new Song[n];
	foreach (i; 0 .. n) {
		r(arr[i].len, arr[i].percentage);
	}

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}

import std.stdio;
import std.algorithm;
import std.conv;
import std.format;

void main() {
	struct Song {
		int len, percentage;
	}

	int n;
	scanf("%d\n", &n);

	Song[] arr;

	foreach (line; stdin.byLine) {
		Song s;
		line.to!string.formattedRead!"%d %d"(s.len, s.percentage);
		arr ~= s;
	}

	writeln(arr);
	return;

	bool compare(Song a, Song b) {
		if (a.percentage == 100 && b.percentage != 100) return true;
		if (a.percentage != 100 && b.percentage == 100) return false;
		double x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);
		double y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);
		return x > y;
	}

	sort!compare(arr);

	double answer = 0;
	double exp = 0;
	foreach (s; arr) {
		answer += s.len;
		answer += exp * ((100 - s.percentage) / 100.0);
		exp += s.len * (s.percentage / 100.0);
	}

	writef("%0.12f\n", answer);
}


// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    ll n = scan;
    writeln(-(n-1), " ", n);
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

import std.stdio, std.algorithm, std.array, std.string, std.conv;

void main()
{
    int t;
    scanf("%d", &t);
    foreach(_; 0..t)
    {
        long n;
        scanf("%lld", &n);
        getchar();
        writeln(-1 * (n - 1), ' ', n);
    }
}


void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.random, std.array;

  // const int n=10;
  // auto rnd=Random(unpredictableSeed);
  // auto a=new char[](n), b=new char[](n);
  // foreach(i; 0..n){
  //   a[i]=(uniform!"[]"(0, 1, rnd)+'0').to!(char);
  //   b[i]=(uniform!"[]"(0, 1, rnd)+'0').to!(char);
  // }

  int n; rd(n);
  auto a=readln.chomp.to!(char[]);
  auto b=readln.chomp.to!(char[]);

  long solve(){
    long p, q, r, s;
    foreach(i; 0..n){
      if(a[i]=='0' && b[i]=='0') p++;
      else if(a[i]=='0' && b[i]=='1') q++;
      else if(a[i]=='1' && b[i]=='0') r++;
      else s++;
    }
    return p*r+p*s+q*r;
  }

  long brute(){
    auto _a=a.map!((e)=>(e-'0')).array, _b=b.map!((e)=>(e-'0')).array;
    long ret=0;
    foreach(i; 0..n)foreach(j; 0..i){
      int o1=_a[i]|_b[i], o2=_a[j]|_b[j];
      if(o1!=(_a[j]|_b[i]) || o2!=(_a[i]|_b[j])) ret++;
    }
    return ret;
  }

  // if (solve()!=brute()){
  //   writeln(a);
  //   writeln(b);
  //   writeln(solve());
  //   writeln(brute());
  // }

  writeln(solve());
}

/*
  0 0 p
  0 1 q
  1 0 r
  1 1 s
*/

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto s = readln.chomp;
    auto t = readln.chomp;

    int oo = 0, oz = 0, zo = 0, zz = 0;
    foreach (a, b; lockstep(s, t)) {
        if (a == '1' && b == '1') ++oo;
        if (a == '1' && b == '0') ++oz;
        if (a == '0' && b == '1') ++zo;
        if (a == '0' && b == '0') ++zz;
    }

    auto ans = cast(long)oo * zz + cast(long)oz * (zo + zz);

    ans.writeln;
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		auto t = readln.strip;
		int [2] [2] d;
		foreach (k; 0..n)
		{
			d[s[k] - '0'][t[k] - '0'] += 1;
		}

		long res = 0;
		foreach (i; 0..2)
		{
			foreach (j; 0..2)
			{
				foreach (p; 0..2)
				{
					foreach (q; 0..2)
					{
						if (i != p &&
						    (((i | j) != (p | q)) ||
						    ((i | q) != (p | j))))
						{
							debug {writeln (i, j,
							    p, q, " ", d[i][j],
							    " ", d[p][q]);}
							res += d[i][j] * 1L *
							    d[p][q];
						}
					}
				}
			}
		}
		writeln (res / 2);
	}
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const A = readToken();
      const B = readToken();

      long[2][2] cnt;
      foreach (i; 0 .. N) {
        ++cnt[A[i] - '0'][B[i] - '0'];
      }

      long ans;
      foreach (p; 0 .. 2) foreach (q; 0 .. 2) foreach (r; 0 .. 2) foreach (s; 0 .. 2) {
        if ((p | q) != (r | q) || (r | s) != (p | s)) {
          if ([p, q] == [r, s]) {
            ans += cnt[p][q] * (cnt[p][q] - 1) / 2;
          } else if ([p, q] < [r, s]) {
            ans += cnt[p][q] * cnt[r][s];
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.chomp.map!(a => a == '1').array;
    auto B = readln.chomp.map!(a => a == '1').array;

    auto cnt = new long[](4);

    foreach (i; 0..N) {
        if (!A[i] && !B[i]) {
            cnt[0] += 1;
        } else if (A[i] && !B[i]) {
            cnt[1] += 1;
        } else if (!A[i] && B[i]) {
            cnt[2] += 1;
        } else {
            cnt[3] += 1;
        }
    }

    auto ans = cnt[0] * cnt[1] + cnt[0] * cnt[3] + cnt[1] * cnt[2];
    ans.writeln;
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto q = RD!int;
	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto s = RD!string;

		auto dp = new long[3][](n+1);
		auto str = "RGB";
		long cnt = k;
		foreach (j; 0..3)
		{
			foreach (l; 0..n)
			{
				dp[l+1][j] = dp[l][j];
				if (s[l] != str[(j+l)%3])
					++dp[l+1][j];
				if (l+1 >= k)
				{
					cnt = min(cnt, dp[l+1][j] - dp[l+1-k][j]);
				}
			}
		}
		ans[i] = cnt;
	}

	foreach (e; ans)
	{
		writeln(e);
	}
	stdout.flush();
	debug readln();
}

import std.stdio;
import std.algorithm;

char[] charset = ['R', 'G', 'B'];
int[200005] sum;

void main() {
    int q;
    readf(" %s", q);

    foreach (_; 0..q) {
        int n, k;
        readf(" %s %s", n, k);

        readln();
        string s = " " ~ readln();

        auto result = n;
        foreach (j; 0..3) {
            foreach (i; 1..s.length) {
                auto ch = charset[(i + j) % 3];
                if (ch == s[i]) {
                    sum[i] = sum[i-1] + 1;
                } else {
                    sum[i] = sum[i-1];
                }
            }
            foreach(i; k..s.length) {
                result = min(result, k - (sum[i] - sum[i-k]));
            }
        }
        writeln(result);
    }
}

import std.stdio;
import std.algorithm;

char[] charset = ['R', 'G', 'B'];
int[200005] sum;

void main() {
    int q;
    readf(" %s", q);

    foreach (_; 0..q) {
        int n, k;
        readf(" %s %s", n, k);

        readln;
        string s = " " ~ readln;

        auto result = n;
        foreach (j; 0..3) {
            foreach (i; 1..s.length) {
                auto ch = charset[(i + j) % 3];
                if (ch == s[i]) {
                    sum[i] = sum[i-1] + 1;
                } else {
                    sum[i] = sum[i-1];
                }
            }
            foreach(i; k..s.length) {
                result = min(result, k - (sum[i] - sum[i-k]));
            }
        }
        writeln(result);
    }
}


import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int NA = -1;

void main ()
{
	int n;
	int k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		auto p = new int [n];
		p[] = NA;
		foreach (j; 0..k)
		{
			int m;
			readf (" %s", &m);
			int prev;
			readf (" %s", &prev);
			foreach (i; 1..m)
			{
				int next;
				readf (" %s", &next);
				p[n - next] = n - prev;
				prev = next;
			}
		}

		int res = 0;
		foreach (i; 0..n)
		{
			if (p[i] != NA && p[i] != i + 1)
			{
				p[i] = NA;
				res++;
			}
		}

		foreach_reverse (i; 0..n - 2)
		{
			if (p[i] != NA && p[i + 1] == NA)
			{
				p[i] = NA;
				res++;
			}
		}

		foreach (i; 0..n - 1)
		{
			if (p[i] == NA)
			{
				p[i] = i + 1;
				res++;
			}
		}

		foreach (i; 0..n - 1)
		{
			assert (p[i] == i + 1);
		}
		assert (p[n - 1] == NA);

		writeln (res);
	}
}

import std.stdio;

immutable int NA = -1;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		auto p = new int [n];
		p[] = NA;
		foreach (j; 0..k)
		{
			int m, prev;
			readf (" %s %s", &m, &prev);
			foreach (i; 1..m)
			{
				int next;
				readf (" %s", &next);
				p[n - next] = n - prev;
				prev = next;
			}
		}

		int res = 0;
		foreach (i; 0..n)
		{
			if (p[i] != NA && p[i] != i + 1)
			{
				p[i] = NA;
				res++;
			}
		}

		foreach_reverse (i; 0..n - 2)
		{
			if (p[i] != NA && p[i + 1] == NA)
			{
				p[i] = NA;
				res++;
			}
		}

		foreach (i; 0..n - 1)
		{
			if (p[i] == NA)
			{
				p[i] = i + 1;
				res++;
			}
		}

		writeln (res);
	}
}

import std.stdio;

void main(string[] args) {
    //stdin = File("input.txt", "r");

    int n, k;
    readf("%d %d\n", &n, &k);
    int answer = 0;
    foreach (int i; 0..k) {
        int m;
        readf("%d", &m);
        int[] a = new int[m];
        foreach (int j; 0..m) {
            readf(" %d", &a[j]);
        }
        readf("\n");

        if (a[0] == 1) {
            int j = 1;
            while (j < m && a[j] == j + 1) {
                ++j;
            }
            answer += 2 * (m - j + 1) - 1;
        } else {
            answer += 2 * m - 1;
        }
    }
    answer -= 1;
    writeln(answer);
}


import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void main()
{
    int n, h, a, b, k;
    readf("%s %s %s %s %s", &n, &h, &a, &b, &k);
    readln;

    while (k--) {
        int ta, fa, tb, fb;
        readf("%s %s %s %s", &ta, &fa, &tb, &fb);
        readln;

        auto ans = 0;
        if (ta == tb) {
            ans = abs(fa - fb);
        } else {
            if (fa > fb) swap(fa, fb);

            ans = abs(ta - tb);
            if ((fa >= a && fa <= b) || (fb >= a && fb <= b)) {
                ans += abs(fa - fb);
            } else {
                ans += min(abs(fa - a) + abs(fb - a), abs(fa - b) + abs(fb - b));
            }
        }

        writeln(ans);
    }
}

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, h, a, b, k; rd(n, h, a, b, k);
  struct T{long t, f;}
  import std.math;
  while(k--){
    auto data=new T[](2);
    rd(data[0].t, data[0].f, data[1].t, data[1].f);
    data.sort!"a.t==b.t ? a.f<b.f : a.t<b.t";
    if(data[0].t==data[1].t){
      writeln(abs(data[0].f-data[1].f));
    }else{
      long d=0;
      d+=(data[1].t-data[0].t);
      if(data[0].f<a){
        d+=(a-data[0].f);
        d+=abs(a-data[1].f);
      }else if(data[0].f>b){
        d+=(data[0].f-b);
        d+=abs(b-data[1].f);
      }else{
        d+=abs(data[0].f-data[1].f);
      }
      writeln(d);
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, h, a, b, k; rd(n, h, a, b, k);
  struct T{long t, f;}
  import std.math;
  while(k--){
    auto data=new T[](2);
    rd(data[0].t, data[0].f, data[1].t, data[1].f);
    data.sort!"a.t==b.t ? a.f<b.f : a.t<b.t";
    if(data[0].t==data[1].t){
      writeln(abs(data[0].f-data[1].f));
    }else{
      long d=0;
      d+=(data[1].t-data[0].t);
      if(data[0].f<a){
        d+=(a-data[0].f);
        d+=abs(a-data[1].f);
      }else if(data[0].f>b){
        d+=(data[0].f-b);
        d+=abs(b-data[1].f);
      }else{
        d+=abs(a-data[1].f);
      }
      writeln(d);
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}