#include <bits/stdc++.h>
using namespace std;
int N, A[100022], Pair[100022];
int Sum[100022];
char S[100022];
inline void Up(int &a, int b) {
  if (a < b) a = b;
}
inline char Match(char a) {
  if (a == '[') return ']';
  if (a == '(') return ')';
  if (a == ']') return '[';
  if (a == ')') return '(';
  assert(0);
  return 'F';
}
int main() {
  scanf("%s", S + 1);
  N = strlen(S + 1);
  Sum[0] = 0;
  for (int i = 1; i <= N; ++i) {
    Sum[i] = Sum[i - 1] + (S[i] == '[');
  }
  static pair<char, int> Stack[100022];
  int Stop = 0;
  Pair[0] = 1000000000;
  for (int i = 1; i <= N; ++i) {
    int &res = Pair[i] = 1000000000;
    char c = S[i];
    if (c == '(' || c == '[') {
      Stack[++Stop] = pair<char, int>(c, i);
      res = 1000000000;
      continue;
    }
    assert(c == ')' || c == ']');
    if (Stop == 0 || Stack[Stop].first != Match(c)) {
      res = 1000000000;
      Stop = 0;
      continue;
    }
    int left = res = Stack[Stop].second;
    if (left == 1 || Pair[left - 1] == 1000000000)
      res = left;
    else
      res = Pair[left - 1];
    --Stop;
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i)
    if (Pair[i] != 1000000000) Up(ans, Sum[i] - Sum[Pair[i] - 1]);
  printf("%d\n", ans);
  if (ans == 0) {
    printf("\n");
    return 0;
  }
  for (int i = 1; i <= N; ++i)
    if (Pair[i] != 1000000000)
      if (Sum[i] - Sum[Pair[i] - 1] == ans) {
        for (int itr = Pair[i]; itr <= i; ++itr) putchar(S[itr]);
        puts("");
        break;
      }
  return 0;
}
