#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  int fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
int n;
int ans = 0, ansl, ansr;
char s[100005];
int sum[100005];
signed main() {
  cin >> s + 1;
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (s[i] == '[' ? 1 : 0);
  stack<int> stk;
  stk.push(0);
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '(' || s[i] == '[')
      stk.push(i);
    else {
      if (!stk.empty() && s[stk.top()] == '(' && s[i] == ')' ||
          s[stk.top()] == '[' && s[i] == ']') {
        stk.pop();
      } else {
        stk.push(i);
      }
    }
  }
  int r = n;
  while (!stk.empty()) {
    int l = stk.top() + 1;
    stk.pop();
    if (l <= r) {
      if (sum[r] - sum[l - 1] > ans) {
        ans = sum[r] - sum[l - 1];
        ansl = l;
        ansr = r;
      }
    }
    r = l - 2;
  }
  cout << ans << endl;
  if (ans != 0) {
    for (int i = ansl; i <= ansr; ++i) cout << s[i];
    cout << endl;
  }
  return 0;
}
