/*
*State: cchun	 C - Bracket Sequence	 MS C++	Accepted	46 ms
*题目大意：
*		给定一个括号序列，序列只有"[]"和"()",这个括号序列可能不正确，
*		求出其正确子序列中含最多"[]"的子序列
*解题思路：
*		运用栈。
*		//第一次判断是否是左括号
*		//第二次判断是否是右括号
*		//第三次判断是更新解，还是清空栈（栈里面只保存左括号）
*解题感想：
*		//括号匹配
*		//很值得细细品味的题目，我自己写的烂透了
*		//看别人分析题目分析得到尾，直接三次判断就过了，
*		//只能说各种优雅了
*		我还用了树状数组，其实是没有必要的。直接用一个数组标志下就行了。
*/

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <iomanip>

#define pi 3.1415926535897932
#define abs(x) ((x)>0?(x):-(x))
#define sqr(x) ((x)*(x))
#define fill(m,v) memset(m,v,sizeof(m))
#define SS(x) scanf("%d",&x)
#define SP(x) printf("%d\n",x)

#define inf 0x7fffffff
#define hinf 0x3f3f3f3f
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define y0 stupid_cmath
#define y1 very_stupid_cmath
#define ll __int64
#define ull unsigned __int64
#define pb push_back
#define mp make_pair
#define FOR(i,a,b)		for(int i=(a); i<(b);i++)
#define FF(i,a)			for(int i=0; i<(a);i++)
#define FFD(i,a)		for(int i=(a)-1; i>=0;i--)
#define CC(m,what)		memset(m,what,sizeof(m))
#define SZ(a)			((int)a.size())
#define viewPP(a,n,m)	{puts("---");FF(i,n){FF(j,m) cout<<a[i][j] <<' ';puts("");}}
#define viewP(a, n)     {FF(i, n) {cout<<a[i]<<" ";} puts("");}

#define read			freopen("in.txt","r",stdin)
#define write			freopen("out.txt","w",stdout)
const double eps = 1e-11;
int dx[] = {-1, 0, 1, 0};//up Right down Left
int dy[] = {0,  1, 0, -1};

using namespace std;
const int maxn = 100005;
string str;
int nstr[maxn];
int tree[maxn];
typedef struct _node {
	int f, i;
	_node() {}
	_node(int _f, int _i): f(_f), i(_i) {}
}N;

inline int lowbit(int x) {
	return x&(-x);
}

void add(int ind) {
	for(int i = ind; i < maxn; i += lowbit(i)) {
		tree[i] += 1;
	}
}

int get_sum(int ind) {
	int sum = 0;
	for(int i = ind; i >= 1; i -= lowbit(i)) {
		sum += tree[i];
	}
	return sum;
}

void init() {
	memset(nstr, 0, sizeof(nstr));
	memset(tree, 0, sizeof(tree));
}

bool match(int i, int j) {
	if((str[i] == '(' && str[j] == ')') ||
		(str[i] == '[' && str[j] == ']'))
		return true;
	return false;
}

