#include <bits/stdc++.h>
using namespace std;
long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
const long long maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
long long q[maxn], t;
long long match[maxn];
long long pref[maxn];
long long en[maxn];
int32_t main() {
  string s;
  cin >> s;
  long long n = s.size();
  long long ans = 0;
  long long l = 0, sz = 0;
  memset(match, -1, sizeof match);
  for (long long i = 0; i < n; i++) pref[i + 1] = pref[i] + (s[i] == '[');
  for (long long i = 0; i < n; i++) {
    if (s[i] == '(' || s[i] == '[')
      q[t++] = i;
    else {
      if (s[i] == ')') {
        if (t && s[q[t - 1]] == '(') {
          match[q[t - 1]] = i;
          match[i] = q[t - 1];
          if (q[t - 1] > 0 && match[q[t - 1] - 1] + 1)
            match[i] = match[q[t - 1] - 1], match[match[q[t - 1] - 1]] = i;
          t--;
        } else
          t = 0;
      } else {
        if (t && s[q[t - 1]] == '[') {
          match[q[t - 1]] = i;
          match[i] = q[t - 1];
          if (q[t - 1] > 0 && match[q[t - 1] - 1] + 1)
            match[i] = match[q[t - 1] - 1], match[match[q[t - 1] - 1]] = i;
          t--;
        } else
          t = 0;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    if (match[i] + 1 && i < match[i]) {
      long long value = pref[match[i] + 1] - pref[i];
      if (value > ans) ans = value, l = i, sz = match[i] - i + 1;
    }
  }
  cout << ans << endl;
  cout << s.substr(l, sz) << endl;
}
