#include <bits/stdc++.h>
using namespace std;
char g[1 << 20];
int s[1 << 20], p, n;
bool opp(int a, int b) {
  return (g[a] == '(' && g[b] == ')') || (g[a] == '[' && g[b] == ']');
}
int main() {
  scanf("%s", g);
  n = strlen(g);
  for (int(i) = 0; i < int(n); ++i) {
    if (!p)
      s[++p] = i;
    else if (opp(s[p], i))
      --p;
    else
      s[++p] = i;
  }
  s[p + 1] = n;
  s[0] = -1;
  int l, r, best = 0;
  for (int i = 0; i <= p; ++i) {
    int c = 0;
    for (int j = s[i] + 1; j < s[i + 1]; ++j) c += g[j] == '[';
    if (c > best) {
      best = c;
      l = s[i] + 1;
      r = s[i + 1];
    }
  }
  cout << best << endl;
  if (best)
    for (int j = l; j < r; ++j) printf("%c", g[j]);
}