void solve() {
	stack<N> S;
	int Max = -1, s, e, LL = -1;
	for(unsigned i = 0; i < str.length(); i++) {
		if(nstr[i] == 2) add(i+1);
		if(nstr[i] > 0) //左括号
			S.push(N(nstr[i], i));
		else if(nstr[i] < 0) {
			if(!S.empty() && match(S.top().i, i)) {
				S.pop();
				int t = S.empty() ? LL : S.top().i;
				int ans = get_sum(i+1)-get_sum(t+1);
				if(ans > Max) {
					Max = ans;
					s = t+1, e = i;
				}
			}
			else {
				while(!S.empty()) S.pop();
				LL = i;
			}
		}
	}
	if(Max == -1) cout << "0" << endl;
	else {
		cout << Max << endl;
		cout << string(str.begin()+s, str.begin()+e+1) << endl;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	while(cin >> str) {

		init();
		FF(i, str.length()) {
			if(str[i] == '[')
				nstr[i] = 2;
			else if(str[i] == ']')
				nstr[i] = -2;
			else if(str[i] == '(')
				nstr[i] = 1;
			else nstr[i] = -1;
		}
		solve();
	}
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <assert.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <math.h>
using namespace std;
int main( )
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    vector<int> stck;
    string s,s1;
    cin >> s1;
    s.resize(s1.size());
    for (int i = 0; i< s1.size(); i++)
        if (s1[i] == '(')
            s[i] = 1;
        else if (s1[i] == '[')
            s[i] = 2;
        else if (s1[i] == ')')
            s[i] = -1;
        else if (s1[i] == ']')
            s[i] = -2;
    int n = s.size();
    int ansl = 0,ansr = 0;
    int l = 0,r = 0;
    int cnt = 0;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 1 || s[i] == 2)
            stck.push_back (s[i]);
        else
        {
            if (stck.empty())
            {
                cnt = 0;
                l = i + 1;
                r = i + 1;
            }
            else
            {
                if (stck.back() != -s[i])
                {
                    cnt = 0;
                    l = i + 1;
                    r = i + 1;
                    stck.clear();
                }
                else
                {
                    if (s[i] == -2)
                        cnt++;
                    stck.pop_back();
                }
            }
        }
        if (cnt > mx)
        {
            mx = cnt;
            ansl = l + stck.size();
            ansr = r;
        }
        r = i + 1;
    }
    if (mx == 0)
        printf ("0");
    else
        printf ("%d\n%s",mx,s1.substr(ansl,ansr - ansl + 1).c_str());
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <assert.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <math.h>
using namespace std;
char mark[100001] = {0};
int main( )
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    vector<pair<int,int> > stck;
    string s,s1;
    cin >> s1;
    s.resize(s1.size());
    for (int i = 0; i< s1.size(); i++)
        if (s1[i] == '(')
            s[i] = 1;
        else if (s1[i] == '[')
            s[i] = 2;
        else if (s1[i] == ')')
            s[i] = -1;
        else if (s1[i] == ']')
            s[i] = -2;
    int n = s.size();
    int ansl = 0,ansr = 0;
   // int l = 0,r = 0;
   // int cnt = 0;
    //int mx = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 1 || s[i] == 2)
            stck.push_back (make_pair(s[i],i));
        else
        {
            if (stck.empty())
            {
                continue;
            }
            else
            {
                if (stck.back().first != -s[i])
                {
                    stck.clear();
                }
                else
                {
                    mark[stck.back().second] = 1;
                    mark[i] = 1;
                    stck.pop_back();
                }
            }
        }
    }
    int mx = 0;
    int cnt = 0;
    int l = 0;
    int r = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (mark[i] == 0)
        {
            cnt = 0;
            l = i + 1;
            r = i + 1;
        }
        else
        {
            if (s1[i] == '[')
                cnt++;
            r++;
        }
        if (cnt >= mx)
        {
            mx = cnt;
            ansl = l;
            ansr = r;
        }
    }
    if (mx == 0)
        printf ("0");
    else
        printf ("%d\n%s",mx,s1.substr(ansl,ansr - ansl).c_str());
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <assert.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <math.h>
using namespace std;
int main( )
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    vector<int> stck;
    string s,s1;
    cin >> s1;
    s.resize(s1.size());
    for (int i = 0; i< s1.size(); i++)
        if (s1[i] == '(')
            s[i] = 1;
        else if (s1[i] == '[')
            s[i] = 2;
        else if (s1[i] == ')')
            s[i] = -1;
        else if (s1[i] == ']')
            s[i] = -2;
    int n = s.size();
    int ansl = 0,ansr = 0;
    int l = 0,r = 0;
    int cnt = 0;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 1 || s[i] == 2)
            stck.push_back (s[i]);
        else
        {
            if (stck.empty())
            {
                cnt = 0;
                l = i + 1;
                r = i + 1;
            }
            else
            {
                if (stck.back() != -s[i])
                {
                    cnt = 0;
                    l = i + 1;
                    r = i + 1;
                    stck.clear();
                }
                else
                {
                    if (s[i] == -2)
                        cnt++;
                    stck.pop_back();
                }
            }
        }
        if (cnt > mx)
        {
            mx = cnt;
            ansl = l + stck.size();
            ansr = r;
        }
        r = i;
    }
    if (mx == 0)
        printf ("0");
    else
        printf ("%d\n%s",mx,s1.substr(ansl,ansr - ansl + 2).c_str());
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <assert.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <math.h>
using namespace std;
int main( )
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    vector<int> stck;
    string s,s1;
    cin >> s1;
    s.resize(s1.size());
    for (int i = 0; i< s1.size(); i++)
        if (s1[i] == '(')
            s[i] = 1;
        else if (s1[i] == '[')
            s[i] = 2;
        else if (s1[i] == ')')
            s[i] = -1;
        else if (s1[i] == ']')
            s[i] = -2;
    int n = s.size();
    int ansl = 0,ansr = 0;
    int l = 0,r = 0;
    int cnt = 0;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 1 || s[i] == 2)
            stck.push_back (s[i]);
        else
        {
            if (stck.empty())
            {
                cnt = 0;
                l = i + 1;
                r = i + 1;
            }
            else
            {
                if (stck.back() != -s[i])
                {
                    cnt = 0;
                    l = i + 1;
                    r = i + 1;
                }
                else
                {
                    if (s[i] == -2)
                        cnt++;
                    stck.pop_back();
                }
            }
        }
        if (cnt > mx)
        {
            mx = cnt;
            ansl = l + stck.size();
            ansr = r;
        }
        r++;
    }
    if (cnt == 0)
        printf ("0");
    else
        printf ("%d\n%s",cnt,s1.substr(ansl,ansr).c_str());
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
using namespace std;

