#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v, out;
stack<pair<char, int> > st;
char s[100010];
int l;
int curr_lo, curr_hi, curr_cnt, max_cnt, lo, hi;
int sum[100010];
void cal() {
  int i, j, k;
  l = strlen(s);
  for (i = 0; i < l; ++i) {
    if (s[i] == '(' || s[i] == '[')
      st.push({s[i], i});
    else {
      if ((s[i] == ')' && !st.empty() && st.top().first == '(') ||
          (s[i] == ']' && !st.empty() && st.top().first == '[')) {
        curr_lo = st.top().second;
        curr_hi = i;
        v.push_back({curr_lo, curr_hi});
        st.pop();
      } else {
        while (!st.empty()) st.pop();
      }
    }
  }
}
int main() {
  scanf("%s", s);
  int i;
  int maxi, ind, curr;
  maxi = -1;
  sum[0] = (s[0] == '[');
  cal();
  for (i = 1; i < l; ++i) {
    sum[i] = sum[i - 1];
    if (s[i] == '[') ++sum[i];
  }
  if (v.size() == 0)
    puts("0");
  else {
    sort(v.begin(), v.end());
    out.push_back(v[0]);
    for (i = 1; i < v.size(); ++i) {
      if (v[i].second < out[out.size() - 1].second) continue;
      if (v[i].first == out[out.size() - 1].second + 1)
        out[out.size() - 1].second = v[i].second;
      else
        out.push_back(v[i]);
    }
    for (i = 0; i < out.size(); ++i) {
      curr = sum[out[i].second] - sum[out[i].first];
      if (s[out[i].first] == '[') ++curr;
      if (curr > maxi) {
        maxi = curr;
        ind = i;
      }
    }
    printf("%d\n", maxi);
    for (i = out[ind].first; i <= out[ind].second; ++i) putchar(s[i]);
    puts("");
  }
  return 0;
}
