#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double err = 1e-12;
const double PI = 3.141592653589793;
const int N = 1e5 + 5;
int mx = 0;
string s;
stack<int> st;
vector<int> pre(N, 0);
void solve() {
  int lid = 0, rid = -1;
  cin >> s;
  st.push(0);
  for (int i = 0; i < s.length(); i++) {
    pre[i + 1] = pre[i] + (s[i] == '[');
    if (s[i] == '[' || s[i] == '(')
      st.push(i + 1);
    else {
      if (st.size() != 1 && ((s[i] == ')' && s[st.top() - 1] == '(') ||
                             (s[i] == ']' && s[st.top() - 1] == '['))) {
        st.pop();
        if (pre[i + 1] - pre[st.top()] > mx) {
          mx = pre[i + 1] - pre[st.top()];
          lid = st.top();
          rid = i;
        }
      } else
        st.push(i + 1);
    }
  }
  cout << mx << "\n" << s.substr(lid, rid - lid + 1) << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
