#include using namespace std; typedef long long ll; int main() { string S; cin >> S; ll n = S.length(); // i 文字目を MMA の二文字目としたときの MMA の総数 vector> sum(n, vector(26)); for (ll i = n - 2; i >= 0; --i) { for (ll j = 0; j < 26; ++j) sum[i][j] = sum[i + 1][j]; ll index = S[i] - 'A'; sum[i][index] += n - i - 1; } // i 文字目までのアルファベットの個数 vector> num(n, vector(26)); num[0][S[0] - 'A'] = 1; for (ll i = 1; i < n; ++i) { for (ll j = 0; j < 26; ++j) num[i][j] = num[i - 1][j]; ll index = S[i] - 'A'; num[i][index]++; } ll ans = 0; for (ll i = 0; i < n; ++i) { ll index = S[i] - 'A'; if (num[i][index] == 1) continue; ll score = n - i - 1; ll tmp = sum[i][index] - (num[n - 1][index] - num[i][index]); ans += tmp; } cout << ans << endl; }