#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <cstring>
#include <stack>
#include <iostream>
#include <vector>
#include <map>
#define FAIL (make_pair(0,0))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
char a[] = "01+-*()=";
int pr[500];
char s[100];
char t[100];
int n,ans;
map<char,char> m;
bool work(stack<LL> &res,stack<char> & op){
    if(res.empty())return 0;
    if(res.top() == '(')return 0;
    if(op.top() == '#'){
        res.top() = -res.top();
        op.pop();
        return 1;
    }
    LL tem = res.top();
    res.pop();
    if(res.empty())return 0;
    if(op.top() == '+'){
        res.top() += tem;
    }else if(op.top() == '-'){
        res.top() -= tem;
    }else{
        res.top() *= tem;
    }
    op.pop();
    return 1;
}
pair<LL, bool>get(int l,int r){
    if(l >= r)return make_pair(0, 0);
    if(t[l] == '+' || t[l] == '*' || t[l] == ')')return FAIL;
    if(t[r - 1] == '+' || t[r - 1] == '*' || t[r - 1] == '(' || t[r - 1] == '-')return FAIL;
    stack<LL> res;
    stack<char> op;
    for(int i = l;i < r; ++i){
        //cout << l <<" "<<i<<endl;
        if(isdigit(t[i])){
            LL tem = 0;
            int st = i;
            while(i < r && isdigit(t[i])){
                tem = tem * 2 + t[i] - '0';
                i++;
            }
            if(st + 1 < i && t[st] == '0')return FAIL;
            res.push(tem);
            i--;
            continue;
        }
        if(t[i] == '('){
            op.push('(');
            if(i > l && (isdigit(t[i - 1]) || t[i - 1] == ')'))return FAIL;
            if(i < r -1 && !(isdigit(t[i + 1]) || t[i + 1] == '(' || t[i + 1] == '#'))return FAIL;
            continue;
        }
        if(t[i] == ')'){
            //cout <<l <<endl;
            if(i > l && !(isdigit(t[i - 1]) || t[i - 1] == ')'))return FAIL;
            if(i < r - 1 && (isdigit(t[i + 1]) || t[i + 1] == '('))return FAIL;
            while(op.empty() == false && op.top() != '('){
                bool flag = work(res, op);
                if(flag == 0)return FAIL;
            }
            if(op.empty() == true)return FAIL;
            op.pop();
            continue;
        }
        while(op.empty() == false && pr[op.top()] >= pr[t[i]]){
            bool flag = work(res, op);
            if(flag == 0)return FAIL;
        }
        op.push(t[i]);
    }
    while(!op.empty()){
        bool flag = work(res, op);
        if(flag == 0)return FAIL;
    }
    if(res.size() == 1)return make_pair(res.top(),1);
    return FAIL;
}
bool check(){
    for(int i = 0;i < n; ++i){
        if(isalpha(s[i])){
            t[i] = m[s[i]];
        }else{
            t[i] = s[i];
        }
    }
    int n = ::n;
    for(int i = 0;i < n; ++i){
        if(t[i] != '-')continue;
        if(i && (t[i - 1] == ')' || isdigit(t[i - 1]))){
            continue;
        }
        t[i] = '#';
    }
    for(int i = 1; i < n; ++i){
        if(t[i - 1] == '#' && t[i] == '#'){
            for(int j = i + 1; j < n; ++j){
                t[j - 2] = t[j];
            }
            n -= 2;
            i --;
        }
    }
    if(t[0] == '=' || t[n - 1] == '=')return 0;
    int equal = 0,pos = -1;
    for(int i = 0;i < n; ++i){
        if(t[i] == '='){
            equal++;
            pos = i;
        }
    }
    if(equal != 1)return 0;
    pair<LL,bool> left = get(0,pos);
    if(left.second == false)return 0;
    pair<LL,bool> righ = get(pos + 1,n);
    if(righ.second == false)return 0;
//    if(left == righ){
//        for(int i = 0;i < n; ++i){
//            cout << t[i];
//        }
//        cout << endl;
//    }
    return left == righ;
}
void dfs(int o){
    if(o == n){
        ans += check();
        return;
    }
    if(isalpha(s[o])){
        if(m.find(s[o]) != m.end()){
            dfs(o + 1);
        }else{
            for(int i = 0;i < 8; ++i){
                if(m.find(a[i]) != m.end())continue;
                m[s[o]] = a[i];
                m[a[i]] = s[o];
                dfs(o + 1);
                m.erase(s[o]);
                m.erase(a[i]);
            }
        }
        
    }else{
        t[o] = s[o];
        dfs(o + 1);
    }
}
int main(){
    pr['('] = -1;
    pr['*'] = 1;
    pr['+'] = 0;
    pr['-'] = 0;
    pr[')'] = -1;
    pr['#'] = 3;
    scanf("%s",s);
    n = int(strlen(s));
    dfs(0);
    cout << ans << endl;
    return 0;
}