#include <bits/stdc++.h>
using namespace std;
template <class F, class T>
T convert(F a, int p = -1) {
  stringstream ss;
  if (p >= 0) ss << fixed << setprecision(p);
  ss << a;
  T r;
  ss >> r;
  return r;
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T cube(T x) {
  return x * x * x;
}
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return s == 0 ? 0 : cntbit(s >> 1) + (s & 1);
}
const double PI = acos(-1.0);
const double eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const long long linf = (long long)1e16 + 5;
const long long mod = (long long)1e9 + 7;
int n, top, f[100005], st[100005], dp[100005], trace[100005];
char a[100005];
char twin(char c) {
  if (c == ')') return '(';
  if (c == ']') return '[';
  if (c == '(') return ')';
  if (c == '[') return ']';
  return '?';
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  f[0] = 0;
  for (int i = (1); i <= (n); ++i) f[i] = f[i - 1] + (a[i] == '[' ? 1 : 0);
  dp[0] = 0;
  top = 0;
  for (int j = (1); j <= (n); ++j) {
    char c = a[j];
    if (c == '(' || c == '[' || top == 0) {
      st[++top] = j;
      dp[j] = 0;
    } else {
      if (a[st[top]] == twin(c)) {
        int i = st[top--];
        dp[j] = dp[i - 1] + f[j] - f[i - 1];
        trace[j] = i;
      } else {
        st[++top] = j;
        dp[j] = 0;
      }
    }
  }
  int best = 0, jbest, ibest;
  for (int j = (1); j <= (n); ++j)
    if (best < dp[j]) {
      best = dp[j];
      jbest = j;
    }
  printf("%d\n", best);
  if (best > 0) {
    int j = jbest;
    while (dp[j] > 0) {
      ibest = trace[j];
      j = ibest - 1;
    }
    for (int i = (ibest); i <= (jbest); ++i) printf("%c", a[i]);
  }
  return 0;
}
