#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

vi f(string s){
    int n = s.size();
    vp v;
    int t = 0;
    vector<vi> num;
    rep(i,n){
        if(isdigit(s[i])){
            t *= 10;
            t += s[i]-'0';
        }else{
            if(i && isdigit(s[i-1]))num.push_back(vi(1,t));
            t = 0;
            if(s[i] == '+' || s[i] == '*' || s[i] == '-' || s[i] == '/')v.push_back(pii(i,v.size()));
            else if(s[i] == '('){
                int cnt = 0;
                loop(j,i+1,n){
                    if(s[j] == '(')cnt++;
                    if(s[j] == ')'){
                        if(cnt)cnt--;
                        else{
                            num.push_back(f(s.substr(i+1,j-i-1)));
                            i = j;
                            j = n;
                        }
                    }
                }
            }
        }
    }
    if(isdigit(s.back()))num.push_back(vi(1,t));
    vi ret;
    if(v.size()){
        do{
            vector<vi> tnum = num;
            rep(i,v.size()){
                int op = v[i].first;
                int l = v[i].second, r = v[i].second+1;
                while(l && tnum[l].empty())l--;
                while(r < tnum.size() && tnum[r].empty())r++;
                if(l < 0 || r >= tnum.size()){
                    i = v.size();
                    tnum.resize(0);
                    break;
                }
                // num[l]とnum[r]をopで結合する
                vi tmp;
                for(auto x: tnum[l])for(auto y: tnum[r]){
                    if(s[op] == '+')tmp.push_back(x+y);
                    if(s[op] == '-')tmp.push_back(x-y);
                    if(s[op] == '*')tmp.push_back(x*y);
                    if(y && s[op] == '/')tmp.push_back(x/y);
                }
                tnum[l] = tmp;
                tnum[r].resize(0);
            }
            rep(i,tnum.size())if(tnum[i].size()){
                rep(j,tnum[i].size())ret.push_back(tnum[i][j]);
            }
        }while(next_permutation(all(v)));
    }else{
        rep(i,num.size())if(num[i].size()){
            rep(j,num[i].size())ret.push_back(num[i][j]);
        }
    }
    sort(all(ret));
    ret.erase(unique(all(ret)),ret.end());
    return ret;
}
signed main(void) {
    string s;
    while(cin >> s, s != "#"){
        vi ans = f(s);
        cout << ans.size() << endl;
    }
}



Measured memory_bytes: 9752