#include #include using namespace std; using namespace atcoder; using ll = int_fast64_t; using ull = uint_fast64_t; using mint = modint998244353; constexpr ll INF = 1ll << 60; #define iscontain(container, value) (find(container.begin(), container.end(), value) != container.end()) template void printelem(const T& container, const D& divide){ for(const auto& i : container) cout << i << divide; cout << endl; } template void printelem(const T& container) { printelem(container, ", "); } template T input(){ T ret; cin >> ret; return ret; } int main(){ //インプット string S; cin >> S; map> ch; for(ll i = 0; i < S.size(); i++) ch[S[i]].push_back(i); ll ans = 0; for(auto&& [_, i] : ch) if(i.size() >= 2){ for(ll j = 1; j < i.size(); j++){ ans += j * (S.size() - i[j] - 1 - (i.size() - j - 1)); } } //アウトプット cout << ans; return 0; }