#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 1e5 + 10;
const long long int MINN = 1e5 + 10;
const long long int inf = 1e9 + 7;
int pre[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin.exceptions(cin.failbit);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  string s;
  cin >> s;
  for (int i = 0; i < (s.length()); ++i)
    pre[i] = (i ? pre[i - 1] : 0) + (s[i] == '[');
  int ans = -1, i1, i2;
  stack<pair<int, char>> st;
  vector<pair<int, int>> v, fin;
  for (int i = 0; i < (s.length()); ++i) {
    if (s[i] == '(' || s[i] == '[')
      st.push({i, s[i]});
    else {
      if ((st.empty()) || (st.top().second == '(' && s[i] == ']') ||
          (st.top().second == '[' && s[i] == ')')) {
        while (!st.empty()) st.pop();
        continue;
      }
      pair<int, char> tmp = st.top();
      st.pop();
      v.push_back({tmp.first, i});
    }
  }
  pair<int, int> curr = {0, -1};
  sort(v.begin(), v.end());
  for (int i = 0; i < (v.size()); ++i) {
    if (v[i].first >= curr.first && v[i].second <= curr.second)
      continue;
    else if (v[i].first == curr.second + 1)
      curr = {curr.first, v[i].second};
    else
      curr = v[i];
    fin.push_back(curr);
  }
  for (int i = 0; i < (fin.size()); ++i) {
    int l = fin[i].first, r = fin[i].second, cnt = 0;
    if (pre[r] - (l ? pre[l - 1] : 0) > ans) {
      ans = pre[r] - (l ? pre[l - 1] : 0);
      i2 = r;
      i1 = l;
    }
  }
  if (ans == -1)
    cout << "0" << endl;
  else {
    cout << ans << endl;
    for (int j = i1; j <= (i2); ++j) cout << s[j];
    cout << endl;
  }
  return 0;
}
