#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100500;
int sum[MaxN], ind[MaxN];
struct tt {
  char c;
  int ind;
};
vector<tt> st;
int main() {
  int i, ansl, ansr, ans, l, r, cnt, bal1, bal2, ans1, ans1l, ans1r;
  string s, s1;
  tt t;
  for (i = 0; i < MaxN; i++) {
    sum[i] = 0;
    ind[i] = -1;
  }
  st.clear();
  sum[0] = 0;
  cin >> s;
  if (s[0] == '[') sum[0]++;
  for (i = 1; i < s.length(); i++) {
    sum[i] = sum[i - 1];
    if (s[i] == '[') sum[i]++;
  }
  for (i = 0; i < s.length(); i++) {
    if ((s[i] == '[') || (s[i] == '(')) {
      t.ind = i;
      t.c = s[i];
      st.push_back(t);
      continue;
    }
    if (s[i] == ')') {
      if ((st.size()) && (st[st.size() - 1].c == '(')) {
        ind[st[st.size() - 1].ind] = i;
        st.pop_back();
      } else {
        st.clear();
      }
    }
    if (s[i] == ']') {
      if ((st.size()) && (st[st.size() - 1].c == '[')) {
        ind[st[st.size() - 1].ind] = i;
        st.pop_back();
      } else {
        st.clear();
      }
    }
  }
  for (i = 0; i < s.length(); i++) {
    if (ind[i] != -1) {
      if (ind[ind[i] + 1] != -1) {
        ind[i] = ind[ind[i] + 1];
        i--;
      }
    }
  }
  ans = -1;
  ansl = -1;
  ansr = -1;
  int cur = 0;
  for (i = 0; i < s.length(); i++) {
    if (ind[i] != -1) {
      if (i == 0) {
        cur = sum[ind[i]];
      } else {
        cur = sum[ind[i]] - sum[i - 1];
      }
      if (cur > ans) {
        ans = cur;
        ansl = i;
        ansr = ind[i];
      }
    }
  }
  if (ans == -1) {
    cout << 0 << endl;
    cout << endl;
    return 0;
  }
  cout << ans << endl;
  for (i = ansl; i <= ansr; i++) {
    cout << s[i];
  }
  cout << endl;
  cin.get();
  cin.get();
}
