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

const ll INF = 1LL << 60;

struct Parser{
	string s;
	int N;
	int c;

	ll parse(string s){
		this->s = s;
		N = s.size();
		c = 0;
		try{
			ll ret = expr();
			if(c != N) throw "";
			return ret;
		}
		catch(...){
			return INF;
		}
	}

	void debug(string text){
		return;
		cout << text + " ";
		for(int i = 0; i < N; i++){
			if(i == c) cout << '[' << s[i] << ']';
			else cout << s[i];
		}
		cout << endl;
	}

	ll expr(){
		debug("expr");
		ll x = term();
		while(c < N){
			if(s[c] == '+'){
				c++;
				x += term();
			}
			else if(s[c] == '-'){
				c++;
				x -= term();
			}
			else break;
		}
		return x;
	}

	ll term(){
		debug("term");
		ll x = factor();
		while(c < N){
			if(s[c] == '*'){
				c++;
				x *= factor();
			}
			else break;
		}
		return x;
	}

	ll factor(){
		debug("factor");
		if(s[c] == '-'){
			c++;
			return -factor();
		}
		if(s[c] == '('){
			c++;
			ll ret = expr();
			if(s[c] != ')') throw "";
			//assert(s[c] == ')');
			c++;
			return ret;
		}
		return num();
	}

	ll num(){
		debug("num");
		if(!isdigit(s[c])) throw "";
		ll ret = 0;
		string digit;
		while(c < N && isdigit(s[c])){
			ret = ret * 2 + s[c] - '0';
			digit += s[c];
			c++;
		}
		if(digit != "0" && digit[0] == '0') throw "";
		return ret;
	}
} parser;

string s;
int ans;

vector<char> cs;
string op = "01+-*()=";
int used[10];
map<char, char> m;

void dfs(int n){
	if(n == cs.size()){
		string t = s;
		for(int i = 0; i < t.size(); i++){
			if(m.count(t[i])) t[i] = m[t[i]];
		}
		int eq = t.find('=');
		if(eq == string::npos) return;
		string e1 = t.substr(0, eq);
		string e2 = t.substr(eq + 1);
		if(e1 == "" || e2 == "") return;
		ll res1 = parser.parse(e1), res2 = parser.parse(e2);
		if(res1 != INF && res2 != INF && res1 == res2){
			ans++;
		}
		return;
	}

	for(int i = 0; i < op.size(); i++){
		if(used[i]) continue;
		used[i] = 1;
		m[cs[n]] = op[i];
		dfs(n + 1);
		used[i] = 0;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	while(cin >> s){
		cs.clear();
		for(auto c : s){
			if(isalpha(c)) cs.push_back(c);
		}
		sort(cs.begin(), cs.end());
		cs.erase(unique(cs.begin(), cs.end()), cs.end());
		m.clear();

		ans = 0;
		dfs(0);
		//cout << s << endl;
		cout << ans << endl;
	}
}