#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vp = vector<Pii>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

bool isOperator(char c) {
    return c == '/' || c == '*' || c == '+' || c == '-';
}

vector<vector<bool>> trclOp(string s) {
    vi op_pos;
    rep(i, s.size()) {
        if (isOperator(s[i])) {
            op_pos.emplace_back(i);
        }
    }
    int num_op = op_pos.size();

    vp ranges;
    ranges.emplace_back(-inf, inf);
    rep(i, s.size()) {
        if (s[i] == '(') {
            int depth = 1;
            int j = i + 1;
            while (depth > 0) {
                if (s[j] == '(') depth++;
                else if (s[j] == ')') depth--;
                j++;
            }
            ranges.emplace_back(i, j);
        }
    }
    int num_range = ranges.size();
    sort(all(ranges));

    vi op_range(num_op);
    rep(i, num_range) {
        rep(j, num_op) {
            if (ranges[i].first <= op_pos[j] && op_pos[j] < ranges[i].second) {
                op_range[j] = i;
            }
        }
    }

    vector<vector<bool>> trcl_range(num_range, vector<bool>(num_range));
    rep(i, num_range) {
        rep(j, num_range) {
            if (ranges[i].first < ranges[j].first && ranges[j].second < ranges[i].second) {
                trcl_range[i][j] = true;
            }
        }
    }

    // printVV(trcl_range);

    vector<vector<bool>> trcl_op(num_op, vector<bool>(num_op));
    rep(i, num_op) {
        rep(j, num_op) {
            trcl_op[j][i] = trcl_range[op_range[i]][op_range[j]];
        }
    }

    return trcl_op;
}

bool valid(const vi& perm, const vector<vector<bool>>& trcl_op) {
    rep(i, perm.size()) {
        rep2(j, i + 1, perm.size()) {
            if (trcl_op[perm[j]][perm[i]]) return false;
        }
    }
    return true;
}

int op(int a, int b, char c) {
    if (a == inf || b == inf) return inf;
    if (c == '+') return a + b;
    if (c == '-') return a - b;
    if (c == '*') return a * b;
    if (c == '/') {
        if (b == 0) return inf;
        int x = ceil(1. * a / b);
        int y = floor(1. * a / b);
        if (abs(x) < abs(y)) return x;
        else return y;
    }
}

int eval(vi numbers, vector<char> operators, vi perm) {
    while(!perm.empty()) {
        int p = perm[0];
        int a = numbers[p];
        int b = numbers[p + 1];
        int x = op(a, b, operators[p]);
        if (x == inf) return inf;
        numbers.erase(numbers.begin() + p, numbers.begin() + p + 2);
        numbers.insert(numbers.begin() + p, x);
        operators.erase(operators.begin() + p);
        perm.erase(perm.begin());
        for (auto& q : perm) {
            if (q > p) q--;
        }
    }
    return numbers[0];
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    string s;
    int testcase = 0;
    while (cin >> s, s != "#") {
        // output("testcase = ", testcase++);
        auto trcl_op = trclOp(s);
        // printVV(trcl_op);

        // parse
        vi numbers;
        vector<char> operators;
        {
            string t;
            rep(i, s.size()) {
                if (isdigit(s[i])) {
                    t += s[i];
                }
                else {
                    if (t != "") {
                        numbers.emplace_back(stoi(t));
                        t = "";
                    }
                    if (isOperator(s[i])) {
                        operators.emplace_back(s[i]);
                    }
                }
            }
            if (t != "") {
                numbers.emplace_back(stoi(t));
            }
        }

        // printV(numbers);
        // printV(operators);

        if (operators.empty()) {
            cout << 1 << endl;
            continue;
        }

        vi perm(operators.size());
        rep(i, operators.size()) perm[i] = i;
        sort(all(perm));
        set<int> st;
        do {
            if (!valid(perm, trcl_op)) continue;
            // printV(perm);
            int x = eval(numbers, operators, perm);
            if (x != inf) st.insert(x);
        } while (next_permutation(all(perm)));

        cout << st.size() << endl;
    }
}

Measured memory_bytes: 3220