#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

typedef string::const_iterator State;
int num(State &begin);
void consume(State &begin, char expected);
set<int> expr(State &begin);
int operate(int r, int l, char op);
set<int> gen_pattern(vector<set<int>> &v, vector<char> op);

class ParseError
{
};

int num(State &begin)
{
    int ret = 0;
    while (isdigit(*begin))
    {
        ret = 10 * ret + (*begin) - '0';
        begin++;
    }
    return ret;
}
void consume(State &begin, char expected)
{
    if (*begin == expected)
    {
        begin++;
    }
    else
    {
        cerr << "expected:" << expected << ", but got" << *begin << endl;
        cerr << "rest string is";
        while (*begin)
        {
            cerr << *begin;
            begin++;
        }
        cerr << endl;
        throw ParseError();
    }
}

set<int> term(State &begin)
{
    if (isdigit(*begin))
    {

        return set<int>{num(begin)};
    }
    if (*begin == '(')
    {
        begin++;
        set<int> ret = expr(begin);
        consume(begin, ')');
        return ret;
    }
}

set<int> expr(State &begin)
{
    vector<set<int>> v;
    vector<char> op;
    while (*begin != ')' && *begin)
    {
        set<int> val = term(begin);
        v.push_back(val);
        char c = *begin;
        if (c == ')' || c == '\0')
            break;
        assert(c == '+' || c == '-' || c == '*' || c == '/');
        op.push_back(c);
        begin++;
    }
    return gen_pattern(v, op);
}

int operate(int r, int l, char op)
{
    if (op == '+')
    {
        return r + l;
    }
    if (op == '*')
    {
        return r * l;
    }
    if (op == '-')
    {
        return r - l;
    }
    if (op == '/')
    {
        return r / l;
    }
}

set<int> gen_pattern(vector<set<int>> &v, vector<char> op)
{
    if (op.empty())
    {
        assert(v.size() == 1);
        return v[0];
    }
    set<int> ret;
    rep(i, op.size())
    {
        auto _v = v;
        auto _op = op;
        set<int> tmp;
        for (auto j : _v[i])
        {
            for (auto k : _v[i + 1])
            {
                if (_op[i] != '/' || k != 0)
                    tmp.insert(operate(j, k, _op[i]));
                else
                    continue;
            }
        }

        _v[i] = tmp;

        _v.erase(_v.begin() + i + 1);

        _op.erase(_op.begin() + i);

        set<int> rec = gen_pattern(_v, _op);
        ret.insert(rec.begin(), rec.end());
    }
    return ret;
}

int main(int argc, char const *argv[])
{

    while (true)
    {
        string s;
        cin >> s;
        if (s == "#")
            break;
        State begin = s.begin();
        auto ret = expr(begin);
        cout << ret.size() << endl;
    }
    return 0;
}



Measured memory_bytes: 3260