#include <bits/stdc++.h>
using namespace std;
const int mod = 1e6;
bool match(char x, char y) {
  if (x == '(' && y == ')')
    return true;
  else if (x == '[' && y == ']')
    return true;
  else
    return false;
}
bool open(char x) {
  if (x == '(' || x == '[')
    return true;
  else
    return false;
}
stack<int> stk;
string s;
int f[100005];
int ret = 0;
int main() {
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    char x = s[i];
    if (open(x)) {
      stk.push(i);
    } else {
      if (!stk.empty() && match(s[stk.top()], x)) {
        f[i] = f[stk.top()] = 0;
        stk.pop();
        if (s[i] == ']') f[i] = 1;
      } else {
        f[i] = -1;
        while (!stk.empty()) {
          f[stk.top()] = -1;
          stk.pop();
        }
      }
    }
  }
  while (!stk.empty()) {
    f[stk.top()] = -1;
    stk.pop();
  }
  for (int i = 0; i < s.length(); i++) {
    if (f[i] != -1 && i > 0 && f[i - 1] != -1) f[i] = f[i - 1] + f[i];
    ret = max(ret, f[i]);
  }
  string ans;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (ret == f[i]) {
      int j = i;
      while (j >= 0 && f[j] >= 0) {
        ans = s[j] + ans;
        j--;
      }
      break;
    }
  }
  cout << ret << "\n";
  cout << ans;
}
