#include <cassert>
#include <cctype>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

#define whole(xs) (xs).begin(),(xs).end()
#define uniq(xs) ((xs).erase(unique((xs).begin(), (xs).end()), (xs).end()))

template<class T>
ostream& operator<<(ostream& os, const vector<T> xs) {
    if (xs.empty()) return os << "[]";
    os << "[" << xs[0];
    for (int i = 1; i < xs.size(); i++) os << " " << xs[i];
    return os << "]";
}

string s;
bool input() {
    getline(cin, s);
    if (s == "#") return false;
    return true;
}

bool check_op(char x) {
    const string ops = "+-*/(";
    if (ops.find(x) == string::npos) return false;
    return true;
}

int calc(char op, int l, int r) {
    switch (op) {
        case '+': return l + r;
        case '-': return l - r;
        case '*': return l * r;
        case '/': return l / r;
        default: assert(0);
    }
}

int number(const string& s, int& i) {
    int x = 0;
    while (i < s.size() && isdigit(s[i])) {
        x = x * 10 + (s[i] - '0');
        i++;
    }
    return x;
}

vector<int> dfs(const vector< vector<int> >& values, const vector<char>& ops);
vector<int> expr(const string& s,int& i) {
    vector<int> L;
    if (s[i] == '(') {
        i++;
        L = expr(s, i);
        assert(s[i] == ')');
        i++;
    } else {
        L.push_back(number(s, i));
    }
    vector<char> ops;
    vector< vector<int> > values;
    values.push_back(L);
    while (true) {
        if (i == s.size() || s[i] == ')') break;
        assert(check_op(s[i]));
        ops.push_back(s[i]); i++;
        vector<int> value;
        if (s[i] == '(') {
            i++;
            value = expr(s, i);
            assert(s[i] == ')');
            i++;
        } else {
            value.push_back(number(s, i));
        }
        values.push_back(value);
    }
    assert(ops.size() + 1 == values.size());
    return dfs(values, ops);
}

vector<int> dfs(const vector< vector<int> >& values, const vector<char>& ops) {
    int N = ops.size();
    if (N == 0) {
        assert(values.size() == 1);
        return values[0];
    }
    vector<int> ret;
    for (int i = 0; i < N; i++) {
        char op = ops[i];
        vector< vector<int> > lvalues; for (int j = 0; j <= i; j++) lvalues.push_back(values[j]);
        vector<char> lops; for (int j = 0; j < i; j++) lops.push_back(ops[j]);
        vector< vector<int> > rvalues; for (int j = i + 1; j <= N; j++) rvalues.push_back(values[j]);
        vector<char> rops; for (int j = i + 1; j < N; j++) rops.push_back(ops[j]);
        vector<int> L = dfs(lvalues, lops);
        vector<int> R = dfs(rvalues, rops);
        assert(L.size() > 0);
        assert(R.size() > 0);
        for (int j = 0; j < L.size(); j++) {
            for (int k = 0; k < R.size(); k++) {
                if (op == '/' && R[k] == 0) continue;
                ret.push_back(calc(op, L[j], R[k]));
            }
        }
    }
    sort(whole(ret));
    uniq(ret);
    if (false) {
        cout << "values: " << values << endl;
        cout << "ops: " << ops << endl;
        cout << ret << endl;
    }
    return ret;
}

void solve() {
    int i = 0;
    cout << expr(s, i).size() << endl;
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 1228