#include <bits/stdc++.h>
using namespace std;
inline void wait(double seconds) {
  double endtime = clock() + (seconds * CLOCKS_PER_SEC);
  while (clock() < endtime) {
    ;
  }
}
inline int fastIn() {
  register char c = 0;
  register int a = 0;
  while (c < 33) c = getchar();
  while (c > 33) {
    a = (a * 10) + (c - '0');
    c = getchar();
  }
  return a;
}
char S[100005];
inline void read() {
  S[0] = '.';
  scanf("%s", S + 1);
}
int cnt[100005];
int tmp[100005];
inline void proc() {
  int l = strlen(S);
  stack<int> st;
  int bst = -1;
  int s, e;
  for (int i = 1; i < l; ++i) {
    cnt[i] = cnt[i - 1];
    if (S[i] == '[') ++cnt[i];
    if (st.empty())
      st.push(i);
    else {
      if (S[i] - S[st.top()] == 1 || S[i] - S[st.top()] == 2) {
        if (tmp[st.top() - 1] > 0)
          tmp[i] = tmp[st.top() - 1];
        else {
          tmp[i] = st.top();
        }
        if (cnt[i] - cnt[tmp[i] - 1] >= bst) {
          bst = cnt[i] - cnt[tmp[i] - 1];
          s = tmp[i], e = i;
        }
        st.pop();
      } else {
        st.push(i);
      }
    }
  }
  if (bst == -1) {
    puts("0");
    return;
  }
  cout << bst << "\n";
  for (int i = s; i <= e; ++i) {
    putchar(S[i]);
  }
  puts("");
}
int main() {
  int kase = 1;
  for (int i = 0, j1 = kase; i < j1; ++i) {
    read();
    proc();
  }
  return 0;
}
