#include <bits/stdc++.h>
using namespace std;
char a[200000];
int l, e[200000], s1[200000], s2[200000], l1, l2, aib[200000], smax, pmax;
void add(int poz) {
  for (; poz <= l; poz += poz & (-poz)) aib[poz]++;
}
int sum(int poz) {
  int r = 0;
  for (; poz; poz -= poz & (-poz)) r += aib[poz];
  return r;
}
int q(int x, int y) { return sum(y) - sum(x - 1); }
int main() {
  int i;
  cin.getline(a + 1, 200000);
  l = strlen(a + 1);
  for (i = 1; i <= l; ++i) {
    if (a[i] == '(') {
      s1[++l1] = i;
    }
    if (a[i] == '[') {
      s2[++l2] = i;
      add(i);
    }
    if (a[i] == ')') {
      if (!l1 || s2[l2] > s1[l1]) {
        l1 = 0;
        l2 = 0;
        continue;
      }
      e[s1[l1]] = i;
      --l1;
    }
    if (a[i] == ']') {
      if (!l2 || s1[l1] > s2[l2]) {
        l1 = 0;
        l2 = 0;
        continue;
      }
      e[s2[l2]] = i;
      --l2;
    }
  }
  for (i = l - 1; i; --i) {
    if (e[i] && e[e[i] + 1]) e[i] = e[e[i] + 1];
  }
  for (i = 1; i <= l; ++i) {
    if (e[i]) {
      int t = q(i, e[i]);
      if (t > smax) {
        smax = t;
        pmax = i;
      }
    }
  }
  if (smax == 0) {
    cout << smax;
    return 0;
  }
  cout << smax << "\n";
  for (i = pmax; i <= e[pmax]; ++i) cout << a[i];
  return 0;
}
