#include <bits/stdc++.h>
using namespace std;
string s;
class sbs {
 public:
  sbs(int _b, int _e, int _val) {
    b = _b;
    e = _e;
    val = _val;
    update();
  }
  void update() {
    while (b > 0 && e < s.size() - 1 &&
           (((s[b - 1]) == '(' && (s[e + 1]) == ')') ||
            ((s[b - 1]) == '[' && (s[e + 1]) == ']'))) {
      b--;
      e++;
      if (s[b] == '[') val++;
    }
  }
  int b;
  int e;
  int val;
};
list<sbs> l;
int main() {
  cin >> s;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == '(' && s[i + 1] == ')') {
      l.push_back(sbs(i, i + 1, 0));
    }
    if (s[i] == '[' && s[i + 1] == ']') {
      l.push_back(sbs(i, i + 1, 1));
    }
  }
  bool upd = true;
  while (upd) {
    upd = false;
    for (typeof((l).begin()) it = (l).begin(); it != (l).end(); it++) {
      list<sbs>::iterator next = it;
      next++;
      if (next == l.end()) break;
      if (it->e + 1 == next->b) {
        it->e = next->e;
        it->val += next->val;
        it->update();
        l.erase(next);
        upd = true;
      }
    }
  }
  int res = 0;
  int b = 0;
  int e = -1;
  for (typeof((l).begin()) it = (l).begin(); it != (l).end(); it++) {
    if (it->val > res) {
      res = it->val;
      b = it->b;
      e = it->e;
    }
  }
  cout << res << endl;
  cout << s.substr(b, e - b + 1) << endl;
  return 0;
}
