/*
 * Author:Kongwen Lu
 * Created Time:  2012-09-17-11.05
 * File Name:
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORD(i,a,b) for (int i=(a); i>=(b); i--)
#define REP(i,b) FOR(i,0,b)
#define tests(tc) int tc;scanf("%d",&tc);while(tc--)
#define sf scanf
#define pf printf
using namespace std;
const int maxint = -1u>>1;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<int>::iterator vit;
struct node
{
  char ch;
  int id;
};
char s[200000];
int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   gets(s);
   stack<node> st;
   node now;
   int len=strlen(s);
   int ans=0,tmp=0;
   int ansl,ansr,l=-1,r=-1;
   REP(i,len)
   {
       now.ch=s[i];
       now.id=i;
       if(s[i]=='('||s[i]=='[')
       {
           st.push(now);
           continue;
       }
       if(st.empty())
       {
           if(tmp>ans)
           {
              ans=tmp;
              ansl=l;
              ansr=r;
           }
           l=-1;
           tmp=0;
       }
       else
          {
              if(s[i]==')'&&st.top().ch=='(')
              {
                  if(l==-1)
                  l=st.top().id;
                  else
                  if(l>st.top().id)
                  l=st.top().id;
                  r=i;
                  st.pop();
              }
              else
              if(s[i]==']'&&st.top().ch=='[')
              {
                  if(l==-1)
                  l=st.top().id;
                  else
                  if(l>st.top().id)
                  l=st.top().id;
                  r=i;
                  st.pop();
                  tmp++;
              }
              else
              {
                  //cout<<'#'<<endl;
             //     if(st.empty())
                  if(tmp>ans)
                  {
                     ans=tmp;
                     ansl=l;
                     ansr=r;
                  }
                  l=-1;
                  tmp=0;
                  while(!st.empty())
                  st.pop();
              }
          }

   }
   if(st.empty())
   if(tmp>ans)
    {
        ans=tmp;
        ansl=l;
        ansr=r;
    }
   if(!ans) pf("0\n");
   else
   {
       //cout<<ansl<<'#'<<ansr<<endl;
       pf("%d\n",ans);
       FOR(i,ansl,ansr+1)
       pf("%c",s[i]);
       pf("\n");
   }
      return 0;
}


/*
 * Author:Kongwen Lu
 * Created Time:  2012-09-17-11.05
 * File Name:
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORD(i,a,b) for (int i=(a); i>=(b); i--)
#define REP(i,b) FOR(i,0,b)
#define tests(tc) int tc;scanf("%d",&tc);while(tc--)
#define sf scanf
#define pf printf
using namespace std;
const int maxint = -1u>>1;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<int>::iterator vit;
struct node
{
  char ch;
  int id;
};
char s[200000];
int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   gets(s);
   stack<node> st;
   node now;
   int len=strlen(s);
   int ans=0,tmp=0;
   int ansl,ansr,l=-1,r=-1;
   REP(i,len)
   {
       now.ch=s[i];
       now.id=i;
       if(s[i]=='('||s[i]=='[')
       {
           st.push(now);
           continue;
       }
       if(st.empty())
       {
           if(tmp>ans)
           {
              ans=tmp;
              ansl=l;
              ansr=r;
           }
           l=-1;
           tmp=0;
       }
       else
          {
              if(s[i]==')'&&st.top().ch=='(')
              {
                  if(l==-1)
                  l=st.top().id;
                  else
                  if(l>st.top().id)
                  l=st.top().id;
                  r=i;
                  st.pop();
              }
              else
              if(s[i]==']'&&st.top().ch=='[')
              {
                  if(l==-1)
                  l=st.top().id;
                  else
                  if(l>st.top().id)
                  l=st.top().id;
                  r=i;
                  st.pop();
                  tmp++;
              }
              else
              {
                  //cout<<'#'<<endl;
                  if(st.empty())
                  if(tmp>ans)
                  {
                     ans=tmp;
                     ansl=l;
                     ansr=r;
                  }
                  l=-1;
                  tmp=0;
                  while(!st.empty())
                  st.pop();
              }
          }

   }
   if(st.empty())
   if(tmp>ans)
    {
        ans=tmp;
        ansl=l;
        ansr=r;
    }
   if(!ans) pf("0\n");
   else
   {
       //cout<<ansl<<'#'<<ansr<<endl;
       pf("%d\n",ans);
       FOR(i,ansl,ansr+1)
       pf("%c",s[i]);
       pf("\n");
   }
      return 0;
}


#include <iostream>
#include <string>
#include <stack>

using namespace std;

#define fs first
#define sc second

main(){
	string s;
	cin >> s;

	stack< pair<int,int> > st;

	int result = 0; string str = "";
	int p = -1, tmp = 0;
	for (int i=0; i<s.length(); i++){
		switch (s[i]){
			case '(' :
				st.push(make_pair(s[i],i));
				break;
			case '[' :
				if (p == -1) p = i;
				st.push(make_pair(s[i],i));
				break;
			case ')' :
				if (!st.empty() && st.top().fs == '('){
					if (p != -1) p = min(p,st.top().sc);
					st.pop();
				} else {
					while(!st.empty())
						st.pop();
					p = -1; tmp = 0;
				}
				break;
			case ']' :
				if (!st.empty() && st.top().fs == '[' && p != -1){
					p = min(p,st.top().sc);
					tmp++; st.pop();
					if (result < tmp && (st.empty() || st.top().sc < p)){
						result = tmp;
						str = s.substr(p,i-p+1);
					}
				} else {
					while(!st.empty())
						st.pop();
					p = -1; tmp = 0;
				}
				break;
		}
	}

	cout << result << endl;
	cout << str << endl;
}


#include <iostream>
#include <string>
#include <stack>

using namespace std;

#define fs first
#define sc second

main(){
	string s;
	cin >> s;

	stack<int> st;

	bool flg[100001];
	for (int i=0; i<s.length(); i++){
		switch (s[i]){
			case '(' :
				st.push(i);
				break;
			case '[' :
				st.push(i);
				break;
			case ')' :
				if (!st.empty() && s[st.top()] == '('){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				} else st.push(i);
				break;
			case ']' :
				if (!st.empty() && s[st.top()] == '['){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				} else st.push(i);
				break;
		}
	}

	int result = 0; string str = "";
	for (int i=0; i<s.length(); i++){
		int j = i, tmp = 0;
		while(flg[j]){
			if (s[j] == '[')
				tmp++;
			j++;
		}
		if (tmp>result){
			result = tmp;
			str = s.substr(i,j-i);
		}
		i = max(i,j-1);
	}

	cout << result << endl;
	cout << str << endl;
}


#include <iostream>
#include <string>
#include <stack>

using namespace std;

#define fs first
#define sc second

main(){
	string s;
	cin >> s;

	stack<int> st;

	bool flg[100001];
	for (int i=0; i<s.length(); i++){
		switch (s[i]){
			case '(' :
				st.push(i);
				break;
			case '[' :
				st.push(i);
				break;
			case ')' :
				if (!st.empty() && s[st.top()] == '('){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
			case ']' :
				if (!st.empty() && s[st.top()] == '['){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
		}
	}

	int result = 0; string str = "";
	for (int i=0; i<s.length(); i++){
		int j = i, tmp = 0;
		while(flg[j]){
			if (s[j] == '[')
				tmp++;
			j++;
		}
		if (tmp>result){
			result = tmp;
			str = s.substr(i,j-i+1);
		}
		i = j-1;
	}

	cout << result << endl;
	cout << str << endl;
}


#include <iostream>
#include <string>
#include <stack>

using namespace std;

#define fs first
#define sc second

main(){
	string s;
	cin >> s;

	stack<int> st;

	bool flg[100001] = {false};
	for (int i=0; i<s.length(); i++){
		switch (s[i]){
			case '(' :
				st.push(i);
				break;
			case '[' :
				st.push(i);
				break;
			case ')' :
				if (!st.empty() && s[st.top()] == '('){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				} else st.push(i);
				break;
			case ']' :
				if (!st.empty() && s[st.top()] == '['){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				} else st.push(i);
				break;
		}
	}

	int result = 0; string str = "";
	for (int i=0; i<s.length(); i++){
		int j = i, tmp = 0;
		while(flg[j]){
			if (s[j] == '[')
				tmp++;
			j++;
		}
		if (tmp>result){
			result = tmp;
			str = s.substr(i,j-i);
		}
		i = max(i,j-1);
	}

	cout << result << endl;
	cout << str << endl;
}


#include <iostream>
#include <string>
#include <stack>

using namespace std;

#define fs first
#define sc second

main(){
	string s;
	cin >> s;

	stack<int> st;

	bool flg[100001];
	for (int i=0; i<s.length(); i++){
		switch (s[i]){
			case '(' :
				st.push(i);
				break;
			case '[' :
				st.push(i);
				break;
			case ')' :
				if (!st.empty() && s[st.top()] == '('){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
			case ']' :
				if (!st.empty() && s[st.top()] == '['){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
		}
	}

	int result = 0; string str = "";
	for (int i=0; i<s.length(); i++){
		int j = i, tmp = 0;
		while(flg[j]){
			if (s[j] == '[')
				tmp++;
			j++;
		}
		if (tmp>result){
			result = tmp;
			str = s.substr(i,j-1);
		}
		i = j-1;
	}

	cout << result << endl;
	cout << str << endl;
}


#include <iostream>
#include <string>
#include <stack>

using namespace std;

#define fs first
#define sc second

main(){
	string s;
	cin >> s;

	stack<int> st;

	bool flg[100001];
	for (int i=0; i<s.length(); i++){
		switch (s[i]){
			case '(' :
				st.push(i);
				break;
			case '[' :
				st.push(i);
				break;
			case ')' :
				if (!st.empty() && s[st.top()] == '('){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
			case ']' :
				if (!st.empty() && s[st.top()] == '['){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
		}
	}

	int result = 0; string str = "";
	for (int i=0; i<s.length(); i++){
		int j = i, tmp = 0;
		while(flg[j]){
			if (s[j] == '[')
				tmp++;
			j++;
		}
		if (tmp>result){
			result = tmp;
			str = s.substr(i,j-i);
		}
		i = max(i,j-1);
	}

	cout << result << endl;
	cout << str << endl;
}


#include <iostream>
#include <string>
#include <stack>

using namespace std;

#define fs first
#define sc second

main(){
	string s;
	cin >> s;

	stack<int> st;

	bool flg[100001];
	for (int i=0; i<s.length(); i++){
		switch (s[i]){
			case '(' :
				st.push(i);
				break;
			case '[' :
				st.push(i);
				break;
			case ')' :
				if (!st.empty() && s[st.top()] == '('){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
			case ']' :
				if (!st.empty() && s[st.top()] == '['){
					flg[st.top()] = true;
					flg[i] = true;
					st.pop();
				}
				break;
		}
	}

	int result = 0; string str = "";
	for (int i=0; i<s.length(); i++){
		int j = i, tmp = 0;
		while(flg[j]){
			if (s[j] == '[')
				tmp++;
			j++;
		}
		if (tmp>result){
			result = tmp;
			str = s.substr(i,j-i+1);
		}
		i = max(i,j-1);
	}

	cout << result << endl;
	cout << str << endl;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}
int sz = S.size();

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
     * [][][]
     *
     */

    sz = S.size();
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        //if(S[i]!='[')continue;
        int cur = i, next = rec[cur];
        while(1){
            bool ok = false;
            if(next!=-1){
                for(int k=next+1; k<sz; k++){
                    if((S[i]=='(' && S[k]=='(') || (S[i]=='[' && S[k]=='[') ){
                        //if(S[k]=='['){
                        cur = k;ok=true;break;
                    }
                    }
                }
                if(ok&&rec[cur]!=-1){
                    next = rec[cur];
                }else{
                    break;
                }
            }
            right = next;
            int num = 0;
            for(int i=ans_left; i<=ans_right; i++){
                if(S[i]=='['){
                    num++;
                }
            }
            if(num>ans){
                ans_left = left, ans_right = right;
                ans = num;
            }
        }

        if(ans==-1){
            cout<<0<<endl;
        }else{
            cout<<ans<<endl;
            for(int i=ans_left; i<=ans_right; i++){
                cout<<S[i];
            }cout<<endl;
        }

    }

    int main(){
        cin>>S;
        work();

        return 0;
    }


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}
int sz = S.size();

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
     * [][][]
     *
     */

    sz = S.size();
    int ans = -1;
    int ans_left, ans_right;
    int cur = 0;
    string t_str, ans_str;
    while(1){
        //cout<<"cur at "<<cur<<endl;
        if(cur>=sz)break;
        if(rec[cur]!=-1){
            t_str += S.substr(cur, rec[cur]-cur+1);
            cur = rec[cur]+1;
            int cnt =0;
            for(int k=0; k<t_str.size(); k++){
                if(t_str[k]=='['){
                    cnt++;
                }
            }
            if(cnt>ans){
                ans = cnt;
                ans_str = t_str;
            }
        }else{
            t_str = "";
            cur++;
        }
    }
    if(ans==-1){
        cout<<0<<endl;
    }else{
        cout<<ans<<endl;
        cout<<ans_str<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
    for(int i=0; i<S.size(); i++){
        cout<<rec[i]<<" ";
    }cout<<endl;
    */
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
            }
        }
    }

    if(ans==-1){
        cout<<0<<endl;
    }else if(ans==0){
        cout<<0<<endl;
        cout<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
    for(int i=0; i<S.size(); i++){
        cout<<rec[i]<<" ";
    }cout<<endl;
    */
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
            }
        }
    }

    if(ans==-1){
        cout<<0<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}
