#include <bits/stdc++.h>
using namespace std;
const long long mxN = 1e5 + 5;
long long a[mxN];
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  long long n = s.length(), l = 0, r = 0, ans = 0;
  stack<long long> stk;
  stk.push(0);
  for (long long i = 0; i < n; i++) {
    char ch = s[i];
    if (ch == '[') a[i + 1]++;
    a[i + 1] += a[i];
    long long k = stk.top() - 1;
    if (k >= 0 && (ch == ')' && s[k] == '(' || ch == ']' && s[k] == '[')) {
      stk.pop();
      k = stk.top();
      long long len = a[i + 1] - a[k];
      if (len > ans) {
        ans = len;
        l = k;
        r = i + 1;
      }
    } else {
      stk.push(i + 1);
    }
  }
  cout << ans << '\n';
  for (long long i = l; i < r; i++) cout << s[i];
  return 0;
}
