#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)5e5 + 5;
string s;
deque<char> q;
vector<long long> kq, a, fikq;
long long fin, luu = -1, thu;
int main() {
  cin >> s;
  for (long long i = 0; i <= (int)s.size() - 1; i++) {
    if ((int)a.size() != 0 && (s[a.back()] == '(' && s[i] == ')' ||
                               (s[a.back()] == '[' && s[i] == ']'))) {
      kq.push_back(a.back());
      kq.push_back(i);
      a.pop_back();
    } else {
      a.push_back(i);
    }
  }
  sort(kq.begin(), kq.end());
  a.clear();
  long long dem = 0, pre = -2, res = 0;
  for (auto i : kq) {
    if (i - 1 != pre) {
      if (dem > res) {
        res = dem;
        fikq = a;
      }
      dem = 0;
      a.clear();
      dem += (s[i] == '[');
      a.push_back(i);
    } else {
      dem += (s[i] == '[');
      a.push_back(i);
    }
    pre = i;
  }
  if (dem > res) {
    res = dem;
    fikq = a;
  }
  cout << res << "\n";
  for (auto i : fikq) cout << s[i];
}
