#ifndef _WIN32
#include<iostream>
#endif

#include<string>
#include<cmath>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<utility>
#include<tuple>
#include<set>
using namespace std;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ITR(x,v) for(auto &x:v)
typedef pair<int, int> P;
typedef vector<int> V;
typedef vector<V > VV;
const int B = 1e9;
string s;
int parse_num(int &id) {
	int res = 0;
	while (id < s.size() && isdigit(s[id])) {
		res = res * 10 + s[id] - '0';
		id++;
	}
	return res;
}
const int O = B+5;
const int C = B+6;
void nobu(V &v,V &l,V& r,int id) {
	while (l[id]!=-1&&r[id]!=-1&&v[l[id]] == O&&v[r[id]] == C) {
		int left = l[id];
		int right = r[id];
		l[id] = l[left];
		r[id] = r[right];
		v[left] = B + 10;
		v[right] = B + 10;
		if (l[left] != -1)r[l[left]] = id;
		if (r[right] != -1)l[r[right]] = id;
	}
}
bool myadd(V &v, V &l, V& r, int id) {
	int left = l[id];
	int right = r[id];
	if (v[l[id]] <= B&&v[r[id]] <= B);
	else {
		return false;
	}
	v[id] = v[left] + v[right];
	l[id] = l[left];
	r[id] = r[right];
	v[left] = B + 10;
	v[right] = B + 10;
	if (l[left] != -1)r[l[left]] = id;
	if (r[right] != -1)l[r[right]] = id;
	nobu(v, l, r, id);
	return true;
}
bool mysub(V &v, V &l, V& r, int id) {
	int left = l[id];
	int right = r[id];
	if (v[l[id]] <= B&&v[r[id]] <= B);
	else {
		return false;
	}
	v[id] = v[left] - v[right];
	l[id] = l[left];
	r[id] = r[right];
	v[left] = B + 10;
	v[right] = B + 10;
	if (l[left] != -1)r[l[left]] = id;
	if (r[right] != -1)l[r[right]] = id;
	nobu(v, l, r, id);
	return true;
}
bool mymul(V &v, V &l, V& r, int id) {
	int left = l[id];
	int right = r[id];
	if (v[l[id]] <= B&&v[r[id]] <= B);
	else {
		return false;
	}
	v[id] = v[left] * v[right];
	l[id] = l[left];
	r[id] = r[right];
	v[left] = B + 10;
	v[right] = B + 10;
	if (l[left] != -1)r[l[left]] = id;
	if (r[right] != -1)l[r[right]] = id;
	nobu(v, l, r, id);
	return true;
}
bool mydiv(V &v, V &l, V& r, int id) {
	int left = l[id];
	int right = r[id];
	if (v[l[id]] <= B&&v[r[id]] <= B);
	else {
		return false;
	}
	if (v[right] == 0)return false;
	v[id] = v[left] / v[right];
	l[id] = l[left];
	r[id] = r[right];
	v[left] = B + 10;
	v[right] = B + 10;

	if (l[left] != -1)r[l[left]] = id;
	if (r[right] != -1)l[r[right]] = id;
	nobu(v, l, r, id);
	return true;
}

int main() {

	while (cin >> s, s != "#") {
		int id = 0;
		vector<int> v,op;
		set<int> ss;
		while (id < s.size()) {
			switch (s[id]) {
			case '+':v.push_back(B + 1); id++; break;
			case '-':v.push_back(B + 2); id++; break;
			case '*':v.push_back(B + 3); id++; break;
			case '/':v.push_back(B + 4); id++; break;
			case '(':v.push_back(B + 5); id++; break;
			case ')':v.push_back(B + 6); id++; break;
			default: v.push_back(parse_num(id)); break;
			}
		}
		int m = v.size();
		REP(i, m)if (B<v[i]&&v[i]<B+5)op.push_back(i);
		int k = op.size();
		do {
			bool flag = true;
			vector<int> l(m, -1);
			vector<int> r(m, -1);
			auto u = v;
			REP(i, m - 1)l[i + 1] = i;
			REP(i, m - 1)r[i] = i+1;
			REP(i, m)if (v[i] <= B)nobu(u, l, r,i);
			REP(i, k) {
				int id = op[i];
				if (l[id] <= B&&r[id] <= B) {
					switch (u[id]){
					case B + 1:flag&=myadd(u, l, r, id); break;
					case B + 2:flag&=mysub(u, l, r, id); break; 
					case B + 3:flag&=mymul(u, l, r, id); break; 
					case B + 4: 
						flag&=mydiv(u, l, r, id); 
						break;
					

					default:flag = false;
						break;
					}

				}
				else {
					flag = false;
				}
				if (flag == false)break;
			}

			if (flag) {
				int res;
				REP(i, m)if (u[i] != B + 10)res = u[i];
				ss.insert(res);



			}
		}while(next_permutation(op.begin(), op.end()));
		cout << ss.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 3068