#include <bits/stdc++.h>
using namespace std;
vector<string> vec;
vector<string> ve;
vector<string> res;
stack<char> st;
string as, bs;
void clear() {
  while (!st.empty()) st.pop();
  bs.clear();
}
void check() {
  stack<char> s;
  int flag = 0, mx = 0;
  for (int i = 0; i < ve.size(); i++) {
    string bs = ve[i];
    while (!s.empty()) s.pop();
    flag = 0;
    for (int j = 0; j < bs.size(); j++) {
      if (bs[0] == ']' || bs[0] == ')') {
        flag = 1;
        break;
      }
      if (bs[j] == '(' || bs[j] == '[')
        s.push(bs[j]);
      else if (bs[j] == ')') {
        if (s.size() > 0) {
          if (s.top() == '(') {
            s.pop();
          } else {
            flag = 1;
            break;
          }
        } else {
          flag = 1;
          break;
        }
      } else if (bs[j] == ']') {
        if (s.size() > 0) {
          if (s.top() == '[') {
            s.pop();
          } else {
            flag = 1;
            break;
          }
        } else {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0) {
      res.push_back(bs);
    }
  }
  while (!s.empty()) s.pop();
}
void reverse_check(string as) {
  for (int i = 0; i < as.size(); i++) {
    if (as[i] == ']' || as[i] == ')') {
      st.push(as[i]);
      bs += as[i];
    } else if (as[i] == '(') {
      if (st.size() > 0) {
        if (st.top() == ')') {
          bs += as[i];
          st.pop();
        } else {
          reverse(bs.begin(), bs.end());
          ve.push_back(bs);
          clear();
        }
      } else {
        reverse(bs.begin(), bs.end());
        ve.push_back(bs);
        clear();
      }
    } else if (as[i] == '[') {
      if (st.size() > 0) {
        if (st.top() == ']') {
          bs += as[i];
          st.pop();
        } else {
          reverse(bs.begin(), bs.end());
          ve.push_back(bs);
          clear();
        }
      } else {
        reverse(bs.begin(), bs.end());
        ve.push_back(bs);
        clear();
      }
    }
  }
  if (bs.size() > 0) {
    reverse(bs.begin(), bs.end());
    ve.push_back(bs);
  }
  bs.clear();
}
int main() {
  while (cin >> as) {
    for (int i = 0; i < as.size(); i++) {
      if (as[i] == '[' || as[i] == '(') {
        st.push(as[i]);
        bs += as[i];
      } else if (as[i] == ')') {
        if (st.size() > 0) {
          if (st.top() == '(') {
            bs += as[i];
            st.pop();
          } else {
            vec.push_back(bs);
            clear();
          }
        } else {
          vec.push_back(bs);
          clear();
        }
      } else if (as[i] == ']') {
        if (st.size() > 0) {
          if (st.top() == '[') {
            bs += as[i];
            st.pop();
          } else {
            vec.push_back(bs);
            clear();
          }
        } else {
          vec.push_back(bs);
          clear();
        }
      }
    }
    if (bs.size() > 0) vec.push_back(bs);
    clear();
    for (int i = 0; i < vec.size(); i++) {
      string cs = vec[i];
      reverse(cs.begin(), cs.end());
      reverse_check(cs);
    }
    check();
    if (res.size() == 0)
      cout << "0" << endl;
    else {
      string ans;
      int cnt = 0, mx = 0;
      for (int i = 0; i < res.size(); i++) {
        string cs = res[i];
        cnt = 0;
        for (int j = 0; j < cs.size(); j++) {
          if (cs[j] == '[') cnt++;
        }
        if (cnt > mx) {
          mx = cnt;
          ans = cs;
        }
      }
      cout << mx << endl << ans << endl;
    }
    clear();
    res.clear();
    vec.clear();
    ve.clear();
    res.clear();
  }
  return 0;
}