#define PI acos(-1.0)
typedef long long ll;
struct stu
{
	char s;
	int i;
}stak[100001];
int main(){
	char arr[100001];
	int i,g=0,all=0,h=-1,nall=0,nh=0,ne=-1;
	i=0;
	bool flag[100001]={0};
	scanf("%s",arr);
	while(arr[i])
	{
		if(arr[i]=='(' || arr[i]=='[')
		{
			stak[g].s=arr[i];
			stak[g++].i=i;
		}
		else
		{
			if(g>0)
			{
				if(arr[i]==')')
				{
					if(stak[g-1].s == '(')
					{
						flag[i]=1;
						flag[stak[g-1].i]=1;
						g--;
					}
					else g=0;

				}
				else
				{
					if(arr[i] == ']')
					{
						if(stak[g-1].s == '[')
						{
							flag[i]=1;
							flag[stak[g-1].i]=1;
							g--;
						}
						else g=0;
					}
				}
			}
		}
		i++;
	}
	//for(i=0;arr[i];i++)
	//{
	//	printf("%d ",flag[i]);
	//}
	//printf("\n");
	bool si=0;
	for( i=0; arr[i] ;i++)
	{
		if(flag[i]==1)
		{
			if(si==0)h=i;
			si=1;
			if(arr[i]=='[')nall++;
		}
		else
		{

			if(nall>all ||(nall == all && si==1))
			{
				all=nall;
				nh=h;
				ne=i-1;
			}
			si=0;
			h=i+1;
			nall=0;
		}
	}
	if(nall> all ||(nall == all && si==1))
	{
		all=nall;
		nh=h;
		ne=i-1;
	}
	printf("%d\n",all);
	for(i=nh;i<=ne;i++)
	{
		printf("%c",arr[i]);
	}
	return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
using namespace std;

#define PI acos(-1.0)
typedef long long ll;
struct stu
{
	char s;
	int i;
}stak[100001];
int main(){
	char arr[100001];
	int i,g=0,all=0,h=-1,nall=0,nh=0,ne=-1;
	i=0;
	bool flag[100001]={0};
	scanf("%s",arr);
	while(arr[i])
	{
		if(arr[i]=='(' || arr[i]=='[')
		{
			stak[g].s=arr[i];
			stak[g++].i=i;
		}
		else
		{
			if(g>0)
			{
				if(arr[i]==')')
				{
					if(stak[g-1].s == '(')
					{
						flag[i]=1;
						flag[stak[g-1].i]=1;
						g--;
					}
					else g=0;

				}
				else
				{
					if(arr[i] == ']')
					{
						if(stak[g-1].s == '[')
						{
							flag[i]=1;
							flag[stak[g-1].i]=1;
							g--;
						}
						else g=0;
					}
				}
			}
		}
		i++;
	}
	//for(i=0;arr[i];i++)
	//{
	//	printf("%d ",flag[i]);
	//}
	//printf("\n");
	bool si=0;
	for( i=0; arr[i] ;i++)
	{
		if(flag[i]==1)
		{
			if(si==0)h=i;
			si=1;
			if(arr[i]=='[')nall++;
		}
		else
		{

			if(nall>all ||(nall == all && si==1))
			{
				all=nall;
				nh=h;
				ne=i-1;
			}
			si=0;
			h=i+1;
		}
	}
	if(nall> all ||(nall == all && si==1))
	{
		all=nall;
		nh=h;
		ne=i-1;
	}
	printf("%d\n",all);
	for(i=nh;i<=ne;i++)
	{
		printf("%c",arr[i]);
	}
	return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
using namespace std;

#define PI acos(-1.0)
typedef long long ll;
struct stu
{
	char s;
	int i;
}stak[100001];
int main(){
	char arr[100001];
	int i,g=0,all=0,h=-1,nall=0,nh=0,ne=-1;
	i=0;
	bool flag[100001]={0};
	scanf("%s",arr);
	while(arr[i])
	{
		if(arr[i]=='(' || arr[i]=='[')
		{
			stak[g].s=arr[i];
			stak[g++].i=i;
		}
		else
		{
			if(g>0)
			{
				if(arr[i]==')')
				{
					if(stak[g-1].s == '(')
					{
						flag[i]=1;
						flag[stak[g-1].i]=1;
						g--;
					}
					else g=0;

				}
				else
				{
					if(arr[i] == ']')
					{
						if(stak[g-1].s == '[')
						{
							flag[i]=1;
							flag[stak[g-1].i]=1;
							g--;
						}
						else g=0;
					}
				}
			}
		}
		i++;
	}
	//for(i=0;arr[i];i++)
	//{
	//	printf("%d ",flag[i]);
	//}
	//printf("\n");
	bool si=0;
	for( i=0; arr[i] ;i++)
	{
		if(flag[i]==1)
		{
			if(si==0)h=i;
			si=1;
			if(arr[i]=='[')nall++;
		}
		else
		{
			si=0;
			if(nall>all ||(nall == all && si==1))
			{
				all=nall;
				nh=h;
				ne=i-1;
			}
			h=i+1;
		}
	}
	if(nall> all ||(nall == all && si==1))
	{
		all=nall;
		nh=h;
		ne=i-1;
	}
	printf("%d\n",all);
	for(i=nh;i<=ne;i++)
	{
		printf("%c",arr[i]);
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define f0(i,n) for((int)i=0;(int)i<(int)n;i++)
#define SORT(c) sort((c).begin(),(c).end())
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll BIG_PRIME7 = 1000000007;
const ll BIG_PRIME9 = 1000000009;

template <typename T>
T gcd(T x, T y) {return y ? gcd(y, x%y): x;}

vector<ll> vi,vv;
vector<string> vs;
pair<ll,ll> pii;
vector<pair <ll, ll> >vp;
set<ll> seti;
map<string,int> mymap;
queue<string> q;

char st[11];
bool ar[500000];

string s,ss,s1,s2,ss1,ss2,jami;
int i,j,k,m,n,h,d,g,t,l,w,r,a,b,c,sum;
ll I,J,L,K,M,N,C,R,SUM,maxi,mini;
bool ind, flag;
double x,y,z;
unsigned long long UI,UJ;

int main(){
	cin>>s;
	int left = -1;
	for(int i=0;i<s.size();i++){
		ar[i] = false;
		if(s[i]==']'){
			if(left>=0  && s[left]=='['){
				ar[i] = true;
				ar[left] = true;
				left--;
				while(ar[left])left--;
			}
		}
		if(s[i]==')'){
			if(left>=0 && s[left]=='('){
				ar[i] = true;
				ar[left] = true;
				left--;
				while(ar[left])left--;
			}
		}

		if(ar[i]==false)left = i;
	}
	i=0;
	while(true){
		int K=0;
		int l=i;
		int r = i;
		while(ar[i]){
			if(s[i]=='[')K++;
			i++;
		}
		r = i-1;
		if(K>maxi){
			maxi = K;
			L = l;
			R=r;
		}
		i++;
		if(i>=s.size())break;
	}
	if(maxi==0){
		cout<<0<<endl;
		return 0;
	} else{
		cout<<maxi<<endl;
		cout<<s.substr(L,R-L+1)<<endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][3], x, curr;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			st[tp = 0][2] = 0;
			st[0][0] = x;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (tp < 0 || !st[tp][0]) break;
					--tp;
				} else {
					if (tp < 0 || st[tp][0]) break;
					curr = d[x] - d[st[tp][1]] + 1;
					if (curr > ans) {
						ans = curr;
						str = st[tp][1];
						fin = x;
					}
					--tp;
					st[tp][2] += curr;
					if (st[tp][2] > ans) {
						ans = st[tp][2];
						str = st[tp][1] + 1;
						fin = x;
					}
				}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][3], x, curr;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			st[tp = 0][2] = 0;
			st[0][1] = x - 1;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (!tp || !st[tp][0]) {
						if (ans < st[tp][2]) {
							ans = st[tp][2];
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					--tp;
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1] + 1;
						fin = x;
					}
				} else {
					if (!tp || st[tp][0]) {
						if (ans < st[tp][2]) {
							ans = st[tp][2];
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					curr = d[x] - d[st[tp][1]] + 1;
					if (curr > ans) {
						ans = curr;
						str = st[tp][1];
						fin = x;
					}
					st[--tp][2] += curr;
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1] + 1;
						fin = x;
					}
				}
				if (!tp)
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1];
						fin = x;
					}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][2], x, cur;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			tp = -1;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (tp < 0 || !st[tp][0]) break;
					--tp;
				} else {
					if (tp < 0 || st[tp][0]) break;
					cur = d[x] - d[st[tp][1]] + 1;
					if (cur > ans) {
						ans = cur;
						str = st[tp][1];
						fin = x;
					}
					--tp;
				}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][2], x, curr;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			st[tp = 0][1] = 0;
			st[0][0] = x;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (tp < 0 || !st[tp][0]) break;
					--tp;
				} else {
					if (tp < 0 || st[tp][0]) break;
					curr = d[x] - d[st[tp][1]] + 1;
					if (curr > ans) {
						ans = curr;
						str = st[tp][1];
						fin = x;
					}
					--tp;
					st[tp][1] += curr;
					if (st[tp][1] > ans) {
						ans = st[tp][1];
						str = st[tp][0];
						fin = x;
					}
				}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][3], x, curr;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			st[tp = 0][2] = 0;
			st[0][0] = x;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (!tp || !st[tp][0]) {
						if (ans < st[tp][2]) {
							ans = st[tp][2];
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					--tp;
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1] + 1;
						fin = x;
					}
				} else {
					if (!tp || st[tp][0]) {
						if (ans < st[tp][2]) {
							ans = st[tp][2];
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					curr = d[x] - d[st[tp][1]] + 1;
					if (curr > ans) {
						ans = curr;
						str = st[tp][1];
						fin = x;
					}
					st[--tp][2] += curr;
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1] + 1;
						fin = x;
					}
				}
				if (!tp)
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1];
						fin = x;
					}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][2], x, curr, kk;
