#include <bits/stdc++.h>
using namespace std;
char s[123456];
int main() {
  scanf("%s", s);
  stack<pair<int, int> > st;
  int best = 0, rr = -1;
  int sqb = 0;
  for (int i = 0; s[i]; ++i) {
    if (s[i] == '(' || s[i] == '[') {
      st.push(make_pair(i, sqb));
      sqb = 0;
    } else if (s[i] == ')') {
      if (st.size() > 0 && s[st.top().first] == '(') {
        sqb += st.top().second;
        if (best < sqb) {
          best = sqb;
          rr = i;
        }
        st.pop();
      } else {
        stack<pair<int, int> >().swap(st);
        sqb = 0;
      }
    } else if (s[i] == ']') {
      if (st.size() > 0 && s[st.top().first] == '[') {
        sqb += st.top().second + 1;
        if (best < sqb) {
          best = sqb;
          rr = i;
        }
        st.pop();
      } else {
        stack<pair<int, int> >().swap(st);
        sqb = 0;
      }
    }
  }
  s[rr + 1] = 0;
  int ll = rr;
  stack<int> out;
  for (int i = rr; i >= 0; --i) {
    if (s[i] == ')' || s[i] == ']') {
      out.push(i);
    } else if (s[i] == '(') {
      if (out.size() > 0 && s[out.top()] == ')') {
        ll = i;
        out.pop();
      } else
        break;
    } else if (s[i] == '[') {
      if (out.size() > 0 && s[out.top()] == ']') {
        ll = i;
        out.pop();
      } else
        break;
    }
  }
  while (out.size() > 0) {
    ll = out.top() + 1;
    out.pop();
  }
  printf("%d\n", best);
  puts(s + ll);
  return 0;
}
