#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline T euclide(T a, T b, T &x, T &y) {
  if (a < 0) {
    T d = euclide(-a, b, x, y);
    x = -x;
    return d;
  }
  if (b < 0) {
    T d = euclide(a, -b, x, y);
    y = -y;
    return d;
  }
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    T d = euclide(b, a % b, x, y);
    T t = x;
    x = y;
    y = t - (a / b) * y;
    return d;
  }
}
template <class T>
string toString(T n) {
  ostringstream ost;
  ost << n;
  ost.flush();
  return ost.str();
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
double toDouble(string s) {
  double r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
template <class T>
inline void PR(T a) {
  cout << a << endl;
}
const int maxn = 110010;
pair<int, int> pii;
vector<int> vi;
stack<int> q;
int pre[maxn];
void clear() {
  while (!q.empty()) q.pop();
}
int main() {
  string s;
  while (cin >> s) {
    int len = s.size();
    for (int i(0); i <= (len - 1); i++) {
      if (s[i] == '(') {
        q.push(i);
        pre[i] = -1;
      }
      if (s[i] == '[') {
        q.push(i);
        pre[i] = -1;
      }
      if (s[i] == ')') {
        if (q.empty() || s[q.top()] != '(') {
          pre[i] = -1;
          clear();
        } else {
          pre[i] = q.top();
          q.pop();
        }
      }
      if (s[i] == ']') {
        if (q.empty() || s[q.top()] != '[') {
          pre[i] = -1;
          clear();
        } else {
          pre[i] = q.top();
          q.pop();
        }
      }
    }
    int j;
    string ret = "", tret;
    int mini = 0, t;
    for (int i = len - 1; i >= 0;) {
      if ((s[i] == ']' || s[i] == ')') && pre[i] != -1) {
        j = i;
        t = 0;
        tret = "";
        while (j >= 0 && pre[j] != -1) {
          for (int m = j; m >= pre[j]; m--) {
            if (s[m] == '[') t++;
            tret += s[m];
          }
          j = pre[j] - 1;
        }
        if (t > mini) {
          mini = t;
          ret = tret;
        }
        i = j;
      } else {
        i--;
      }
    }
    PR(mini);
    for (int i = ret.size() - 1; i >= 0; i--) putchar(ret[i]);
    PR("");
  }
}
