#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[300], p[100100], ps[100100];
pair<int, int> sk[100100];
int sz;
char s[2 * 100100], ss[100100];
int main() {
  sz = 0;
  memset(p, -1, sizeof(p));
  f['('] = 1;
  f['['] = 2;
  f[')'] = -1;
  f[']'] = -2;
  scanf("%s", s);
  n = strlen(s);
  ps[0] = 0;
  for (int i = (1); i <= (n); i++) {
    ps[i] = ps[i - 1];
    if (s[i - 1] == '[') ps[i]++;
  }
  for (int i = (0); i < (n); i++) {
    if (f[s[i]] > 0)
      sk[sz++] = pair<int, int>(f[s[i]], i);
    else {
      int x = sk[sz - 1].first, y = sk[sz - 1].second;
      if (x + f[s[i]]) sz = 0;
      if (!sz) continue;
      p[i] = y;
      sz--;
    }
  }
  int mx = -1;
  for (int i = (0); i < (n); i++) {
    if (p[i] <= 0) continue;
    if (p[p[i] - 1] != -1) p[i] = p[p[i] - 1];
  }
  for (int i = (0); i < (n); i++) {
    if (p[i] == -1) continue;
    if (mx != -1 && ps[i + 1] - ps[p[i]] <= ps[mx + 1] - ps[p[mx]]) continue;
    mx = i;
  }
  if (mx == -1)
    puts("0");
  else {
    printf("%d\n", ps[mx + 1] - ps[p[mx]]);
    for (int i = (p[mx]); i <= (mx); i++) printf("%c", s[i]);
    puts("");
  }
  return 0;
}
