#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::pair;
using std::stable_sort;
using std::string;
using std::vector;
using namespace std;
vector<pair<char, int>> vect(0);
vector<int> wr(0);
int main() {
  string str = "";
  cin >> str;
  string temp = "";
  string temp2 = "";
  int ans = 0;
  int finalans = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '(' || str[i] == '[')
      vect.push_back(make_pair(str[i], i));
    else {
      if (str[i] == ')') {
        if (vect.size() == 0 || vect[vect.size() - 1].first != '(') {
          for (int j = 0; j < vect.size(); j++) wr.push_back(vect[j].second);
          wr.push_back(i);
          vect.erase(vect.begin(), vect.end());
        }
        if (vect.size() != 0 && vect[vect.size() - 1].first == '(') {
          vect.pop_back();
        }
      }
      if (str[i] == ']') {
        if (vect.size() == 0 || vect[vect.size() - 1].first != '[') {
          for (int j = 0; j < vect.size(); j++) wr.push_back(vect[j].second);
          wr.push_back(i);
          vect.erase(vect.begin(), vect.end());
        }
        if (vect.size() != 0 && vect[vect.size() - 1].first == '[') {
          vect.pop_back();
        }
      }
    }
    if (i == str.length() - 1) {
      for (int j = 0; j < vect.size(); j++) wr.push_back(vect[j].second);
    }
  }
  sort(wr.begin(), wr.end());
  wr.push_back(str.length() + 10);
  int i2 = 0;
  int k = 0;
  int start = 0;
  int finalstart = 0;
  int end = 0;
  while (i2 < str.size()) {
    if (wr[k] == i2) {
      if (ans > finalans) {
        finalstart = start;
        end = i2;
        finalans = ans;
      }
      ans = 0;
      start = i2 + 1;
      k++;
    } else {
      if (str[i2] == ']') ans++;
    }
    i2++;
  }
  if (ans > finalans) {
    finalans = ans;
    finalstart = start;
    end = str.length();
  }
  for (int i = finalstart; i < end; i++) temp += str[i];
  cout << finalans << endl << temp;
  return 0;
}
