#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
const int INF = 1000000000;
char s[MAXN + 10];
int r[MAXN + 10], lef[MAXN + 10];
vector<pair<char, int> > st;
int bL = -1, bR = -1;
int main() {
  scanf("%s", s);
  int len = strlen(s);
  memset(r, 0, sizeof(r));
  for (int i = 0; i < len; i++) {
    r[i + 1] = r[i] + (s[i] == '[');
  }
  int best = 0;
  for (int i = 0; i <= len + 1; i++) lef[i] = -1;
  for (int i = 0; i < len; i++) {
    if (st.size() > 0 && ((st.back().first == '(' && s[i] == ')') ||
                          (st.back().first == '[' && s[i] == ']'))) {
      int pos = st.back().second - 1;
      while (lef[pos] >= 0) pos = lef[pos];
      if (r[i + 1] - r[pos] > best) {
        best = r[i + 1] - r[pos];
        bL = pos;
        bR = i;
      }
      lef[i + 1] = pos;
      st.pop_back();
    } else {
      st.push_back(make_pair(s[i], i + 1));
    }
  }
  printf("%d\n", best);
  if (best > 0) {
    for (int i = bL; i <= bR; i++) printf("%c", s[i]);
    printf("\n");
  }
  return 0;
}
