#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll

int num(State& now) {
    int ans = 0;
    while (*now >= '0' && *now <= '9') {
        ans *= 10;
        ans += *now - '0';
        now++;
    }
    return ans;
}

vector<int> sol(State& now) {
    vector<vector<int>> inputs;
    vector<int> calc;
    while (*now != ')') {
        if (*now == '(') {
            now++;
            inputs.push_back(sol(now));
        }
        else if(*now >= '0'&&*now <= '9'){
            inputs.push_back(vector<int>{num(now)});
        }
        else {
            if (*now == '+') {
                calc.push_back(0);
            }
            else if (*now == '-') {
                calc.push_back(1);
            }
            else if (*now == '/') {
                calc.push_back(2);
            }
            else if (*now == '*') {
                calc.push_back(3);
            }
            now++;
        }
    }
    assert(calc.size() == inputs.size() - 1);
    set<int> gogo;
    vector<int> geko;
    REP(i, calc.size()) {
        geko.push_back(i);
    }
    do {
        vector<vector<int>> now = inputs;
        REP(i, geko.size()) {
            int target = geko[i];
            REP(q, i) {
                if (geko[q] < geko[i])target--;
            }
            set<int> tmp;
            REP(q, now[target].size()) {
                REP(j, now[target + 1].size()) {
                    if (calc[geko[i]] == 0) {
                        tmp.insert(now[target][q] + now[target + 1][j]);
                    }
                    else if (calc[geko[i]] == 1) {
                        tmp.insert(now[target][q] - now[target + 1][j]);
                    }
                    else if (calc[geko[i]] == 2) {
                        if (now[target + 1][j] == 0) continue;
                        tmp.insert(now[target][q] / now[target + 1][j]);
                    }
                    else {
                        tmp.insert(now[target][q] * now[target + 1][j]);
                    }
                }
            }
            REP(t, 2) {
                now.erase(now.begin() + target);
            }
            vector<int> hogea;
            for (auto i : tmp) {
                hogea.push_back(i);
            }
            now.insert(now.begin() + target, hogea);
        }
        if (now.size() != 1) continue;
        REP(q, now[0].size()) {
            gogo.insert(now[0][q]);
        }
    } while (next_permutation(ALL(geko)));
    vector<int> ans;
    for (auto i : gogo) {
        ans.push_back(i);
    }
    now++;
    return ans;
}

void solve(){
    while (true) {
        string s;
        cin >> s;
        if (s == "#") return;
        s.push_back(')');
        State start = s.begin();
        cout << sol(start).size() << endl;
    }
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 3228