#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

typedef set<int> seti;

#define N 105

int cur;
string s;
seti parse() {
  seti dp[N][N];
  int idx = 0;
  char op[N];
  int num = 0;
  while(cur < s.length()) {
    char c = s[cur];
    if('0' <= c && c <= '9') {
      if(num == -1) {
        num = c - '0';
      } else {
        num = 10*num + (c - '0');
      }
    } else if(c == '(') {
      ++cur;
      dp[idx][idx] = parse();
      //cout << idx SP num << endl;
      num = -1;
    } else if(c == ')') {
      break;
    } else {
      // "+", "-", "/", "*"
      if(num != -1) {
        dp[idx][idx].insert(num);
        //cout << idx SP num << endl;
      }
      op[idx] = c;
      num = -1;
      ++idx;
    }
    ++cur;
  }

  if(num != -1) {
    dp[idx][idx].insert(num);
    //cout << idx SP num << endl;
  }

  //cout << "solve " << idx << endl;

  int sz = idx;
  repl(l, 1, sz) {
    rep(i, sz-l+1) {
      int j = i+l;
      repl(k, i, j-1) {
        //cout << "s" SP l SP i SP j SP k << endl;
        // dp[i][k] + dp[k][j]
        seti ss;
        seti &s1 = dp[i][k], &s2 = dp[k+1][j];
        //cout << "op " << op[k] << endl;
        //cout << "sz " << s1.size() SP s2.size() << endl;
        switch(op[k]) {
          case '+': {
                      repe(v1, s1) {
                        repe(v2, s2) {
                          ss.insert(v1+v2);
                        }
                      }
                      break;
                    }
          case '-':
                    {
                      repe(v1, s1) {
                        repe(v2, s2) {
                          ss.insert(v1-v2);
                        }
                      }
                      break;
                    }
          case '*':
                    {
                      repe(v1, s1) {
                        repe(v2, s2) {
                          ss.insert(v1*v2);
                        }
                      }
                      break;
                    }
          case '/':
                    {
                      repe(v1, s1) {
                        repe(v2, s2) {
                          if(v2 != 0) ss.insert(v1/v2);
                        }
                      }
                      break;
                    }
        }
        dp[i][j].insert(ss.begin(), ss.end());
      }
      //cout << "w" SP i SP j SP dp[i][j].size() << endl;
    }
  }
  /*
  cout << "return " SP dp[0][sz].size() << endl;
  cout << "{";
  repe(v, dp[0][sz]) cout << " " << v;
  cout << " }" << endl;
  */
  return dp[0][sz];
}

int main() {
  while(cin >> s && s[0] != '#') {
    cur = 0;
    set<int> res = parse();
    cout << res.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 6752