int sz = S.size();

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
     * [][][]
     *
    */

    sz = S.size();
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        if(S[i]!='[')continue;
        int cur = i, next = rec[cur];
        while(1){
            if(next+1>=sz || rec[next+1]==-1)break;
            //cout<<"cur is "<<cur<<" nextis "<<next<<endl;
            cur = next+1;
            next = rec[cur];
        }
        right = next;
        //cout<<"left and right are "<<left<<" "<<right<<endl;
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
            }
        }
    }

    if(ans==-1){
        cout<<0<<endl;
    }else if(ans==0){
        cout<<0<<endl;
        cout<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
    for(int i=0; i<S.size(); i++){
        cout<<rec[i]<<" ";
    }cout<<endl;
    */
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
            }
        }
    }
    if(ans==-1){
        cout<<0<<endl;
        cout<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}
int sz = S.size();

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
     * [][][]
     *
    */

    sz = S.size();
    for(int i=0; i<S.size(); i++){
        cout<<rec[i]<<" ";
    }cout<<endl;
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        int cur = i, next;
        while(1){
            next = rec[cur];
            if(rec[next+1]==-1)break;
            cout<<"cur is "<<cur<<" nextis "<<next<<endl;
            cur = next+1;
        }
        right = next;
        cout<<"left and right are "<<left<<" "<<right<<endl;
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
            }
        }
    }

    if(ans==-1){
        cout<<0<<endl;
    }else if(ans==0){
        cout<<0<<endl;
        cout<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}
int sz = S.size();

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
     * [][][]
     *
    */

    sz = S.size();
    /*
    for(int i=0; i<S.size(); i++){
        cout<<rec[i]<<" ";
    }cout<<endl;
    */
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        if(S[i]!='[')continue;
        int cur = i, next;
        while(1){
            next = rec[cur];
            if(rec[next+1]==-1)break;
            //cout<<"cur is "<<cur<<" nextis "<<next<<endl;
            cur = next+1;
        }
        right = next;
        //cout<<"left and right are "<<left<<" "<<right<<endl;
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
            }
        }
    }

    if(ans==-1){
        cout<<0<<endl;
    }else if(ans==0){
        cout<<0<<endl;
        cout<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}
