#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


char component_array[8] = {'0','1','+','-','*','(',')','=',};
int table[40320][8];
int num_of_type,table_index;

int calc_E(char line[32],int left,int right);
int calc_T(char line[32],int left,int right);
int calc_F(char line[32],int left,int right);
int calc_NUM(char line[32],int left,int right);

bool is_component(char ch){

	for(int i = 0; i < 8; i++){
		if(ch == component_array[i])return true;
	}

	return false;
}

void makeTable(bool used[8],int change_list[8],int index){

	if(index == num_of_type){ //対応表の作成が完成した場合
		for(int i = 0; i < num_of_type; i++){
			table[table_index][i] = change_list[i];
		}
		table_index++;
		return;
	}

	for(int i = 0; i < 8; i++){
		if(used[i] == false){

			bool next_used[8];
			int next_change_list[8];

			for(int k = 0; k < 8; k++)next_used[k] = used[k];
			for(int k = 0; k < index; k++)next_change_list[k] = change_list[k];

			next_used[i] = true;
			next_change_list[index] = i;

			makeTable(next_used,next_change_list,index+1);
		}
	}
}

bool is_OK(char work[32]){

	int length;
	for(length = 0; work[length] != '\0'; length++);

	int equal_count = 0;
	for(int i = 0; work[i] != '\0'; i++){
		if(work[i] == '=')equal_count++;
	}
	if(equal_count != 1)return false; //'='の数が1でないなら不可

	int eq_pos;
	for(int i = 0; i < length; i++){
		if(work[i] == '='){
			eq_pos = i;
			break;
		}
	}

	if(eq_pos == 0 || eq_pos == length-1)return false; //'='の場所が左端、または右端なら不可


	//異種カッコが連続していないか調べる
	for(int i = 0; i < length; i++){
		if(work[i] == '(' && work[i+1] == ')')return false;
		if(work[i] == ')' && work[i+1] == '(')return false;
	}


	//カッコの対応が取れているかチェック(左半分)
	stack<int> S;
	for(int i = 0; i < eq_pos; i++){
		if(work[i] == '(')S.push(i);
		else if(work[i] == ')'){
			if(S.size() == 0)return false;
			else{
				S.pop();
			}
		}
	}
	if(S.size() > 0)return false;

	//カッコの対応が取れているかチェック(右半分)
	for(int i = eq_pos+1; i < length; i++){
		if(work[i] == '(')S.push(i);
		else if(work[i] == ')'){
			if(S.size() == 0)return false;
			else{
				S.pop();
			}
		}
	}
	if(S.size() > 0)return false;

	//左端を調べる
	if(work[0] == '+' || work[0] == '*')return false;
	if(work[eq_pos+1] == '+' || work[eq_pos+1] == '*')return false;

	//数字と開きカッコ、開きカッコと(*or+)が連結していないか調べる
	for(int i = 0; i < length; i++){
		if((work[i] == '0' || work[i] == '1') && work[i+1] == '(')return false;
		if((work[i] == '(') && (work[i+1] == '*' || work[i+1] == '+'))return false;
	}


	//バイナリが複数桁の場合、1スタートか調べる
	for(int i = 0; work[i] != '\0';){
		if(work[i] != '0' && work[i] != '1')i++;
		else{
			if(work[i] == '1'){
				while(work[i] == '1' || work[i] == '0')i++;
			}else{ //左端の0
				if(work[i+1] == '1' || work[i+1] == '0')return false;

				i++;
			}
		}
	}

	//opの連結を調べる
	for(int i = 0; work[i] != '\0'; i++){
		if((work[i] == '+' || work[i] == '*') &&
				(work[i+1] == '+' || work[i+1] == '*' || work[i+1] == '='|| work[i+1] == ')' || work[i+1] == '\0'))return false;

		if((work[i] == '-') &&
				(work[i+1] == '+' || work[i+1] == '*' || work[i+1] == '=' || work[i+1] == ')' || work[i+1] == '\0'))return false;
	}



	return true;
}

int calc_E(char line[32],int left,int right){

	/*printf("E\n");
	for(int i = left; i <= right; i++){
		printf("%c",line[i]);
	}
	printf("\n");*/

	int depth = 0;
	queue<int> Q;

	//深さ0の、プラスまたは-を探す
	for(int i = left; i <= right; ){
		if(line[i] == '(')depth++;
		else if(line[i] == ')')depth--;

		if(depth != 0){
			i++;
		}else if(line[i] != '+' && line[i] != '-'){
			i++;
		}else{
			if(line[i] == '+'){
				Q.push(i);
				i++;
			}else{ //line[i] == '-'
				if((i != left) && (line[i-1] == '0' || line[i-1] == '1' || line[i-1] == ')')){ //-は、depthが0でもnegの場合あり
					Q.push(i);
				}
				while(i <=right && line[i] == '-')i++; //negの-が続いている場合があるので、読み飛ばす
			}
		}
	}

	if(Q.empty()){ //深さ0の+-がない
		return calc_T(line,left,right);
	}

	int tmp = calc_E(line,left,Q.front()-1),tmp_right;

	if(tmp == BIG_NUM)return BIG_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_T(line,loc+1,right);
		}else{
			tmp_right = calc_T(line,loc+1,Q.front()-1);
		}

		if(tmp_right == BIG_NUM){
			return BIG_NUM;
		}

		if(line[loc] == '+'){
			tmp += tmp_right;
		}else{
			tmp -= tmp_right;
		}
	}

	return tmp;
}

