#include <algorithm>
#include <iostream>
#include <vector>
#include <cctype>
using namespace std;

int expr(string &s, int &p);
int term(string &s, int &p);
int factor(string &s, int &p);
int number(string &s, int &p);

bool ng;
// Q ::= E=E
bool is_eq(string &s) {
    if (count(s.begin(), s.end(), '=') != 1) return false;
    int k = s.find('=');
    string a = s.substr(0, k), b = s.substr(k + 1);
    auto check = [](string &s) {
        if (s.size() == 0) return false;
        int br = 0;
        for (char c: s) {
            br += (c == '(') - (c == ')');
            if (br < 0) return false;
        }
        return br == 0;
    };
    if (!check(a) || !check(b)) return false;
    ng = false;
    int p = 0, x = expr(a, p);
    if (ng || p != a.size()) return false;
    int q = 0, y = expr(b, q);
    if (ng || q != b.size()) return false;
    return x == y;
}
// E ::= T | E+T | E−T
int expr(string &s, int &p) {
    int res = term(s, p);
    while (p < s.size()) {
        if (s[p] == '+') { res += term(s, ++p); continue; }
        if (s[p] == '-') { res -= term(s, ++p); continue; }
        break;
    }
    return res;
}
// T ::= F | T*F
int term(string &s, int &p) {
    int res = factor(s, p);
    while (p < s.size()) {
        if (s[p] == '*') { res *= factor(s, ++p); continue; }
        break;
    }
    return res;
}
// F ::= N | −F | (E)
int factor(string &s, int &p) {
    int res;
    if (s[p] == '-') {
        res = -factor(s, ++p);
    } else if (s[p] == '(') {
        ++p;
        res = expr(s, p);
        ++p;
    } else if (isdigit(s[p])) {
        res = number(s, p);
    } else {
        return ng = true;
    }
    return res;
}
// N ::= 0 | 1B
// B ::= ϵ | 0B | 1B
int number(string &s, int &p) {
    if (s[p] == '0') {
        if (p + 1 < s.size() && isdigit(s[p + 1])) return ng = true;
        return p++, 0;
    }
    int res = 0;
    while (p < s.size() && isdigit(s[p])) res = res * 2 + s[p++] - '0';
    return res;
}

int main() {
    string s; cin >> s;
    vector<char> cs;
    for (auto c: s) if (isalpha(c)) cs.emplace_back(c);
    sort(cs.begin(), cs.end());
    cs.erase(unique(cs.begin(), cs.end()), cs.end());
    if (cs.size() > 8) return !(cout << 0 << endl);
    int cnt = 0;
    string p = "=+-*()01";
    sort(p.begin(), p.end());
    do {
        string t = s;
        for (auto &c: t) if (isalpha(c)) {
            int k = lower_bound(begin(cs), end(cs), c) - begin(cs);
            c = p[k];
        }
        cnt += is_eq(t);
    } while (next_permutation(p.begin(), p.end()));
    for (int i = 0; i < p.size() - cs.size(); i++) cnt /= i + 1;
    cout << cnt << endl;
    return 0;
}
