#include <bits/stdc++.h>
using namespace std;
char s[100100];
stack<pair<int, int> > p;
void esvazia() {
  while (!p.empty()) p.pop();
}
bool v[100100];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int res = 0;
  int lb = -1, up = -1;
  memset(v, 0, sizeof(v));
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      p.push(make_pair(0, i));
    } else if (s[i] == '[') {
      p.push(make_pair(1, i));
    } else if (s[i] == ')') {
      if (p.empty()) continue;
      int y = p.top().second;
      int ind = p.top().first;
      p.pop();
      if (ind == 0) {
        v[y] = 1;
        v[i] = 1;
      } else {
        esvazia();
      }
    } else {
      if (p.empty()) continue;
      int y = p.top().second;
      int ind = p.top().first;
      p.pop();
      if (ind == 1) {
        v[y] = 1;
        v[i] = 1;
      } else {
        esvazia();
      }
    }
  }
  int a = 0x3f3f3f3f;
  int b = -1;
  int x = 0;
  if (v[0] == 1) {
    if (s[0] == '[') x++;
    a = 0;
  }
  for (int i = 1; i < n; i++) {
    if (v[i] == 0 && v[i - 1] == 1) {
      b = i - 1;
      if (x >= res) {
        lb = a;
        up = b;
        res = x;
      }
    } else if (v[i] == 1 && v[i - 1] == 1) {
      if (s[i] == '[') x++;
    } else if (v[i] == 1) {
      a = i;
      x = 0;
      if (s[i] == '[') x++;
    }
  }
  if (v[n - 1] == 1) {
    b = n - 1;
    if (x >= res) {
      lb = a;
      up = b;
      res = x;
    }
  }
  if (lb == -1) {
    printf("0\n");
    return 0;
  }
  printf("%d\n", res);
  for (int i = lb; i <= up; i++) {
    printf("%c", s[i]);
  }
  printf("\n");
  return 0;
}
