#include <bits/stdc++.h>
using namespace std;
int pre[100001];
vector<int> opening;
vector<vector<int> > pos(100001);
int elzeroelb3di[100001];
int main() {
  string s;
  cin >> s;
  set<int> se;
  stack<char> st;
  int from = 0, to = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '[') opening.push_back(i);
    if (st.empty())
      st.push(s[i]);
    else if (st.top() == '(' && s[i] == ')')
      st.pop();
    else if (st.top() == '[' && s[i] == ']')
      st.pop();
    else
      st.push(s[i]);
    pre[i] = (int)st.size();
    pos[pre[i]].push_back(i);
  }
  for (int i = 0; i < pos.size(); i++) sort(pos[i].begin(), pos[i].end());
  for (int i = (int)s.size() - 1; i >= 0; i--) {
    if (pre[i] == 0 || pre[i] == 1) continue;
    int u = 1e9 + 10;
    int p = upper_bound(pos[pre[i] - 2].begin(), pos[pre[i] - 2].end(), i) -
            pos[pre[i] - 2].begin();
    if (p >= pos[pre[i] - 2].size()) goto go;
    u = min(u, pos[pre[i] - 2][p]);
  go:;
    elzeroelb3di[i] = u;
  }
  int ans = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (pre[i]) continue;
    int u = upper_bound(opening.begin(), opening.end(), i) -
            lower_bound(opening.begin(), opening.end(), 0);
    if (u > ans) ans = u, from = 0, to = i;
  }
  for (int i = 1; i < (int)s.size(); i++) {
    int diff = pre[i] - 1;
    if (diff <= 0) continue;
    int p = lower_bound(pos[diff].begin(), pos[diff].end(), elzeroelb3di[i]) -
            pos[diff].begin();
    p--;
    if (p >= 0 && pos[diff][p] > i) {
      int u = upper_bound(opening.begin(), opening.end(), pos[diff][p]) -
              lower_bound(opening.begin(), opening.end(), i);
      if (u > ans) ans = u, from = i, to = pos[diff][p];
    }
  }
  cout << ans << '\n';
  if (ans)
    for (int i = from; i <= to; i++) cout << s[i];
  return 0;
}
