#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef set<int> si;

enum { T_NUM, T_OP, T_PR0, T_PR1 };

struct Elm {
  int type, v;
  Elm() {}
  Elm(int _t, int _v): type(_t), v(_v) {}

  void print() const {
    if (type == T_NUM) printf("%d", v);
    else printf("%c", v);
  }
};

typedef vector<Elm> ve;

/* global variables */

si ans;

/* subroutines */

void parse(ve& expr, string str) {
  expr.clear();
  int len = str.length();

  for (int i = 0; i < len; i++)
    switch (str[i]) {
    case '(': expr.push_back(Elm(T_PR0, '(')); break;
    case ')': expr.push_back(Elm(T_PR1, ')')); break;
    case '+': expr.push_back(Elm(T_OP, '+')); break;
    case '-': expr.push_back(Elm(T_OP, '-')); break;
    case '*': expr.push_back(Elm(T_OP, '*')); break;
    case '/': expr.push_back(Elm(T_OP, '/')); break;
    default:
      int num = 0;
      while (i < len && str[i] >= '0' && str[i] <= '9')
	num = 10 * num + (str[i++] - '0');
      i--;
      expr.push_back(Elm(T_NUM, num));
    }
}

int calc(const Elm& e0, const Elm& op, const Elm& e1) {
  switch (op.v) {
  case '+': return e0.v + e1.v;
  case '-': return e0.v - e1.v;
  case '*': return e0.v * e1.v;
  case '/': return (e1.v) ? e0.v / e1.v : INF;
  }
  return INF;
}

void print_expr(ve expr) {
  for (ve::iterator vit = expr.begin(); vit != expr.end(); vit++)
    vit->print(), putchar(' ');
  putchar('\n');
}

void rec(ve expr) {
  //print_expr(expr);
  int elen = expr.size();
  if (elen == 1) {
    ans.insert(expr.front().v);
    return;
  }

  for (int i = 0; i < elen - 2; i++) {
    Elm e0 = expr[i], e1 = expr[i + 1], e2 = expr[i + 2];
    if (e0.type == T_NUM && e1.type == T_OP && e2.type == T_NUM) {
      int num = calc(e0, e1, e2);
      if (num >= INF) continue;

      int pos0 = i, pos1 = i + 3;
      int npr = 0;

      while (pos0 > 0 && pos1 < elen &&
	     expr[pos0 - 1].type == T_PR0 &&
	     expr[pos1].type == T_PR1) {
	npr++;
	pos0--;
	pos1++;
      }

      expr.erase(expr.begin() + pos0, expr.begin() + pos1);
      expr.insert(expr.begin() + pos0, Elm(T_NUM, num));

      //cout << "--> "; print_expr(expr);
      rec(expr);

      expr.erase(expr.begin() + pos0);
      for (int j = 0; j < npr; j++)
	expr.insert(expr.begin() + pos0++, Elm(T_PR0, '('));
      expr.insert(expr.begin() + pos0++, e0);
      expr.insert(expr.begin() + pos0++, e1);
      expr.insert(expr.begin() + pos0++, e2);
      for (int j = 0; j < npr; j++)
	expr.insert(expr.begin() + pos0++, Elm(T_PR1, ')'));
      //cout << "<-- "; print_expr(expr);
    }
    else if (e0.type == T_PR0 && e1.type == T_NUM && e2.type == T_PR1) {
      int pos0 = i, pos1 = i + 3;
      int npr = 0;

      while (pos0 > 0 && pos1 < elen &&
	     expr[pos0 - 1].type == T_PR0 &&
	     expr[pos1].type == T_PR1) {
	npr++;
	pos0--;
	pos1++;
      }

      expr.erase(expr.begin() + pos0, expr.begin() + pos1);
      expr.insert(expr.begin() + pos0, e1);

      //cout << "--> "; print_expr(expr);
      rec(expr);

      expr.erase(expr.begin() + pos0);
      for (int j = 0; j < npr; j++)
	expr.insert(expr.begin() + pos0++, Elm(T_PR0, '('));
      expr.insert(expr.begin() + pos0++, e0);
      expr.insert(expr.begin() + pos0++, e1);
      expr.insert(expr.begin() + pos0++, e2);
      for (int j = 0; j < npr; j++)
	expr.insert(expr.begin() + pos0++, Elm(T_PR1, ')'));
      //cout << "<-- "; print_expr(expr);
    }
  }
}

/* main */

int main() {
  for (;;) {
    string str;
    cin >> str;
    if (str == "#") break;

    ve expr;
    parse(expr, str);

    ans.clear();
    rec(expr);
    cout << ans.size() << endl;
  }

  return 0;
}

Measured memory_bytes: 1240