#include <bits/stdc++.h>
using namespace std;
char s[100010];
int dp[100010], stk[100010], has[100010];
void solve() {
  int len = strlen(s);
  int top = 0;
  for (int i = 0; i < len; i++) dp[i] = -1;
  for (int i = 0; i < len; i++) {
    if (s[i] == '[' || s[i] == '(')
      stk[top++] = i;
    else if (s[i] == ')') {
      if (top && s[stk[top - 1]] == '(')
        dp[i] = stk[--top];
      else
        top = 0;
    } else if (s[i] == ']') {
      if (top && s[stk[top - 1]] == '[')
        dp[i] = stk[--top];
      else
        top = 0;
    }
  }
  for (int i = 0; i < len; i++)
    if (dp[i] > 0 && dp[dp[i] - 1] != -1) dp[i] = dp[dp[i] - 1];
  has[0] = 0;
  for (int i = 0; i < len; i++) has[i + 1] = has[i] + (s[i] == '[');
  int ans = 0, l = -1, r = -1;
  for (int i = 0; i < len; i++)
    if (dp[i] != -1) {
      int st = dp[i], ed = i + 1;
      int fuck = has[ed] - has[st];
      if (fuck > ans) {
        ans = fuck;
        l = st, r = ed;
      }
    }
  if (ans) {
    printf("%d\n", ans);
    for (int i = l; i < r; i++) printf("%c", s[i]);
    printf("\n");
  } else
    printf("0\n\n");
}
int main() {
  while (scanf("%s", s) != EOF) solve();
  return 0;
}
