#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


set<int> SET;

int calc(int a,int b,char op){
	switch(op){
	case '+':return a+b;
	case '-':return a-b;
	case '*':return a*b;
	case '/':
		if(b == 0){
			return BIG_NUM;
		}else{
			return a/b;
		}
	}
}

bool is_op(char ch){
	if(ch == '+' || ch == '-' || ch == '*' || ch == '/'){
		return true;
	}else{
		return false;
	}
}

bool is_num(char ch){
	return ch >= '0' && ch <= '9';
}

void remove_brackets(char equation[201],int length){

	char work[201];
	bool op_FLG;

	stack<int> S;
	int left,right;

	for(int i = 0; i < length; i++){
		if(equation[i] == '('){
			S.push(i);
		}else if(equation[i] == ')'){
			op_FLG = false;
			//対応する開きカッコから自分までの間に、演算子があるか調べる
			left = S.top();
			S.pop();
			right = i;
			for(int k = left+1; k < right; k++){
				if(is_op(equation[k])){
					op_FLG = true;
					break;
				}
			}
			if(!op_FLG){ //対応する区間に演算子がない場合:削除する
				equation[left] = '.';
				equation[right] = '.';
			}
		}
	}

	int index = 0;
	for(int i = 0; i < length; i++){
		if(equation[i] == '.')continue;
		work[index++] = equation[i];
	}
	for(int i = 0; i < index; i++){
		equation[i] = work[i];
	}
	equation[index] = '\0';
}

void recursive(char equation[201],int length){

	stack<int> S;

	//演算可能な演算子を走査する(左右にカッコがあるものはSKIP)
	for(int i = 0; i < length; i++){
		if(is_op(equation[i]) == true && equation[i+1] != '(' && equation[i-1] != ')'){
			S.push(i);
		}
	}

	if(S.empty()){ //計算できる演算子がない場合:SETに最終結果を突っ込む
		int number = 0;
		bool neg_FLG = false;

		for(int i = 0; i < length; i++){
			if(equation[i] == '@'){ //マイナス
				neg_FLG = true;
				continue;
			}
			number = 10*number+equation[i]-'0';
		}
		if(neg_FLG)number *= -1;
		SET.insert(number);

		return;
	}

	int loc,left,right,left_num,start,right_num,new_num,index,num_length,next_length;
	bool left_neg_FLG,right_neg_FLG,new_num_neg_FLG;

	stack<int> WORK;

	//演算し、演算部を結果で置換する
	while(!S.empty()){
		loc = S.top();
		S.pop();

		left_neg_FLG = false;
		//左側の数字の開始位置を調べる
		for(left = loc-1; left >= 0 && is_num(equation[left]) == true; left--);
		left++;
		if(left > 0 && equation[left-1] == '@'){
			left--; //演算部の左端をデクリメント
			left_neg_FLG = true;
		}

		if(equation[loc+1] == '@'){
			right_neg_FLG = true;
			start = loc+2;
		}else{
			right_neg_FLG = false;
			start = loc+1;
		}

		//右側の数字の終了位置を調べる
		for(right = start; right < length && is_num(equation[right]) == true; right++);
		right--;

		//左側の数字を計算する
		left_num = 0;
		for(int i = left; i < loc; i++){
			if(equation[i] == '@')continue;
			left_num = 10*left_num+equation[i]-'0';
		}
		if(left_neg_FLG)left_num *= -1;

		//右側の数字を計算する
		right_num = 0;
		for(int i = start; i <= right; i++){
			right_num = 10*right_num+equation[i]-'0';
		}
		if(right_neg_FLG)right_num *= -1;

		//演算
		new_num = calc(left_num,right_num,equation[loc]);

		if(new_num == BIG_NUM)continue; //0割り発生

		if(new_num < 0){
			new_num_neg_FLG = true;
			new_num *= -1;
		}else{
			new_num_neg_FLG = false;
		}

		//新しい数式を作る
		char next_equation[201];
		index = 0;

		//演算部の前まで
		for(int i = 0; i < left; i++){
			next_equation[index++] = equation[i];
		}

		//new_numを分解し、char型にする
		num_length = 0;

		do{
			WORK.push(new_num%10);
			new_num /= 10;
			num_length++;

		}while(new_num > 0);

		if(new_num_neg_FLG){ //結果が負の場合
			next_equation[index++] = '@';
			num_length++; //★★マイナスも数字長に含む★★
		}

		while(!WORK.empty()){
			next_equation[index++] = '0'+WORK.top();
			WORK.pop();
		}

		//演算部の右側
		for(int i = right+1; i < length; i++){
			next_equation[index++] = equation[i];
		}
		next_equation[index] = '\0';

		//★★今回の演算によって、演算子を含まない()ができれば、()を除去する
		remove_brackets(next_equation,index);
		for(next_length = 0; next_equation[next_length] != '\0'; next_length++);

		recursive(next_equation,next_length);
	}
}

/*
 * 簡単のため、単項の-は@で表す
 * */

int main(){

	int length;
	char equation[201],work[201];

	while(true){
		scanf("%s",equation);
		if(equation[0] == '#')break;

		for(length = 0; equation[length] != '\0'; length++);
		remove_brackets(equation,length); //カッコを取り除く

		for(length = 0; equation[length] != '\0'; length++);

		SET.clear();
		recursive(equation,length);

		printf("%lld\n",SET.size());
	}

	return 0;
}



Measured memory_bytes: 3184