char s[111111];

inline int cnt(int l, int r) {
	if (r <= l) return 0;
	return d[r] - d[l] + (s[l] == '[');
}

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[' || s[x] == '(') {
			st[tp = 0][1] = x - 1;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (!tp || !st[tp][0]) {
						kk = cnt(st[tp][1] + 1, x - 1);
						if (ans < kk) {
							ans = kk;
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					kk = cnt(st[tp][1], x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1];
						fin = x;
					}
					kk = cnt(st[--tp][1] + 1, x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1] + 1;
						fin = x;
					}
				} else {
					if (!tp || st[tp][0]) {
						kk = cnt(st[tp][1] + 1, x - 1);
						if (ans < kk) {
							ans = kk;
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					kk = cnt(st[tp][1], x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1];
						fin = x;
					}
					kk = cnt(st[--tp][1] + 1, x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1] + 1;
						fin = x;
					}
				}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][2], x, curr, kk;
char s[111111];

inline int cnt(int l, int r) {
	if (r <= l) return 0;
	return d[r] - d[l] + (s[l] == '[');
}

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			st[tp = 0][1] = x - 1;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (!tp || !st[tp][0]) {
						kk = cnt(st[tp][1] + 1, x - 1);
						if (ans < kk) {
							ans = kk;
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					kk = cnt(st[tp][1], x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1];
						fin = x;
					}
					--tp;
					kk = cnt(st[tp][1] + 1, x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1] + 1;
						fin = x;
					}
				} else {
					if (!tp || st[tp][0]) {
						kk = cnt(st[tp][1] + 1, x - 1);
						if (ans < kk) {
							ans = kk;
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					kk = cnt(st[tp][1], x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1];
						fin = x;
					}
					--tp;
					kk = cnt(st[tp][1] + 1, x);
					if (ans < kk) {
						ans = kk;
						str = st[tp][1] + 1;
						fin = x;
					}
				}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, cur, str, fin, tp, st[111111], x, good, y, goodf;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			tp = -1;
			cur = good = goodf = 0;
			y = x;
			while (x < ls) {
				if (s[x] == '(') st[++tp] = 1; else
				if (s[x] == '[') {
					st[++tp] = 0;
					++cur;
				} else
				if (s[x] == ')') {
					if (tp < 0 || !st[tp]) break;
					--tp;
				} else {
					if (tp < 0 || st[tp]) break;
					--tp;
				}
				if (tp == -1) {
					good = cur;
					goodf = x;
				}
				++x;
			}
			if (good > ans) {
				ans = good;
				str = y;
				fin = goodf;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][3], x, curr;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			st[tp = 0][2] = 0;
			st[0][0] = x;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (tp < 0 || !st[tp][0]) break;
					--tp;
				} else {
					if (tp < 0 || st[tp][0]) break;
					curr = d[x] - d[st[tp][1]] + 1;
					if (curr > ans) {
						ans = curr;
						str = st[tp][1];
						fin = x;
					}
					--tp;
					st[tp][2] += curr;
					if (st[tp][2] > ans) {
						ans = st[tp][2];
						str = st[tp][0];
						fin = x;
					}
				}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int ls, d[111111], ans, str, fin, tp, st[111111][3], x, curr;
