#include <bits/stdc++.h>
using namespace std;
int main() {
  stack<int> p;
  stack<char> b;
  char a[100005];
  cin >> a;
  int ans = 0, x = 0, y = 0, ansx = 0, ansy = 0, oans = 0, a_olen[100005],
      a_len[100005];
  a_olen[0] = 0;
  a_len[0] = 0;
  for (int i = 0; a[i] != '\0'; i++) {
    if (a[i] == '(' || a[i] == '[') {
      if (x == y) {
        x = i;
        y = i;
        b.push(a[i]);
        p.push(x);
      } else {
        if ((ans < (a_len[y] - a_len[x])) ||
            ((ans == (a_len[y] - a_len[x])) &&
             (oans < (a_olen[y] - a_olen[x])))) {
          ansx = x;
          ansy = y;
          ans = a_len[y] - a_len[x];
          oans = a_olen[y] - a_olen[x];
        }
        b.push(a[i]);
        p.push(x);
        x = i;
        y = i;
      }
      if (i) {
        a_olen[i] = a_olen[i - 1];
        a_len[i] = a_len[i - 1];
      }
    } else if (a[i] == ')') {
      if (!b.empty() && b.top() == '(') {
        a_olen[i] = a_olen[i - 1] + 1;
        a_len[i] = a_len[i - 1];
        if (x > p.top()) {
          x = p.top();
        }
        y = i;
        b.pop();
        p.pop();
      } else {
        if ((ans < (a_len[y] - a_len[x])) ||
            ((ans == (a_len[y] - a_len[x])) &&
             (oans < (a_olen[y] - a_olen[x])))) {
          ansx = x;
          ansy = y;
          ans = a_len[y] - a_len[x];
          oans = a_olen[y] - a_olen[x];
        }
        x = i;
        y = i;
        a_olen[i] = 0;
        a_len[i] = 0;
        while (!b.empty()) {
          b.pop();
          p.pop();
        }
      }
    } else if (a[i] == ']') {
      if (!b.empty() && b.top() == '[') {
        a_olen[i] = a_olen[i - 1];
        a_len[i] = a_len[i - 1] + 1;
        if (x > p.top()) {
          x = p.top();
        }
        y = i;
        b.pop();
        p.pop();
      } else {
        if ((ans < (a_len[y] - a_len[x])) ||
            ((ans == (a_len[y] - a_len[x])) &&
             (oans < (a_olen[y] - a_olen[x])))) {
          ansx = x;
          ansy = y;
          ans = a_len[y] - a_len[x];
          oans = a_olen[y] - a_olen[x];
        }
        x = i;
        y = i;
        a_olen[i] = 0;
        a_len[i] = 0;
        while (!b.empty()) {
          b.pop();
          p.pop();
        }
      }
    }
  }
  if ((ans < (a_len[y] - a_len[x])) ||
      ((ans == (a_len[y] - a_len[x])) && (oans < (a_olen[y] - a_olen[x])))) {
    ansx = x;
    ansy = y;
    ans = a_len[y] - a_len[x];
    oans = a_olen[y] - a_olen[x];
  }
  if (ans == 0 && oans == 0) {
    printf("0\n");
  } else {
    cout << ans << endl;
    for (int i = ansx; i <= ansy; i++) {
      cout << a[i];
    }
    cout << endl;
  }
  return 0;
}