int calc_T(char line[32],int left,int right){

	int depth = 0;
	queue<int> Q;

	//深さ0の、*を探す
	for(int i = left; i <= right; ){
		if(line[i] == '(')depth++;
		else if(line[i] == ')')depth--;

		if(depth != 0){
			i++;
		}else if(line[i] != '*'){
			i++;
		}else{
			Q.push(i);
			i++;
		}
	}

	if(Q.empty()){ //深さ0の*がない
		return calc_F(line,left,right);
	}

	int tmp = calc_T(line,left,Q.front()-1),tmp_right;

	if(tmp == BIG_NUM)return BIG_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_F(line,loc+1,right);
		}else{
			tmp_right = calc_F(line,loc+1,Q.front()-1);
		}

		if(tmp_right == BIG_NUM){
			return BIG_NUM;
		}

		tmp *= tmp_right;
	}
	return tmp;
}

int calc_F(char line[32],int left,int right){

	if(line[left] == '1' || line[left] == '0'){
		return calc_NUM(line,left,right);
	}else if(line[left] == '-'){
		return -1*calc_F(line,left+1,right);
	}else if(line[left] == '('){

		/*printf("Minhi!\n");
		for(int i = left; i <= right; i++){
			printf("%c",line[i]);
		}
		printf("\n");*/


		int depth = 0;
		int close_pos = BIG_NUM;

		for(int i = left; i <= right; i++){
			if(line[i] == '(')depth++;
			else if(line[i] == ')'){
				depth--;
				if(depth == 0){
					close_pos = i;
					break;
				}
			}
		}

		if(close_pos == BIG_NUM || close_pos != right)return BIG_NUM;

		return calc_E(line,left+1,close_pos-1);
	}else{
		return BIG_NUM;
	}
}

int calc_NUM(char line[32],int left,int right){

	//left～rightに0か1以外の文字が入っていたら不適
	for(int i = left; i <= right; i++){
		if(line[i] != '0' && line[i] != '1')return BIG_NUM;
	}

	int ret = 0;
	for(int i = left; i <= right; i++){
		ret = 2*ret+line[i]-'0';
	}
	return ret;
}


int main(){

	char buf[32];
	scanf("%s",buf);

	int check_table[128];
	for(int i = 0; i < 128; i++)check_table[i] = 0;

	vector<int> CHAR_LIST,REPLACE_LOC[128];
	num_of_type = 0; //置き換える文字の種類数

	for(int i = 0; buf[i] != '\0'; i++){
		if(!is_component(buf[i])){ //置き換える必要のある文字である場合

			REPLACE_LOC[buf[i]].push_back(i); //buf[i]が何文字目にあるかのリスト

			if(check_table[buf[i]] == 0){ //初登場
				num_of_type++;
				check_table[buf[i]]++;
				CHAR_LIST.push_back(buf[i]); //置き換える文字のリストに追加
			}
		}
	}

	if(num_of_type > 8){ //構成要素は8種類しかないので、9種類以上置き換え文字があったら答えは0
		printf("0\n");
		return 0;
	}

	char work[32],left_table[32],right_table[32];
	int eq_pos,left_result,right_result,right_length,ans = 0;

	if(num_of_type == 0){ //置き換えるべき文字が無い場合

		if(!is_OK(buf)){ //入力の文字列が文法的に間違っている場合
			printf("0\n");
			return 0;
		}

		//左辺と右辺に数式を分解する
		for(int i = 0; buf[i] != '\0'; i++){
			if(buf[i] == '='){
				eq_pos = i;
				break;
			}
			left_table[i] = buf[i];
			left_table[i+1] = '\0';
		}

		right_length = 0;
		for(int i = 0; buf[eq_pos+1+i] != '\0'; i++){
			right_table[i] = buf[eq_pos+1+i];
			right_length++;
			right_table[i+1] = '\0';
		}

		left_result = calc_E(left_table,0,eq_pos-1);
		if(abs(left_result) == BIG_NUM){
			printf("0\n");
			return 0;
		}

		right_result = calc_E(right_table,0,right_length-1);

		if(left_result == right_result){
			printf("1\n");
		}else{
			printf("0\n");
		}

		return 0;
	}

	bool first_used[8];
	for(int i = 0; i < 8; i++)first_used[i] = false;
	int first_change_list[8];
	table_index = 0;
	makeTable(first_used,first_change_list,0); //アルファベットと、文字の変換表を作る

	for(int i = 0; i < table_index; i++){

		for(int k = 0; buf[k] != '\0'; k++){
			work[k] = buf[k];
			work[k+1] = '\0';
		}

		//文字を置き換える
		for(int k = 0; k < num_of_type; k++){
			int word = CHAR_LIST[k];
			for(int a = 0; a < REPLACE_LOC[word].size(); a++){
				int loc = REPLACE_LOC[word][a];
				work[loc] = component_array[table[i][k]];
			}
		}

		//文法的に適切かどうかざっと確かめる(OKでも不適な場合が多数ある)
		if(!is_OK(work))continue;

		//左辺と右辺に数式を分解する
		for(int i = 0; work[i] != '\0'; i++){
			if(work[i] == '='){
				eq_pos = i;
				break;
			}
			left_table[i] = work[i];
			left_table[i+1] = '\0';
		}

		right_length = 0;
		for(int i = 0; work[eq_pos+1+i] != '\0'; i++){
			right_table[i] = work[eq_pos+1+i];
			right_length++;
			right_table[i+1] = '\0';
		}

	/*	printf("left:%s\n",left_table);
					printf("right:%s\n",right_table);*/

		left_result = calc_E(left_table,0,eq_pos-1);
		//printf("left_res:%d\n",left_result);
		if(abs(left_result) == BIG_NUM)continue;

		right_result = calc_E(right_table,0,right_length-1);
		//printf("right_res:%d\n\n",right_result);
		if(abs(right_result) == BIG_NUM)continue;

		if(left_result == right_result){
			/*printf("left:%s\n",left_table);
			printf("right:%s\n",right_table);*/

			ans++;
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 4532