#include <bits/stdc++.h>
using namespace std;
string A;
stack<pair<int, int> > S;
int i, j;
int ANS, CANS;
int L, R;
int D[100010], St[100010];
void Clear() {
  while (!S.empty()) S.pop();
}
int main() {
  getline(cin, A);
  A = ' ' + A;
  ANS = 0;
  St[0] = -1;
  for (i = 1; i < A.size(); i++) {
    D[i] = D[i - 1] + (A[i] == '[');
    St[i] = -1;
  }
  for (i = 1; i < A.size(); i++) {
    if (A[i] == '[') {
      S.push(make_pair(1, i));
      continue;
    }
    if (A[i] == '(') {
      S.push(make_pair(2, i));
      continue;
    }
    if (A[i] == ')') {
      if (S.empty()) {
        continue;
      }
      if (S.top().first != 2) {
        Clear();
        continue;
      }
      j = S.top().second;
      S.pop();
      St[i] = j;
      if (St[St[i] - 1] != -1) St[i] = St[St[i] - 1];
      CANS = D[i] - D[St[i] - 1];
      if (CANS >= ANS) {
        ANS = CANS;
        L = St[i];
        R = i;
      }
      continue;
    }
    if (A[i] == ']') {
      if (S.empty()) {
        CANS = 0;
        continue;
      }
      if (S.top().first != 1) {
        CANS = 0;
        Clear();
        continue;
      }
      j = S.top().second;
      S.pop();
      St[i] = j;
      if (St[St[i] - 1] != -1) St[i] = St[St[i] - 1];
      CANS = D[i] - D[St[i] - 1];
      if (CANS >= ANS) {
        ANS = CANS;
        L = St[i];
        R = i;
      }
      continue;
    }
  }
  cout << ANS << '\n';
  if (ANS == 0) return 0;
  for (i = L; i <= R; i++) cout << A[i];
  cout << '\n';
  return 0;
}
