#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<char, int> > st;
  vector<pair<int, int> > tmp;
  int ans[300001][2], i, j, t, q, sm, max, tmax, qmax;
  string inp;
  cin >> inp;
  i = 0;
  for (j = 0; j < inp.size(); ++j) {
    if ((inp[j] == '(') || (inp[j] == '[')) {
      st.push_back(make_pair(inp[j], j));
    } else if (inp[j] == ')') {
      if ((st.size() > 0) && (st.back().first == '(')) {
        if (st.size() == 1) {
          sm = 0;
          for (q = st.back().second; q < j; ++q) {
            if (inp[q] == '[') {
              sm++;
            }
          }
          ans[i][0] = sm;
          ans[i][1] = st.back().second;
          i++;
        }
        st.pop_back();
      } else {
        tmp.push_back(make_pair(-1, j));
        t = j;
        while (st.size() > 0) {
          sm = 0;
          for (q = st.back().second + 1; q < t; ++q) {
            if (inp[q] == '[') {
              sm++;
            }
          }
          tmp.push_back(make_pair(sm, st.back().second + 1));
          tmp.push_back(make_pair(-1, st.back().second));
          t = st.back().second;
          st.pop_back();
        }
        while (tmp.size() > 0) {
          ans[i][0] = tmp.back().first;
          ans[i][1] = tmp.back().second;
          i++;
          tmp.pop_back();
        }
      }
    } else if (inp[j] == ']') {
      if ((st.size() > 0) && (st.back().first == '[')) {
        if (st.size() == 1) {
          sm = 0;
          for (q = st.back().second; q < j; ++q) {
            if (inp[q] == '[') {
              sm++;
            }
          }
          ans[i][0] = sm;
          ans[i][1] = st.back().second;
          i++;
        }
        st.pop_back();
      } else {
        tmp.push_back(make_pair(-1, j));
        t = j;
        while (st.size() > 0) {
          sm = 0;
          for (q = st.back().second + 1; q < t; ++q) {
            if (inp[q] == '[') {
              sm++;
            }
          }
          tmp.push_back(make_pair(sm, st.back().second + 1));
          tmp.push_back(make_pair(-1, st.back().second));
          t = st.back().second;
          st.pop_back();
        }
        while (tmp.size() > 0) {
          ans[i][0] = tmp.back().first;
          ans[i][1] = tmp.back().second;
          i++;
          tmp.pop_back();
        }
      }
    }
  }
  if (st.size() > 0) {
    tmp.push_back(make_pair(-1, j));
    t = j;
    while (st.size() > 0) {
      sm = 0;
      for (q = st.back().second + 1; q < t; ++q) {
        if (inp[q] == '[') {
          sm++;
        }
      }
      tmp.push_back(make_pair(sm, st.back().second + 1));
      tmp.push_back(make_pair(-1, st.back().second));
      t = st.back().second;
      st.pop_back();
    }
    while (tmp.size() > 0) {
      ans[i][0] = tmp.back().first;
      ans[i][1] = tmp.back().second;
      i++;
      tmp.pop_back();
    }
  }
  max = sm = 0;
  tmax = t = -1;
  qmax = q = -1;
  for (j = 0; j < i; ++j) {
    if (ans[j][0] >= 0) {
      sm += ans[j][0];
      if (t < 0) {
        t = ans[j][1];
      }
      if (j < i - 1) {
        q = ans[j + 1][1];
      } else {
        q = inp.size();
      }
      if (sm > max) {
        max = sm;
        tmax = t;
        qmax = q;
      }
    } else {
      sm = 0;
      t = q = -1;
    }
  }
  cout << max;
  if (max > 0) {
    cout << "\n" << inp.substr(tmax, qmax - tmax);
  }
  return 0;
}
