#include<bits/stdc++.h>
using namespace std;


constexpr int SIZE=8;
string symbol="01+-*()=";

using Flag=bitset<SIZE>;
using Er=runtime_error;

using ll=long long;
ll E(int &p,string &exp);
ll N(int &p,string &exp){
    char dig=exp[p++];
    if(dig=='0') return 0;
    ll res=1;
    while(p<exp.size() && isdigit(exp[p])){
        res*=2;
        res+=(exp[p++]-'0');
    }
    return res;
}
ll F(int &p,string &exp){
    if(p>=exp.size()) throw Er("F_iter");
    if(isdigit(exp[p])){
        return N(p,exp);
    }
    if(exp[p]=='-'){
        p++;
        return -(F(p,exp));
    }
    if(exp[p]=='('){
        p++;
        ll res=E(p,exp);
        if(p>=exp.size() || exp[p]!=')') throw Er("F_par");
        p++;
        return res;
    }
    throw Er("F_no "+to_string(p));    

}
ll T(int &p,string &exp){
    ll res=F(p,exp);
    while(p<exp.size() && exp[p]!='=' && exp[p]!='+' && exp[p]!='-' && exp[p]!=')'){
        char op=exp[p++];
        if(op!='*') throw Er("T "+to_string(p));
        ll rhs=F(p,exp);
        res*=rhs;
    }
    return res;
}
ll E(int &p,string &exp){
    ll res=T(p,exp);
    while(p<exp.size() && exp[p]!='=' && exp[p]!=')'){
        char op=exp[p++];
        if(op!='+' && op!='-') throw Er("E");
        ll rhs=T(p,exp);
        if(op=='+') res+=rhs;
        else res-=rhs;
    }
    return res;
}
bool Q(int &p,string& exp){
    try{
        ll lhs=E(p,exp);
        if(p>=exp.size() || exp[p]!='=') return false;
        p++;
        ll rhs=E(p,exp);
        if(p!=exp.size()) return false;
        else{
            return lhs==rhs;
        }
    }
    catch(std::runtime_error re){
        // cerr<<re.what()<<endl;
        return false;
    }
}
int judge(string exp){
    int p=0;
    return Q(p,exp);
}
int dfs(int p,string str,map<char,char> mp,Flag used){
    if(p==str.size()){
        return judge(str);
    }
    if(find(symbol.begin(),symbol.end(),str[p])!=symbol.end()){
        return dfs(p+1,str,mp,used);
    }
    if(mp.count(str[p])){
        str[p]=mp[str[p]];
        return dfs(p+1,str,mp,used);
    }    
    int res=0;
    char org=str[p];
    for(int i=0;i<SIZE;i++){
        if(!used[i]){
            used[i]=true;
            mp[str[p]]=symbol[i];
            str[p]=symbol[i];
            res+=dfs(p+1,str,mp,used);
            str[p]=org;
            mp.erase(org);
            used[i]=false;
        }
    }
    return res;
}
int solve(string str){
    map<char,char> mp;
    return dfs(0,str,mp,Flag());
}
int main(){
    string str;
    cin>>str;
    cout<<solve(str)<<endl;    
    return 0;
}
