#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

bool cyk[201][201][15];

int main() {
  while (true) {
    string s;
    cin>>s;
    if (s == "#") break;
    int n = s.size();
    vector<vector<vector<set<int>>>> dp(n+1, vector<vector<set<int>>>(n+1, vector<set<int>>(15)));
    REP(i,n+1)REP(j,n+1)REP(k,15) cyk[i][j][k] = false;
    REP(i,n+1) {
      cyk[i][0][14] = true;
    }
    REP(i,n) {
      if (isdigit(s[i])) {
        cyk[i][1][2] = true;
        dp[i][1][2].insert(s[i] - '0');
      } else {
        switch (s[i]) {
          case '(':
          cyk[i][1][8] = true;
          break;
          case ')':
          cyk[i][1][9] = true;
          break;
          case '+':
          cyk[i][1][10] = true;
          break;
          case '-':
          cyk[i][1][11] = true;
          break;
          case '*':
          cyk[i][1][12] = true;
          break;
          case '/':
          cyk[i][1][13] = true;
          break;
        }
      }
    }
    using T = tuple<int,int,int>;
    vector<T> rule = {
      T( 8, 3, 0),
      T( 0, 4, 0),
      T( 0, 5, 0),
      T( 0, 6, 0),
      T( 0, 7, 0),
      T( 0, 9, 3),
      T(10, 0, 4),
      T(11, 0, 5),
      T(12, 0, 6),
      T(13, 0, 7),
      T( 1, 2, 1),
      T( 2,14, 1),
      T( 1,14, 0)
    };
     
    FOR(l,1,n+1)REP(i,n) {
      FOR(k,1,l+1)REP(m,rule.size()) {
        int first, second, result;
        tie(first, second, result) = rule[m];
        if (cyk[i][k][first] && cyk[i+k][l-k][second]) {
          cyk[i][l][result] = true;
          switch(m) {
            case 0: // <(> + <3>
            case 6: // <+> + <expr>
            case 7: // <-> + <expr>
            case 8: // <*> + <expr>
            case 9: // </> + <expr>
              dp[i][l][result] = dp[i+k][l-k][second];
              break;
            case 5: // <expr> + <)>
            case 11: // <digit> + empty
            case 12: // <num> + empty
              dp[i][l][result] = dp[i][k][first];
              break;
            case 1: // <expr> + <4>
              for (int x:dp[i][k][first]) {
                for (int y:dp[i+k][l-k][second]) {
                  dp[i][l][result].insert(x+y);
                }
              }
              break;
            case 2: // <expr> + <5>
              for (int x:dp[i][k][first]) {
                for (int y:dp[i+k][l-k][second]) {
                  dp[i][l][result].insert(x-y);
                }
              }
              break;
            case 3: // <expr> + <6>
              for (int x:dp[i][k][first]) {
                for (int y:dp[i+k][l-k][second]) {
                  dp[i][l][result].insert(x*y);
                }
              }
              break;
            case 4: // <expr> + <7>
              for (int x:dp[i][k][first]) {
                for (int y:dp[i+k][l-k][second]) {
                  if (y != 0) {
                    dp[i][l][result].insert(x/y);
                  }
                }
              }
              break;
            case 10: // <num> + <digit>
              dp[i][l][result].insert(
                  *begin(dp[i][k][first]) * 10 + *begin(dp[i+k][l-k][second]));
              break;
          }
        }
      }
    }
    cout << dp[0][n][0].size() << endl;
  }
  return 0;
}

Measured memory_bytes: 5988