#include <bits/stdc++.h>
int IntMaxVal = (int)1e20;
int IntMinVal = (int)-1e20;
long long LongMaxVal = (long long)1e20;
long long LongMinVal = (long long)-1e20;
using namespace std;
template <typename T>
struct argument_type;
template <typename T, typename U>
struct argument_type<T(U)> {};
template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& s) {
  is >> s.first >> s.second;
  return is;
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  ;
  int n = s.length();
  vector<int> braces(n + 1);
  for (int i = 0; i < n + 1; ++i) {
    if (i) braces[i] = braces[i - 1];
    if (i)
      if (s[i - 1] == '[') braces[i]++;
  }
  braces[n] = braces[n - 1];
  vector<pair<bool, int> > st;
  pair<int, pair<int, int> > ans = make_pair(0, make_pair(0, 0));
  vector<int> end(n, -1);
  for (int i = 0; i < n; ++i) {
    if (s[i] == '(')
      st.push_back(make_pair(false, i));
    else if (s[i] == '[')
      st.push_back(make_pair(true, i));
    else if (s[i] == ')') {
      if (st.size() && st.back().first == false) {
        int begin = st.back().second;
        while (begin && end[begin - 1] != -1) begin = end[begin - 1];
        int res = braces[i + 1] - braces[begin];
        { ans = max(ans, make_pair(res, make_pair(begin, i + 1))); };
        st.pop_back();
        end[i] = begin;
        end[i] = begin;
      } else
        st.clear();
    } else {
      if (st.size() && st.back().first == true) {
        int begin = st.back().second;
        while (begin && end[begin - 1] != -1) begin = end[begin - 1];
        int res = braces[i + 1] - braces[begin];
        { ans = max(ans, make_pair(res, make_pair(begin, i + 1))); };
        st.pop_back();
        end[i] = begin;
        end[i] = begin;
      } else
        st.clear();
    }
  }
  cout << ans.first << endl;
  cout << s.substr(ans.second.first, ans.second.second - ans.second.first);
}
