#include <bits/stdc++.h>
using namespace std;
template <class T>
T cdiv(T num, T den) {
  return (num / den) + (num % den > 0);
}
template <typename TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
template <class t>
t mag(t a) {
  return a > 0 ? a : -a;
}
std::ifstream term("/dev/tty");
string tempstring;
int tc = 1;
string s, tp;
vector<int> dp;
int escape() {
  cin >> tp;
  s = " " + tp;
  dp.resize(s.size() + 3);
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == ')') {
      if (s[i - 1] == '(') {
        dp[i] = dp[i - 2] + 2;
      }
      if (s[i - 1] == ')' and s[i - 1 - dp[i - 1]] == '(') {
        dp[i] = dp[i - 1] + 2 + dp[i - 1 - dp[i - 1] - 1];
      }
      if (s[i - 1] == ']' and s[i - 1 - dp[i - 1]] == '(') {
        dp[i] = dp[i - 1] + 2 + dp[i - 1 - dp[i - 1] - 1];
      }
    }
    if (s[i] == ']') {
      if (s[i - 1] == '[') {
        dp[i] = dp[i - 2] + 2;
      }
      if (s[i - 1] == ']' and s[i - 1 - dp[i - 1]] == '[') {
        dp[i] = dp[i - 1] + 2 + dp[i - 1 - dp[i - 1] - 1];
      }
      if (s[i - 1] == ')' and s[i - 1 - dp[i - 1]] == '[') {
        dp[i] = dp[i - 1] + 2 + dp[i - 1 - dp[i - 1] - 1];
      }
    }
  }
  vector<int> cnt;
  ;
  ;
  int cur = 0;
  for (auto& e : s) {
    cur += e == '[';
    cnt.push_back(cur);
  }
  int maxcnt = 0;
  for (int i = 1; i < s.size(); i++) {
    if (cnt[i] - cnt[i - dp[i]] > maxcnt) {
      maxcnt = cnt[i] - cnt[i - dp[i]];
    }
  }
  if (maxcnt == 0) {
    cout << 0 << '\n';
    return 0;
  }
  for (int i = 1; i < s.size(); i++) {
    if (cnt[i] - cnt[i - dp[i]] == maxcnt) {
      cout << maxcnt << '\n';
      for (int c = i - dp[i] + 1; c <= i; c++) {
        cout << s[c];
      }
      return 0;
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  while (tc--) escape();
}
