#include <bits/stdc++.h>
using namespace std;
char line[100001];
int dp[100001], f[100001];
int n;
string s;
stack<pair<int, int> > st;
int main() {
  memset(dp, -1, sizeof(dp));
  memset(f, -1, sizeof(f));
  memset(line, 0, sizeof(line));
  scanf("%s", line);
  s = line;
  n = (int)s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] == '(') st.push(make_pair(s[i], i));
    if (s[i] == '[') st.push(make_pair(s[i], i));
    if (s[i] == ')') {
      if (st.size() && st.top().first == '(') {
        if (dp[i - 1] == -1)
          dp[i] = 0;
        else
          dp[i] = dp[i - 1];
        f[i] = st.top().second;
        st.pop();
      } else
        while (st.size()) st.pop();
    }
    if (s[i] == ']') {
      if (st.size() && st.top().first == '[') {
        if (dp[i - 1] == -1)
          dp[i] = 1;
        else
          dp[i] = dp[i - 1] + 1;
        f[i] = st.top().second;
        st.pop();
      } else
        while (st.size()) st.pop();
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (dp[i] == -1) continue;
    int prv = f[i] - 1;
    if (i >= 1 && dp[i - 1] != -1) {
      if (s[i] == ']')
        dp[i] = dp[i - 1] + 1;
      else
        dp[i] = dp[i - 1];
    }
    if (prv >= 0 && dp[prv] != -1) {
      dp[i] += dp[prv];
      f[i] = f[prv];
    }
    if (dp[i] > ans) ans = dp[i];
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; ++i) {
    if (f[i] == -1) continue;
    if (dp[i] == ans) {
      for (int j = f[i]; j <= i; ++j) printf("%c", s[j]);
      break;
    }
  }
  printf("\n");
  return 0;
}
