#include <bits/stdc++.h>
using namespace std;
const int V = 100000 + 20;
char str[V];
int n;
int a0[V], a1[V], b0[V], b1[V];
void clear(stack<pair<int, char> >& st) {
  while (!st.empty()) st.pop();
}
int ans, ans_l, ans_r;
void update(int pos, int i) {
  if (b1[i] - b1[pos] > ans) {
    ans = b1[i] - b1[pos];
    ans_l = pos + 1;
    ans_r = i;
  }
}
int main() {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  int na0, na1, nb0, nb1;
  na0 = na1 = nb0 = nb1 = 0;
  a0[0] = a1[0] = b0[0] = b1[0] = 0;
  for (int i = 1; i <= n; ++i) {
    na0 += (str[i] == '(');
    na1 += (str[i] == ')');
    nb0 += (str[i] == '[');
    nb1 += (str[i] == ']');
    a0[i] = na0;
    a1[i] = na1;
    b0[i] = nb0;
    b1[i] = nb1;
  }
  stack<pair<int, char> > st;
  st.push(make_pair(0, '?'));
  str[n + 1] = ']';
  ans = 0;
  int lmost = 0;
  for (int i = 1; i <= n + 1; ++i) {
    if (str[i] == '(' || str[i] == '[') {
      st.push(make_pair(i, str[i]));
    }
    if (str[i] == ']') {
      if (st.top().second != '[') {
        clear(st);
        st.push(make_pair(i, '?'));
        continue;
      }
      st.pop();
      update(st.top().first, i);
    }
    if (str[i] == ')') {
      if (st.empty() || st.top().second != '(') {
        clear(st);
        st.push(make_pair(i, '?'));
        continue;
      }
      st.pop();
      update(st.top().first, i);
    }
  }
  printf("%d\n", ans);
  if (ans > 0) {
    for (int i = ans_l; i <= ans_r; ++i) printf("%c", str[i]);
    puts("");
  }
}
