#include <bits/stdc++.h>
using namespace std;
string cad;
int fin[100300];
int main() {
  memset(fin, -1, sizeof fin);
  cin >> cad;
  stack<char> s;
  stack<int> pos;
  for (int i = 0; i < cad.size(); i++) {
    if (cad[i] == '(') {
      s.push(cad[i]);
      pos.push(i);
    } else if (cad[i] == '[') {
      s.push(cad[i]);
      pos.push(i);
    } else if (cad[i] == ')') {
      if (!s.empty()) {
        char c = s.top();
        s.pop();
        int p = pos.top();
        pos.pop();
        if (c == '(') {
          fin[p] = i;
        } else {
          s.push(')');
          pos.push(i);
        }
      }
    } else if (cad[i] == ']') {
      if (!s.empty()) {
        char c = s.top();
        s.pop();
        int p = pos.top();
        pos.pop();
        if (c == '[') {
          fin[p] = i;
        } else {
          s.push(']');
          pos.push(i);
        }
      }
    }
  }
  int r = 0;
  int ini = 0, fin1 = 0;
  for (int i = 0; i < cad.size();) {
    if (fin[i] != -1) {
      int rr = 0;
      int fi = fin[i] + 1;
      int ini2 = i;
      while (fi < cad.size()) {
        if (fin[fi] != -1)
          fi = fin[fi] + 1;
        else
          break;
      }
      while (i < fi) {
        if (cad[i] == '[') rr++;
        i++;
      }
      if (rr > r) {
        ini = ini2;
        fin1 = fi - 1;
        r = rr;
      }
    } else
      i++;
  }
  cout << r << endl;
  if (r) cout << cad.substr(ini, fin1 - ini + 1) << endl;
  return 0;
}
