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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

string S;
int N;

enum Type {
    Open,
    Close,
    Num,
    Ope,
    None
};

struct Expr {
    Expr() {
        right = -1;
        left = -1;
        type = None;
    }
    Type type;

    int num;
    char ope;

    int left;
    int right;
};

vector<Expr> exprs;
VI ope_idxes;

PII parse_num(int pos) {
    string num_s;
    while (pos < N && isdigit(S[pos])) {
        num_s += S[pos];
        ++pos;
    }
    return MP(pos, fromString<int>(num_s));
}

void link(int a, int b) {
    if (a != -1) {
        exprs[a].right = b;
    }
    if (b != -1) {
        exprs[b].left = a;
    }
}

void link2(vector<Expr> &es, int a, int b) {
    if (a != -1) {
        es[a].right = b;
    }
    if (b != -1) {
        es[b].left = a;
    }
}

int make_expr(int before) {
    Expr cur;
    int idx = exprs.size();
    exprs.PB(cur);
    link(before, idx);
    return idx;
}

void parse() {
    exprs.resize(0);
    ope_idxes.resize(0);

    int before = -1;

    for (int i = 0; i < N; i++) {
        int cur = make_expr(before);
        Expr &e = exprs[cur];
        char c = S[i];

        if (c == '(') {
            e.type = Open;
        } else if (c == ')') {
            e.type = Close;
        } else if (isdigit(c)) {
            e.type = Num;
            PII tmp = parse_num(i);
            i = tmp.fst - 1; // ?????´
            e.num = tmp.snd;
        } else { // ope
            e.type = Ope;
            e.ope = c;
            ope_idxes.PB(cur);
        }

        before = cur;
    }
}

void remove_blocks(vector<Expr> &es, int i) {
    while (true) {
        int l = es[i].left;
        int r = es[i].right;

        if (l == -1 || r == -1) return;
        if (es[l].type != Open || es[r].type != Close) return;

        link2(es, es[l].left, i);
        link2(es, i, es[r].right);
    }
}

pair<int, bool> calc(VI &idxes, vector<Expr> es) {
    int val = es[(int)es.size() / 2].num;
    
    for (int i = 0; i < (int)idxes.size(); i++) {
        int cur = idxes[i];
        int left = es[cur].left;
        int right = es[cur].right;

        if (es[left].type == Close ||
            es[right].type == Open ) {
            return MP(1, false);
        }

        char ope = es[cur].ope;
        int a = es[left].num;
        int b = es[right].num;

        // ?¨????
        if (ope == '+') {
            val = a + b;
        } else if (ope == '-') {
            val = a - b;
        } else if (ope == '*') {
            val = a * b;
        } else if (ope == '/') {
            if (b == 0) {
                return MP(2, false);
            }
            val = a / b;
        }

        // ?????????
        Expr new_expr;
        new_expr.num = val;
        new_expr.type = Num;
        int new_idx = es.size();
        es.PB(new_expr);
        link2(es, es[left].left, new_idx);
        link2(es, new_idx, es[right].right);

        // ??¬??§??????????????????????????¬??§?????????
        remove_blocks(es, new_idx);
    }

    return MP(val, true);
}

int solve() {
    parse();

    // (num) ??? num ???
    for (int i = 0; i < (int)exprs.size(); i++) {
        remove_blocks(exprs, i);
    }

    set<int> anses;

    sort(ALL(ope_idxes));

    do {
        auto ans = calc(ope_idxes, exprs);
        if (ans.snd) {
            anses.insert(ans.fst);
        }
    } while (next_permutation(ALL(ope_idxes)));

    return anses.size();
}

int main(void) {
    while (cin >> S, S != "#") {
        N = S.size();
        cout << solve() << endl;
    }

	return 0;
}

Measured memory_bytes: 1288