#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
auto start = high_resolution_clock::now();
inline void measure();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string second;
  cin >> second;
  int st = 0, num = 0, nd;
  stack<pair<char, int> > ch;
  ch.push({second[0], 0});
  int cnt[100002] = {0};
  cnt[0] = (second[0] == '[' ? 1 : 0);
  for (int i = (1); i < (second.length()); i++) {
    cnt[i] = cnt[i - 1] + (second[i] == '[' ? 1 : 0);
  }
  for (int i = (1); i < (second.length()); i++) {
    if (ch.empty()) {
      ch.push({second[i], i});
    } else {
      if (second[i] == ']' && ch.top().first == '[' ||
          second[i] == ')' && ch.top().first == '(') {
        int x, z = i, y;
        ch.pop();
        if (ch.empty())
          x = 0;
        else
          x = ch.top().second + 1;
        if (x == 0)
          y = cnt[z];
        else
          y = cnt[z] - cnt[x - 1];
        if (num < y) {
          num = y;
          st = x;
          nd = z;
        }
      } else {
        ch.push({second[i], i});
      }
    }
  }
  cout << num << endl;
  if (num) {
    for (int i = (st); i <= (nd); i++) {
      cout << second[i];
    }
    cout << endl;
  }
  return 0;
}
inline void measure() {
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stop - start);
  cout << duration.count() << endl;
}
