#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000");
using namespace std;
char s[200010];
struct N {
  int st;
  char c;
} st[200010];
int site[200010];
int main() {
  int i, len, top, h;
  scanf("%s", s);
  bool mark = false;
  memset(site, -1, sizeof(site));
  for (i = 0, len = 0, top = 0; s[i] != 0; ++i) {
    if (len == 0 || (!((st[len - 1].c == '(' && s[i] == ')') ||
                       (st[len - 1].c == '[' && s[i] == ']')))) {
      if (mark) {
        site[st[len].st] = i - 1;
      }
      st[len].c = s[i];
      st[len++].st = i;
      mark = false;
    } else {
      mark = true;
      len--;
    }
  }
  if (mark == true) {
    site[st[len].st] = i - 1;
  }
  int l, r;
  int Max = 0, temp, tl = 0, tr = 1;
  bool mv = false;
  for (i = 0, h = 0; s[i] != '\0';) {
    if (site[i] != -1) {
      if (mv == false) {
        h = i;
        mv = true;
      }
      i = site[i] + 1;
    } else {
      if (mv) {
        l = h, r = i - 1;
        mv = false;
        temp = 0;
        for (int j = l; j <= r; ++j) {
          if (s[j] == '[') {
            temp++;
          }
        }
        if (temp > Max) {
          Max = temp;
          tl = l;
          tr = r;
        }
      }
      ++i;
    }
  }
  if (mv) {
    l = h, r = i - 1;
    mv = false;
    temp = 0;
    for (int j = l; j <= r; ++j) {
      if (s[j] == '[') {
        temp++;
      }
    }
    if (temp > Max) {
      Max = temp;
      tl = l;
      tr = r;
    }
  }
  cout << Max << endl;
  if (Max != 0 || mv) {
    for (i = tl; i <= tr; ++i) {
      cout << s[i];
    }
    cout << endl;
  } else {
    cout << endl;
  }
  return 0;
}
