#include <bits/stdc++.h>
using namespace std;
int cnt[100500];
int bestAns, start, len;
int longest[100500];
inline void updAns(int L, int R) {
  int val = cnt[R + 1] - cnt[L];
  if (val > bestAns) {
    bestAns = val;
    start = L;
    len = R - L + 1;
  }
}
int main() {
  stack<pair<char, int> > seq;
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 1; i <= n; i++) {
    cnt[i] = s[i - 1] == '[';
    cnt[i] += cnt[i - 1];
    longest[i - 1] = n + 234;
  }
  for (int i = 0; i < n; i++) {
    pair<char, int> cur(s[i], i);
    if (seq.empty())
      seq.push(cur);
    else {
      char pr = seq.top().first;
      if (s[i] == ']' and pr == '[' or s[i] == ')' and pr == '(') {
        pair<char, int> ws = seq.top();
        seq.pop();
        int low = ws.second, high = i;
        longest[i] = min(longest[i], low);
        if (low > 0 and longest[low - 1] < low - 1) {
          longest[i] = min(longest[i], longest[low - 1]);
        }
        updAns(longest[i], i);
      } else
        seq.push(cur);
    }
  }
  cout << bestAns << endl;
  cout << s.substr(start, len) << endl;
  return 0;
}
