#include<iostream>
using namespace std;
int fact(int f)
{
if (f == 0) return 1;
if (f <= 2) return f;
return (f * fact(f - 1));
}
void solve(string s,int n)
{
int ans = 1;
int arr[26] = {0};
int len = n - 1;
for (int i = 0; i < n; i++) {
s[i] = toupper(s[i]);
arr[s[i] - 'A']++;
}
for(int i = 0; i < n; i++) {
int temp = 0;
int x = 1;
char c = s[i];
for(int j = 0; j < c - 'A'; j++) temp += arr[j];
for (int j = 0; j < 26; j++) x = (x * fact(arr[j]));
arr[c - 'A']--;
ans = ans + (temp * ((fact(len)) / x));
len--;
}
cout << ans;
}
int main()
{
int i,n;
string s;
cin>>s;
n=s.size();
solve(s,n);
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBmYWN0KGludCBmKQp7CglpZiAoZiA9PSAwKSByZXR1cm4gMTsKCWlmIChmIDw9IDIpIHJldHVybiBmOwoJcmV0dXJuIChmICogZmFjdChmIC0gMSkpOwp9CnZvaWQgc29sdmUoc3RyaW5nIHMsaW50IG4pCnsKCWludCBhbnMgPSAxOwoJaW50IGFyclsyNl0gPSB7MH07CglpbnQgbGVuID0gbiAtIDE7Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewoJICAgIHNbaV0gPSB0b3VwcGVyKHNbaV0pOwoJICAgIGFycltzW2ldIC0gJ0EnXSsrOwoJfQoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgewoJCWludCB0ZW1wID0gMDsKCQlpbnQgeCA9IDE7CgkJY2hhciBjID0gc1tpXTsKIAoJCWZvcihpbnQgaiA9IDA7IGogPCBjIC0gJ0EnOyBqKyspIHRlbXAgKz0gYXJyW2pdOwoJCWZvciAoaW50IGogPSAwOyBqIDwgMjY7IGorKykgeCA9ICh4ICogZmFjdChhcnJbal0pKTsKCQlhcnJbYyAtICdBJ10tLTsKCQlhbnMgPSBhbnMgKyAodGVtcCAqICgoZmFjdChsZW4pKSAvIHgpKTsKCQlsZW4tLTsKCX0KCWNvdXQgPDwgYW5zOwp9CmludCBtYWluKCkKewoJaW50IGksbjsKCXN0cmluZyBzOwoJY2luPj5zOwoJbj1zLnNpemUoKTsKCXNvbHZlKHMsbik7CglyZXR1cm4gMDsKfQ==