#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  char s[100005];
  scanf("%s", s);
  bool b[100005] = {0};
  stack<char> st;
  int i, len;
  for (i = 0; s[i] != 0; i++) {
    if (st.empty()) {
      if (s[i] == ')' || s[i] == ']') {
        b[i] = true;
      } else {
        st.push(s[i]);
      }
    } else {
      if (s[i] == '(' || s[i] == '[') {
        st.push(s[i]);
      } else {
        if ((st.top() == '(' && s[i] == ']') ||
            (st.top() == '[' && s[i] == ')')) {
          b[i] = true;
          while (!st.empty()) {
            st.pop();
          }
        } else {
          st.pop();
        }
      }
    }
  }
  len = i;
  i--;
  while (!st.empty()) st.pop();
  for (; i >= 0; i--) {
    if (st.empty()) {
      if (s[i] == '(' || s[i] == '[') {
        b[i] = true;
      } else {
        st.push(s[i]);
      }
    } else {
      if (s[i] == ')' || s[i] == ']') {
        st.push(s[i]);
      } else {
        if ((st.top() == ')' && s[i] == '[') ||
            (st.top() == ']' && s[i] == '(')) {
          b[i] = true;
          while (!st.empty()) {
            st.pop();
          }
        } else {
          st.pop();
        }
      }
    }
  }
  int j = 0, max = -1, init_ind = 0, end_ind = -1, mii = 0, mei = -1;
  for (i = 0; i < len; i++) {
    if (!b[i] && s[i] == '[') j++;
    if (b[i]) {
      j = 0;
      init_ind = i + 1;
    } else {
      end_ind = i;
      if (max == j) {
        mei = end_ind;
      }
    }
    if (max <= j) {
      max = j;
      mii = init_ind;
      mei = end_ind;
    }
  }
  printf("%d\n", max);
  for (int k = mii; k <= mei; k++) {
    printf("%c", s[k]);
  }
  printf("\n");
  return 0;
}
