#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int Max = 1000;
const long long int limit = 1e9;
const double eps = 1e-4;
vector<pair<int, int> > validSegment;
vector<pair<int, int> > bigestSegment;
vector<int> braketCount;
string seq;
void cumulativeBracketCount() {
  int n = seq.size();
  braketCount.resize(n + 1);
  braketCount[0] = 0;
  for (int i = 1; i <= n; i++)
    braketCount[i] = braketCount[i - 1] + (seq[i - 1] == '[');
}
void calculateSegment() {
  int n = seq.size();
  stack<pair<int, char> > check;
  for (int i = 0; i < n; i++) {
    if (seq[i] == '(' or seq[i] == '[')
      check.push({i + 1, seq[i]});
    else if (seq[i] == ')') {
      if (!check.empty()) {
        if (check.top().second == '(') {
          validSegment.push_back({check.top().first, i + 1});
          check.pop();
        } else
          while (!check.empty()) check.pop();
      }
    } else if (seq[i] == ']') {
      if (!check.empty()) {
        if (check.top().second == '[') {
          validSegment.push_back({check.top().first, i + 1});
          check.pop();
        } else
          while (!check.empty()) check.pop();
      }
    }
  }
}
void maskigBigSegment() {
  sort(validSegment.begin(), validSegment.end());
  for (int i = 0; i < validSegment.size(); i++) {
    bigestSegment.push_back(validSegment[i]);
    int j = i + 1;
    while (j < validSegment.size() and
           (validSegment[j].first > validSegment[i].first and
            validSegment[j].second < validSegment[i].second)) {
      j++;
    }
    i = j - 1;
  }
  for (int i = 0; i < bigestSegment.size(); i++) {
    pair<int, int> temp = bigestSegment[i];
    int j = i + 1;
    while (j < bigestSegment.size() and
           bigestSegment[j].first - 1 == temp.second) {
      temp = bigestSegment[j];
      j++;
    }
    j--;
    bigestSegment[i] = {bigestSegment[i].first, bigestSegment[j].second};
    i = j;
  }
}
pair<int, string> solution() {
  cumulativeBracketCount();
  calculateSegment();
  maskigBigSegment();
  int maxx = 0, pos = -1;
  string res = "";
  for (int i = 0; i < bigestSegment.size(); i++) {
    int temp = braketCount[bigestSegment[i].second] -
               braketCount[bigestSegment[i].first - 1];
    if (temp > maxx) {
      maxx = temp;
      pos = i;
    }
  }
  if (pos != -1)
    for (int i = bigestSegment[pos].first - 1; i < bigestSegment[pos].second;
         i++)
      res += seq[i];
  return {maxx, res};
}
int main() {
  cin >> seq;
  pair<int, string> ans = solution();
  cout << ans.first << endl << ans.second << endl;
  return 0;
}
