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