#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1009;
const double esp = 1e-6;
const int N = 100009;
char str[N];
int ok[N];
int st[N];
int sum[N];
struct point {
  int l, v;
} p[N];
int main() {
  scanf("%s", str + 1);
  int top = -1;
  int ans = 0;
  int tmp = 0;
  sum[0] = 0;
  p[0].v = 0;
  p[0].l = 1;
  for (int i = 1; str[i]; i++) {
    p[i].v = 0;
    p[i].l = i + 1;
    sum[i] = sum[i - 1] + (str[i] == '[');
    st[++top] = i;
    int j = top, a, b;
    while (j >= 1) {
      b = st[j--];
      a = st[j--];
      if (str[a] == '(' && str[b] == ')') {
        top -= 2;
        p[b].v = p[a - 1].v + sum[b] - sum[a - 1];
        p[b].l = p[a - 1].l;
        if (p[b].v > tmp) {
          tmp = p[b].v;
          ans = b;
        }
      } else if (str[a] == '[' && str[b] == ']') {
        top -= 2;
        p[b].v = p[a - 1].v + sum[b] - sum[a - 1];
        p[b].l = p[a - 1].l;
        if (p[b].v > tmp) {
          tmp = p[b].v;
          ans = b;
        }
      } else
        break;
    }
  }
  printf("%d\n", tmp);
  for (int i = p[ans].l; i <= ans; i++) putchar(str[i]);
  puts("");
  return 0;
}
