#include <bits/stdc++.h>
using namespace std;
stack<pair<int, bool> > st;
char s[100001];
int cnt[100001], dp[100001];
int main() {
  gets(s);
  if (s[0] == '{') cnt[0] = 1;
  for (int i = 1; s[i]; i++) cnt[i] = cnt[i - 1] + (s[i] == '[');
  for (int i = 0; s[i]; i++) {
    dp[i] = -1;
    pair<int, bool> top = pair<int, bool>(0, false);
    if (s[i] == '[' || s[i] == '(') st.push(pair<int, bool>(i, true));
    if ((s[i] == ']' || s[i] == ')') && st.size() > 0) {
      top = st.top();
      st.pop();
    }
    if (s[i] == ']') {
      if (top.second == true && s[top.first] == '[')
        dp[i] = top.first;
      else
        st.push(pair<int, bool>(0, false));
    }
    if (s[i] == ')') {
      if (top.second == true && s[top.first] == '(')
        dp[i] = top.first;
      else
        st.push(pair<int, bool>(0, false));
    }
  }
  for (int i = 0; s[i]; i++)
    if (dp[i] >= 0 && dp[i] - 1 >= 0 && dp[dp[i] - 1] >= 0)
      dp[i] = dp[dp[i] - 1];
  int ans = 0;
  for (int i = 0; s[i]; i++)
    if (dp[i] >= 0) ans = max(ans, cnt[i] - cnt[dp[i]] + (s[dp[i]] == '['));
  for (int i = 0; s[i]; i++)
    if (dp[i] >= 0 && cnt[i] - cnt[dp[i]] + (s[dp[i]] == '[') == ans) {
      printf("%d\n", ans);
      for (int j = dp[i]; j <= i; j++) printf("%c", s[j]);
      return 0;
    }
  printf("%d", ans);
  return 0;
}
