#include <bits/stdc++.h>
using namespace std;
char str[100010];
int f[100010], l[100010], n = 0;
int main() {
  scanf("%s", str + 1);
  memset(f, -1, sizeof(f));
  for (int i = 1; str[i]; ++i, ++n) {
    l[i] = 10000000;
    if (str[i] == ')') {
      if (str[i - 1] == '(') {
        f[i] = 0;
        l[i] = i - 1;
        if (i - 2 > 0 && f[i - 2] >= 0) {
          f[i] = f[i - 2];
          l[i] = l[i - 2];
        }
      } else if (str[i - 1] == ']' || str[i - 1] == ')') {
        if (str[l[i - 1] - 1] != '(') {
          f[i] = -1;
          l[i] = i + 1;
        } else {
          if (l[i - 1] - 2 > 0 && f[l[i - 1] - 2] >= 0) {
            f[i] = f[i - 1] + f[l[i - 1] - 2];
            l[i] = l[l[i - 1] - 2];
          } else {
            f[i] = f[i - 1];
            l[i] = l[i - 1] - 1;
          }
        }
      } else {
        f[i] = -1;
        l[i] = i + 1;
      }
    } else if (str[i] == ']') {
      if (str[i - 1] == '[') {
        f[i] = 1;
        l[i] = i - 1;
        if (i - 2 > 0 && f[i - 2] >= 0) {
          f[i] = f[i - 2] + 1;
          l[i] = l[i - 2];
        }
      } else if (str[i - 1] == ']' || str[i - 1] == ')') {
        if (str[l[i - 1] - 1] != '[') {
          f[i] = -1;
          l[i] = i + 1;
        } else {
          if (l[i - 1] - 2 > 0 && f[l[i - 1] - 2] >= 0) {
            f[i] = f[i - 1] + f[l[i - 1] - 2] + 1;
            l[i] = l[l[i - 1] - 2];
          } else {
            f[i] = f[i - 1] + 1;
            l[i] = l[i - 1] - 1;
          }
        }
      } else {
        f[i] = -1;
        l[i] = i + 1;
      }
    }
  }
  int ans = -1, left, right;
  for (int i = 1; i <= n; ++i)
    if (f[i] > ans && l[i] < i) {
      ans = f[i];
      left = l[i];
      right = i;
    }
  if (ans == -1) {
    puts("0");
    return 0;
  }
  printf("%d\n", ans);
  for (int i = left; i <= right; ++i) printf("%c", str[i]);
  puts("");
  return 0;
}