char s[111111];

int main() {
	sIO();
	gets(s);
	ls = strlen(s);
	fill(d, 0);
	d[0] = (s[0] == '[');
	for (int i = 1; i < ls; ++i)
		d[i] = d[i - 1] + (s[i] == '[');
	ans = str = fin = 0;
	x = 0;
	while (x < ls) {
		if (s[x] == '[') {
			st[tp = 0][2] = 0;
			st[0][1] = x;
			while (x < ls) {
				if (s[x] == '(' || s[x] == '[') st[++tp][1] = x;
				if (s[x] == '(') st[tp][0] = 1; else
				if (s[x] == '[') st[tp][0] = 0; else
				if (s[x] == ')') {
					if (!tp || !st[tp][0]) {
						if (ans < st[tp][2]) {
							ans = st[tp][2];
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					--tp;
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1];
						fin = x;
					}
				} else {
					if (!tp || st[tp][0]) {
						if (ans < st[tp][2]) {
							ans = st[tp][2];
							str = st[tp][1] + 1;
							fin = x - 1;
						}
						break;
					}
					curr = d[x] - d[st[tp][1]] + 1;
					if (curr > ans) {
						ans = curr;
						str = st[tp][1];
						fin = x;
					}
					st[--tp][2] += curr;
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1];
						fin = x;
					}
				}
				if (!tp)
					if (ans < st[tp][2]) {
						ans = st[tp][2];
						str = st[tp][1];
						fin = x;
					}
				++x;
			}
		}
		++x;
	}
	printf("%d\n", ans);
	if (!ans) return 0;
	for (int i = str; i <= fin; ++i)
		putchar(s[i]);
	return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a < (*(tstruct1*)arg2).a)
    {
        return -1;
    }
    else if ((*(tstruct1*)arg1).a > (*(tstruct1*)arg2).a) return 1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
