#include <bits/stdc++.h>
using namespace std;
string s;
int cor[100001], score[100001];
int check(int idx) {
  int& ans = cor[idx];
  if (ans != -1) return ans;
  int idx2 = idx + 1;
  while (0 <= idx2 && idx2 < s.length() && (s[idx2] == '(' || s[idx2] == '['))
    idx2 = check(idx2) + 1;
  if (0 > idx2 || idx2 >= s.length())
    ans = -2;
  else if ((s[idx] == '(' && s[idx2] == ')') ||
           (s[idx] == '[' && s[idx2] == ']'))
    ans = idx2;
  else
    ans = -2;
  while (ans != -2 && ans != s.length() && check(ans + 1) != -2) {
    ans = check(ans + 1);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  score[0] = 0;
  for (int i = 0; i < s.length(); ++i) score[i + 1] = score[i] + (s[i] == '[');
  memset(cor, -1, sizeof cor);
  int best = -1, bestVal = -1;
  for (int i = 0; i < s.length(); ++i)
    if (s[i] == '(' || s[i] == '[') {
      int j = check(i);
      if (j != -2 && bestVal < score[j + 1] - score[i])
        best = i, bestVal = score[j + 1] - score[i];
    }
  if (best == -1)
    cout << 0 << endl;
  else {
    cout << bestVal << endl;
    for (int i = best; i <= check(best); ++i) cout << s[i];
    cout << endl;
  }
}
