#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#define debug cout

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

set <int> add(string l,string r);
set <int> sub(string l,string r);
set <int> mul(string l,string r);
set <int> div(string l,string r);

set<int> addAll(set<int> a,set<int> b){
	set<int> res;
	for(set<int>::iterator it=a.begin();it!=a.end();++it)res.insert(*it);
	for(set<int>::iterator it=b.begin();it!=b.end();++it)res.insert(*it);
	return res;
}

set<int> expr(string s){
//debug<<s<<endl;
	bool in=true;
	int n=0;
	rep(i,sz(s)){
		if(s[i]=='(')++n;
		if(s[i]==')')--n;
		if(n==0){
			if(s[i]==')'&&i==sz(s)-1)break;
			in=false;
			break;
		}
	}
//debug<<in<<endl;
	if(in)return expr(s.substr(1,sz(s)-2));
	set<int> res;
	bool dig=true;
	n=0;
	rep(i,sz(s)){
		if(!isdigit(s[i])){
			dig=false;
			break;
		}
	}
	if(dig){
		SS ss;
		ss<<s;
		int num;
		ss>>num;
		res.insert(num);
		return res;
	}
	n=0;
	rep(i,sz(s)){
		if(s[i]=='(')++n;
		if(s[i]==')')--n;
		if(n==0&&s[i]=='+')res=addAll(res,add(s.substr(0,i),s.substr(i+1,sz(s)-i-1)));
		if(n==0&&s[i]=='-')res=addAll(res,sub(s.substr(0,i),s.substr(i+1,sz(s)-i-1)));
		if(n==0&&s[i]=='*')res=addAll(res,mul(s.substr(0,i),s.substr(i+1,sz(s)-i-1)));
		if(n==0&&s[i]=='/')res=addAll(res,div(s.substr(0,i),s.substr(i+1,sz(s)-i-1)));
	}
	return res;
}

set<int> add(string l,string r){
	set<int> left=expr(l);
	set<int> right=expr(r);
	set<int> res;
	for(set<int>::iterator itl=left.begin();itl!=left.end();++itl){
		for(set<int>::iterator itr=right.begin();itr!=right.end();++itr){
			res.insert(*itl+*itr);
		}
	}
	return res;
}

set<int> sub(string l,string r){
	set<int> left=expr(l);
	set<int> right=expr(r);
	set<int> res;
	for(set<int>::iterator itl=left.begin();itl!=left.end();++itl){
		for(set<int>::iterator itr=right.begin();itr!=right.end();++itr){
			res.insert(*itl-*itr);
		}
	}
	return res;
}

set<int> mul(string l,string r){
	set<int> left=expr(l);
	set<int> right=expr(r);
	set<int> res;
	for(set<int>::iterator itl=left.begin();itl!=left.end();++itl){
		for(set<int>::iterator itr=right.begin();itr!=right.end();++itr){
			res.insert(*itl**itr);
		}
	}
	return res;
}

set<int> div(string l,string r){
	set<int> left=expr(l);
	set<int> right=expr(r);
	set<int> res;
	for(set<int>::iterator itl=left.begin();itl!=left.end();++itl){
		for(set<int>::iterator itr=right.begin();itr!=right.end();++itr){
			if(*itr==0)continue;
			res.insert(*itl/ *itr);
		}
	}
	return res;
}

int main() {
	string s;
	IL{
		cin>>s;
		if(s=="#")break;
		cout<<sz(expr(s))<<endl;
	}
	return 0;
}

Measured memory_bytes: 1020