#include <bits/stdc++.h>
using namespace std;
char s[100009];
int r[100009], num[100009];
pair<char, int> stk[100009];
int top = 0;
int main() {
  gets(s);
  for (int i = 0; s[i]; i++) {
    if (top == 0 && s[i] != ']' && s[i] != ')') {
      stk[top++] = (pair<char, int>(s[i], i));
    } else if (top != 0) {
      pair<char, int> x = stk[top - 1];
      if ((x.first == '[' && s[i] == ']') || (x.first == '(' && s[i] == ')')) {
        r[x.second] = i;
        top--;
      } else if ((x.first == '[' && s[i] != ')') ||
                 (x.first == '(' && s[i] != ']')) {
        stk[top++] = (pair<char, int>(s[i], i));
      } else {
        top = 0;
      }
    }
  }
  num[0] = (s[0] == '[');
  for (int i = 1; s[i]; i++) {
    num[i] = num[i - 1] + (s[i] == '[');
  }
  int j = 0;
  int ansl, ansr, mx = -1;
  int n = strlen(s);
  while (s[j] && j < n) {
    if (r[j] != 0) {
      int tl = j;
      int tr;
      while (r[j] != 0 && j < n) {
        tr = r[j];
        j = tr + 1;
      }
      int tmp = num[tr] - (tl != 0 ? num[tl - 1] : 0);
      if (tmp > mx) {
        ansl = tl, ansr = tr, mx = tmp;
      }
    } else
      j++;
  }
  printf("%d\n", mx == -1 ? 0 : mx);
  if (mx != -1) {
    for (int i = ansl; i <= ansr; i++) putchar(s[i]);
    puts("");
  }
  return 0;
}
