#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vector<bool> v(n, 0);
  stack<int> st;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(' || s[i] == '[')
      st.push(i);
    else {
      if (st.empty()) continue;
      int top = st.top();
      if ((s[top] == '(' && s[i] == ')') || (s[top] == '[' && s[i] == ']')) {
        st.pop();
        v[top] = v[i] = 1;
      } else {
        while (!st.empty()) {
          st.pop();
        }
      }
    }
  }
  int count = 0;
  int sqb = 0;
  string answer = "";
  for (int i = 0; i < n; i++) {
    if (v[i])
      count++;
    else {
      if (count) {
        int tmp = 0;
        string ans = "";
        for (int j = i - count; j < i; j++) {
          if (s[j] == ']') tmp++;
          ans += s[j];
        }
        if (tmp > sqb) {
          sqb = tmp;
          answer = ans;
        }
      }
      count = 0;
    }
  }
  if (count) {
    int tmp = 0;
    string ans = "";
    for (int j = n - count; j < n; j++) {
      if (s[j] == ']') tmp++;
      ans += s[j];
    }
    if (tmp > sqb) {
      sqb = tmp;
      answer = ans;
    }
  }
  cout << sqb;
  cout << "\n";
  cout << answer;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int tests = 1;
  for (long long int test_case = 1; test_case <= tests; test_case++) {
    solve();
  }
  cerr << "Execution Time : " << (float)clock() / CLOCKS_PER_SEC << " secs"
       << endl;
  return 0;
}
