#include <bits/stdc++.h>
using namespace std;
long long partner[1000009], cs[1000009];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long siz = s.size();
  stack<long long> st;
  for (long long i = 1; i <= siz; i++) {
    cs[i] = cs[i - 1] + (s[i - 1] == '[');
  }
  memset(partner, -1, sizeof partner);
  long long maxcnt = 0, lo = 0, hi = -1;
  for (long long i = 0; i < siz; i++) {
    if (s[i] == '(' or s[i] == '[') {
      st.push(i);
    } else if (!st.empty() and s[i] - s[st.top()] >= 1 and
               s[i] - s[st.top()] <= 2) {
      long long x = st.top();
      if (x > 0 and partner[x - 1] > -1) x = partner[x - 1];
      partner[i] = x;
      long long reccnt = cs[i + 1] - cs[x];
      if (reccnt > maxcnt) maxcnt = reccnt, lo = x, hi = i;
      st.pop();
    } else {
      while (!st.empty()) st.pop();
    }
  }
  cout << maxcnt << "\n";
  for (long long i = lo; i <= hi; i++) {
    cout << s[i];
  }
  cout << "\n";
  return 0;
}
