#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
int n;
string s;
stack<pair<char, int> > st;
bool b[100100];
int ansl = -1, ansr = -1, ansk = -1;
bool chk(char c) {
  if (st.empty()) return 0;
  if ((c == ')') && (st.top().first == '(')) return 1;
  if ((c == ']') && (st.top().first == '[')) return 1;
  return 0;
}
int main() {
  memset(b, 0, sizeof(b));
  cin >> s;
  n = s.size();
  for (int i = 0; i < (n); i++) {
    if ((s[i] == '(') || (s[i] == '['))
      st.push(make_pair(s[i], i));
    else if (chk(s[i])) {
      b[st.top().second] = 1;
      b[i] = 1;
      st.pop();
    } else {
      while (!st.empty()) st.pop();
    }
  }
  int l, k;
  s += '#';
  for (int i = 0; i < n;) {
    l = i;
    k = 0;
    while (b[i] == 1) {
      if (s[i] == '[') k++;
      i++;
    }
    if (k > ansk) {
      ansk = k;
      ansl = l;
      ansr = i;
    }
    if (l == i) i++;
  }
  if (ansk == -1)
    cout << 0;
  else {
    cout << ansk << endl;
    for (int i = ansl; i < ansr; i++) cout << s[i];
  }
  return 0;
}
