#include <bits/stdc++.h>
using namespace std;
char str[100006];
int cnt[100006];
stack<int> S;
vector<pair<int, int> > valid, touse;
bool check(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first - 1 && a.second == b.second + 1) return true;
  return false;
}
int main() {
  int i, t, ans;
  pair<int, int> p;
  while (scanf("%s", str + 1) != EOF) {
    while (!S.empty()) S.pop();
    valid.clear();
    for (i = 1; str[i]; ++i) {
      cnt[i] = cnt[i - 1] + (str[i] == '[');
      if (str[i] == ')') {
        if (S.empty()) continue;
        if (str[S.top()] == '(') {
          p = make_pair(S.top(), i);
          if (valid.size() && check(p, valid[valid.size() - 1]))
            valid.pop_back();
          valid.push_back(p);
          S.pop();
        } else
          while (!S.empty()) S.pop();
      } else if (str[i] == ']') {
        if (S.empty()) continue;
        if (str[S.top()] == '[') {
          p = make_pair(S.top(), i);
          if (valid.size() && check(p, valid[valid.size() - 1]))
            valid.pop_back();
          valid.push_back(p);
          S.pop();
        } else
          while (!S.empty()) S.pop();
      } else
        S.push(i);
    }
    if (valid.size() == 0) {
      puts("0\n");
      continue;
    }
    sort(valid.begin(), valid.end());
    touse.clear();
    touse.push_back(valid[0]);
    for (i = 1; i < valid.size(); ++i) {
      t = touse.size() - 1;
      if (valid[i].first < touse[t].second) continue;
      if (touse[t].second + 1 == valid[i].first)
        touse[t].second = valid[i].second;
      else
        touse.push_back(valid[i]);
    }
    ans = -1;
    for (i = 0; i < touse.size(); ++i) {
      t = cnt[touse[i].second] - cnt[touse[i].first - 1];
      if (t > ans) {
        ans = t;
        p = touse[i];
      }
    }
    printf("%d\n", ans);
    for (i = p.first; i <= p.second; ++i) putchar(str[i]);
    puts("");
  }
  return 0;
}
