#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; int main() { string S; cin >> S; map> mp; for (int i = 0; i < S.size(); i++) { mp[S[i]].push_back(i); } ll ans = 0; for (int i = 0; i < S.size(); i++) { if (mp[S[i]].size() >= 2) { int pos1 = lower_bound(mp[S[i]].begin(), mp[S[i]].end(), i) - mp[S[i]].begin(); if (pos1 < mp[S[i]].size() - 1) { for (int j = pos1 + 1; j < mp[S[i]].size(); j++) { int siz = max(0, (int)mp[S[i]].size() - j - 1); ans += S.size() - mp[S[i]][j] - 1 - siz; //cout << S[i] << ' ' << S.size() - mp[S[i]][pos1 + 1] - 1 - siz << endl; } } } } cout << ans << endl; return 0; }