#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<stack>
#include<bitset>
#include<map>
#include<numeric>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;
const ll mod = 1000000007;
const long double eps = 1e-8;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

typedef long double ld;

bool isnum(char t) {
	return '0' <= t && t <= '9';
}
bool isord(char t) {
	return t == '+' || t == '-' || t == '*';
}

int trans(char t) {
	if ('a' <= t && t <= 'z')return t - 'a';
	if ('A' <= t && t <= 'Z')return 26 + (t - 'A');
	return -1;
}
const string str = "01-+*()";
int n;

ll trans_num(string s) {
	int len = s.length();
	ll ret = 0;
	rep(i, len) {
		if (s[len - i - 1] == '1')ret += (ll)1 << i;
	}
	return ret;
}

bool ok;
ll expr(string&s, int& i);
ll term(string&s, int& i);
ll factor(string&s, int& i);
ll number(string&s, int& i);

ll expr(string& s, int& i) {
	ll val = term(s, i);
	while (s[i] == '+' || s[i] == '-') {
		char op = s[i]; i++;
		ll val2 = term(s, i);
		if (op == '+')val += val2;
		else val -= val2;
	}
	return val;
}
ll term(string& s, int& i) {
	ll val = factor(s, i);
	while (s[i] == '*') {
		i++;
		ll val2 = factor(s, i);
		val *= val2;
	}
	return val;
}
ll factor(string& s, int& i) {
	if (isnum(s[i]))return number(s, i);
	if (i<s.length()&&s[i] == '-') {
		i++;
		ll ret = factor(s, i);
		return -ret;
	}
	if (i==s.length()||s[i] != '(') {
		ok = false; return 0;
	}
	i++;
	ll ret = expr(s, i);
	if (i == s.length() || s[i] != ')') {
		ok = false; return 0;
	}
	i++;
	return ret;
}
ll number(string& s, int& i) {
	int le = i;
	while (i + 1 < s.length() && isnum(s[i + 1]))i++;
	string u = s.substr(le, i - le + 1);
	if (u.size() > 1 && u[0] == '0') {
		ok = false; return 0;
	}
	i++;
	return trans_num(u);
}

bool query(string &s) {
	int len = s.length();
	ok = true;
	string le, ri;
	rep(i, len) {
		if (s[i] == '=') {
			le = s.substr(0, i);
			ri = s.substr(i+1, len-1-i);
			break;
		}
	}
	int i = 0;
	ll cl = expr(le, i);
	if (i != le.length())return false;
	i = 0;
	ll cr = expr(ri, i);
	if (i != ri.length())return false;
	if (!ok)return false;
	return cl == cr;
}

void solve() {
	string s;
	cin >> s; n = s.length();
	int c[52] = {};
	vector<int> a(n);
	rep(i, n) {
		a[i] = trans(s[i]);
		if (a[i] >= 0) {
			c[a[i]]++;
		}
	}
	vector<int> v;
	vector<int> trans(52);
	rep(i, 52) {
		if (c[i]) {
			trans[i] = v.size();
			v.push_back(i);
		}
	}
	if (v.size() > 8) {
		cout << 0 << endl; return;
	}
	bool exieq = false;
	rep(i, n) {
		if (s[i] == '=')exieq = true;
	}
	int ans = 0;
	if (exieq) {
		if (v.size() > 7) {
			cout << 0 << endl; return;
		}
		int num = 0;
		rep(i, n)if (s[i] == '=')num++;
		if (num > 1) {
			cout << 0 << endl; return;
		}
		vector<int> b(7,7); rep(i, 7)b[i] = i;
		map<vector<int>, bool> used;
		while (true) {
			bool f = true;
			vector<int> u = b; u.resize(v.size());
			if (used[u])f = false;
			else used[u] = true;
			if (f) {
				string cop = s;
				rep(i, n) {
					if (a[i] >= 0) {
						cop[i] = str[b[trans[a[i]]]];
					}
				}
				//cout << cop << endl;
				if (query(cop))ans++;
			}
			if (!next_permutation(b.begin(), b.end()))break;
		}
	}
	else {
		rep(i, v.size()) {
			if (c[v[i]] != 1)continue;
			string ss = s;
			rep(j, n)if (a[j] == v[i])ss[j] = '=';
			//cout << v[i] << " " << ss << endl;
			vector<int> b(7, 7); rep(j, 7)b[j] = j;
			map<vector<int>,bool> used;
			while (true) {
				bool f = true;
				vector<int> u = b; u.resize((int)v.size() - 1);
				if (used[u])f = false;
				else used[u] = true;
				if (f) {
					string cop = ss;
					rep(j, n) {
						if (a[j] >= 0&&a[j]!=v[i]) {
							int z = trans[a[j]];
							if (a[j] > v[i])z--;
							cop[j] = str[b[z]];
						}
					}
					//cout << i<<" "<<cop << endl;
					if (query(cop)) {
						ans++;
						//cout << "this!!" << " " << cop << endl;
						//cout << "this!!" << endl;
					}
				}
				if (!next_permutation(b.begin(), b.end()))break;
			}
		}
	}
	cout << ans << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//string s = "-0=0";
	//cout << valid(s) << endl;
	//cout << fixed << setprecision(10);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 3796