#include <bits/stdc++.h>
using namespace std;
stack<pair<char, long long> > st;
char s[100005];
int cumSum[100010];
int main() {
  long long len, i, l, r, cnt, ans = 0;
  bool f = 0;
  scanf("%s", s);
  len = strlen(s);
  l = r = 0;
  int c = 0;
  vector<pair<int, int> > ranges;
  for (i = 0, cnt = 0; i < len; i++) {
    if (s[i] == '(') {
      st.push(pair<char, long long>(s[i], i));
    } else if (s[i] == ')') {
      if (!st.empty()) {
        if (st.top().first == '(') {
          ranges.push_back(make_pair(st.top().second, i));
          st.pop();
        } else {
          st.push(pair<char, long long>(s[i], i));
          cnt = 0;
        }
      } else {
        st.push(pair<char, long long>(s[i], i));
        cnt = 0;
      }
    } else if (s[i] == '[') {
      c++;
      st.push(pair<char, long long>(s[i], i));
    } else {
      if (!st.empty()) {
        if (st.top().first == '[') {
          ranges.push_back(make_pair(st.top().second, i));
          st.pop();
        } else {
          st.push(pair<char, long long>(s[i], i));
          cnt = 0;
        }
      } else {
        st.push(pair<char, long long>(s[i], i));
        cnt = 0;
      }
    }
    cumSum[i + 1] = c;
  }
  sort(ranges.begin(), ranges.end());
  int ansl = 0, ansr = 0, c1 = 0;
  for (int i = 0; i < ranges.size(); i++) {
    if (i != 0) {
      if (ranges[i].second < ranges[i - 1].second) continue;
    }
    c = cumSum[ranges[i].second + 1] - cumSum[ranges[i].first];
    if (i != 0) {
      if (ranges[i].second < r)
        continue;
      else if (ranges[i].first == r + 1) {
        r = ranges[i].second;
        c = cumSum[r + 1] - cumSum[l];
        if (c > ans) {
          ans = c;
          ansl = l;
          ansr = r;
        }
      } else {
        l = ranges[i].first;
        r = ranges[i].second;
        c = cumSum[r + 1] - cumSum[l];
        if (c > ans) {
          ans = c;
          ansl = l;
          ansr = r;
        }
      }
    } else {
      l = ranges[i].first;
      r = ranges[i].second;
      c = cumSum[r + 1] - cumSum[l];
      ans = c;
      ansl = l;
      ansr = r;
    }
  }
  printf("%lld\n", ans);
  if (ans > 0) {
    for (i = ansl; i <= ansr; i++) {
      printf("%c", s[i]);
    }
    printf("\n");
  }
  return 0;
}
