#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
const int inf = 1e+9;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int xabs(int a) { return a >= 0 ? a : -a; }
int sign(int a) { return (a < 0) ? -1 : 1; }
int sqr(int a) { return a * a; }
int main() {
  string s;
  cin >> s;
  int n = s.size();
  stack<pair<char, int> > q;
  set<pair<char, char> > sp;
  sp.insert(make_pair('[', ']'));
  sp.insert(make_pair('(', ')'));
  for (int i = 0; i < n; i++) {
    if (q.size() == 0) {
      q.push(make_pair(s[i], i));
    } else {
      if (sp.count(make_pair(q.top().first, s[i]))) {
        q.pop();
      } else {
        q.push(make_pair(s[i], i));
      }
    }
  }
  vector<int> ans;
  while (q.size() != 0) {
    ans.push_back(q.top().second);
    q.pop();
  }
  reverse(ans.begin(), ans.end());
  ans.push_back(n);
  int cnt = 0;
  int j = 0;
  int ma = 0;
  string res;
  while (j < ans.size()) {
    int cnt = 0;
    int start = (j > 0) ? ans[j - 1] + 1 : 0;
    for (int i = start; i < ans[j]; i++) {
      if (s[i] == '[') cnt++;
    }
    if (cnt > ma) {
      ma = cnt;
      res = s.substr(start, ans[j] - start);
    }
    j++;
  }
  cout << ma << endl;
  cout << res << endl;
  return 0;
}
