#include <bits/stdc++.h>
using namespace std;
bool correct[112345];
char temp[112345];
int main() {
  scanf("%s", temp);
  stack<pair<char, int> > s;
  for (int i = 0; temp[i] != '\0'; i++) {
    if (s.size() && ((temp[i] == ')' && s.top().first == '(') ||
                     (temp[i] == ']' && s.top().first == '['))) {
      correct[i] = true;
      correct[s.top().second] = true;
      s.pop();
    } else {
      s.push({temp[i], i});
    }
  }
  int al = 0, ar = -1, _max = 0;
  bool aok = false;
  int m = strlen(temp);
  for (int i = 0; i < m; i++) {
    if (correct[i]) {
      int qtd = 0;
      int j = i;
      while (j < m && correct[j]) {
        if (temp[j] == '[') qtd++;
        j++;
      }
      j--;
      if (aok == false || _max < qtd) {
        aok = true;
        al = i;
        ar = j;
        _max = qtd;
      }
      i = j;
    }
  }
  printf("%d\n", _max);
  for (int i = al; i <= ar; i++) printf("%c", temp[i]);
  return 0;
}
