#include <bits/stdc++.h>
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;
  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;
  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;
  }
  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 {
        if (work[i + 1] == '1' || work[i + 1] == '0') return false;
        i++;
      }
    }
  }
  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] == '\0'))
      return false;
    if ((work[i] == '=') && (work[i + 1] == '+' || work[i + 1] == '*'))
      return false;
  }
  if (work[0] == '+' || work[0] == '*') return false;
  return true;
}
int calc_E(char line[32], int left, int right) {
  int depth = 0;
  queue<int> Q;
  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 {
        if (i != left) {
          Q.push(i);
        }
        while (line[i] == '-') i++;
      }
    }
  }
  if (Q.empty()) {
    return calc_T(line, left, right);
  }
  int tmp = calc_E(line, left, Q.front() - 1), tmp_right;
  if (tmp == 2000000000) return 2000000000;
  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 == 2000000000) {
      return 2000000000;
    }
    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;
  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()) {
    return calc_F(line, left, right);
  }
  int tmp = calc_T(line, left, Q.front() - 1), tmp_right;
  if (tmp == 2000000000) return 2000000000;
  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 == 2000000000) {
      return 2000000000;
    }
    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] == '(') {
    int depth = 0;
    int close_pos = 2000000000;
    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 == 2000000000) return 2000000000;
    return calc_E(line, left + 1, close_pos - 1);
  } else {
    return 2000000000;
  }
}
int calc_NUM(char line[32], int left, int right) {
  for (int i = left; i <= right; i++) {
    if (line[i] != '0' && line[i] != '1') return 2000000000;
  }
  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);
      if (check_table[buf[i]] == 0) {
        num_of_type++;
        check_table[buf[i]]++;
        CHAR_LIST.push_back(buf[i]);
      }
    }
  }
  if (num_of_type > 8) {
    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) == 2000000000) {
      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]];
      }
    }
    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';
    }
    left_result = calc_E(left_table, 0, eq_pos - 1);
    if (abs(left_result) == 2000000000) continue;
    right_result = calc_E(right_table, 0, right_length - 1);
    if (abs(right_result) == 2000000000) continue;
    if (left_result == right_result) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
