#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 5;
long long a[maxn], c[maxn];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string st;
  cin >> st;
  long long n = st.size();
  stack<long long> s;
  vector<long long> b;
  for (auto it : st) {
    if (it == '(') b.emplace_back(1);
    if (it == ')') b.emplace_back(-1);
    if (it == '[') b.emplace_back(2);
    if (it == ']') b.emplace_back(-2);
  }
  for (long long i = 0; i < n; ++i) {
    if (s.empty() or b[s.top()] + b[i] != 0 or b[i] > 0)
      s.push(i);
    else {
      a[s.top()] = i;
      a[i] = s.top();
      s.pop();
    }
  }
  for (long long i = 1; i <= n - 1; ++i) {
    c[i] = c[i - 1];
    if (st[i - 1] == '[') c[i]++;
  }
  for (long long i = n - 2; i >= 0; --i) {
    if (a[i] <= i) continue;
    if (a[i] >= n - 1) continue;
    if (a[a[i] + 1] <= a[i] + 1) continue;
    a[i] = a[a[i] + 1];
  }
  long long ans = 0, len = 0;
  long long val = 0;
  for (long long i = 0; i < n; ++i) {
    if (a[i] <= i) continue;
    if (val < c[a[i]] - c[i]) {
      val = c[a[i]] - c[i];
      ans = i;
      len = a[i] - i + 1;
    }
  }
  cout << val << '\n';
  ;
  cout << st.substr(ans, len) << '\n';
  ;
  return 0;
}
