#include <bits/stdc++.h>
using namespace std;
int const M = 2e5 + 10, inf = 1e9 + 10, M3 = 1e3 + 10, M2 = 1e6 + 10;
int a[M], dp[M];
int ps[M];
int main() {
  string x;
  cin >> x;
  for (int i = 0; i < x.size(); i++) {
    if (i != 0) ps[i] = ps[i - 1];
    if (x[i] == '[') ps[i]++;
  }
  int ans = 0;
  int st, en;
  for (int i = (int)x.size() - 1; i >= 0; i--) {
    if (x[i] == '(') {
      if (i != (int)x.size() - 1 && x[i + 1] == ')')
        dp[i] = max(dp[i + 2], i + 2);
      else if (i != (int)x.size() - 1 && dp[i + 1] != 0 && x[dp[i + 1]] == ')')
        dp[i] = max(dp[dp[i + 1] + 1], dp[i + 1] + 1);
    }
    if (x[i] == '[') {
      if (i != (int)x.size() - 1 && x[i + 1] == ']')
        dp[i] = max(dp[i + 2], i + 2);
      else if (i != (int)x.size() - 1 && dp[i + 1] != 0 && x[dp[i + 1]] == ']')
        dp[i] = max(dp[dp[i + 1] + 1], dp[i + 1] + 1);
    }
    int tmp = 0;
    if (i != 0) tmp = ps[i - 1];
    if (dp[i] != 0 && ps[dp[i] - 1] - tmp > ans)
      ans = ps[dp[i] - 1] - tmp, st = i, en = dp[i] - 1;
  }
  cout << ans << endl;
  if (ans == 0) return 0;
  for (int i = st; i <= en; i++) cout << x[i];
}
