#include <bits/stdc++.h>
using namespace std;
struct Node {
  int id;
  char c;
} tmp;
stack<Node> s;
char cc[100005];
int x[100005];
int dis[100005];
bool ok(char a, char b) {
  if (a == '[' && b == ']') return 1;
  if (a == '(' && b == ')') return 1;
  return 0;
}
int main(int argc, char** argv) {
  while (!s.empty()) s.pop();
  int n;
  scanf(" %s", cc);
  n = strlen(cc);
  tmp.id = 0;
  tmp.c = '.';
  s.push(tmp);
  memset(dis, 0, sizeof(dis));
  for (int i = (0); i < (n); i++) {
    if (ok(s.top().c, cc[i])) {
      s.pop();
      x[i + 1] = s.top().id;
    } else {
      tmp.c = cc[i];
      tmp.id = i + 1;
      s.push(tmp);
      x[i + 1] = i + 1;
    }
  }
  for (int i = (0); i < (n); i++) {
    if (cc[i] == '[')
      dis[i + 1] = dis[i] + 1;
    else
      dis[i + 1] = dis[i];
  }
  int u = -1;
  int tmp = -1;
  for (int i = (1); i < (n + 1); i++) {
    if (x[i] != i) {
      if (dis[i] - dis[x[i]] > tmp) {
        u = i;
        tmp = dis[i] - dis[x[i]];
      }
    }
  }
  if (u == -1) {
    printf("0\n");
    return 0;
  }
  printf("%d\n", tmp);
  for (int i = (x[u]); i < (u); i++) printf("%c", cc[i]);
  printf("\n");
  return 0;
}
