#include <bits/stdc++.h>
using namespace std;
stack<pair<char, int> > second;
string word;
pair<int, int> dp[100005];
int main() {
  cin >> word;
  for (int i = 1; i <= word.length(); i++) {
    if (word[i - 1] == '(' || word[i - 1] == '[') {
      second.push(make_pair(word[i - 1], i));
    } else {
      if (word[i - 1] == ')') {
        if (!second.empty()) {
          pair<char, int> top = second.top();
          if (top.first == '(') {
            second.pop();
            dp[i] = make_pair(dp[i - 1].first, dp[i - 1].second + 2);
            if (dp[top.second - 1].second != 0) {
              dp[i].first += dp[top.second - 1].first;
              dp[i].second += dp[top.second - 1].second;
            }
          } else {
            second.push(make_pair(word[i - 1], i));
          }
        } else
          second.push(make_pair(word[i - 1], i));
      } else {
        if (!second.empty()) {
          pair<char, int> top = second.top();
          if (top.first == '[') {
            second.pop();
            dp[i] = make_pair(dp[i - 1].first + 1, dp[i - 1].second + 2);
            if (dp[top.second - 1].second != 0) {
              dp[i].first += dp[top.second - 1].first;
              dp[i].second += dp[top.second - 1].second;
            }
          } else {
            second.push(make_pair(word[i - 1], i));
          }
        } else
          second.push(make_pair(word[i - 1], i));
      }
    }
  }
  int ans = 0, index = -1;
  for (int i = 1; i <= word.length(); i++) {
    if (dp[i].first > ans) {
      ans = dp[i].first;
      index = i;
    }
  }
  printf("%d", ans);
  ;
  printf("\n");
  if (ans) {
    for (int i = index - dp[index].second; i <= index - 1; i++) cout << word[i];
  }
  printf("\n");
  return 0;
}
