#include <iostream>
#include <set>
#include <cctype>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>
#include <fstream>
using namespace std;

set<int> add(const set<int> &s1, const set<int> &s2){
  set<int> res;
  for(set<int>::iterator it1 = s1.begin(); it1 != s1.end(); it1++){
    for(set<int>::iterator it2 = s2.begin(); it2 != s2.end(); it2++){
      int num = *it1 + *it2;
      if(!res.count(num)) res.insert(num);
    }
  }

  return res;
}

set<int> sub(const set<int> &s1, const set<int> &s2){
  set<int> res;
  for(set<int>::iterator it1 = s1.begin(); it1 != s1.end(); it1++){
    for(set<int>::iterator it2 = s2.begin(); it2 != s2.end(); it2++){
      int num = *it1 - *it2;
      if(!res.count(num)) res.insert(num);
    }
  }
  return res;
}

set<int> mul(const set<int> &s1, const set<int> &s2){
  set<int> res;
  for(set<int>::iterator it1 = s1.begin(); it1 != s1.end(); it1++){
    for(set<int>::iterator it2 = s2.begin(); it2 != s2.end(); it2++){
      int num = (*it1) * (*it2);
      if(!res.count(num)) res.insert(num);
    }
  }
  return res;
}

set<int> div(const set<int> &s1, const set<int> &s2){
  set<int> res;
  for(set<int>::iterator it1 = s1.begin(); it1 != s1.end(); it1++){
    for(set<int>::iterator it2 = s2.begin(); it2 != s2.end(); it2++){
      if(*it2 != 0){
	int num = *it1 / *it2;
	  if(!res.count(num))res.insert(num);
      }
    }
  }
  return res;
}

void putset(set<int> &s1, const set<int> &s2){
  for(set<int>::iterator iter = s2.begin(); iter != s2.end();iter++){
    if(!s1.count(*iter)){
      s1.insert(*iter);
    }
  }
}

size_t cur;
string s;

int number(){
  int res = 0;
  while(cur < s.size() && isdigit(s[cur])){
    res = res * 10 + s[cur++] - '0';
  }
  return res;
}

set<int> expr(){
  vector<set<int> > vs;
  vector<char> op;

  while(cur < s.size() && s[cur] != ')'){
    if(s[cur] == '('){
      cur++;
      vs.push_back(expr());
      assert(s[cur] == ')');
      cur++;
    }else if(isdigit(s[cur])){
      int num = number();
      set<int> s;
      s.insert(num);
      vs.push_back(s);
    }else{
      op.push_back(s[cur]);
      cur++;
    }
  }
  
  set<int> dp[12][12];
  int n = vs.size();
  //  cout << "sz "<< n << endl;
  for(int i = 0; i < n; i++){
    dp[i][1] = vs[i];
    //    cout << dp[i][1].size() << endl;
  }
  /*  for(int i = 0; i < n; i++){
    for(set<int>::iterator iter = vs[i].begin(); iter != vs[i].end(); iter++){
      cout << *iter << " ";
    }
    cout << endl;
    }*/
  for(int w = 2; w <= n; w++){
    for(int i = 0; i < n - w + 1; i++){
      for(int j = i + 1; j < i + w; j++){
	
	switch(op[j-1]){
	case '+': 
	  putset(dp[i][w], add(dp[i][j-i], dp[j][i+w-j]));
	  break;
	case '-':
	  putset(dp[i][w], sub(dp[i][j-i], dp[j][i+w-j]));
	  break;
	case '*':
	  putset(dp[i][w], mul(dp[i][j-i], dp[j][i+w-j]));
	  break;
	case '/':
	  putset(dp[i][w], div(dp[i][j-i], dp[j][i+w-j]));
	  break;
	default : 
	  cout << "NG" << endl;
	}
      }
    }
  }
  
  return dp[0][n];
}

int main(){
  //  ofstream cout("D.txt");
  while(cin >> s && s != "#"){
    cur = 0;
    cout << expr().size() << endl;
  }
 
  //  cout.close();
  return 0;
}
      

Measured memory_bytes: 0