#include <bits/stdc++.h>
using namespace std;
char c1[100010], c[100010];
int maxa, maxb, pp;
bool w[100010];
void gc(int a, int b, int p) {
  if (b > maxb) {
    maxa = a;
    maxb = b;
    pp = p;
  }
}
int main() {
  stack<int> sta;
  while (scanf("%s", c) != EOF) {
    int l = strlen(c);
    memset(w, false, sizeof(w));
    maxa = 0;
    maxb = 0;
    pp = 0;
    for (int i = (0); i < (l); i++) {
      if (c[i] == '(' || c[i] == '[')
        sta.push(i);
      else {
        if (sta.empty()) continue;
        if (c[i] == ')') {
          if (c[sta.top()] == '(') {
            w[i] = w[sta.top()] = true;
            sta.pop();
          } else
            while (!sta.empty()) sta.pop();
        } else {
          if (c[sta.top()] == '[') {
            w[i] = w[sta.top()] = true;
            sta.pop();
          } else
            while (!sta.empty()) sta.pop();
        }
      }
    }
    int a = 0, b = 0, p = 0;
    for (int i = (0); i < (l); i++) {
      if (w[i]) {
        a++;
        b += (c[i] == '[');
      } else {
        gc(a, b, p);
        a = b = 0;
        p = i + 1;
      }
      if (i == l - 1) gc(a, b, p);
    }
    int dd = pp + maxa;
    printf("%d\n", maxb);
    for (int i = (pp); i < (dd); i++) printf("%c", c[i]);
    printf("\n");
  }
  return 0;
}
