#include <bits/stdc++.h>
using namespace std;
char str[111111];
int stk[111111];
int top;
int sum[111111];
int Right[111111];
int main() {
  while (cin >> str + 1) {
    int len = strlen(str + 1);
    top = 0;
    for (int i = 0; i <= len; i++) Right[i] = -1;
    for (int i = 1; i <= len; i++) {
      if (top == 0 || str[i] == '(' || str[i] == '[') {
        stk[top++] = i;
      } else if ((str[i] == ')' && str[stk[top - 1]] == '(') ||
                 (str[i] == ']' && str[stk[top - 1]] == '[')) {
        Right[stk[top - 1]] = i;
        top--;
      } else {
        top = 0;
      }
    }
    for (int i = len; i >= 1; i--)
      if (Right[i] > 0 && Right[i] != len) {
        if (Right[Right[i] + 1] != -1) Right[i] = Right[Right[i] + 1];
      }
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= len; i++)
      if (str[i] == '[')
        sum[i] = sum[i - 1] + 1;
      else
        sum[i] = sum[i - 1];
    int ans = 0;
    int l, r;
    l = r = -1;
    for (int i = 1; i <= len; i++)
      if (Right[i] > 0) {
        if (sum[Right[i]] - sum[i - 1] > ans) {
          ans = sum[Right[i]] - sum[i - 1];
          l = i;
          r = Right[i];
        }
      }
    cout << ans << endl;
    if (l == -1) continue;
    for (int i = l; i <= r; i++) cout << str[i];
    cout << endl;
  }
  return 0;
}
