#include <bits/stdc++.h>
using namespace std;
inline long long mulmod(long long x, long long n, long long _mod) {
  long long res = 0;
  while (n) {
    if (n & 1) res = (res + x) % _mod;
    x = (x + x) % _mod;
    n >>= 1;
  }
  return res;
}
inline long long powmod(long long x, long long n, long long _mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * x) % _mod;
    x = (x * x) % _mod;
    n >>= 1;
  }
  return res;
}
inline long long gcd(long long a, long long b) {
  long long t;
  while (b) {
    a = a % b;
    t = a;
    a = b;
    b = t;
  }
  return a;
}
inline int gcd(int a, int b) {
  int t;
  while (b) {
    a = a % b;
    t = a;
    a = b;
    b = t;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long gcd(long long a, long long b, long long c) {
  return gcd(gcd(a, b), c);
}
inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int main() {
  string s;
  cin >> s;
  stack<int> st, st2;
  int n = s.size();
  int dp[n + 1], dp2[n + 1];
  memset(dp, 0, sizeof(dp));
  memset(dp2, 0, sizeof(dp2));
  int index = -1, ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(' || s[i] == '[') {
      st.push(i);
    } else {
      if (!st.empty()) {
        int j = st.top();
        if ((s[j] == '(' && s[i] == ')') || (s[j] == '[' && s[i] == ']')) {
          if (j > 0) {
            dp[i] = dp[j - 1] + i - j + 1;
            dp2[i] += dp2[j - 1];
          } else
            dp[i] = i - j + 1;
          if (i != j + 1) dp2[i] += dp2[i - 1];
          if (s[i] == ']') dp2[i]++;
          st.pop();
        } else {
          while (!st.empty()) st.pop();
        }
      }
    }
  }
  int ans2 = 0;
  for (int i = 0; i < n; i++) {
    if (dp2[i] > ans) {
      ans = dp2[i];
      index = i;
      ans2 = dp[i];
    }
  }
  cout << ans << "\n";
  if (ans)
    for (int i = index - ans2 + 1; i <= index; i++) cout << s[i];
  return 0;
}
