#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
    string s ;
    cin >> s ;
    vector<ll> G[26] ; 
    rep(i,s.size()){
        G[s[i]-'A'].push_back(i) ;
    }
    ll ans = 0 ;
    rep(i,26){
        ll n , m ;
        n = m = G[i].size() ;
        rep(j,n){
            if( n-j-2 < 0 ) continue;
            ll a = G[i][n-j-1] ;
            ans += ( s.size() - j - 1 - a ) * ( m - 1 ) ;
            m-- ;
        }
    }
    cout << ans << endl ;
}