#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int digit(string &s,int &p){
	//<digit> ::= "0" | "1" | "2" | "3" | "4"
	//          | "5" | "6" | "7" | "8" | "9"
	return s[p++]-'0';
}

int num(string &s,int &p){
	//<num> ::= <digit> | <num> <digit>
	assert(isdigit(s[p]));
	int num=digit(s,p);
	while(isdigit(s[p])){
		num*=10;
		num+=digit(s,p);
	}
	return num;
}

bool isop(char c){
	return c=='+'||c=='-'||c=='*'||c=='/';
}

int expr(string &s,int &p,vi &perm){
	//<expr> ::= <num>
	//        | "(" <expr> ")"
	//        | <expr> "+" <expr>
	//        | <expr> "-" <expr>
	//        | <expr> "*" <expr>
	//        | <expr> "/" <expr>
	vi e;
	vector<pair<int,char> >ops;

	bool par=false;
	if(s[p]=='('){
		p++;
		par=true;
	}else{
		return num(s,p);
	}
	e.push_back(expr(s,p,perm));
	if(e[e.size()-1]==INT_MAX){
		return INT_MAX;
	}
	while(isop(s[p])){
		ops.push_back(make_pair(p,s[p]));
		p++;
		e.push_back(expr(s,p,perm));
		if(e[e.size()-1]==INT_MAX){
			return INT_MAX;
		}
	}
	if(par){
		assert(s[p]==')');
		p++;
	}

	REP(i,perm.size()){
		int opi=-1;
		REP(j,ops.size()){
			if(ops[j].first==perm[i]){
				opi=j;
				break;
			}
		}
		if(opi==-1){
			continue;
		}

		switch(ops[opi].second){
		case '+':
			{
				int val=e[opi]+e[opi+1];
				e.erase(e.begin()+opi);
				e.erase(e.begin()+opi);
				e.insert(e.begin()+opi,val);
			}
			break;
		case '-':
			{
				int val=e[opi]-e[opi+1];
				e.erase(e.begin()+opi);
				e.erase(e.begin()+opi);
				e.insert(e.begin()+opi,val);
			}
			break;
		case '*':
			{
				int val=e[opi]*e[opi+1];
				e.erase(e.begin()+opi);
				e.erase(e.begin()+opi);
				e.insert(e.begin()+opi,val);
			}
			break;
		case '/':
			{
				if(e[opi+1]==0){
					return INT_MAX;
				}
				double val=(double)e[opi]/e[opi+1];
				double intpart;
				modf(val,&intpart);
				e.erase(e.begin()+opi);
				e.erase(e.begin()+opi);
				e.insert(e.begin()+opi,(int)intpart);
			}
			break;
		default:
			assert(0);
		}
		ops.erase(ops.begin()+opi);
	}

	return e[0];
}


int main(){
	string s;
	while(cin>>s,s!="#"){
		s="("+s;
		s+=")";
		vi perm;
		REP(i,s.size()){
			if(isop(s[i])){
				perm.push_back(i);
			}
		}
		set<int> ans;
		do{
			vi permrev(s.size());
			REP(i,perm.size()){
				permrev[perm[i]]=i;
			}
			int p=0;
			int e=expr(s,p,perm);
			if(e!=INT_MAX){
				ans.insert(e);
			}
		}while(next_permutation(ALL(perm)));
		cout<<ans.size()<<endl;
	}
}

Measured memory_bytes: 1264