#include <bits/stdc++.h>
using namespace std;
class myobj {
 public:
  int pos;
  char val;
};
int main() {
  char a[100003];
  scanf("%s", a);
  int len = strlen(a);
  int check[len + 3];
  for (int i = (int)0; i < (int)len + 2; ++i) check[i] = 0;
  stack<myobj> myStack;
  for (int i = (int)0; i < (int)len; ++i) {
    if (a[i] == '(' || a[i] == '[') {
      myobj obj;
      obj.val = a[i];
      obj.pos = i;
      myStack.push(obj);
    } else {
      if (myStack.empty()) {
        continue;
      }
      myobj obj = myStack.top();
      if (!myStack.empty()) myStack.pop();
      if ((obj.val == '(' && a[i] == ')') || (obj.val == '[' && a[i] == ']')) {
        check[obj.pos] = 1;
        check[i] = 1;
      } else {
        while (!myStack.empty()) {
          myStack.pop();
        }
      }
    }
  }
  check[len] = 0;
  int maxcount = 0, maxleftcount = 0;
  int left = 0, prevleft = 0, right = len - 1, count = 0, leftcount = 0;
  bool found = false;
  for (int i = 0; i < len + 1; i++) {
    if (check[i] == 0) {
      if (leftcount > maxleftcount) {
        maxleftcount = leftcount;
        right = i - 1;
        prevleft = left;
      }
      leftcount = 0;
      left = i + 1;
    } else {
      found = true;
      if (a[i] == '[') leftcount++;
    }
  }
  if (!found || maxleftcount == 0)
    printf("0\n");
  else {
    printf("%d\n", maxleftcount);
    for (int i = prevleft; i <= right; i++) printf("%c", a[i]);
    printf("\n");
  }
  return 0;
}