m[0].a=0;
m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {count=0;}
qsort(m,count+1,sizeof(tstruct1),compare1);
string answstr="",tanswstr="";
int k=0,ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a<=ii+1)
{
for(int j=ii; j<=m[i].b; j++)
{
	ii++;
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
	}
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>

using namespace std;
struct tstruct{int a,b,c,d;};
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s,s1;
cin>>s;
int min=0;
int n=s.length();

int answ;
tstruct m[100000];
for (int i=0; i<n; i++)
{
	m[i].a=0;
	m[i].b=0;
	m[i].c=0;
	m[i].d=0;
}
int a=0,b=0,c=0,d=0;
for (int i=0; i<n; i++)
{
	if (s[i]=='[') {a++;}
	if (s[i]==']') {b++;}
	if (s[i]=='(') {c++;}
	if (s[i]==')') {d++;}
	m[i].a=a;
	m[i].b=b;
	m[i].c=c;
	m[i].d=d;
}
int max=m[n-1].a;
int st=0,f=0;
int ast=0,af=0;
while (min!=max)
{
	answ=((min+max)+1)/2;
	st=0; f=0;
	int count=0;
	bool fl=true;
	while ((f<n)&&(fl))
	{
		if (count<answ)
		{
			f++;
			if (s[f]=='[')
			{count++;}
		}
		else
		{
			if (((m[f].a-m[st].a)==(m[f].b-m[st].b))&&((m[f].c-m[st].c)==(m[f].d-m[st].d)))
			{fl=false; min=answ; ast=st; af=f;}
			else
			{
				if (s[st]=='[')
				{count--;}
				st++;
			}
		}
	}
	if ((f==n)&&(max==answ)) {max=min;}
	else
	{
	if (f==n) {max=answ;}
	}
}
cout<<min;
if (af>0)
{
for (int i=ast; i<=af+1; i++)
{
	cout<<s[i];
}
}
else
{
	cout<<endl;
}

#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a > (*(tstruct1*)arg2).a)
    {
        return 1;
    }
    else if ((*(tstruct1*)arg1).a < (*(tstruct1*)arg2).a) return -1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
m[0].a=0;
m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {count=0;}
qsort(m,count,sizeof(tstruct1),compare1);
string answstr="",tanswstr="";
int k=0,ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a<=ii+1)
{
for(int j=ii; j<=m[i].b; j++)
{
	ii++;
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
	}
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a > (*(tstruct1*)arg2).a)
    {
        return 1;
    }
    else if ((*(tstruct1*)arg1).a < (*(tstruct1*)arg2).a) return -1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
m[0].a=0;
m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {count=0;}
qsort(m,count,sizeof(tstruct1),compare1);
string answstr="",tanswstr;
int k=0,ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a==ii+1)
{
for(int j=m[i].a; j<=m[i].b; j++)
{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
	}
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a < (*(tstruct1*)arg2).a)
    {
        return -1;
    }
    else if ((*(tstruct1*)arg1).a > (*(tstruct1*)arg2).a) return 1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
m[0].a=0;
m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {count=0;}
qsort(m,count+1,sizeof(tstruct1),compare1);
string answstr="",tanswstr="";
int ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a<=ii+1)
{
for(int j=ii; j<=m[i].b; j++)
{
	ii++;
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	}
	ii=m[i].b;
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a > (*(tstruct1*)arg2).a)
    {
        return 1;
    }
    else if ((*(tstruct1*)arg1).a < (*(tstruct1*)arg2).a) return -1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
