#include <bits/stdc++.h>
using namespace std;
const long double PI = 4 * atan((long double)1);
const long long INF = 1e18;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  for (long long qq = 1; qq <= (tt); ++qq) {
    string s;
    cin >> s;
    stack<pair<long long, long long>> st;
    long long n = s.size();
    vector<long long> v(n, -1);
    for (long long i = 0; i < (n); ++i) {
      if (s[i] == '(' or s[i] == '[')
        st.push({s[i], i});
      else {
        if (st.size()) {
          if (s[i] == ')' and st.top().first == '(') {
            v[st.top().second] = i;
            v[i] = st.top().second;
            st.pop();
          } else if (s[i] == ']' and st.top().first == '[') {
            v[st.top().second] = i;
            v[i] = st.top().second;
            st.pop();
          } else {
            while (st.size()) st.pop();
          }
        }
      }
    }
    long long ans = 0;
    pair<long long, long long> use;
    for (long long i = 0; i < n;) {
      if (v[i] > i) {
        long long last = v[i], st = i;
        while (i < n and v[i] > i) {
          last = v[i];
          i = v[i] + 1;
        }
        long long c = 0;
        for (long long j = st; j <= (last); ++j) {
          if (s[j] == '[') c++;
        }
        if (c > ans) {
          ans = c;
          use = {st, last};
        }
      } else
        i++;
    }
    cout << ans << '\n';
    string s1;
    if (use.first != use.second)
      for (long long i = use.first; i <= (use.second); ++i) s1.push_back(s[i]);
    cout << s1 << '\n';
  }
}
