#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  long long res = binpow(a, b / 2) % 1000000007;
  if (b % 2)
    return (((long long)res * (long long)res % 1000000007) * (long long)a) %
           1000000007;
  else
    return ((long long)res * (long long)res) % 1000000007;
}
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  int dp[n][2];
  memset(dp, 0, sizeof(dp));
  for (int i = n - 2; i >= 0; i--) {
    if (s[i] == ']' || s[i] == ')') continue;
    int t = dp[i + 1][0];
    if (s[i] == '(') {
      if (i + t + 1 < n && s[i + t + 1] == ')') {
        dp[i][0] = dp[i + 1][0] + 2 + ((i + t + 2 < n) ? dp[i + t + 2][0] : 0);
        dp[i][1] = dp[i + 1][1] + ((i + t + 2 < n) ? dp[i + t + 2][1] : 0);
      }
    }
    if (s[i] == '[') {
      if (i + t + 1 < n && s[i + t + 1] == ']') {
        dp[i][0] = dp[i + 1][0] + 2 + ((i + t + 2 < n) ? dp[i + t + 2][0] : 0);
        dp[i][1] = dp[i + 1][1] + 1 + ((i + t + 2 < n) ? dp[i + t + 2][1] : 0);
      }
    }
  }
  int id = -1, mx = 0;
  for (int i = 0; i < n; i++) {
    if (dp[i][1] > mx) {
      mx = dp[i][1];
      id = i;
    }
  }
  cout << mx << endl;
  if (mx == 0) return;
  for (int i = id; i < id + dp[id][0]; i++) {
    cout << s[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
}
