#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 100;
int st[MN];
inline int getSum(int a, int b) { return st[b + 1] - st[a]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  s.push_back('[');
  s.insert(s.begin(), ']');
  list<pair<int, int> > lt;
  for (int i = 0; i < s.size(); ++i) {
    lt.push_back({s[i], i});
    if (s[i] == '[') {
      st[i + 1] = 1;
    }
    st[i + 1] += st[i];
  }
  list<pair<int, int> >::iterator it = lt.begin();
  int lol = 0;
  int siz = lt.size();
  while (siz > 1 && it != lt.end()) {
    list<pair<int, int> >::iterator it2 = it;
    ++it2;
    if (it2 == lt.end()) break;
    if (it->first == '(' && it2->first == ')') {
      it = lt.erase(it);
      it = lt.erase(it);
      siz -= 2;
      if (it != lt.begin() && !lt.empty()) --it;
    } else if (it->first == '[' && it2->first == ']') {
      it = lt.erase(it);
      it = lt.erase(it);
      siz -= 2;
      if (it != lt.begin() && !lt.empty()) --it;
    } else {
      ++it;
    }
  }
  int ma = 0;
  if (lt.size() == 0) {
    cout << getSum(0, s.size() - 1) << '\n';
    cout << s << '\n';
    return 0;
  }
  it = lt.begin();
  while (it != lt.end()) {
    list<pair<int, int> >::iterator it2 = it;
    ++it2;
    if (it2 == lt.end()) break;
    ma = max(ma, getSum(it->second + 1, it2->second - 1));
    ++it;
  }
  if (ma == 0) {
    cout << 0 << '\n';
    return 0;
  }
  it = lt.begin();
  while (it != lt.end()) {
    list<pair<int, int> >::iterator it2 = it;
    ++it2;
    if (it2 == lt.end()) break;
    if (getSum(it->second + 1, it2->second - 1) == ma) {
      cout << ma << '\n';
      for (int i = it->second + 1; i < it2->second; ++i) {
        cout << s[i];
      }
      cout << '\n';
      return 0;
    }
    ++it;
  }
  cout << 0 << '\n';
}