m[0].a=0;
m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {count=0;}
qsort(m,count,sizeof(tstruct1),compare1);
string answstr="",tanswstr;
int k=0,ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a==ii+1)
{
for(int j=m[i].a; j<=m[i].b; j++)
{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
	}
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a > (*(tstruct1*)arg2).a)
    {
        return 1;
    }
    else if ((*(tstruct1*)arg1).a < (*(tstruct1*)arg2).a) return -1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
}
qsort(m,count,sizeof(tstruct1),compare1);
string answstr="",tanswstr;
int k=0,ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a==ii+1)
{
for(int j=m[i].a; j<=m[i].b; j++)
{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
	}
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>

using namespace std;
struct tstruct{int a,b,c,d;};
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s,s1;
cin>>s;
int min=0;
int n=s.length();

int answ;
tstruct m[100000];
for (int i=0; i<n; i++)
{
	m[i].a=0;
	m[i].b=0;
	m[i].c=0;
	m[i].d=0;
}
int a=0,b=0,c=0,d=0;
for (int i=0; i<n; i++)
{
	if (s[i]=='[') {a++;}
	if (s[i]==']') {b++;}
	if (s[i]=='(') {c++;}
	if (s[i]==')') {d++;}
	m[i].a=a;
	m[i].b=b;
	m[i].c=c;
	m[i].d=d;
}
int max=m[n-1].a;
int st=0,f=0;
int ast=0,af=0;
while (min!=max)
{
	answ=((min+max)+1)/2;
	st=0; f=0;
	int count=0;
	bool fl=true;
	while ((f<n)&&(fl))
	{
		if (count<answ)
		{
			f++;
			if (s[f]=='[')
			{count++;}
		}
		else
		{
			if (((m[f].a-m[st].a)==(m[f].b-m[st].b))&&((m[f].c-m[st].c)==(m[f].d-m[st].d)))
			{fl=false; min=answ; ast=st; af=f;}
			else
			{
				if (s[st]=='[')
				{count--;}
				st++;
			}
		}
	}
	if ((f==n)&&(max==answ)) {max=min;}
	else
	{
	if (f==n) {max=answ;}
	}
}
cout<<min<<endl;
if (af>0)
{
for (int i=ast; i<=af+1; i++)
{
	cout<<s[i];
}
}
else
{
	cout<<endl;
}

#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a < (*(tstruct1*)arg2).a)
    {
        return -1;
    }
    else if ((*(tstruct1*)arg1).a > (*(tstruct1*)arg2).a) return 1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
m[0].a=0;
m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {count=0;}
qsort(m,count+1,sizeof(tstruct1),compare1);
string answstr="",tanswstr="";
int ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count+1; i++)
{
if (m[i].a<=ii+1)
{
for(int j=ii; j<=m[i].b; j++)
{
	ii++;
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	ii++;
	}
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a < (*(tstruct1*)arg2).a)
    {
        return -1;
    }
    else if ((*(tstruct1*)arg1).a > (*(tstruct1*)arg2).a) return 1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
m[0].a=0;
m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {count=0;}
qsort(m,count+1,sizeof(tstruct1),compare1);
string answstr="",tanswstr="";
int ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a<=ii+1)
{
for(int j=ii+1; j<=m[i].b; j++)
{
	ii++;
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	}
	ii=m[i].b;
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#ifdef ONLINE_JUDGE
#include <iostream>
#else
#include <fstream>
#endif
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;
struct tstruct{int a,key;};
struct tstruct1{int a,b;};
int compare1(const void *arg1, const void *arg2)
{
	if ((*(tstruct1*)/*���������� ��������� ������?������ ������?? ��� ������*/arg1).a < (*(tstruct1*)arg2).a)
    {
        return -1;
    }
    else if ((*(tstruct1*)arg1).a > (*(tstruct1*)arg2).a) return 1;
	else return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	#pragma comment(linker, "/STACK:268435456")
    ifstream cin ("input.txt");
    ofstream cout ("output.txt");
#endif
string s;
cin>>s;
int count=-1;
vector<tstruct> stack;
tstruct1 m[100000];
//m[0].a=0;
//m[0].b=0;
for (int i=0; i<(int)s.length(); i++)
{
	tstruct tmp;
	if (s[i]=='[') {tmp.a=i; tmp.key=1; stack.push_back(tmp);}
	if (s[i]=='(') {tmp.a=i; tmp.key=2; stack.push_back(tmp);}
	if (s[i]==']')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==1)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
	if (s[i]==')')
	{
	if (stack.size()>0)
	{
	if (stack[stack.size()-1].key==2)
	{count++; m[count].a=stack[stack.size()-1].a; m[count].b=i; stack.pop_back();}
	else
	{
		stack.clear();
	}
	}
	else
	{
		stack.clear();
	}
	}
}
if (count<0) {cout<<0;} else
{
qsort(m,count+1,sizeof(tstruct1),compare1);
string answstr="",tanswstr="";
int ii=0;
int answ=0,tansw=0;
for(int i=m[0].a; i<=m[0].b; i++)
{
	if (s[i]=='[') {tansw++;}
	tanswstr+=s[i];
}
ii=m[0].b;
for (int i=1; i<=count; i++)
{
if (m[i].a<=ii+1)
{
for(int j=ii+1; j<=m[i].b; j++)
{
	ii++;
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
}
}
else
{
	if (m[i].a>ii+1)
	{
	if (tansw>answ) {answ=tansw; answstr=tanswstr;}
	tansw=0;
	tanswstr="";
	for(int j=m[i].a; j<=m[i].b; j++)
	{
	if (s[j]=='[') {tansw++;}
	tanswstr+=s[j];
	}
	ii=m[i].b;
	}
	}
}
if (tansw>answ) {answ=tansw; answstr=tanswstr;}
cout<<answ<<endl<<answstr;
}
#ifndef ONLINE_JUDGE
cin.close();
cout.close();
#endif
return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
	int *ass;
	for (;;)
	{
		ass = new int[2500000];
		for (int i = 0; i < 2500000; i++)
			ass[i] = rand();
	}
}

string str;
int n;
void LoAd()
{
	cin >> str;
	n = (int) str.size();
}

vector< vector<char> > a;
vector<char> st;

