#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s;
int a[200],p,f;
char b[11];
int bns1();
int g_A(){
  int r=0;
  if(s[p]=='(')p++,r=bns1(),p++;
  else while(isdigit(s[p]))r=r*10+(s[p++]-'0');
  return r;
}
int bns10(){
  int res=g_A();
  while(a[s[p]]==10){
    int t=p++;
    if(b[s[t]]=='+')res+=g_A();
    if(b[s[t]]=='-')res-=g_A();
    if(b[s[t]]=='*')res*=g_A();
    if(b[s[t]]=='/'){
      int tt=g_A();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns9(){
  int res=bns10();
  while(a[s[p]]==9){
    int t=p++;
    if(b[s[t]]=='+')res+=bns10();
    if(b[s[t]]=='-')res-=bns10();
    if(b[s[t]]=='*')res*=bns10();
    if(b[s[t]]=='/'){
      int tt=bns10();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns8(){
  int res=bns9();
  while(a[s[p]]==8){
    int t=p++;
    if(b[s[t]]=='+')res+=bns9();
    if(b[s[t]]=='-')res-=bns9();
    if(b[s[t]]=='*')res*=bns9();
    if(b[s[t]]=='/'){
      int tt=bns9();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns7(){
  int res=bns8();
  while(a[s[p]]==7){
    int t=p++;
    if(b[s[t]]=='+')res+=bns8();
    if(b[s[t]]=='-')res-=bns8();
    if(b[s[t]]=='*')res*=bns8();
    if(b[s[t]]=='/'){
      int tt=bns8();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns6(){
  int res=bns7();
  while(a[s[p]]==6){
    int t=p++;
    if(b[s[t]]=='+')res+=bns7();
    if(b[s[t]]=='-')res-=bns7();
    if(b[s[t]]=='*')res*=bns7();
    if(b[s[t]]=='/'){
      int tt=bns7();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns5(){
  int res=bns6();
  while(a[s[p]]==5){
    int t=p++;
    if(b[s[t]]=='+')res+=bns6();
    if(b[s[t]]=='-')res-=bns6();
    if(b[s[t]]=='*')res*=bns6();
    if(b[s[t]]=='/'){
      int tt=bns6();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns4(){
  int res=bns5();
  while(a[s[p]]==4){
    int t=p++;
    if(b[s[t]]=='+')res+=bns5();
    if(b[s[t]]=='-')res-=bns5();
    if(b[s[t]]=='*')res*=bns5();
    if(b[s[t]]=='/'){
      int tt=bns5();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns3(){
  int res=bns4();
  while(a[s[p]]==3){
    int t=p++;
    if(b[s[t]]=='+')res+=bns4();
    if(b[s[t]]=='-')res-=bns4();
    if(b[s[t]]=='*')res*=bns4();
    if(b[s[t]]=='/'){
      int tt=bns4();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns2(){
  int res=bns3();
  while(a[s[p]]==2){
    int t=p++;
    if(b[s[t]]=='+')res+=bns3();
    if(b[s[t]]=='-')res-=bns3();
    if(b[s[t]]=='*')res*=bns3();
    if(b[s[t]]=='/'){
      int tt=bns3();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
int bns1(){
  int res=bns2();
  while(a[s[p]]==1){
    int t=p++;
    if(b[s[t]]=='+')res+=bns2();
    if(b[s[t]]=='-')res-=bns2();
    if(b[s[t]]=='*')res*=bns2();
    if(b[s[t]]=='/'){
      int tt=bns2();
      if(!tt)f++,tt=1;
      else res/=tt;
    }
  }
  return res;
}
main(){
  while(cin>>s,s!="#"){
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    int cnt=0,lx[10];
    set<int>se;
    r(i,s.size())if(!isdigit(s[i])&&s[i]!='('&&s[i]!=')')b[cnt+'a']=s[i],s[i]='a'+cnt++;
    r(i,cnt)lx[i]=i;
    do{
      f=p=0;
      r(i,cnt)a[lx[i]+'a']=i+1;
      int ppp=bns1();
      if(!f)se.insert(ppp);
    }while(next_permutation(lx,lx+cnt));
    cout<<se.size()<<endl;
  }
}

Measured memory_bytes: 3224