#include <bits/stdc++.h>
using namespace std;
char s[100099];
int D[100099];
int C[100099];
int L[100099];
int main() {
  cin >> s;
  int i = 0;
  while (s[i] != 0) {
    if (s[i] == '[')
      D[i] = D[i - 1] + 1;
    else
      D[i] = D[i - 1];
    i++;
  }
  i = 0;
  stack<pair<char, int> > st;
  int Max = -1;
  int sl = -1;
  int sr = -1;
  while (s[i] != 0) {
    if (s[i] == '[' || s[i] == '(')
      st.push(make_pair(s[i], i));
    else {
      if (!st.empty()) {
        if ((s[i] == ']' && st.top().first == '[') ||
            (s[i] == ')' && st.top().first == '(')) {
          if (C[st.top().second - 1] > 0) {
            C[i] = D[i] - D[st.top().second - 1] + C[st.top().second - 1];
            L[i] = L[st.top().second - 1];
          } else {
            C[i] = D[i] - D[st.top().second - 1];
            L[i] = st.top().second;
          }
          if (C[i] > Max) {
            Max = C[i];
            sl = L[i];
            sr = i;
          }
          st.pop();
        } else
          while (!st.empty()) st.pop();
      }
    }
    i++;
  }
  if (Max >= 1) {
    cout << Max << endl;
    for (int i = sl; i <= sr; i++) cout << s[i];
    cout << endl;
  } else
    puts("0");
  return 0;
}
