using namespace std; #include #include #include #include int main(){ string S; cin >> S; int S_len = S.length(); vector> chars_indexes(26, vector(0)); for (int i = 0; i < S_len; i++){ chars_indexes.at(S.at(i)-65).push_back(i); } long long ans = 0; for (auto indexes : chars_indexes){ if (indexes.size() < 2){ continue; } long long last_number = S_len - indexes.back() - 1; int count = 0; for (int i = indexes.size()-2; i >= 0; i--){ count ++; ans += last_number; last_number += S_len - indexes.at(i) - 1 - count; } } cout << ans << endl; }