class BracketSequenceDiv1 {
  public:
  map<pair<int, string>, int> mapka;
  int dp(string& s, int to_cons, string acc) {
    if (mapka.count({to_cons, acc})) {
      return mapka[{to_cons, acc}];
    }
    if (to_cons == SZ(s)) {
      return (acc == "");
    }
    if (SZ(s) - to_cons < SZ(acc)) {
      return 0;
    }
    int here = dp(s, to_cons + 1, acc);
    string orig = acc;
    if (s[to_cons] == '(' || s[to_cons] == '[') {
      here += dp(s, to_cons + 1, acc + s[to_cons]);
    } else {
      if (!acc.empty() && ((s[to_cons] == ']' && acc.back() == '[') || (s[to_cons] == ')' && acc.back() == '('))) {
        acc.pop_back();
        here += dp(s, to_cons + 1, acc);
      }
    }
    mapka[{to_cons, orig}] = here;
    return here;
  }
#undef int
  long long count(string s) {
#define int long long
    return dp(s, 0, "") - 1;
  }

};