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

using State = string::const_iterator;

bool equation(State &itr);
int expr(State &itr);
int term(State &itr);
int factor(State &itr);
int number(State &itr);


bool valid;

void error(State &itr){
    valid = false;
    while(*itr){
        itr++;
    }
}

void next_char(State &itr, char expected){
    if(*itr == expected){
        itr++;
    }else{
        error(itr);
    }
}

bool equation(State &itr){
    int lhs = expr(itr);
    next_char(itr, '=');
    int rhs = expr(itr);
    return lhs == rhs;
}

int expr(State &itr){
    int res = term(itr);
    while(1){
        if(*itr == '+'){
            itr++;
            res += term(itr);
        }else if(*itr == '-'){
            itr++;
            res -= term(itr);
        }else{
            break;
        }
    }
    return res;
}
int term(State &itr){
    int res = factor(itr);
    while(1){
        if(*itr == '*'){
            itr++;
            res *= factor(itr);
        }else{
            break;
        }
    }
    return res;
}

int factor(State &itr){
    int res;
    if(*itr == '-'){
        itr++;
        res = -factor(itr);
    }else if(*itr == '('){
        next_char(itr, '(');
        res = expr(itr);
        next_char(itr, ')');
    }else{
        res = number(itr);
    }
    return res;
}

int number(State &itr){
    if(isdigit(*itr)){
        if(*itr == '0'){
            itr++;
            return 0;
        }
        int res = 0;
        while(isdigit(*itr)){
            res <<= 1;
            res |= *itr-'0';
            itr++;
        }
        return res;
    }else{
        error(itr);
        return 0;
    }
}

constexpr char chs[] = {'=','+','-','*','(',')','0','1'};
map<char,int> mp;
string s;
vector<char> v;
vector<bool> used;
string formula;

int rec(int n){
    if(n==0){
        State begin = formula.begin();
        valid = true;
        valid &= equation(begin);
        valid &= begin == formula.end();
        return (valid ? 1 : 0);
    }
    int res = 0;
    if(isalpha(s[n-1])){
        int idx = mp[s[n-1]];
        if(v[idx] == '#'){
            for(int i=0;i<8;i++){
                if(!used[i]){
                    used[i] = true;
                    v[idx] = chs[i];
                    formula[n-1] = chs[i];
                    res += rec(n-1);
                    used[i] = false;
                    v[idx] = '#';
                }
            }
        }
        else{
            formula[n-1] = v[idx];
            res += rec(n-1);
        }
    }else{
        formula[n-1] = s[n-1];
        res = rec(n-1);
    }
    return res;
}

int main(){
    cin >> s;
    int n = 0;
    for(auto c : s){
        if(isalpha(c) && mp.find(c) == mp.end()){
            mp[c] = n;
            n++;
        }
    }
    v.resize(n, '#');
    used.resize(n, false);
    formula.resize(s.size());
    cout << rec(int(s.size())) << endl;
    return 0;
}

