#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

set<int> ans;
string line; 
int len;

int apply(char opr, int a, int b) {
    if (opr == '+') return a + b;
    if (opr == '-') return a - b;
    if (opr == '*') return a * b;
    if (opr == '/') return a / b;
}

int reduce(stack<int>& N, stack<char>& O) {
    char opr = O.top(); O.pop();
    int v = N.top(); N.pop();
    int w = N.top(); N.pop();
    if (opr == '/' && !v) return 0;
    N.push(apply(opr, w, v));
    return 1;
}

void debug(stack<int> N, stack<char> O) {
    while (N.size()) { cout << N.top() << endl; N.pop(); }
    while (O.size()) { cout << O.top() << endl; O.pop(); }
}

void read(int i, stack<int> N, stack<char> O) {
    if (i == len) {
        while (O.size()) if (!reduce(N, O)) return;
        ans.insert(N.top());
        return;
    }
    if (line[i] >= '0') {
        int v = 0;
        while (i < len && line[i] >= '0') v *= 10, v += line[i++] - '0';

        N.push(v);
        read(i, N, O);

        while (!O.empty() && O.top() != '(' && reduce(N, O)) read(i, N, O);
        // if (O.empty() || O.top() == '(' || !reduce(N, O)) return;
        // read(i, N, O);
        return;
    }
    if (line[i] == ')') {
        while (O.top() != '(') if (!reduce(N, O)) return;
        O.pop();
        read(i+1, N, O);
        while (!O.empty() && O.top() != '(' && reduce(N, O)) read(i+1, N, O);
        // if (O.empty() || O.top() == '(' || !reduce(N, O)) return;
        // read(i+1, N, O);
        return;
    }
    O.push(line[i]);
    read(i+1, N, O);
    return;
}

vector<string> inn = {
"6/2*(1+2)",
"1-1-1",
"(1-1-1)/2",
"9369/589/182446-1",
"166/(6679+817)",
"3+5536",
"(6*(525483)+(3656+(4432)+318))",
"(1)*15473/1-(823/68)-2-168-565",
"911509/(7803)/276*4",
"116/7232/351+544*443169/693/5513/2/20024+2/62",
"(946730/((667/(6)))-51)",
"3874+(358)*1+25897",
"135229-5506/7/222827/7+3-396",
"2174+3278-4138/1317982*267+8/523297",
"1*15625*3+39325",
"(3)*68287",
"326965/982552-3+4871854/4873-354467-3+477259+3",
"(40510)+(8/60+2214*1)",
"5+7-828*4",
"49969+86987-(6460)+956302+957509+7765",
"6+25/98487+31545/8",
"471+9+483763",
"467669+(23*9-3561154-4047+8750330-728)-8939",
"(((37450)/5960))",
"8982/1/18859",
"8*7+8213/78857/398-5-254",
"68086-7/796615",
"(2/60+3)-53127",
"((42778)*(9077))",
"5-53743+(51*787)",
"92*7350",
"(271)/67",
"211797/464581/6-1+68981-58667/9808592/5208414+1",
"682/(5)",
"(((15+986)+532)+1)*37",
"((296852)+(12887))",
"(3)*7",
"77*1190359/8585*294-25536",
"87*2-47621",
"315536-(407778*3*(4))-6+61755",
"4/7",
"47290+1/(395)/40631/6619+840839/656+7870421-202",
"15980+(4822382)",
"4345701*4-3",
"754508+1-2",
"(219890)/6",
"6378/3*694",
"3/(2270301)*46",
"(7300-4)+900/7098+54",
"3/166999",
"4+980067/613828*82/26874-9+4",
"(4-3914)",
"21490/83921+(42706)",
"(1*491920+6*2)",
"98+299-620717/95328*28*2/86",
"86530+24456/9*98-1693/83603",
"2802732/(3)-(9-4-9+22294)",
"7/82/8017*4+3624+83823",
"(6597383)-(2467)/(797)",
"1699-894/47400+8327+3231219*7",
"(6+70)",
"(5763+(7)+75890-(6)+53989-74)",
"3867426-9/3815340+7/46-405635+561986*131/939",
"210103+71496+8*88",
"(6669+((7))-49)",
"9949/9691+81+156",
"3709/(1+2)+(61*471-6820744+7)/257+589523*78",
"6*(433674/(8+1)-6462)",
"86-7+1331*727",
"(48)/(99)+7-5/563834/1116438/8464629+7854*6",
"932+61735/53",
"916/2*471",
"1547312+1164764",
"106-20869+63359*9-3*9+2-1153",
"6-71+8127+86*4/13-6*8009",
"53423+314/7",
"(7903*5)-(4)",
"4/935/58-7406244/615",
"352/949877-707156+391869+3+(52)-84",
"6+1484+1/6583331-24364/(9/6)/5030597",
"1903/9312+1668376/5-448-411508/90229",
"702954+(690)/398178-6",
"6222+4/7/7/5426",
"9*5962441/505",
"21270-4+688669/11+9+543*4",
"4+627-88709+((7398*(81782/827262*3)/5019257)+7849)/1013372",
"4*(628945/(6-22350)+991+9142107)+237037",
"((56)*(478-63037)/90906)",
"13376-(8+27*2)",
"413-6059581/397+6/141/49/23291-57-1+1402",
"89+49*8*(4+(92)/703947)",
"(91163/15506)/3256248+379194/168482/((6))*8-4",
"9*8897/7547785-5-9"
};

int main()
{
    //for (string v : inn) {
    while (1) {
        ans.clear();
        cin >> line;
        //line = v;
        len = line.length();
        if (line == "#") break;
        read(0, stack<int>(), stack<char>());
        cout << ans.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3244