#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int INF = 0x3f3f3f3f;
const int N = 100010;
const double eps = 1e-6;
char s[N];
int a[N];
stack<int> Q;
int main() {
  scanf("%s", s);
  memset(a, 0, sizeof(a));
  int len = strlen(s);
  if (!Q.empty()) Q.pop();
  for (int i = 0; i < len; i++) {
    if (s[i] == '[' || s[i] == '(')
      Q.push(i);
    else if (s[i] == ']') {
      if (!Q.empty() && s[Q.top()] == '[') {
        a[Q.top()] = 1;
        a[i] = 1;
        Q.pop();
      } else {
        while (!Q.empty()) Q.pop();
      }
    } else {
      if (!Q.empty() && s[Q.top()] == '(') {
        a[Q.top()] = 1;
        a[i] = 1;
        Q.pop();
      } else {
        while (!Q.empty()) Q.pop();
      }
    }
  }
  int ansl, ansr, ans = 0;
  int l = 0, now = 0;
  for (int i = 0; i <= len; i++) {
    if (a[i] == 1) {
      if (s[i] == '[') now++;
    } else {
      if (ans < now) {
        ans = now;
        ansl = l;
        ansr = i - 1;
      }
      l = i + 1;
      now = 0;
    }
  }
  printf("%d\n", ans);
  if (ans != 0) {
    for (int i = ansl; i <= ansr; i++) printf("%c", s[i]);
  }
  printf("\n");
  return 0;
}
