// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 0;
  for (char c='A'; c<='Z'; c++) {
    vector<vector<ll>> dp(n+1, vector<ll> (3, 0));
    ll tmp = 0;
    for (int i=0;i<n;i++) {
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = dp[i][1];
      if (s[i] == c) {
        dp[i+1][0] += 1;
        dp[i+1][1] += dp[i][0];
      } else {
        tmp += dp[i+1][1];
      }
    }
    ans += tmp;
  }
  cout << ans << endl;
}