int sz = S.size();

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
     * [][][]
     *
    */

    sz = S.size();
    /*
    for(int i=0; i<S.size(); i++){
        cout<<rec[i]<<" ";
    }cout<<endl;
    */
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        int cur = i, next;
        while(1){
            next = rec[cur];
            if(rec[next+1]==-1)break;
            //cout<<"cur is "<<cur<<" nextis "<<next<<endl;
            cur = next+1;
        }
        right = next;
        //cout<<"left and right are "<<left<<" "<<right<<endl;
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
            }
        }
    }

    if(ans==-1){
        cout<<0<<endl;
    }else if(ans==0){
        cout<<0<<endl;
        cout<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

const int MAXN = 150001;
typedef pair<char, int> pcc;
string S;

int rec[MAXN];
int cnt[MAXN];
void pre(){
    memset(cnt,0,sizeof(cnt));
    if(S[0]=='['){
        cnt[0] = 1;
    }

    for(int i=1; i<S.size(); i++){
        if(S[i]=='['){
            cnt[i] = cnt[i-1]+1;
        }else{
            cnt[i] = cnt[i-1];
        }
    }
}
int sz = S.size();

void work(){
    pre();
    stack< pcc > my_stack;
    memset(rec,-1,sizeof(rec));
    for(int i=0; i<S.size(); i++){
        if(my_stack.empty()){
            my_stack.push( pcc(S[i], i) );
        }else{
            char top = my_stack.top().first;
            char now = S[i];
            if((top=='(' && now==')') || (top=='[' && now==']') ){
                rec[my_stack.top().second] = i;
                my_stack.pop();
            }else if((top=='(' && now==']') && (top=='['&&now==')'))  {
                while(!my_stack.empty()){
                    my_stack.pop();
                }
            }else{
                my_stack.push( pcc(S[i],i));
            }
        }
    }
    /*
     * [][][]
     *
    */

    sz = S.size();
    /*
    for(int i=0; i<S.size(); i++){
        cout<<rec[i]<<" ";
    }cout<<endl;
    */
    int ans = -1;
    int ans_left, ans_right;
    for(int i=0; i<S.size(); i++){
        int left = i, right = rec[left];
        if(S[i]!='[')continue;
        int cur = i, next;
        while(1){
            next = rec[cur];
            if(rec[next+1]==-1)break;
            //cout<<"cur is "<<cur<<" nextis "<<next<<endl;
            cur = next+1;
        }
        right = next;
        //cout<<"left and right are "<<left<<" "<<right<<endl;
        if(right==-1){
            continue;
        }else{
            int num;
            if(cnt[right] == cnt[left] && cnt[right]==0){
                num = 0;
            }else{
                num = cnt[right]-cnt[left]+1;
            }
            if(num>ans){
                ans = num;
                ans_left = left, ans_right = right;
                cout<<"ok , left right are "<<left<<" "<<right<<" num are "<<cnt[left]<<" "<<cnt[right]<<endl;
            }
        }
    }

    if(ans==-1){
        cout<<0<<endl;
    }else if(ans==0){
        cout<<0<<endl;
        cout<<endl;
    }else{
        cout<<ans<<endl;
        for(int i=ans_left; i<=ans_right; i++){
            cout<<S[i];
        }cout<<endl;
    }

}

int main(){
    cin>>S;
    work();

    return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
#define INF (int)HUGE_VAL
#define llINF (ll)HUGE_VAL
#define ldINF (ld)HUGE_VAL
#define set(a, x) memset(a, x, sizeof(a));
#define cpy(a, b) memcpy(a, b, sizeof(a));
#define sqr(x) ((x)*(x))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define EPS (1e-7)
#define PI 3.1415926535897932384626433833
#define y1 _y1

string s;
int n;
stack<pii> st;
int cur = 0, curl = -1, tl = 0;
int ans = 0, ansl = -1, ansr = -1;

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin >> s;
  n = s.length();

  for (int i = 0; i < n; ++i) {
    if (s[i] == '(') st.push(make_pair(0, i));
    else if (s[i] == '[') st.push(make_pair(1, i));
    else if (s[i] == ')') {
      if (st.empty() ||
          st.top().first == 1 ||
          st.top().second < tl) {
        cur = 0;
        curl = -1;
        tl = i+1;
      } else {
        st.pop();
      }
    } else if (s[i] == ']') {
      if (st.empty() ||
          st.top().first == 0 ||
          st.top().second < tl) {
        cur = 0;
        curl = -1;
        tl = i+1;
      } else {
        cur++;
        if (curl == -1 || st.top().second < curl) curl = st.top().second;
        if (cur > ans) {
          ans = cur;
          ansl = curl;
          ansr = i;
        }
        st.pop();
      }
    }
  }

  cout << ans << endl;
  if (ansl != -1 && ansr != -1)
    cout << s.substr(ansl, ansr-ansl+1);
  cout << endl;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
#define INF (int)HUGE_VAL
#define llINF (ll)HUGE_VAL
#define ldINF (ld)HUGE_VAL
#define set(a, x) memset(a, x, sizeof(a));
#define cpy(a, b) memcpy(a, b, sizeof(a));
#define sqr(x) ((x)*(x))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define EPS (1e-7)
#define PI 3.1415926535897932384626433833
#define y1 _y1

string s;
int n;
stack<pii> st;
int cur = 0, curl = -1, br[100000];
int ans = 0, ansl = -1, ansr = -1;

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin >> s;
  n = s.length();

  br[0] = s[0] == '[';
  for (int i = 1; i < n; ++i)
    br[i] = (s[i] == '[') + br[i-1];
  for (int i = 0; i < n; ++i)
    if (s[i] == '(' ||
        s[i] == '[') st.push(make_pair(s[i] == '[', i));
    else {
      if (st.empty() ||
          st.top().first != (s[i] == ']')) {
        st = stack<pii>();
        curl = i;
      } else {
        st.pop();
        int l = st.empty() ? curl : st.top().second;
        cur = br[i] - br[l];
        if (cur > ans) {
          ans = cur;
          ansl = l+1;
          ansr = i;
        }
      }
    }

  cout << ans << endl;
  if (ans != 0)
    cout << s.substr(ansl, ansr-ansl+1);
  cout << endl;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
#define INF (int)HUGE_VAL
#define llINF (ll)HUGE_VAL
#define ldINF (ld)HUGE_VAL
#define set(a, x) memset(a, x, sizeof(a));
#define cpy(a, b) memcpy(a, b, sizeof(a));
#define sqr(x) ((x)*(x))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define EPS (1e-7)
#define PI 3.1415926535897932384626433833
#define y1 _y1

string s;
int n;
stack<pii> st;
int cur = 0, curl = -1;
int ans = 0, ansl = -1, ansr = -1;

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin >> s;
  n = s.length();

  for (int i = 0; i < n; ++i)
    if (s[i] == '(' ||
        s[i] == '[') st.push(make_pair(s[i] == '[', i));
    else {
      if (st.empty() ||
          st.top().first != (s[i] == ']')) {
        st = stack<pii>();
        cur = 0;
        curl = -1;
      } else {
        if (s[i] == ']')
          cur++;
        if (curl == -1 || st.top().second < curl)
          curl = st.top().second;
        st.pop();
        if (cur >= ans &&
            (st.empty() ||
             st.top().second < curl)) {
          ans = cur;
          ansl = curl;
          ansr = i;
        }
      }
    }

  cout << ans << endl;
  if (ans != 0 && ansl != -1 && ansr != -1)
    cout << s.substr(ansl, ansr-ansl+1);
  cout << endl;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
#define INF (int)HUGE_VAL
#define llINF (ll)HUGE_VAL
#define ldINF (ld)HUGE_VAL
#define set(a, x) memset(a, x, sizeof(a));
#define cpy(a, b) memcpy(a, b, sizeof(a));
#define sqr(x) ((x)*(x))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define EPS (1e-7)
#define PI 3.1415926535897932384626433833
#define y1 _y1

string s;
int n;
stack<pii> st;
int cur = 0, curl = -1;
int ans = 0, ansl = -1, ansr = -1;

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin >> s;
  n = s.length();

  for (int i = 0; i < n; ++i)
    if (s[i] == '(' ||
        s[i] == '[') st.push(make_pair(s[i] == '[', i));
    else {
      if (st.empty() ||
          st.top().first != (s[i] == ']')) {
        st = stack<pii>();
        cur = 0;
        curl = -1;
      } else {
        if (s[i] == ']')
          cur++;
        if (curl == -1 || st.top().second < curl)
          curl = st.top().second;
        if (cur >= ans && st.size() == 1) {
          ans = cur;
          ansl = curl;
          ansr = i;
        }
        st.pop();
      }
    }

  cout << ans << endl;
  if (ans != 0 && ansl != -1 && ansr != -1)
    cout << s.substr(ansl, ansr-ansl+1);
  cout << endl;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
#define INF (int)HUGE_VAL
#define llINF (ll)HUGE_VAL
#define ldINF (ld)HUGE_VAL
#define set(a, x) memset(a, x, sizeof(a));
#define cpy(a, b) memcpy(a, b, sizeof(a));
#define sqr(x) ((x)*(x))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define EPS (1e-7)
#define PI 3.1415926535897932384626433833
#define y1 _y1

string s;
int n;
stack<pii> st;
int cur = 0, curl = -1, tl = 0;
int ans = 0, ansl = -1, ansr = -1;

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin >> s;
  n = s.length();

  for (int i = 0; i < n; ++i)
    if (s[i] == '(' ||
        s[i] == '[') st.push(make_pair(s[i] == '[', i));
    else {
      if (st.empty() ||
          st.top().first != (s[i] == ']')) {
        st = stack<pii>();
        cur = 0;
        curl = -1;
      } else {
        if (s[i] == ']')
          cur++;
        if (curl == -1 || st.top().second < curl)
          curl = st.top().second;
        if (cur >= ans) {
          ans = cur;
          ansl = curl;
          ansr = i;
        }
        st.pop();
      }
    }

  cout << ans << endl;
  if (ans > 0)
    cout << s.substr(ansl, ansr-ansl+1);
  cout << endl;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
#define INF (int)HUGE_VAL
#define llINF (ll)HUGE_VAL
#define ldINF (ld)HUGE_VAL
#define set(a, x) memset(a, x, sizeof(a));
#define cpy(a, b) memcpy(a, b, sizeof(a));
#define sqr(x) ((x)*(x))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define EPS (1e-7)
#define PI 3.1415926535897932384626433833
#define y1 _y1

string s;
int n;
stack<pii> st;
int cur = 0, curl = -1, tl = 0;
int ans = 0, ansl = -1, ansr = -1;

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin >> s;
  n = s.length();

  for (int i = 0; i < n; ++i)
    if (s[i] == '(' ||
        s[i] == '[') st.push(make_pair(s[i] == '[', i));
    else {
      if (st.empty() ||
          st.top().first != (s[i] == ']')) {
        st = stack<pii>();
        cur = 0;
        curl = -1;
      } else {
        if (s[i] == ']') {
          cur++;
          if (curl == -1 || st.top().second < curl)
            curl = st.top().second;
          if (cur > ans) {
            ans = cur;
            ansl = curl;
            ansr = i;
          }
        }
        st.pop();
      }
    }

  cout << ans << endl;
  if (ansl != -1 && ansr != -1)
    cout << s.substr(ansl, ansr-ansl+1);
  cout << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans = 0, tmp = 0, p, alef = -2, arig = -2, lef = -2, rig = -2;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[')p = 2;
		else if (s[i] == ')') p = 3;
		else p = 4;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			st.push(pp);
		}
		else {
			if (st.empty()) {
				tmp = 0;
				continue;
			}
			else {
				if (st.top().first == p - 2) {
					if (rig + 1 == i) {
						tmp += (p == 4);
					}
					else tmp = (p == 4);
					rig = i;
					lef = st.top().second;
					if (arig + 1 == lef) {
						ans += tmp;
						arig = rig;
					}
					if (ans <= tmp) {
						ans = tmp;
						alef = lef;
						arig = rig;
					}
					st.pop();
				}
				else {
					while (!st.empty()) st.pop();
					tmp = 0;
				}
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		for (int i = alef; i <= arig; ++i) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans = 0, tmp = 0, p, alef = -2, arig = -2, lef = -2, rig = -2;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[')p = 2;
		else if (s[i] == ')') p = 3;
		else p = 4;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			st.push(pp);
		}
		else {
			if (st.empty()) {
				tmp = 0;
				continue;
			}
			else {
				if (st.top().first == p - 2) {
					//cout << lef << " " << rig << " " << st.top().second << " " << i << endl;
					if (rig + 1 == i) {
						tmp += (p == 4);
						lef = st.top().second;
						rig = i;
					}
					else if (rig + 1 == st.top().second) {
						tmp += (p == 4);
						rig = i;
					}
					else {
						tmp = (p == 4);
						lef = st.top().second;
						rig = i;
					}
					//cout << s[i] << " " << lef << " " << rig << " " << tmp << endl;
					if (arig + 1 == lef) {
						ans += tmp;
						arig = rig;
					}
					if (ans <= tmp) {
						ans = tmp;
						alef = lef;
						arig = rig;
					}
					st.pop();
				}
				else {
					while (!st.empty()) st.pop();
					tmp = 0;
				}
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		for (int i = alef; i <= arig; ++i) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans = 0, p, tmp = 0, lef = -2, rig = -2;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		PII pp = make_pair(p, i);
		if (p <= 2) st.push(pp);
		else {
			if (st.empty()) continue;
			else if (st.top().first == p - 2) {
				if (p == 4) ++tmp;
				if (st.top().second == rig + 1) {
					ans += tmp;
					rig = i;
				}
				else if (ans <= tmp) {
					ans = tmp;
					lef = st.top().second;
					rig = i;
					tmp = 0;
				}
				st.pop();
			}
			else {
				tmp = 0;
				while (!st.empty()) st.pop();
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		for (int i = lef; i <= rig; ++i) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans = 0, p, tmp = 0, lef = -2, rig = -2;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		PII pp = make_pair(p, i);
		if (p <= 2) st.push(pp);
		else {
			if (st.empty()) continue;
			else if (st.top().first == p - 2) {
				if (p == 4) ++tmp;
				if (st.top().second == rig + 1) {
					ans += tmp;
					rig = i;
				}
				else if (ans <= tmp) {
					ans = tmp;
					lef = st.top().second;
					rig = i;
				}
				st.pop();
			}
			else {
				tmp = 0;
				while (!st.empty()) st.pop();
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		for (int i = lef; i <= rig; ++i) putchar(s[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
char s[MAXN];
int vis[MAXN], oo[MAXN], ooo[MAXN];
stack <PII> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s), p, ans = 0, anss = 0,  cnt = 0, tmp = 0;
	s[len++] = '0';
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		else p = 5;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			ss.push(pp);
		}
		else {
			if (ss.empty()) {
				if (tmp >= ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
			}
			else if (ss.top().first == p - 2) {
				if (p == 4) ++tmp;
				oo[++cnt] = i;
				oo[++cnt] = ss.top().second;
				ss.pop();
			}
			else {
				if (tmp > ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
				while (!ss.empty()) ss.pop();
				tmp = cnt = 0;
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= anss; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len - 1; ++i) if (vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100009;
char s[MAXN];
stack <int> st;
bool vis[MAXN];
int main()
{
	scanf("%s", s);
	memset(vis, 0, sizeof(vis));
	int len = strlen(s);
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(' || s[i] == '[') st.push(i);
		else {
			if (st.empty()) continue;
			if ((s[st.top()] == '(' && s[i] == ')') || (s[st.top()] == '[' && s[i] == ']')) {
				vis[i] = 1;
				vis[st.top()] = 1;
				st.pop();
			}
			else {
				while (!st.empty()) st.pop();
			}
		}
	}
	int ans = 0, lef, rig;
	for (int i = 0; i < len; ++i) {
		if (!vis[i]) continue;
		int j = i, tmp = 0;
		while (j < len && vis[j]) {
			if (s[j] == '[') ++tmp;
			if (tmp >= ans) {
				ans = tmp;
				lef = i;
				rig = j;
			}
			++j;
		}
		i = j - 1;
	}
	printf("%d\n", ans);
	if (ans) {
		for (int i = lef; i <= rig; ++i) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans = 0, tmp = 0, p, alef = -2, arig = -2, lef = -2, rig = -2;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[')p = 2;
		else if (s[i] == ')') p = 3;
		else p = 4;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			st.push(pp);
		}
		else {
			if (st.empty()) {
				tmp = 0;
				continue;
			}
			else {
				if (st.top().first == p - 2) {
					if (rig + 1 == st.top().first) {
						tmp += (p == 4);
					}
					else tmp = (p == 4);
					rig = i;
					lef = st.top().second;
					//cout << s[i] << " " << rig << " " << lef << " " << tmp << endl;
					if (arig + 1 == lef) {
						ans += tmp;
						arig = rig;
					}
					if (ans <= tmp) {
						ans = tmp;
						alef = lef;
						arig = rig;
					}
					st.pop();
				}
				else {
					while (!st.empty()) st.pop();
					tmp = 0;
				}
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		for (int i = alef; i <= arig; ++i) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
char s[MAXN];
int vis[MAXN], oo[MAXN], ooo[MAXN];
stack <PII> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s), p, ans = 0, anss = 0,  cnt = 0, tmp = 0;
	s[len++] = '0';
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		else p = 5;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			ss.push(pp);
		}
		else {
			if (ss.empty()) {
				if (tmp > ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
				cnt = tmp = 0;
			}
			else if (ss.top().first == p - 2) {
				if (p == 4) ++tmp;
				oo[++cnt] = i;
				oo[++cnt] = ss.top().second;
				ss.pop();
			}
			else {
				if (tmp > ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
				while (!ss.empty()) ss.pop();
				tmp = cnt = 0;
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= anss; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len - 1; ++i) if (vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int oo[MAXN], ooo[MAXN], vis[MAXN];
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans1 = 0, ans2 = 0, p, tmp = 0, cnt = 0;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		PII pp = make_pair(p, i);
		if (st.empty()) {
			if (p <= 2) st.push(pp);
			else {
				if (tmp > ans1) {
					ans1 = tmp;
					ans2 = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
				tmp = cnt = 0;
			}
		}
		else {
			if (p <= 2) {
				st.push(pp);
			}
			else {
				if (st.top().first == p - 2) {
					if (p == 4) ++tmp;
					oo[++cnt] = st.top().second;
					oo[++cnt] = i;
					st.pop();
				}
				else {
					if (tmp > ans1) {
						ans1 = tmp;
						ans2 = cnt;
						for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
					}
					while (!st.empty()) st.pop();
					tmp = cnt = 0;
				}
			}
		}
	}
	if (st.empty() && tmp > ans1) {
		ans1 = tmp;
		ans2 = cnt;
		for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
	}
	printf("%d\n", ans1);
	if (ans1) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= ans2; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len; ++i) if(vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int oo[MAXN], ooo[MAXN], vis[MAXN];
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans1 = 0, ans2 = 0, p, tmp = 0, cnt = 0;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		PII pp = make_pair(p, i);
		if (st.empty()) {
			if (p <= 2) st.push(pp);
			else {
				if (tmp > ans1) {
					ans1 = tmp;
					ans2 = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
				tmp = cnt = 0;
			}
		}
		else {
			if (p <= 2) {
				st.push(pp);
			}
			else {
				if (st.top().first == p - 2) {
					if (p == 4) ++tmp;
					oo[++cnt] = st.top().second;
					oo[++cnt] = i;
					st.pop();
				}
				else {
					if (tmp > ans1) {
						ans1 = tmp;
						ans2 = cnt;
						for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
					}
					while (!st.empty()) st.pop();
					tmp = cnt = 0;
				}
			}
		}
	}
	if (tmp > ans1) {
		ans1 = tmp;
		ans2 = cnt;
		for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
	}
	printf("%d\n", ans1);
	if (ans1) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= ans2; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len; ++i) if(vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
char s[MAXN];
int vis[MAXN], oo[MAXN], ooo[MAXN];
stack <PII> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s), p, ans = 0, anss = 0,  cnt = 0, tmp = 0;
	s[len++] = '0';
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		else p = 5;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			ss.push(pp);
		}
		else {
			if (ss.empty()) {
				if (tmp >= ans) {
					ans = tmp;
					anss = cnt;
					for (int j = 1; j <= cnt; ++j) ooo[j] = oo[j];
				}
			}
			else if (ss.top().first == p - 2) {
				if (p == 4) ++tmp;
				oo[++cnt] = i;
				oo[++cnt] = ss.top().second;
				ss.pop();
			}
			else {
				if (tmp > ans) {
					ans = tmp;
					anss = cnt;
					for (int j = 1; j <= cnt; ++j) ooo[j] = oo[j];
				}
				while (!ss.empty()) ss.pop();
				tmp = cnt = 0;
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= anss; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len - 1; ++i) if (vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
char s[MAXN];
int vis[MAXN], oo[MAXN], ooo[MAXN];
stack <PII> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s), p, ans = 0, anss = 0,  cnt = 0, tmp = 0;
	s[len++] = '0';
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		else p = 5;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			ss.push(pp);
		}
		else {
			if (ss.empty()) {
				if (tmp > ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
			}
			else if (ss.top().first == p - 2) {
				if (p == 4) ++tmp;
				oo[++cnt] = i;
				oo[++cnt] = ss.top().second;
				ss.pop();
			}
			else {
				if (tmp > ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
				while (!ss.empty()) ss.pop();
				tmp = cnt = 0;
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= anss; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len - 1; ++i) if (vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int oo[MAXN], ooo[MAXN], vis[MAXN];
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans1 = 0, ans2 = 0, p, tmp = 0, cnt = 0;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		PII pp = make_pair(p, i);
		if (st.empty()) {
			if (p <= 2) st.push(pp);
			else {
				if (tmp > ans1) {
					ans1 = tmp;
					ans2 = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
			}
		}
		else {
			if (p <= 2) {
				st.push(pp);
			}
			else {
				if (st.top().first == p - 2) {
					if (p == 4) ++tmp;
					oo[++cnt] = st.top().second;
					oo[++cnt] = i;
					st.pop();
				}
				else {
					if (tmp > ans1) {
						ans1 = tmp;
						ans2 = cnt;
						for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
					}
					while (!st.empty()) st.pop();
					tmp = cnt = 0;
				}
			}
		}
	}
	if (tmp > ans1) {
		ans1 = tmp;
		ans2 = cnt;
		for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
	}
	printf("%d\n", ans1);
	if (ans1) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= ans2; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len; ++i) if(vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
char s[MAXN];
int vis[MAXN], oo[MAXN], ooo[MAXN];
stack <PII> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s), p, ans = 0, anss = 0,  cnt = 0, tmp = 0;
	s[len++] = '0';
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		else p = 5;
		PII pp = make_pair(p, i);
		if (ss.empty()) {
			if (tmp >= ans) {
				ans = tmp;
				anss = cnt;
				for (int j = 1; j <= cnt; ++j) ooo[j] = oo[j];
			}
		}
		if (p <= 2) {
			ss.push(pp);
		}
		else {
			if (!ss.empty() && ss.top().first == p - 2) {
				if (p == 4) ++tmp;
				oo[++cnt] = ss.top().second;
				oo[++cnt] = i;
				ss.pop();
			}
			else {
				while(!ss.empty()) ss.pop();
				tmp = cnt = 0;
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= anss; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len - 1; ++i) if (vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
char s[MAXN];
int vis[MAXN], oo[MAXN], ooo[MAXN];
stack <PII> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s), p, ans = 0, anss = 0,  cnt = 0, tmp = 0;
	s[len++] = '0';
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		else p = 5;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			ss.push(pp);
		}
		else {
			if (ss.empty()) {
				if (tmp >= ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
			}
			else if (ss.top().first == p - 2) {
				if (p == 4) ++tmp;
				oo[++cnt] = i;
				oo[++cnt] = ss.top().second;
				ss.pop();
			}
			else {
				if (tmp >= ans) {
					ans = tmp;
					anss = cnt;
					for (int i = 1; i <= cnt; ++i) ooo[i] = oo[i];
				}
				while (!ss.empty()) ss.pop();
				tmp = cnt = 0;
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= anss; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len - 1; ++i) if (vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
char s[MAXN];
int vis[MAXN], oo[MAXN], ooo[MAXN];
stack <PII> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s), p, ans = 0, anss = 0,  cnt = 0, tmp = 0;
	s[len++] = '0';
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[') p = 2;
		else if (s[i] == ')') p = 3;
		else if (s[i] == ']') p = 4;
		else p = 5;
		PII pp = make_pair(p, i);
		if (ss.empty()) {
			if (tmp >= ans) {
				ans = tmp;
				anss = cnt;
				for (int j = 1; j <= cnt; ++j) ooo[j] = oo[j];
			}
		}
		if (p <= 2) {
			ss.push(pp);
		}
		else {
			if (!ss.empty() && ss.top().first == p - 2) {
				if (p == 4) ++tmp;
				oo[++cnt] = ss.top().second;
				oo[++cnt] = i;
				ss.pop();
			}
			else if (!ss.empty()){
				while(!ss.empty()) ss.pop();
				tmp = cnt = 0;
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= anss; ++i) vis[ooo[i]] = 1;
		for (int i = 0; i < len - 1; ++i) if (vis[i]) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int MAXN = 100009;
char s[MAXN], oo[MAXN];
int OO[MAXN], OOO[MAXN];
stack <int> ss;
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	s[len++] = '(';
	int ans = 0, tmp = 0, lef = 0, p = 0, cnt = 0;
	while (lef < len) {
		if (s[lef] == '(') p = 1;
		else if (s[lef] == '[') p = 2;
		else if (s[lef] == ')') p = 3;
		else p = 4;
		if (p > 2 && !ss.empty() && ss.top() == p - 2) {
			if (p == 4) ++tmp;
			OOO[++cnt] = p - 2;
			ss.pop();
		} else {
			if (tmp > ans) {
				ans = tmp;
				for (int i = 1; i <= cnt; ++i) OO[i] = OOO[cnt - i + 1];
				OO[0] = cnt;
			}
			if (p > 2) {
				while (!ss.empty()) ss.pop();
				cnt = tmp = 0;
			}
			else ss.push(p);
		}
		++lef;
	}
	for (int i = 1; i <= OO[0]; ++i) {
		if (OO[i] == 1) {
			oo[i - 1] = '(';
			oo[OO[0] * 2 - i] = ')';
		} else {
			oo[i - 1] = '[';
			oo[OO[0] * 2 - i] = ']';
		}
	}
	printf("%d\n", ans);
	if (ans) puts(oo);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> PII;
const int MAXN = 100009;
char s[MAXN];
stack <PII> st;
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	int ans = 0, tmp = 0, p, alef = -2, arig = -2, plef = -2, prig = -2, lef, rig;
	for (int i = 0; i < len; ++i) {
		if (s[i] == '(') p = 1;
		else if (s[i] == '[')p = 2;
		else if (s[i] == ')') p = 3;
		else p = 4;
		PII pp = make_pair(p, i);
		if (p <= 2) {
			st.push(pp);
		}
		else {
			if (st.empty()) {
				tmp = 0;
				continue;
			}
			else {
				if (st.top().first == p - 2) {
					lef = st.top().second;
					rig = i;
					if (prig + 1 == rig) {
						tmp += (p == 4);
					}
					else tmp = (p == 4);
					prig = rig;
					plef = lef;
					if (arig + 1 == plef) {
						ans += tmp;
						arig = prig;
						alef = plef;
					}
					if (ans <= tmp) {
						ans = tmp;
						alef = plef;
						arig = prig;
					}
					st.pop();
				}
				else {
					while (!st.empty()) st.pop();
					tmp = 0;
				}
			}
		}
	}
	printf("%d\n", ans);
	if (ans) {
		for (int i = alef; i <= arig; ++i) putchar(s[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>
#define vp vector<pair<ll,ll>>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s,ans;
    cin >> s;
    stack <ll> idx;
    vp pos;

    for(ll i=0;i<s.size();i++)
    {
        if(idx.empty() || s[i] == '(' || s[i] == '[')
        {
            idx.push(i);
        }
        if(s[i] == ')')
        {
            if(s[idx.top()] == '(')
            {
                pos.push_back(make_pair(idx.top(),i));
                idx.pop();
            }
            else{
                while(!(idx.empty()))
                {
                    idx.pop();
                }
            }
        }
        if(s[i] == ']')
        {
            if (s[idx.top()] == '[')
            {
                pos.push_back(make_pair(idx.top(), i));
                idx.pop();
            }
            else {
                while (!(idx.empty())) {
                    idx.pop();
                }

            }
        }
    }

    ll m=0,start=0,end=0;
    sort(pos.begin(),pos.end());
    for(ll i=1;i<pos.size();i++)
    {
        if(pos[i].first < pos[i-1].second)
        {
            pos[i].first = pos[i-1].first;
            pos[i].second = pos[i-1].second;
            continue;
        }
        if(pos[i].first == pos[i-1].second + 1)
        {
            pos[i].first = pos[i-1].first;
        }
    }

    for(ll i=0;i<pos.size();i++)
    {
        ll x = 0;
        for(ll j=pos[i].first;j<pos[i].second;j++)
        {
            if(s[j] == '[')
            {
                x++;
            }
        }
        if(m < x)
        {
            m = x;
            start = pos[i].first;
            end = pos[i].second;
        }
    }

    for(ll i=start;i<=end;i++)
    {
        ans += s[i];
    }
    if(m) {
        cout << m;
        cout << endl << ans;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll m=0,count=0,state=1;
    string s,temp,fin;
    cin >> s;

    stack<char> st;

    for(ll i=0;i<s.size();i++)
    {
        if(st.empty() || s[i] == '(' || s[i] == '['){
            st.push(s[i]);
            temp+=s[i];
            state = 1;
        }
        else if(s[i] == ')'){
            if(st.top() == '('){
                state = 1;
                temp+=')';
                st.pop();
                if(m < count){
                    m = count;
                    fin = temp;
                }
                continue;
            }
            count = 0;
            state = 0;
            temp.erase(temp.begin(),temp.end());
        }
        else if(s[i] == ']'){
            if(st.top() == '['){
                state = 1;
                temp+=']';
                count++;
                st.pop();
                if(m < count){
                    m = count;
                    fin = temp;
                }
                continue;
            }
            count = 0;
            state = 0;
            temp.erase(temp.begin(),temp.end());
        }
    }
    if(m <= count && state){
        m = count;
        fin = temp;
    }
    if(m) {
        cout << m << endl << fin;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll m=0,count=0;
    string s,temp;
    cin >> s;

    stack<char> st;

    for(ll i=0;i<s.size();i++)
    {
        if(st.empty() || s[i] == '(' || s[i] == '['){
            st.push(s[i]);
            temp+=s[i];
        }
        else if(s[i] == ')'){
            if(st.top() == '('){
                temp+=')';
                st.pop();
                continue;
            }
            m = max(m,count);
            count = 0;
            temp.erase(temp.begin(),temp.end());
        }
        else if(s[i] == ']'){
            if(st.top() == '['){
                temp+=']';
                count++;
                st.pop();
                continue;
            }
            m = max(m,count);
            count = 0;
            temp.erase(temp.begin(),temp.end());
        }
        m = max(m,count);
    }
    m = max(m,count);
    if(m) {
        cout << m << endl << temp;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>
#define vp vector<pair<ll,ll>>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s,ans;
    cin >> s;
    stack <ll> idx;
    vp pos;

    for(ll i=0;i<s.size();i++)
    {
        if(idx.empty() || s[i] == '(' || s[i] == '[')
        {
            idx.push(i);
        }
        if(s[i] == ')')
        {
            if(s[idx.top()] == '(')
            {
                pos.push_back(make_pair(idx.top(),i));
                idx.pop();
            }
            else{
                while(!(idx.empty()))
                {
                    idx.pop();
                }
            }
        }
        if(s[i] == ']')
        {
            if (s[idx.top()] == '[')
            {
                pos.push_back(make_pair(idx.top(), i));
                idx.pop();
            }
            else {
                while (!(idx.empty())) {
                    idx.pop();
                }

            }
        }
    }

    ll m=0,start=0,end=0,prev=0;
    sort(pos.begin(),pos.end());
    for(ll i=1;i<pos.size();i++)
    {
        if(pos[i].first < pos[prev].second)
        {
            continue;
        }
        if(pos[i].first == pos[prev].second + 1)
        {
            pos[i].first = pos[prev].first;
            prev = i;
        }
    }

    for(ll i=0;i<pos.size();i++)
    {
        ll x = 0;
        for(ll j=pos[i].first;j<pos[i].second;j++)
        {
            if(s[j] == '[')
            {
                x++;
            }
        }
        if(m < x)
        {
            m = x;
            start = pos[i].first;
            end = pos[i].second;
        }
    }

    for(ll i=start;i<=end;i++)
    {
        ans += s[i];
    }
    if(m) {
        cout << m;
        cout << endl << ans;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll m=0,count=0;
    string s,temp,fin;
    cin >> s;

    stack<char> st;

    for(ll i=0;i<s.size();i++)
    {
        if(st.empty() || s[i] == '(' || s[i] == '['){
            st.push(s[i]);
            temp+=s[i];
        }
        else if(s[i] == ')'){
            if(st.top() == '('){
                temp+=')';
                st.pop();
                continue;
            }
            if(m < count){
                m = count;
                fin = temp;
            }
            count = 0;
            temp.erase(temp.begin(),temp.end());
        }
        else if(s[i] == ']'){
            if(st.top() == '['){
                temp+=']';
                count++;
                st.pop();
                continue;
            }
            if(m < count){
                m = count;
                fin = temp;
            }
            count = 0;
            temp.erase(temp.begin(),temp.end());
        }
        m = max(m,count);
    }
    if(m < count){
        m = count;
        fin = temp;
    }
    if(m) {
        cout << m << endl << fin;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll m=0,count=0;
    string s,temp,fin;
    cin >> s;

    stack<char> st;

    for(ll i=0;i<s.size();i++)
    {
        if(st.empty() || s[i] == '(' || s[i] == '['){
            st.push(s[i]);
            temp+=s[i];
        }
        else if(s[i] == ')'){
            if(st.top() == '('){
                temp+=')';
                st.pop();
                if(m < count){
                    m = count;
                    fin = temp;
                }
                continue;
            }
            count = 0;
            temp.erase(temp.begin(),temp.end());
        }
        else if(s[i] == ']'){
            if(st.top() == '['){
                temp+=']';
                count++;
                st.pop();
                if(m < count){
                    m = count;
                    fin = temp;
                }
                continue;
            }
            count = 0;
            temp.erase(temp.begin(),temp.end());
        }
    }
    if(m < count){
        m = count;
        fin = temp;
    }
    if(m) {
        cout << m << endl << fin;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>
#define vp vector<pair<ll,ll>>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s,ans;
    cin >> s;
    stack <ll> idx;
    v pos(s.size() + 10);

    for(ll i=0;i<s.size();i++)
    {
        if(idx.empty() || s[i] == '(' || s[i] == '[')
        {
            idx.push(i);
        }
        if(s[i] == ')')
        {
            if(s[idx.top()] == '(')
            {
                pos[idx.top()] = 1;
                pos[i] = 1;
                idx.pop();
            }
            else{
                while(!(idx.empty()))
                {
                    idx.pop();
                }
            }
        }
        if(s[i] == ']')
        {
            if (s[idx.top()] == '[')
            {
                pos[idx.top()] = 1;
                pos[i] = 1;
                idx.pop();
            }
            else {
                while (!(idx.empty())) {
                    idx.pop();
                }

            }
        }
    }

    ll m=0,start=0,end=0;

    for(ll i=0;i<s.size()+1;i++)
    {
        ll j = i,count=0;
        for(;pos[j] == 1;j++);

        for(ll k =i;k<j;k++)
        {
            if(s[k] == '[')
            {
                count++;
            }
        }

        if(m < count)
        {
            m = count;
            start = i;
            end = j-1;
        }
        i = j;
    }

    for(ll i=start;i<=end;i++)
    {
        ans += s[i];
    }
    if(m) {
        cout << m;
        cout << endl << ans;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vv vector<v>
#define vvs vector<vs>
#define vu vector<lu>
#define vld vector<ld>
#define vs vector<string>
#define vb vector<bool>
#define vp vector<pair<ll,ll>>

void swap(ll *x,ll *y)
{
    ll temp = *x;
    *x = *y;
    *y = temp;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s,ans;
    cin >> s;
    stack <ll> idx;
    vp pos;

    for(ll i=0;i<s.size();i++)
    {
        if(idx.empty() || s[i] == '(' || s[i] == '[')
        {
            idx.push(i);
        }
        if(s[i] == ')')
        {
            if(s[idx.top()] == '(')
            {
                pos.push_back(make_pair(idx.top(),i));
                idx.pop();
            }
            else{
                while(!(idx.empty()))
                {
                    idx.pop();
                }
            }
        }
        if(s[i] == ']')
        {
            if (s[idx.top()] == '[')
            {
                pos.push_back(make_pair(idx.top(), i));
                idx.pop();
            }
            else {
                while (!(idx.empty())) {
                    idx.pop();
                }

            }
        }
    }

    for(ll i=1;i<pos.size();i++)
    {
        if(pos[i-1].second == pos[i].first - 1 )
        {
            pos[i].first = pos[i-1].first;
        }
    }

    ll m=0,start=0,end=0;

    for(ll i=0;i<pos.size();i++)
    {
        ll x = 0;
        for(ll j=pos[i].first;j<pos[i].second;j++)
        {
            if(s[j] == '[')
            {
                x++;
            }
        }
        if(m < x)
        {
            m = x;
            start = pos[i].first;
            end = pos[i].second;
        }
    }

    for(ll i=start;i<=end;i++)
    {
        ans += s[i];
    }
    if(m) {
        cout << m;
        cout << endl << ans;
    }
    else{
        cout << 0;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define floop(i,a,b) for(int i=a;i<=b;++i)
const ll mod=1e9+7;
const int maxn=1e5+5;
int dp[maxn];
int main(){
	IOS;
	string s;
	cin>>s;
	int n=s.size();
	for (int i = 0; i < n; ++i)
	{
		if(s[i]=='[') dp[i+1]=1+dp[i];
		else dp[i+1]=dp[i];
	}
	int ans=0;
	int l=1,r=1;
	int a=0,b=0;
	vector<int>v(n+1,0);
	for (int i = 0; i < n; ++i)
	{
		if(s[i]=='(') v[i+1]=1;
		if(s[i]==')') v[i+1]=-1;
		if(s[i]=='[') v[i+1]=2;
		if(s[i]==']') v[i+1]=-2;
	}
	int i=1;
	while(i<=n){
		if(v[i]<0) {
			i++;
			continue;
		}
		a=0,b=0;
		int st=i,en=i;
		while(i<=n){
			if(v[i]==1) a++;
			if(v[i]==2) b++;
			if(v[i]==-1) a--;
			if(v[i]==-2) b--;
			if(b<0 or a<0) {
				if(en>st and ans<dp[en]-dp[st-1]) {
					ans=dp[en]-dp[st-1];
					l=st;
					r=en;
				}
				break;
			}
			if(a==0 and b==0) en=i;
			i++;
		}
	}
	i=n;
	a=0,b=0;
	int st=n,en=n;
	while(i>0){
		if(v[i]==1) a--;
		if(v[i]==2) b--;
		if(v[i]==-1) a++;
		if(v[i]==-2) b++;
		if(b<0 or a<0) {
			if(en>st and ans<dp[en]-dp[st-1]) {
				ans=dp[en]-dp[st-1];
				l=st;
				r=en;
			}
			break;
		}
		if(a==0 and b==0) st=i;
		i--;
	}
	if(i==0 and a==0 and b==0) {
		ans=dp[n]-dp[0];
		l=1,r=n;
	}
	cout<<ans<<endl;
	if(ans>0){
		floop(j,l-1,r-1){
			cout<<s[j];
		}
		cout<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define floop(i,a,b) for(int i=a;i<=b;++i)
const ll mod=1e9+7;
const int maxn=2e5+5;
int32_t main(){
	IOS;
	string s;
	cin>>s;
	int n=s.size();
	pair<int,int>ans={0,0};
	int curr=0;
	for (int i = 0; i < n; ++i)
	{
		int a=0,b=0,val=0,st=i;
		if(s[i]==')' or s[i]==']') continue;
		while(i<n){
			if(s[i]=='(') a++;
			else if(s[i]=='[') b++;
			else if(s[i]==')') a--;
			else b--;
			val=max(val,b);
			if(a==0 and b==0) break;
			i++;
		}
		if(a==0 and b==0 and curr<val) {
			curr=val;
			ans={st,i-st+1};
		}
	}
	// cout<<2<<endl;
	cout<<curr<<endl;
	cout<<s.substr(ans.first,ans.second)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define floop(i,a,b) for(int i=a;i<=b;++i)
const ll mod=1e9+7;
const int maxn=2e5+5;
int a[maxn],c[maxn];
int32_t main(){
	IOS;
	string st;
	cin>>st;
	int n=st.size();
	stack<int>s;
	vector<int>b;
	for(auto it:st){
		if(it=='(') b.emplace_back(1);
		if(it==')') b.emplace_back(-1);
		if(it=='[') b.emplace_back(2);
		if(it==']') b.emplace_back(-2);
	}
	for (int i = 0; i < n; ++i)
	{
		if(s.empty() or b[s.top()]+b[i]!=0 or b[i]>0) s.push(i);
		else {
			a[s.top()]=i;
			a[i]=s.top();
			s.pop();
		}
	}
	floop(i,1,n-1) {
		c[i]=c[i-1];
		if(st[i-1]=='[') c[i]++;
	}
	for(int i=n-2;i>=0;--i){
		if(a[i]<=i) continue;
		if(a[i]>=n-1) continue;
		if(a[a[i]+1] <= a[i]+1) continue;
		a[i] = a[a[i]+1];
	}
	int ans=0,len=0;
	int val=0;
	for (int i = 0; i < n; ++i)
	{
		if(a[i]<=i) continue;
		if(val < c[a[i]]-c[i]){
			val=c[a[i]]-c[i];
			ans=i;
			len=a[i]-i+1;
		}
	}
	cout<<val<<endl;
	cout<<st.substr(ans,len)<<endl;
	return 0;
}


#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define flush fflush(stdout)
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

bool isopen(char x) {
	return x == '(' || x == '[';
}

bool match(char x, char y) {
	return (x == '[' && y == ']') || (x == '(' && y == ')');
}

int main() {
	PLAY();

	string s;
	cin >> s;
	stack<pair<char, pair<int, int>>> st;
	int start = -1, cur = 0, mx = 0;
	int idx1 = 0, idx2 = 0;
	for (int i = 0; i < sz(s); i++) {
		cur += s[i] == '[';
		if (isopen(s[i]))
			st.push(make_pair(s[i], make_pair(i, cur)));
		else {
			if (!sz(st) || !match(st.top().first, s[i])) {
				while (sz(st)) st.pop();
				cur = 0;
				start = i;
			}
			else if (match(st.top().first, s[i])) {
				st.pop();
				if (sz(st)) {
					int top = st.top().second.second;
					if (cur - top > mx) {
						mx = cur - top;
						idx1 = st.top().second.first + 1;
						idx2 = i;
					}
				}
				else
					if (cur > mx) {
						mx = cur;
						idx1 = start + 1;
						idx2 = i;
					}
			}
		}
	}
	cout << mx << endl;
	if (idx1 != idx2)
		cout << s.substr(idx1, (idx2 - idx1) + 1) << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<ll,p2> p3;
typedef vector<int> vi;
const ll Mod = 7 + 1e9;
const ll INF32 = 5 + 2e9;
const ll INF64 = 1 + 1e15;
const ll MAX = 5+ 3e5;

int N,jump[MAX];
string a;
vector<p2> r;

bool cmp(p2 a,p2 b)
{
    return a.sc-a.fr < b.sc-b.fr;
}
bool iscorrect(int l,int r)
{
    int s=0;
    for(int i=l; i<=r; i++)
        if( jump[i] )
        {
            if( jump[i] == -1 )
                return 0;
            i=jump[i];
        }
        else if( a[i] == '(' )
            s++;
        else if( s==0 )
            return 0;
        else
            s--;
    return !s;
}
stack<int> s;
int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
    cin >> a;
    N = a.size();
    for(int i=0; i<N; i++)
        if( a[i] == '[' )
            s.push(i);
        else if( a[i] == ']' && s.size()>0 )
        {
            r.push_back( p2( s.top(),i ) );
            s.pop();
        }

    sort(r.begin(),r.end(),cmp);
    for(auto x : r)
    {
        bool res = iscorrect(x.fr+1,x.sc-1);
        if( res )
            jump[ x.fr ] = x.sc;
        else
            jump[x.fr] = -1;
    }
    int mx = 0;
    p2 ans = p2(0,0);
    for(int i=r.size() -1; i>=0; i--)
        if( jump[ r[i].fr ] > 0 )
        {
            int cnt = 0;
            for(int j=r[i].fr;j<=r[i].sc;j++)
                if( a[j] == '[' )
                cnt++;
            if( mx < cnt )
                mx = cnt,ans = r[i];
        }
    cout << mx << endl;
    if(mx)
    cout << a.substr(ans.fr,ans.sc-ans.fr+1) << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<ll,p2> p3;
typedef vector<int> vi;
const ll Mod = 7 + 1e9;
const ll INF32 = 5 + 2e9;
const ll INF64 = 1 + 1e15;
const ll MAX = 5+ 3e5;

int N,jump[MAX];
string a;
vector<p2> r;

bool cmp(p2 a,p2 b)
{
    return a.sc-a.fr < b.sc-b.fr;
}
bool iscorrect(int l,int r)
{
    int s=0;
    for(int i=l; i<=r; i++)
        if( jump[i] )
        {
            if( jump[i] == -1 )
                return 0;
            i=jump[i];
        }
        else if( a[i] == '(' )
            s++;
        else if( s==0 )
            return 0;
        else
            s--;
    return !s;
}
stack<int> s,ss;
int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
    cin >> a;
    N = a.size();
    for(int i=0; i<N; i++)
        if( a[i] == '[' )
            s.push(i);
        else if( a[i] == ']' && s.size()>0 )
        {
            r.push_back( p2( s.top(),i ) );
            s.pop();
        }
        else if( a[i] == '(' )
            ss.push(i);
        else if( a[i] == ')' && ss.size() >0 )
        {
            r.push_back( p2( ss.top(),i ) );
            ss.pop();
        }
    sort(r.begin(),r.end(),cmp);
    for(auto x : r)
    {
        bool res = iscorrect(x.fr+1,x.sc-1);
        if( res )
            jump[ x.fr ] = x.sc;
        else
            jump[x.fr] = -1;
    }

    int mx = 0;
    p2 ans = p2(0,0);
    for(int i=r.size() -1; i>=0; i--)
        if( jump[ r[i].fr ] > 0 )
        {
            for(int j=r[i].fr; j<=r[i].sc; j++)
                jump[j] = -2;
        }
    for(int i=0; i<N; i++)
        if( jump[i] == -2 )
        {
            int j=i,cnt = 0;
            for(; j<N && jump[j] == -2; j++)
                if( a[j] == '[' )
                    cnt++;
            if(mx < cnt)
                mx = cnt,ans = p2( i,j );
            i=j-1;
        }

    cout << mx << endl;
    if(mx)
        cout << a.substr(ans.fr,ans.sc-ans.fr) << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<ll,p2> p3;
typedef vector<int> vi;
const ll Mod = 7 + 1e9;
const ll INF32 = 5 + 2e9;
const ll INF64 = 1 + 1e15;
const ll MAX = 5+ 3e5;

int N,jump[MAX];
string a;
vector<p2> r;

bool cmp(p2 a,p2 b)
{
    return a.sc-a.fr < b.sc-b.fr;
}
bool iscorrect(int l,int r)
{
    int s=0;
    for(int i=l; i<=r; i++)
        if( jump[i] )
        {
            if( jump[i] == -1 )
                return 0;
            i=jump[i];
        }
        else if( a[i] == '(' )
            s++;
        else if( s==0 )
            return 0;
        else
            s--;
    return !s;
}
stack<int> s;
int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
    cin >> a;
    N = a.size();
    for(int i=0; i<N; i++)
        if( a[i] == '[' )
            s.push(i);
        else if( a[i] == ']' && s.size()>0 )
        {
            r.push_back( p2( s.top(),i ) );
            s.pop();
        }

    sort(r.begin(),r.end(),cmp);
    for(auto x : r)
    {
        bool res = iscorrect(x.fr+1,x.sc-1);
        if( res )
            jump[ x.fr ] = x.sc;
        else
            jump[x.fr] = -1;
    }
    int mx = 0;
    p2 ans = p2(0,0);
    for(int i=r.size() -1; i>=0; i--)
        if( jump[ r[i].fr ] > 0 )
        {
            for(int j=r[i].fr;j<=r[i].sc;j++)
                jump[j] = -2;
        }
    for(int i=0;i<N;i++)
        if( jump[i] == -2 )
        {
            int j=i,cnt = 0;
            for(;j<N && jump[j] == -2;j++)
                if( a[j] == '[' )
                cnt++;
            if(mx < cnt)
            mx = cnt,ans = p2( i,j );
            i=j-1;
        }

    cout << mx << endl;
    if(mx)
    cout << a.substr(ans.fr,ans.sc-ans.fr) << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<ll,p2> p3;
typedef vector<int> vi;
const ll Mod = 7 + 1e9;
const ll INF32 = 5 + 2e9;
const ll INF64 = 1 + 1e15;
const ll MAX = 5+ 3e5;

int N,jump[MAX];
string a;
vector<p2> r;

bool cmp(p2 a,p2 b)
{
    return a.sc-a.fr < b.sc-b.fr;
}
bool iscorrect(int l,int r)
{
    if( r == l-1 )
        return 1;
    stack<char> s;
    for(int i=l; i<=r; i++)
        if( jump[i] )
        {
            if( jump[i] == -1 )
                return 0;
            i=jump[i];
        }
        else if( a[i] == '(' )
            s.push('(');
        else if( s.empty() || s.top() == a[i] )
            return 0;
        else
            s.pop();
    return s.empty();
}
stack<int> s;
int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
    cin >> a;
    N = a.size();
    for(int i=0; i<N; i++)
        if( a[i] == '[' )
            s.push(i);
        else if( a[i] == ']' && s.size()>0 )
        {
            r.push_back( p2( s.top(),i ) );
            s.pop();
        }

    sort(r.begin(),r.end(),cmp);
    for(auto x : r)
    {
        bool res = iscorrect(x.fr+1,x.sc-1);
        if( res )
            jump[ x.fr ] = x.sc;
        else
            jump[x.fr] = -1;
    }
    int mx = 0;
    p2 ans = p2(0,0);
    for(int i=r.size() -1; i>=0; i--)
        if( jump[ r[i].fr ] > 0 )
        {
            int cnt = 0;
            for(int j=r[i].fr;j<=r[i].sc;j++)
                if( a[j] == '[' )
                cnt++;
            if( mx < cnt )
                mx = cnt,ans = r[i];
        }
    cout << mx << endl;
    if(mx)
    cout << a.substr(ans.fr,ans.sc-ans.fr+1) << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+9;
string s;
int l,r,st[MAX],t=1,cnt[MAX],ans;
int main()
{
	//freopen("stdin.inp", "r", stdin);
	//freopen("stdout.out", "w", stdout);
	cin>>s;
	s+='s';
	for (int i=s.size() - 1;i>=1;i--) {
		s[i]=s[i-1];
	}
	s[0]=' ';
	for (int i=1;i<s.size();i++)
	{
		cnt[i]=cnt[i-1]+(s[i]=='[');
		if (s[i]=='[' || s[i]=='(') st[t++]=i;	else
		if (s[i]==']' && s[st[t-1]]!='[' || s[i]==')' && s[st[t-1]]!='(') t=0,st[t++]=i; else
		{
			t--;
			if (ans<cnt[i]-cnt[st[t-1]]) ans=cnt[i]-cnt[st[t-1]],l=st[t-1],r=i;
		}
	}
	cout<<ans<<'\n'<<s.substr(l+1,r-l);
}


#include <bits/stdc++.h>

using namespace std;
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define revforl(i,n) for(int i=n-1;i>=0;i--)
#define revfore(i,n) for(int i=n;i>0;i--)
#define vi vector<int>
#define vvi vector<vector<int>>
#define li long int
#define lli long long int
#define mp make_pair
#define pb push_back
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define MAXN 1e5
#define LIMIT 1000000
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int bs_lowerbound(int a[],int n,int x){
    int l=0;
    int h=n-1;
    while(l<=h){
        int mid=(l+h)/2;
        if(x>a[mid]) l=mid+1;
        else h=mid-1;
    }
    return l;
}
int bs_upperbound(int a[],int n,int x){
    int l=0;
    int h=n-1;
    while(l<=h){
        int mid=(l+h)/2;
        if(x<a[mid]) h=mid-1;
        else l=mid+1;
    }
    return h;
}

int prime_flag[LIMIT];
void calcprime_flag(){
    prime_flag[0]=1;
    prime_flag[1]=1;
    for(long long int i=2;i*i<LIMIT;i++){
        if(!prime_flag[i]){
            for(long long int j=i*i;j<LIMIT;j+=i){
                prime_flag[j]=1;
            }
        }
    }
}

int check_perfect_square(long long n){
    double sqrt1=sqrt(n);
    if(sqrt1==int(sqrt(n))) return 1;
    else return 0;
}

bool is_integer(float k)
{
    return floor(k) == k;
}

bool vis[LIMIT];
int solve(){
    //CODE HERE
    string s; cin>>s;
    memset(vis,0,sizeof(vis));
    stack<int> br;
    vector<pair<int,int>>p;
    int n=s.length();
    forl(i,n){
        if(s[i]=='(' || s[i]=='[') br.push(i);
        else{
            if(br.empty()) continue;
            if((s[i]==')' && s[br.top()]=='(') || (s[i]==']' && s[br.top()]=='[')){
                vis[i]=1;vis[br.top()]=1;
                br.pop();
            }
            else{
                while(!br.empty()) br.pop();
            }
        }
    }
    int ans=0,lef,rig;
    forl(i,n){
        if(!vis[i]) continue;
        int j=i,tmp=0;
        while(vis[j] && j<n){
            if(s[j]=='[') tmp++;
            if(tmp>=ans){
                ans=tmp;
                lef=i;
                rig=j;
            }
            j++;
        }
       // p.pb(mp(lef,rig));
        i=j;
    }
    cout<<ans<<endl;
   // for(int i=0;i<p.size();i++){
        for(int j=lef;j<=rig;j++){
            cout<<s[j];
        }
    //}
    cout<<endl;

}

int main()
{
    IOS
    int T;
    //cin>>T;
    fore(t,1)
    {
       // CASE(t);
        solve();
    }
}