#include <bits/stdc++.h>
using namespace std;
void clean(stack<pair<char, int>> &st) {
  while (!st.empty()) {
    st.pop();
  }
}
int main() {
  stack<pair<char, int>> st;
  string s;
  cin >> s;
  vector<pair<char, int>> v;
  for (int i = 0; i < s.length(); i++) {
    v.push_back(pair<char, int>(s[i], -1));
    if (s[i] == '(' || s[i] == '[') {
      st.push(pair<char, int>(s[i], i));
    } else if (s[i] == ')') {
      if (!(st.empty()) && st.top().first == '(') {
        v[st.top().second].second = i;
        v[i].second = st.top().second;
        st.pop();
      } else {
        clean(st);
      }
    } else {
      if (!(st.empty()) && st.top().first == '[') {
        v[st.top().second].second = i;
        v[i].second = st.top().second;
        st.pop();
      } else {
        clean(st);
      }
    }
  }
  int i = 0, ans = 0, ans_l = 0, ans_r = -1;
  for (int i = 0; i < v.size(); i++) {
    while (v[i].second == -1 && i < v.size()) {
      i++;
    }
    if (i == v.size()) {
      break;
    }
    int nx = v[i].second, ans_cur_cur = 0, flag = 0, j = i, ans_cur = 0,
        ans_l_cur = i, ans_r_cur;
    while (v[j].second != -1 && j < v.size()) {
      for (; j <= nx && j < v.size(); j++) {
        if (v[j].second == -1) {
          ans_cur_cur = 0;
          flag = 1;
          break;
        }
        if (v[j].first == '[') {
          ans_cur_cur++;
        }
      }
      ans_cur += ans_cur_cur;
      ans_cur_cur = 0;
      if (flag == 1) {
        break;
      }
      flag = 0;
      ans_r_cur = nx;
      nx = v[j].second;
    }
    if (ans_cur > ans) {
      ans_l = ans_l_cur;
      ans_r = ans_r_cur;
      ans = ans_cur;
    }
    i = ans_r_cur;
  }
  cout << ans << endl;
  for (int i = ans_l; i <= ans_r; i++) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}
