#include <bits/stdc++.h>
using namespace std;
const int N = 500000 + 5;
stack<int> S;
int a[N];
int main() {
  string str;
  cin >> str;
  for (int i = 0; i < (int)str.size(); i++) {
    if (str[i] == '[')
      a[i] = -1;
    else if (str[i] == '(')
      a[i] = -2;
    else if (str[i] == ']')
      a[i] = 1;
    else if (str[i] == ')')
      a[i] = 2;
  }
  for (int i = 0; i < (int)str.size(); i++) {
    if (S.empty() or a[i] == -1 or a[i] == -2)
      S.push(i);
    else if ((a[i] + a[S.top()]) == 0)
      S.pop();
    else
      S.push(i);
  }
  int left, right;
  S.push((int)str.size());
  int res = 0;
  int start, endd;
  while (!S.empty()) {
    if (S.size() != 1) {
      int temp = S.top();
      S.pop();
      right = temp - 1;
      temp = S.top();
      left = temp + 1;
    } else {
      int temp = S.top();
      S.pop();
      right = temp - 1;
      left = 0;
    }
    int minn = 0;
    for (int i = left; i <= right; i++)
      if (str[i] == '[') minn++;
    if (minn > res) {
      res = minn;
      start = left;
      endd = right;
    }
  }
  cout << res << "\n";
  if (res != 0) {
    for (int i = start; i <= endd; i++) cout << str[i];
    cout << "\n";
  }
  return 0;
}