void fix(vector<char> &s)
{
	st.clear();
	vector<char> res;
	for (int i = (int) s.size() - 1; i >= 0; i--)
	{
		if (!st.empty())
		{
			if ((st[st.size() - 1] == ']' && '[' == s[i]) || (st[st.size() - 1] == ')' && '(' == s[i]))
			{
				res.push_back(s[i]);
				st.pop_back();
			}
			else if(str[i] == ')' || s[i] == ']')
			{
				res.push_back(s[i]);
				st.push_back(s[i]);
			}
			else
			{
				break;
			}
		}
		else if (']' == s[i] || ')' == s[i])
		{
			st.push_back(s[i]);
			res.push_back(s[i]);
		}
	}
	s.clear();
	s.reserve(res.size());
	for (int i = (int) res.size() - 1; i >= 0; i--)
	{
		s.push_back(res[i]);
	}
}

void SoLvE()
{
	int j = 0;
	a.resize(1);
	for (int i = 0; i < n; i++)
	{
		switch(str[i])
		{
		case '(':
		case '[':
			a[j].push_back(str[i]);
			st.push_back(str[i]);
			break;
		case ']':
			if (st.empty())
			{
				j++;
				a.push_back(vector<char>());
				break;
			}
			if (st[st.size() - 1] == '[')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(vector<char>());
			}
			break;
		case ')':
			if (st.empty())
			{
				j++;
				a.push_back(vector<char>());
				break;
			}
			if (st[st.size() - 1] == '(')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(vector<char>());
			}
			break;
		}
	}
	for (int i = 0; i < (int) a.size(); i++)
	{
		fix(a[i]);
	}

	int ind = -1;
	int bres = -1;
	for (int i = 0; i < (int) a.size(); i++)
	{
		if (a[i].empty())
			continue;
		int cnt = 0;
		for (int j = 0; j < (int) a[i].size(); j++)
		{
			if ('[' == a[i][j])
				cnt++;
		}
		if (cnt > bres)
		{
			bres = cnt;
			ind = i;
		}
	}
	if (-1 == ind)
	{
		cout << "-1";
		return;
	}
	cout << bres << endl;
	for (int i = 0; i < (int) a[ind].size(); i++)
		printf("%c", a[ind][i]);
}

int main()
{
	srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
	LoAd();
	SoLvE();
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
	int *ass;
	for (;;)
	{
		ass = new int[2500000];
		for (int i = 0; i < 2500000; i++)
			ass[i] = rand();
	}
}

string str;
int n;
void LoAd()
{
	cin >> str;
	n = (int) str.size();
}

vector< vector<char> > a;
vector<char> st;

void fix(vector<char> &s)
{
	st.clear();
	vector<char> res;
	for (int i = (int) s.size() - 1; i >= 0; i--)
	{
		if (!st.empty())
		{
			if ((st[st.size() - 1] == ']' && '[' == s[i]) || (st[st.size() - 1] == ')' && '(' == s[i]))
			{
				res.push_back(s[i]);
				st.pop_back();
			}
			else if(str[i] == ')' || s[i] == ']')
			{
				res.push_back(s[i]);
				st.push_back(s[i]);
			}
			else
			{
				break;
			}
		}
		else if (']' == s[i] || ')' == s[i])
		{
			st.push_back(s[i]);
			res.push_back(s[i]);
		}
	}
	s.clear();
	s.reserve(res.size());
	for (int i = (int) res.size() - 1; i >= 0; i--)
	{
		s.push_back(res[i]);
	}
}

void SoLvE()
{
	int j = 0;
	a.resize(1);
	for (int i = 0; i < n; i++)
	{
		switch(str[i])
		{
		case '(':
		case '[':
			a[j].push_back(str[i]);
			st.push_back(str[i]);
			break;
		case ']':
			if (st.empty())
			{
				j++;
				a.push_back(vector<char>());
				break;
			}
			if (st[st.size() - 1] == '[')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(vector<char>());
			}
			break;
		case ')':
			if (st.empty())
			{
				j++;
				a.push_back(vector<char>());
				break;
			}
			if (st[st.size() - 1] == '(')
			{
				st.pop_back();
				a[j].push_back(str[i]);
			}
			else
			{
				st.clear();
				j++;
				a.push_back(vector<char>());
			}
			break;
		}
	}
	for (int i = 0; i < (int) a.size(); i++)
	{
		fix(a[i]);
	}

	int ind = -1;
	int bres = -1;
	for (int i = 0; i < (int) a.size(); i++)
	{
		if (a[i].empty())
			continue;
		int cnt = 0;
		for (int j = 0; j < (int) a[i].size(); j++)
		{
			if ('[' == a[i][j])
				cnt++;
		}
		if (cnt > bres)
		{
			bres = cnt;
			ind = i;
		}
	}
	if (-1 == ind)
	{
		cout << "0";
		return;
	}
	cout << bres << endl;
	for (int i = 0; i < (int) a[ind].size(); i++)
		printf("%c", a[ind][i]);
}

int main()
{
	srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
    freopen(TASK".in","r",stdin);   freopen(TASK".out","w",stdout);
#endif
	LoAd();
	SoLvE();
	return 0;
}