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

struct State {
    int pos;
    string str;
    State(string s) : pos(0), str(move(s)) {}
    char get() { return str[pos]; }
    char next() { return str[pos++]; }
    char prev() { return str[pos--]; }
    bool is_end() { return pos == str.size(); }
};

enum ElemType {
    INT,
    OP_ADD,
    OP_SUB,
    OP_MUL,
    OP_DIV,
    L_PAR,
    R_PAR,
    NIL,
};

struct Elem {
    ElemType type;
    int value;
    Elem() {}
    Elem(ElemType type) : type(type) {}
};

list<Elem> lexer(State &state) {
    if (state.is_end()) {
        Elem e;
        e.type = NIL;
        return {e};
    }

    Elem e;
    e.value = -100;
    switch (state.get()) {
    case '(': e.type = L_PAR; break;
    case ')': e.type = R_PAR; break;
    case '+': e.type = OP_ADD; break;
    case '-': e.type = OP_SUB; break;
    case '*': e.type = OP_MUL; break;
    case '/': e.type = OP_DIV; break;
    default:
        e.type = INT;
        int value = 0;
        while ('0' <= state.get() && state.get() <= '9') {
            value *= 10;
            value += state.get() - '0';
            state.next();
        }
        e.value = value;
        state.prev();
        break;
    }
    state.next();

    auto ret = lexer(state);
    ret.push_front(e);
    return ret;
}

void print(list<Elem>::iterator left, list<Elem>::iterator right) {
    if (left == right) {
        cout << endl;
        return;
    }

    switch (left->type) {
    case INT:
        cout << "INT: " << left->value << ", ";
        break;
    case OP_ADD:
        cout << "OP_ADD, ";
        break;
    case OP_SUB:
        cout << "OP_SUB, ";
        break;
    case OP_MUL:
        cout << "OP_MUL, ";
        break;
    case OP_DIV:
        cout << "OP_DIV, ";
        break;
    case L_PAR:
        cout << "L_PAR, ";
        break;
    case R_PAR:
        cout << "R_PAR, ";
        break;
    case NIL:
        cout << "NIL, ";
        break;
    }

    print(next(left), right);
}

void simplify(list<Elem> &elems, list<Elem>::iterator itr) {
    while (prev(itr)->type == L_PAR && next(itr)->type == R_PAR) {
        elems.erase(prev(itr));
        elems.erase(next(itr));
    }
}

bool check_bothside(list<Elem>::iterator itr) {
    return (prev(itr)->type != R_PAR && next(itr)->type != L_PAR);
}

signed main() {
    while (1) {
        string s;
        cin >> s;
        if (s == "#") break;

        State state(s);
        auto elems = lexer(state);
        elems.emplace_front(NIL);


        int op_num = 0;
        for (auto itr = next(elems.begin()); itr != prev(elems.end()); itr++) {
            if (itr->type == OP_ADD || itr->type == OP_SUB || itr->type == OP_MUL || itr->type == OP_DIV) {
                op_num++;
            }
            simplify(elems, itr);
        }
        vector<int> ord(op_num);
        for (int i = 0; i < ord.size(); i++) ord[i] = i;

        set<int> values;
        do {
            if (op_num == 0) break;

            auto tmp = elems;
            vector<list<Elem>::iterator> ops;
            for (auto itr = tmp.begin(); itr != tmp.end(); itr++) {
                if (itr->type == OP_ADD || itr->type == OP_SUB || itr->type == OP_MUL || itr->type == OP_DIV) {
                    ops.push_back(itr);
                }
            }

            bool invalid = false;
            for (int i = 0; i < ord.size(); i++) {
                int idx = ord[i];
                if (!check_bothside(ops[idx])) {
                    invalid = true;
                    break;
                }

                int a = prev(ops[idx])->value;
                int b = next(ops[idx])->value;
                switch (ops[idx]->type) {
                case OP_ADD:
                    ops[idx]->value = a + b;
                    break;
                case OP_SUB:
                    ops[idx]->value = a - b;
                    break;
                case OP_MUL:
                    ops[idx]->value = a * b;
                    break;
                case OP_DIV:
                    if (b == 0) {
                        invalid = true;
                        break;
                    }
                    ops[idx]->value = a / b;
                    break;
                default:
                    assert(false);
                }
                if (invalid) break;
                
                ops[idx]->type = INT;
                tmp.erase(next(ops[idx]));
                tmp.erase(prev(ops[idx]));
                simplify(tmp, ops[idx]);
            }
            if (invalid) continue;
            values.insert(next(tmp.begin())->value);
        } while (next_permutation(ord.begin(), ord.end()));

        if (op_num == 0) {
            values.insert(next(elems.begin())->value);
        }
        cout << values.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3204