#include <bits/stdc++.h>
using namespace std;
int ans, brackets[100000 + 5], L = 0, R = 0;
int stk[100000 + 5];
char in[100000 + 5];
string in2;
void update(int l, int r) {
  if (ans < brackets[r] - brackets[l]) {
    ans = brackets[r] - brackets[l];
    L = l;
    R = r;
  }
}
int main() {
  cin >> in2;
  for (int i = 0; i < in2.size(); i++) in[i + 1] = in2[i];
  int ptr = 0;
  int len = in2.size();
  ans = 0;
  for (int i = 1; i <= len; i++) brackets[i] = brackets[i - 1] + (in[i] == '[');
  for (int i = 1; i <= len; i++) {
    if (in[i] == '[' || in[i] == '(') {
      stk[++ptr] = i;
    } else if ((ptr == 0 && (in[i] == ']' || in[i] == ')')) ||
               (in[i] == ')' && in[stk[ptr]] != '(') ||
               (in[i] == ']' && in[stk[ptr]] != '[')) {
      ptr = 0;
      stk[++ptr] = i;
    } else if (ptr != 0) {
      update(stk[ptr - 1], i);
      ptr--;
    }
  }
  printf("%d\n", ans);
  if (ans != 0) {
    for (int i = L + 1; i <= R; i++) printf("%c", in[i]);
  }
  printf("\n");
}
