#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<pair<char, int> > S;
  string linea;
  cin >> linea;
  vector<bool> check(linea.size(), false);
  for (int i = 0; i < linea.size(); i++) {
    if (linea[i] == '(' || linea[i] == '[') {
      S.push(make_pair(linea[i], i));
    } else {
      if (linea[i] == ')') {
        pair<char, int> x;
        x.first = '*';
        if (!S.empty()) {
          x = S.top();
          S.pop();
        }
        if (x.first == '(') {
          check[i] = true;
          check[x.second] = true;
        } else {
          S.push(make_pair('*', -1));
        }
      } else {
        pair<char, int> x;
        x.first = '*';
        if (!S.empty()) {
          x = S.top();
          S.pop();
        }
        if (x.first == '[') {
          check[i] = true;
          check[x.second] = true;
        } else {
          S.push(make_pair('*', -1));
        }
      }
    }
  }
  int ans = -1;
  int b = 0, bt = 0, e;
  int tmp = 0;
  for (int i = 0; i < int(linea.size()); i++) {
    if (!check[i]) {
      if (tmp > ans) {
        b = bt;
        ans = tmp;
        e = i;
      }
      bt = i + 1;
      tmp = 0;
    } else {
      if (linea[i] == '[') tmp++;
    }
  }
  if (tmp > ans) {
    b = bt;
    ans = tmp;
    e = linea.size();
  }
  if (ans == -1)
    cout << 0 << endl;
  else {
    cout << ans << endl;
    cout << linea.substr(b, e - b);
  }
  return 0;
}
