#include <bits/stdc++.h>
using namespace std;
const int M4 = 1e4 + 100, M5 = 1e5 + 100, M6 = 1e6 + 100, M7 = 1e7 + 100,
          M8 = 1e8 + 100, M9 = 1e9 + 100;
stack<int> s;
int f[M5], m[M5], e[M5];
void clr() {
  while ((int)(s).size()) s.pop();
}
int main() {
  string t;
  cin >> t;
  for (int i = 0; i < (int)(t).size(); i++) {
    f[i] = -1;
    auto c = t[i];
    if (c == '(' || c == '[')
      s.push(i);
    else if ((int)(s).size()) {
      if (c == ']' && t[s.top()] == '[')
        f[i] = s.top(), f[s.top()] = i, s.pop();
      else if (c == ')' && t[s.top()] == '(')
        f[i] = s.top(), f[s.top()] = i, s.pop();
      else
        clr();
    }
  }
  int ptr = 0;
  bool q = 0;
  for (int i = 0; i < (int)(t).size(); i++) {
    if (f[i] == -1 || f[i] < i) {
      ptr += q, q = 0;
      continue;
    }
    if (e[ptr] == 0) e[ptr] = i + 1;
    m[ptr] = f[i], q = 1;
    if (m[ptr] + 1 >= (int)(t).size()) {
      ptr++;
      break;
    }
    if (t[m[ptr] + 1] == ']' || t[m[ptr] + 1] == ')') ptr++, q = 0;
    i = f[i];
  }
  int ans = 0, ind = 0;
  for (int p = 0; p < ptr; p++) {
    int sum = 0;
    for (int i = e[p] - 1; i <= m[p]; i++) sum += (t[i] == '[');
    if (sum > ans) ans = sum, ind = p;
  }
  cout << ans << endl;
  if (ans)
    for (int i = e[ind] - 1; i <= m[ind]; i++) cout << t[i];
  return 0;
}
