#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
char s[N], q[N];
int i, n, l, r, j, c, ans, p[N], ansl, ansr, a[N], b[N];
int main() {
  cin >> s;
  n = strlen(s);
  for (i = 0; i < n; i++) {
    if (s[i] == '[') a[i]++;
    if (i > 0) a[i] += a[i - 1];
    if (s[i] == '[' || s[i] == '(') {
      p[l] = i;
      q[l++] = s[i];
    } else {
      if (l > 0) {
        if (s[i] == ']') {
          if (q[l - 1] == '[') {
            l--;
            b[p[l]] = i;
          } else
            l = 0;
        }
        if (s[i] == ')') {
          if (q[l - 1] != '(')
            l = 0;
          else {
            l--;
            b[p[l]] = i;
          }
        }
      }
    }
  }
  ansr = r = -1;
  for (i = l = 0; i < n; i++) {
    if (s[i] == '[' || s[i] == '(') {
      if (b[i] > 0)
        i = r = b[i];
      else {
        int x = 0;
        if (r > 0) x = a[r];
        if (l > 0) x -= a[l - 1];
        if (x > ans) {
          ans = x;
          ansl = l;
          ansr = r;
        }
        l = i + 1;
      }
    } else {
      int x = 0;
      if (r > 0) x = a[r];
      if (l > 0) x -= a[l - 1];
      if (x > ans) {
        ans = x;
        ansl = l;
        ansr = r;
      }
      l = i + 1;
    }
  }
  int x = 0;
  if (r > 0) x = a[r];
  if (l > 0) x -= a[l - 1];
  if (r >= 0 && x > ans) {
    ans = x;
    ansl = l;
    ansr = r;
  }
  cout << ans << endl;
  for (i = ansl; i <= ansr; i++) cout << s[i];
}
