#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
template <class T>
T SQR(const T &a) {
  return a * a;
}
void run() {
  char str[100100] = {0};
  scanf("%s", str);
  vector<int> vec;
  int best = -1, bestA = -1, bestB = -1;
  int curr = 0, A = 1e9, B = 1e9;
  int n = strlen(str);
  int Cnt[100100] = {0};
  int Best[100100];
  int Start[100100];
  memset(Best, -1, sizeof(Best));
  for (int i = (0), ei = (n); i < ei; i++) {
    if (str[i] == '(' || str[i] == '[') {
      Cnt[i] = curr;
      vec.push_back(i);
    } else {
      if (!vec.empty() && (str[vec.back()] == '(' && str[i] == ')' ||
                           str[vec.back()] == '[' && str[i] == ']')) {
        if (str[i] == ']') curr++;
        Best[i] = curr - Cnt[vec.back()];
        Start[i] = vec.back();
        if (vec.back() != 0 && Best[vec.back() - 1] != -1) {
          Best[i] += Best[vec.back() - 1];
          Start[i] = Start[vec.back() - 1];
        }
        vec.pop_back();
      } else
        vec.clear();
    }
  }
  for (int i = (0), ei = (n); i < ei; i++)
    if (Best[i] > best) {
      best = Best[i];
      bestA = Start[i];
      bestB = i;
    }
  if (best == -1) {
    for (int i = (0), ei = (n - 1); i < ei; i++)
      if (str[i] == '(' && str[i + 1] == ')') {
        best = 0;
        bestA = i;
        bestB = i + 1;
        break;
      }
  }
  if (best == -1)
    printf("0\n");
  else {
    printf("%d\n", best);
    str[bestB + 1] = 0;
    printf("%s\n", str + bestA);
  }
}
int main() {
  run();
  return 0;
}
