#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
void solve() {
  string s;
  cin >> s;
  stack<pair<long long int, char>> st;
  long long int n = s.size();
  long long int start = 0, ans = 0, length = 0;
  vector<long long int> p(n);
  long long int x = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '[') {
      x++;
    }
    p[i] = x;
  }
  long long int i = 0;
  while (i < n) {
    if (s[i] == ']') {
      if (!st.empty()) {
        if (st.top().second == '[') {
          st.pop();
          long long int y;
          if (st.empty()) {
            y = 0;
          } else {
            y = st.top().first + 1;
          }
          long long int cur = p[i] - p[y] + (s[y] == '[');
          if (cur > ans) {
            ans = cur;
            start = y;
            length = i - y + 1;
          }
        } else {
          st.push({i, s[i]});
        }
      } else {
        st.push({i, s[i]});
      }
    } else if (s[i] == '[' || s[i] == '(') {
      st.push({i, s[i]});
    } else {
      if (!st.empty()) {
        if (st.top().second == '(') {
          st.pop();
          long long int y;
          if (st.empty()) {
            y = 0;
          } else {
            y = st.top().first + 1;
          }
          long long int cur = p[i] - p[y] + (s[y] == '[');
          if (cur > ans) {
            ans = cur;
            start = y;
            length = i - y + 1;
          }
        } else {
          st.push({i, s[i]});
        }
      } else {
        st.push({i, s[i]});
      }
    }
    i++;
  }
  long long int aa = 0;
  string res;
  for (long long int i = start; i < start + length; i++) {
    res += s[i];
    if (s[i] == '[') {
      aa++;
    }
  }
  cout << aa << "\n";
  cout << res << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
