#include <bits/stdc++.h>
using namespace std;
int opening[100001];
int ans[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string str;
  int res = 0;
  cin >> str;
  int n = str.size();
  stack<pair<int, int> > s;
  for (int i = 0; i < n; i++) {
    if (str[i] == '(')
      opening[i] = -1, s.push(pair<int, int>(0, i));
    else if (str[i] == '[')
      opening[i] = -1, s.push(pair<int, int>(1, i));
    else if (str[i] == ')') {
      if (s.empty()) {
        opening[i] = -1;
        continue;
      }
      if (s.top().first) {
        opening[i] = -1;
        while (!s.empty()) s.pop();
      } else {
        opening[i] = s.top().second;
        s.pop();
      }
    } else {
      if (s.empty()) {
        opening[i] = -1;
        continue;
      }
      if (s.top().first) {
        opening[i] = s.top().second;
        s.pop();
      } else {
        opening[i] = -1;
        while (!s.empty()) s.pop();
      }
    }
  }
  int start = -1, end = -1;
  for (int i = 1; i <= n; i++) {
    int v;
    if (str[i - 1] == ']')
      v = 1;
    else
      v = 0;
    if (opening[i - 1] != -1) ans[i] = v + ans[i - 1] + ans[opening[i - 1]];
    if (ans[i] > res) {
      res = ans[i];
      end = i - 1;
      start = opening[i - 1];
      while (start && opening[start - 1] != -1) start = opening[start - 1];
    }
  }
  cout << res << "\n";
  if (res) {
    for (int i = start; i <= end; i++) cout << str[i];
  }
  cout << "\n";
  return 0;
}
