50 50 50 50
 49 49 4 1
 48 50 12 11
 5 7 1 10
 1 50 50 50
 5 7 1 4
 32 4 17 3
 1 50 1 50
 50 1 1 1
 32 31 10 9
 5 7 4 1
 49 49 3 3
 50 49 1 2
 50 48 3 1
 50 1 1 50
 5 7 10 10
 1 1 1 1
 49 50 11 12

Second
 Second
 Second
 Second
 Second
 Second
 First
 Second
 First
 First
 Second
 Second
 First
 First
 First
 Second
 Second
 Second

#include <bits/stdc++.h>
using namespace std;
string s;
stack<int> q;
const int mn = 1e5 + 10;
int l[mn];
int rx;
int ry;
int lf = -2;
int rxlf = 0, rylf = 0;
int blf;
int res = 0;
int cnt = 0;
int m[mn];
void check(int x, int y) {
  if (x > 0 && m[x - 1] >= 0)
    m[y] = m[x - 1];
  else
    m[y] = x;
  if (res < l[y] - l[m[y]] + (s[m[y]] == '[')) {
    res = l[y] - l[m[y]] + (s[m[y]] == '[');
    rx = m[y];
    ry = y;
  }
}
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    cnt += s[i] == '[';
    l[i] = cnt;
  }
  memset(m, -1, sizeof m);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '[' || s[i] == '(') {
      q.push(i);
      continue;
    }
    if (q.size() == 0) continue;
    int ind = q.top();
    if (s[i] == ']' && s[ind] == '[') {
      if (res < l[i] - l[ind] + 1) {
        res = l[i] - l[ind] + 1;
        rx = ind;
        ry = i;
      }
      check(ind, i);
      q.pop();
    } else if (s[i] == ')' && s[ind] == '(') {
      q.pop();
      check(ind, i);
    } else {
      while (!q.empty()) q.pop();
      lf = -2;
    }
  }
  cout << res << endl;
  if (res) cout << s.substr(rx, ry - rx + 1) << endl;
  return 0;
}
