#include <bits/stdc++.h>
using namespace std;
string s = "";
int par[100005];
stack<int> St;
void clearst() {
  while (!St.empty()) {
    St.pop();
  }
}
int cntpar(int l, int r) {
  int t = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] == '[') t++;
  }
  return t;
}
vector<char> getsubs(int l, int r) {
  vector<char> ret;
  for (int i = l; i <= r; i++) {
    ret.push_back(s[i]);
  }
  return ret;
}
int main() {
  cin >> s;
  memset(par, -1, sizeof(par));
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '[' || s[i] == '(') {
      St.push(i);
    } else if (s[i] == ']') {
      if (St.empty()) continue;
      if (s[St.top()] == '[') {
        par[i] = St.top();
        par[St.top()] = i;
        St.pop();
      } else
        clearst();
    } else if (s[i] == ')') {
      if (St.empty()) continue;
      if (s[St.top()] == '(') {
        par[i] = St.top();
        par[St.top()] = i;
        St.pop();
      } else
        clearst();
    }
  }
  vector<pair<int, int> > blocks;
  int l, r;
  bool flag = false;
  for (int i = 0; i < s.length(); i++) {
    if (!flag && par[i] != -1) {
      l = i;
      flag = true;
    }
    if (flag && par[i] == -1) {
      r = i - 1;
      blocks.push_back(make_pair(l, r));
      flag = false;
    } else if (flag && i == s.length() - 1) {
      r = i;
      blocks.push_back(make_pair(l, r));
      flag = false;
    }
  }
  int ans = 0;
  vector<char> subs;
  for (int i = 0; i < blocks.size(); i++) {
    l = blocks[i].first;
    r = blocks[i].second;
    if (cntpar(l, r) > ans) {
      ans = cntpar(l, r);
      subs = getsubs(l, r);
    }
  }
  cout << ans << endl;
  for (int i = 0; i < subs.size(); i++) {
    cout << subs[i];
  }
  cout << endl;
  return 0;
}
