#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
const long double pi = 2 * acos(0.0);
string str;
long long int arr[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> str;
  stack<int> st1, st2;
  string a;
  int l = 0, r = 0, curr = 0, ans = 0, pr = 0;
  while (l < str.length()) {
    if (str[l] == '(' || str[l] == '[') {
      r = l;
      pr = l;
      curr = 0;
      while (r < str.length()) {
        if (str[r] == '(')
          st1.push(r);
        else if (str[r] == '[')
          st2.push(r);
        else if (str[r] == ')') {
          if (st1.empty()) {
            arr[r] = -1;
            break;
          } else if (!st2.empty()) {
            if (st1.top() < st2.top()) {
              arr[r] = -1;
              break;
            } else {
              arr[r] = st1.top();
              arr[st1.top()] = r;
              st1.pop();
            }
          } else {
            arr[r] = st1.top();
            arr[st1.top()] = r;
            st1.pop();
          }
        } else if (str[r] == ']') {
          if (st2.empty()) {
            arr[r] = -1;
            break;
          } else if (!st1.empty()) {
            if (st1.top() > st2.top()) {
              arr[r] = -1;
              break;
            } else {
              arr[r] = st2.top();
              arr[st2.top()] = r;
              st2.pop();
            }
          } else {
            arr[r] = st2.top();
            arr[st2.top()] = r;
            st2.pop();
          }
        }
        r++;
      }
      while (!st1.empty()) {
        arr[st1.top()] = -1;
        st1.pop();
      }
      while (!st2.empty()) {
        arr[st2.top()] = -1;
        st2.pop();
      }
      l = r;
    } else {
      arr[l] = -1;
      l++;
    }
  }
  l = 0;
  r = 0;
  while (l < str.length()) {
    if (arr[l] != -1) {
      r = l;
      curr = 0;
      while (r < str.length()) {
        if (arr[r] == -1)
          break;
        else {
          if (str[r] == '[') curr++;
        }
        r++;
      }
      if (curr > ans) {
        ans = curr;
        a = str.substr(l, r - l);
      }
      l = r;
    } else
      l++;
  }
  cout << ans << "\n";
  cout << a << "\n";
  return 0;
}
