#include using namespace std; typedef long long ll; int main() { string S; cin >> S; ll n = S.length(); map> mp; for (ll i = 0; i < n; ++i) { mp[S[i]].insert(i); } ll ans = 0; for (ll i = 0; i < n; ++i) { mp[S[i]].erase(i); if (!mp[S[i]].size()) continue; // j より後ろにある個数 ll nokori = mp[S[i]].size() - 1; for (ll j : mp[S[i]]) { ll tmp = n - j - 1 - nokori; ans += tmp, nokori--; } } cout << ans << endl; }