#include <bits/stdc++.h>
using namespace std;
char a[110010];
int sta[110010];
int vis[110010];
int ans, l, r;
int main() {
  scanf("%s", a);
  int len = strlen(a);
  int tail = 1;
  for (int i = 0; i < len; i++) {
    if (tail == 1) {
      sta[tail++] = i;
      vis[i] += vis[i - 1];
      continue;
    }
    if (a[i] == '(') {
      sta[tail++] = i;
    }
    if (a[i] == ')') {
      if (a[sta[tail - 1]] == '(')
        tail--;
      else
        sta[tail++] = i;
    }
    if (a[i] == '[') {
      sta[tail++] = i;
    }
    if (a[i] == ']') {
      if (a[sta[tail - 1]] == '[') {
        tail--;
        vis[i] = 1;
      } else
        sta[tail++] = i;
    }
    vis[i] += vis[i - 1];
  }
  vis[len] += vis[len - 1];
  if (tail == 1) {
    cout << vis[len] - vis[0] << endl;
    cout << a << endl;
    return 0;
  }
  sta[tail++] = len;
  sta[0] = 0;
  for (int i = 1; i < tail; i++) {
    if (ans < vis[sta[i]] - vis[sta[i - 1]]) {
      ans = vis[sta[i]] - vis[sta[i - 1]];
      if (i - 1)
        l = sta[i - 1] + 1;
      else
        l = 0;
      r = sta[i];
    }
  }
  cout << ans << endl;
  for (int i = l; i < r; i++) cout << a[i];
  return 0;
}
