#include <bits/stdc++.h>
using namespace std;
char s[100005];
struct dt {
  int pos;
  char c;
} a[100005];
int p = 0;
int b[100005] = {0};
int c[100005] = {0};
int v[100005] = {0};
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int ans = 0;
  int st = 1, ed = 0;
  for (int i = 0; i < n; i++) {
    dt j;
    j.pos = i;
    j.c = s[i];
    if (s[i] == '(')
      a[++p] = j;
    else if (s[i] == '[')
      a[++p] = j;
    else if (s[i] == ')') {
      if (p > 0 && a[p].c == '(') {
        if (s[i - 1] == '(' || v[i - 1] != 0) {
          b[i] = b[i - 1];
          c[i] = a[p].pos;
          v[i] = 1;
          if (v[a[p].pos - 1]) b[i] += b[a[p].pos - 1], c[i] = c[a[p].pos - 1];
          if (b[i] > ans) {
            ans = b[i];
            st = c[i];
            ed = i;
          }
          p--;
        }
      } else
        p = 0;
    } else if (s[i] == ']') {
      if (p > 0 && a[p].c == '[') {
        if (s[i - 1] == '[' || v[i - 1] != 0) {
          v[i] = 1;
          b[i] = b[i - 1] + 1;
          c[i] = a[p].pos;
          if (v[a[p].pos - 1]) b[i] += b[a[p].pos - 1], c[i] = c[a[p].pos - 1];
          if (b[i] > ans) {
            ans = b[i];
            st = c[i];
            ed = i;
          }
          p--;
        }
      } else
        p = 0;
    }
  }
  printf("%d\n", ans);
  for (int i = st; i <= ed; i++) putchar(s[i]);
  return 0;
}
