#include <bits/stdc++.h>
using namespace std;
struct stu {
  char s;
  int i;
} stak[100001];
int main() {
  char arr[100001];
  int i, g = 0, all = 0, h = -1, nall = 0, nh = 0, ne = -1;
  i = 0;
  bool flag[100001] = {0};
  scanf("%s", arr);
  while (arr[i]) {
    if (arr[i] == '(' || arr[i] == '[') {
      stak[g].s = arr[i];
      stak[g++].i = i;
    } else {
      if (g > 0) {
        if (arr[i] == ')') {
          if (stak[g - 1].s == '(') {
            flag[i] = 1;
            flag[stak[g - 1].i] = 1;
            g--;
          } else
            g = 0;
        } else {
          if (arr[i] == ']') {
            if (stak[g - 1].s == '[') {
              flag[i] = 1;
              flag[stak[g - 1].i] = 1;
              g--;
            } else
              g = 0;
          }
        }
      }
    }
    i++;
  }
  bool si = 0;
  for (i = 0; arr[i]; i++) {
    if (flag[i] == 1) {
      if (si == 0) h = i;
      si = 1;
      if (arr[i] == '[') nall++;
    } else {
      if (nall > all || (nall == all && si == 1)) {
        all = nall;
        nh = h;
        ne = i - 1;
      }
      si = 0;
      h = i + 1;
      nall = 0;
    }
  }
  if (nall > all || (nall == all && si == 1)) {
    all = nall;
    nh = h;
    ne = i - 1;
  }
  printf("%d\n", all);
  for (i = nh; i <= ne; i++) {
    printf("%c", arr[i]);
  }
  return 0;
}
