#include <bits/stdc++.h>
using namespace std;
char s[100005];
int num[100005], l[100005];
bool check(char a, char b) {
  return ((a == '(' && b == ')') || (a == '[' && b == ']'));
}
int main() {
  scanf("%s", s);
  int len = strlen(s);
  memset(l, 0, sizeof(l));
  num[0] = 0;
  for (int i = 0; i < len; ++i) num[i + 1] = num[i] + (s[i] == '[');
  for (int i = len - 2; i >= 0; --i) {
    if (s[i] == ')' || s[i] == ']') continue;
    int idx = i + 1 + l[i + 1];
    if (check(s[i], s[idx])) l[i] = idx - i + 1 + l[idx + 1];
  }
  int ans = 0, st = 0;
  for (int i = 0; i < len; ++i)
    if (ans < num[i + l[i]] - num[i]) {
      ans = num[i + l[i]] - num[i];
      st = i;
    }
  printf("%d\n", ans);
  for (int i = 0; i < l[st]; ++i) printf("%c", s[st + i]);
  printf("\n");
  return 0;
}
