#include <bits/stdc++.h>
using namespace std;
static const int MAXN = 1e5 + 10;
static const int OO = 0x3fffffff;
inline int read() {
  int ret = 0, f = 1;
  char c;
  while (c = getchar(), !isdigit(c)) f = c == 45 ? -1 : 1;
  while (isdigit(c)) {
    ret = (ret << 3) + (ret << 1);
    ret += c - 48;
    c = getchar();
  }
  return f * ret;
}
char s[MAXN];
int num[MAXN];
int p[MAXN];
int main() {
  scanf(" %s", s + 1);
  int n = strlen(s + 1);
  int l = 1, r = 0;
  for (int i = 1; i <= n; ++i) {
    num[i] = num[i - 1] + (s[i] == ']');
  }
  for (int i = n - 1; i; --i) {
    if (s[i] == ')' || s[i] == ']') continue;
    int nxt = i + 1 + p[i + 1];
    if ((s[i] == '(' && s[nxt] == ')') || (s[i] == '[' && s[nxt] == ']')) {
      p[i] = nxt - i + 1 + p[nxt + 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int tp = i + p[i] - 1;
    if (num[tp] - num[i - 1] > ans) {
      ans = num[tp] - num[i - 1];
      l = i, r = tp;
    }
  }
  printf("%d\n", ans);
  for (int i = l; i <= r; ++i) {
    printf("%c", s[i]);
  }
  puts("");
}
