#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  stack<pair<int, pair<int, int> > > par;
  int ct = 0;
  int mx = -1;
  int ini, fin;
  int n = s.size();
  vector<int> sig(n, -1);
  vector<int> ac(n, 0);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(') {
      par.push(pair<int, pair<int, int> >(0, pair<int, int>(i, ct)));
    } else if (s[i] == '[') {
      par.push(pair<int, pair<int, int> >(1, pair<int, int>(i, ct)));
      ct++;
    } else if (s[i] == ')') {
      if (not par.empty() and par.top().first == 0) {
        if (ct - par.top().second.second > mx) {
          mx = ct - par.top().second.second;
        }
        ini = par.top().second.first;
        fin = i;
        sig[ini] = fin;
        ac[ini] = ct - par.top().second.second;
        par.pop();
      } else {
        par = stack<pair<int, pair<int, int> > >();
        ct = 0;
      }
    } else {
      if (not par.empty() and par.top().first == 1) {
        if (ct - par.top().second.second > mx) {
          mx = ct - par.top().second.second;
        }
        ini = par.top().second.first;
        fin = i;
        sig[ini] = fin;
        ac[ini] = ct - par.top().second.second;
        par.pop();
      } else {
        par = stack<pair<int, pair<int, int> > >();
        ct = 0;
      }
    }
  }
  if (mx == -1)
    cout << 0 << endl;
  else {
    for (int i = 0; i < n; i++) {
      if (sig[i] > -1) {
        while (sig[i] < n - 1 and sig[sig[i] + 1] > -1) {
          int aux = sig[i];
          ac[i] += ac[aux + 1];
          sig[i] = sig[aux + 1];
          sig[aux + 1] = -1;
          ac[aux + 1] = 0;
        }
      }
    }
    mx = -1;
    for (int i = 0; i < n; i++) {
      if (ac[i] > mx) {
        ini = i;
        fin = sig[i];
        mx = ac[i];
      }
    }
    cout << mx << endl << s.substr(ini, fin - ini + 1) << endl;
  }
}
