#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;

string s;
//j番目の前にi番目
bool valid[11][10];
vector<int> num;
vector<char> ord;
bool ope(char t) {
	if (t == '+' || t == '*' || t == '-' || t == '/')return true;
	else return false;
}
void init() {
	rep(i, 10) {
		rep(j, 10) {
			valid[i][j] = true;
		}
	}
	num.clear(); ord.clear();
	int n = s.length();
	rep(i, n) {
		if (s[i] == '(') {
			int c = ord.size(); int ori = c - 1;
			int j = i + 1;
			int z = 1;
			while (z) {
				if (ope(s[j])) {
					if (ori >= 0) {
						valid[c][ori] = false;
						//cout << c << " " << ori << endl;
					}
					c++;
				}
				else if (s[j] == '(')z++;
				else if (s[j] == ')')z--;
				j++;
			}
			Rep(k, ord.size(), c) {
				valid[k][c] = false;
				//cout << c << " " << k << endl;
			}
		}
		else if (ope(s[i])) {
			ord.push_back(s[i]);
		}
		else if ('0' <= s[i] && s[i] <= '9') {
			int memo = i;
			while (i + 1 < n&&'0' <= s[i + 1] && s[i + 1] <= '9') {
				i++;
			}
			num.push_back(stoi(s.substr(memo, i - memo + 1)));
		}
	}
}
int m;
int u[10];
bool ok() {
	rep(i, m) {
		Rep(j, i + 1, m) {
			if (!valid[u[j]][u[i]])return false;
		}
	}
	return true;
}
bool zerodivi;
int calc(int a, int b, char t) {
	if (t == '+')return a + b;
	else if (t == '*')return a * b;
	else if (t == '-')return a - b;
	else if (t == '/') {
		if (b == 0) {
			zerodivi = true; return 0;
		}
		else {
			return a / b;
		}
	}
}
int ans() {
	zerodivi = false;
	int cu[10];
	vector<int> cnum = num;
	vector<char> cord = ord;
	rep(i, m) {
		cu[i] = u[i];
	}
	rep(i, m) {
		rep(j, m) {
			if (cu[i] < cu[j])cu[j]--;
		}
		int alter = calc(cnum[cu[i]], cnum[cu[i]+1], cord[cu[i]]);
	//	cout << alter << endl;
		cord.erase(cord.begin() + cu[i]);
		cnum.erase(cnum.begin() + cu[i]);
		cnum[cu[i]] = alter;
	}
	return cnum[0];
}
int main() {
	while (cin >> s) {
		if (s == "#")break; init();
		//cout << num.size() << " " << ord.size() << endl;
		m = ord.size();
		rep(i, m) {
			u[i] = i;
		}
		vector<int> pos;
		while (true) {
			if (ok()) {
			//	cout << "hello" << endl;
				int z = ans();
				if (!zerodivi)pos.push_back(z);
			}
			if (!next_permutation(u, u + m))break;
		}
		sort(pos.begin(), pos.end());
		/*rep(i, pos.size())cout << pos[i] << endl;
		cout << endl;
		rep(i, num.size())cout << num[i] << endl;
		rep(i, ord.size())cout << ord[i] << endl;*/
		cout << unique(pos.begin(), pos.end()) - pos.begin() << endl;
	}
	return 0;
}



Measured memory_bytes: 6188