#include <bits/stdc++.h>
using namespace std;
int a[100001];
int i, l, r, sum, temp, start, endd, res;
int main() {
  stack<int> s;
  string str;
  cin >> str;
  int l = str.size();
  for (i = 0; i < l; i++) {
    if (str[i] == '(')
      a[i] = -2;
    else if (str[i] == ')')
      a[i] = 2;
    else if (str[i] == '[')
      a[i] = -1;
    else if (str[i] == ']')
      a[i] = 1;
  }
  for (i = 0; i < l; i++) {
    if (s.empty() || a[i] == -1 || a[i] == -2) {
      s.push(i);
    } else if (a[i] + a[s.top()] == 0)
      s.pop();
    else
      s.push(i);
  }
  s.push(l);
  while (!s.empty()) {
    if (s.size() != 1) {
      temp = s.top();
      r = temp - 1;
      s.pop();
      temp = s.top();
      l = temp + 1;
    } else {
      temp = s.top();
      s.pop();
      r = temp - 1;
      l = 0;
    }
    int minn = 0;
    for (i = l; i <= r; i++) {
      if (str[i] == '[') minn++;
    }
    if (minn > res) {
      res = minn;
      start = l;
      endd = r;
    }
  }
  cout << res << endl;
  if (res != 0)
    for (i = start; i <= endd; i++) {
      cout << str[i];
    }
  return 0;
}
