#include <bits/stdc++.h>
using namespace std;
long long a[200005];
string str;
stack<char> s;
stack<int> pos;
int main() {
  long long n, x;
  cin >> str;
  long long len = str.size();
  long long l = 1, r = 0;
  long long ans = 0;
  long long maxx = 0;
  int ansl = l, ansr = r;
  for (int i = 0; i < len; i++) {
    if (!s.empty() && ((s.top() == '[' && str[i] == ']') ||
                       (s.top() == '(' && str[i] == ')'))) {
      pos.pop();
      s.pop();
    } else {
      s.push(str[i]);
      pos.push(i);
    }
  }
  int d = 0;
  int pre = len - 1;
  while (!pos.empty()) {
    ans = 0;
    d = pos.top();
    pos.pop();
    for (int i = pre; i > d; i--) {
      if (str[i] == '[') ans++;
    }
    if (maxx < ans) {
      maxx = ans;
      ansl = d + 1;
      ansr = pre;
    }
    pre = d - 1;
  }
  ans = 0;
  for (int i = pre; i >= 0; i--) {
    if (str[i] == '[') ans++;
  }
  if (maxx < ans) {
    maxx = ans;
    ansl = 0;
    ansr = pre;
  }
  pre = d;
  cout << maxx << endl;
  for (int i = ansl; i <= ansr; i++) {
    cout << str[i];
  }
}
