#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10;
int n;
char s[N];
pair<char, int> stk[N];
int top;
int start[N], earliest[N];
int ans, st, ed, pre[N];
void solve() {
  n = strlen(s);
  st = n;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(' || s[i] == '[') {
      top++;
      stk[top] = pair<char, int>(s[i], i);
    } else {
      if (!top) {
        start[i] = -1;
        earliest[i] = -1;
      }
      if (s[i] == ')') {
        if (stk[top].first != '(') {
          start[i] = -1;
          earliest[i] = -1;
          top = 0;
        } else {
          int id = stk[top].second;
          start[i] = id;
          earliest[i] = id;
          if (id != 0 && (s[id - 1] == ']' || s[id - 1] == ')') &&
              earliest[id - 1] != -1)
            earliest[i] = earliest[id - 1];
          top--;
        }
      }
      if (s[i] == ']') {
        if (stk[top].first != '[') {
          start[i] = -1;
          earliest[i] = -1;
          top = 0;
        } else {
          int id = stk[top].second;
          start[i] = id;
          earliest[i] = id;
          if (id != 0 && (s[id - 1] == ']' || s[id - 1] == ')') &&
              earliest[id - 1] != -1)
            earliest[i] = earliest[id - 1];
          top--;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (s[i - 1] == '[');
  for (int i = 0; i < n; i++)
    if ((s[i] == ')' || s[i] == ']') && earliest[i] != -1) {
      int ST = earliest[i] + 1;
      int ED = i + 1;
      if (pre[ED] - pre[ST - 1] > ans) {
        ans = pre[ED] - pre[ST - 1];
        st = ST - 1;
        ed = ED - 1;
      }
    }
  printf("%d\n", ans);
  for (int i = st; i <= ed; i++) printf("%c", s[i]);
  printf("\n");
}
int main() {
  scanf(" %s", s);
  solve();
  return 0;
}
