#include <bits/stdc++.h>
using namespace std;
int tree[100500];
char st[100500];
int a[100500];
int sum[100500];
int n;
bool u[100500];
bool match(char cur, char prev) {
  if (cur == ')' && prev == '(') return 1;
  if (cur == ']' && prev == '[') return 1;
  return 0;
}
int sumi(int l, int r) {
  if (l == 0) return sum[r];
  return sum[r] - sum[l - 1];
}
void update(int id, int val) {
  while (id <= n) {
    tree[id] += val;
    id += id & (-id);
  }
}
int main() {
  scanf("%s", st);
  for (int i = 0; i < 100500; i++) {
    if (st[i] == '[') {
      a[i]++;
    }
    if (st[i] == '\0') {
      n = i;
      break;
    }
  }
  sum[0] = a[0];
  for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + a[i];
  stack<char> tube;
  stack<int> ind;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    char cur = st[i];
    if (cur == '(' || cur == '[') {
      tube.push(cur);
      ind.push(i);
    } else {
      if (tube.empty()) {
        tube.push(cur);
        ind.push(i);
        continue;
      }
      char prev = tube.top();
      int ind_of_prev = ind.top();
      if (match(cur, prev)) {
        tube.pop();
        ind.pop();
        u[i] = true;
        u[ind_of_prev] = true;
        ans.push_back(i);
        ans.push_back(ind_of_prev);
      } else {
        while (!tube.empty()) {
          tube.pop();
          ind.pop();
        }
      }
    }
  }
  int maxi = 0;
  int l = 0, r = 0, lm, rm = 0;
  for (int i = 0; i < n; i++) {
    if (u[i]) {
      if (u[l] == 0) l = i;
      r = i;
      if (r == n - 1) {
        int tmp = sumi(l, r);
        if (maxi < tmp) {
          maxi = tmp;
          lm = l, rm = r;
        }
      }
    } else {
      if (u[l] && u[r]) {
        int tmp = sumi(l, r);
        if (maxi < tmp) {
          maxi = tmp;
          lm = l, rm = r;
        }
      }
      l = i;
      r = i;
    }
  }
  printf("%d\n", maxi);
  if (maxi == 0) {
    return 0;
  }
  for (int i = lm; i <= rm; i++) printf("%c", st[i]);
  return 0;
}
