#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long mod = 1e9 + 7;
stack<pair<char, int>> stk;
int st, ed;
int ans;
int dp[maxn];
char str[maxn];
int start = 0;
map<char, char> mp;
int main() {
  mp['['] = ']', mp['('] = ')';
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  for (int i = 1; i <= n; i++) {
    if (str[i] == '[' || str[i] == '(' || stk.empty())
      stk.push({str[i], i});
    else if (str[i] == mp[stk.top().first])
      stk.pop();
    else
      stk.push({str[i], i});
    if (str[i] == ']') dp[i] = 1;
    dp[i] += dp[i - 1];
  }
  if (stk.empty()) {
    cout << dp[n] << endl;
    if (dp[n]) printf("%s", str + 1);
  } else {
    if (stk.top().second != n) stk.push({'1', n + 1});
    while (stk.size() > 1) {
      int k = stk.top().second;
      stk.pop();
      if (dp[k - 1] - dp[stk.top().second] > ans) {
        ans = dp[k - 1] - dp[stk.top().second];
        st = stk.top().second + 1;
        ed = k - 1;
      }
    }
    if (stk.top().second != 1) {
      if (dp[stk.top().second - 1] > ans) {
        ans = dp[stk.top().second - 1];
        st = 1;
        ed = stk.top().second - 1;
      }
    }
    cout << ans << endl;
    if (ans)
      for (int i = st; i <= ed; i++) cout << str[i];
  }
}
