#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> L(s.size(), -1);
  vector<pair<char, int>> S;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(') S.push_back({'(', i});
    if (s[i] == '[') S.push_back({'[', i});
    if (s[i] == ')') {
      if (S.empty() || S.back().first != '(')
        S.clear();
      else
        L[i] = S.back().second, S.pop_back();
    }
    if (s[i] == ']') {
      if (S.empty() || S.back().first != '[')
        S.clear();
      else
        L[i] = S.back().second, S.pop_back();
    }
  }
  string best = "";
  int best_cnt = 0;
  vector<string> ats;
  for (int i = s.size() - 1; i >= 0; i--)
    if (L[i] != -1) {
      string x = s.substr(L[i], i - L[i] + 1);
      vector<string> m;
      m.push_back(x);
      i = L[i] - 1;
      while (i >= 0 && L[i] != -1) {
        x = s.substr(L[i], i - L[i] + 1);
        m.push_back(x);
        i = L[i] - 1;
      }
      string z;
      reverse(m.begin(), m.end());
      for (auto& x : m) z += x;
      int cnt = 0;
      for (auto& ch : z)
        if (ch == '[') cnt++;
      if (cnt > best_cnt) best = z, best_cnt = cnt;
    }
  cout << best_cnt << "\n" << best;
}
