#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { string s; cin >> s; vector idx(26, vector(0)); rep(i, s.size()) { idx[s[i] - 'A'].push_back(i); } ll ans = 0; rep(i, s.size()) { rep(j, 26) { if (s[i] == 'A' + j) continue; auto itr = lower_bound(idx[j].begin(), idx[j].end(), i); ll cnt = itr - idx[j].begin(); ans += cnt * (cnt - 1) / 2; } } cout << ans << endl; return 0; }