#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int next_paren(string expr, int i) {
    int level = 0;
    for (; i < (int)expr.length(); i++) {
        switch (expr[i]) {
        case '(':
            level++;
            break;
        case ')':
            level--;
            if (level == 0) return i;
            break;
        }
    }
    assert(0);
}

set<int> eval(string expr) {
    vector<string> terms;
    vector<char> ops;
    REP(i, expr.length()) {
        switch (expr[i]) {
        case '(': {
            int j = next_paren(expr, i);
            terms.push_back(expr.substr(i, j-i+1));
            i = j;
            break;
        }
        case '+':
        case '-':
        case '*':
        case '/':
            ops.push_back(expr[i]);
            break;
        default: {
            string num;
            for (; i < (int)expr.length() && isdigit(expr[i]); i++) {
                num += expr[i];
            }
            terms.push_back(num);
            i--;
        }
        }
    }

    set<int> res;
    if (ops.empty()) {
        if (terms[0][0] == '(') {
            return eval(terms[0].substr(1, terms[0].length()-2));
        } else {
            res.insert(stoi(terms[0]));
        }
    } else {
        FOR(i, 1, terms.size()) {
            string lexpr, rexpr;
            REP(j, i) {
                if (j != 0) lexpr += ops[j-1];
                lexpr += terms[j];
            }
            FOR(j, i, terms.size()) {
                if (j != i) rexpr += ops[j-1];
                rexpr += terms[j];
            }
//            LOG("--> %s %c %s\n", lexpr.c_str(), ops[i-1], rexpr.c_str());
            set<int> l = eval(lexpr);
            set<int> r = eval(rexpr);
//            LOG("# %d\n", l.size());
//            LOG("# %d\n", r.size());
            for (int a : l) for (int b : r) {
//                LOG("-----> %d %c %d\n", a, ops[i-1], b);
                int val;
                switch (ops[i-1]) {
                case '+':
                    val = a + b;
                    break;
                case '-':
                    val = a - b;
                    break;
                case '*':
                    val = a * b;
                    break;
                case '/':
                    if (b == 0) {
                        goto NEXT;
                    }
                    val = a / b;
                    break;
                }
                res.insert(val);
                NEXT : {}
            }
        }
    }
    return res;
}

int main() {
    string expr;
    while (cin  >> expr, expr != "#") {
        cout << eval(expr).size() << endl;
    }
}

Measured memory_bytes: 1280