#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;

bool OK(string s){
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='-'){
      if(i+1==s.size())return 0;
      if(s[i+1]=='+')return 0;
      if(s[i+1]=='*')return 0;
      if(i&&s[i-1]=='('&&s[i+1]==')')return 0;
      if(s[i+1]==')')return 0;
    }
    if(s[i]=='+'){
      if(i==0)return 0;
      if(i+1==s.size())return 0;
      if(s[i+1]=='+')return 0;
      //if(s[i+1]=='-')return 0;
      if(s[i+1]=='*')return 0;
      if(s[i+1]==')')return 0;
    }
     if(s[i]=='*'){
      if(i==0)return 0;
      if(i+1==s.size())return 0;
      if(s[i+1]=='+')return 0;
      //if(s[i+1]=='-')return 0;
      if(s[i+1]=='*')return 0;
      if(s[i+1]==')')return 0;
    }
    if(isdigit(s[i])){
      if(i&&s[i-1]==')')return 0;
      if(s[i]=='0'){
        if(i==0&&isdigit(s[i+1]))return 0;
        if(i&&i<s.size()&&!isdigit(s[i-1])&&isdigit(s[i+1]))return 0;
      }
      if(s[i+1]=='(')return 0;
    }
    if(s[i]=='('){
      cnt++;
      if(i==s.size())return 0;
      if(s[i+1]=='+')return 0;
      if(s[i+1]=='*')return 0;
      if(s[i+1]==')')return 0;
    }
    if(s[i]==')'){
      cnt--;
      if(cnt<0)return 0;
      if(!i)return 0;
      if(isdigit(s[i+1]))return 0;
      if(s[i+1]=='(')return 0;
    }
  }
  if(cnt)return 0;
  return 1;
}

string str,s;
set<char>st;

struct Parse{
    string s;
    int p;
    int g_A(){
        int r=0,x=1;
        if(s[p]=='-'){
          p++;
          return -g_A();
        }
        else if(s[p]=='(')p++,r=bnf1(),p++;
        else while(isdigit(s[p])) r=r*2+(s[p++]-'0');
        return r;
    }
    int bnf2(){
        int res=g_A();
        while(s[p]=='*'){
          int t=p++;
          if(s[t]=='*')res*=g_A();
        }
        return res;
    }
    int bnf1(){
        int res=bnf2();
        while(s[p]=='+'||s[p]=='-'){
            int t=p++;
            if(s[t]=='+')res+=bnf2();
            if(s[t]=='-')res-=bnf2();
        }
    return res;
    }
    int build(string t){
        p=0;
        s=t;
        return bnf1();
    }
};

int ans=0;
string t="01()+*-=";
map<char,int>M1;
int n;

signed main(){

  Parse p;

  cin>>s;
  r(i,s.size())if(isalpha(s[i]))st.insert(s[i]);
  n=st.size();
  int cc=0;
  for(set<char>::iterator it=st.begin();it!=st.end();it++){
    char c=*it;
    M1[c]=cc++;
  }
  set<string>S;
  vector<int>v;
  r(i,8)v.push_back(i);
  do{
    int sum=0,idx;
    string x=s;
    r(i,x.size()){
      if(isalpha(x[i])){
        int y=M1[x[i]];
        x[i]=t[v[y]];
      }
    }

    if(S.count(x))continue;
    r(i,x.size())if(x[i]=='=')sum++,idx=i;
    if(sum!=1)continue;
    if(idx==0||idx==x.size()-1)continue;

    string a=x.substr(0,idx);
    string b=x.substr(idx+1);

    if(!OK(a)||!OK(b))continue;

    int A=p.build(a);
    int B=p.build(b);
    if(A==B){

      S.insert(x);
      ans++;
    }
  }while(next_permutation(v.begin(),v.end()));
  cout<<ans<<endl;
}
