#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s; cin >> s;
    int n = s.size();
    long long ans = 0;
    vector<vector<long long>> sum(n + 1, vector<long long>(26));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 26; j++){
            sum[i + 1][j] += sum[i][j];
        }
        sum[i + 1][s[i] - 'A']++;
    }
    for(int i = n - 1; i >= 0; i--){
        for(int j = 0; j < 26; j++){
            if(s[i] - 'A' == j) continue;
            ans += sum[i][j] * (sum[i][j] - 1) / 2;
        }
    }
    cout << ans << "\n";
}