#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char s[maxn];
int pre_pos[maxn][30], nxt_pos[maxn][30], pre_c[maxn][30], nxt_c[maxn][30],
    mp[30], c_cnt;
bool app[30];
int n, f_nxt[maxn][20], f_pre[maxn][20], l[maxn], r[maxn], cnt[maxn];
long long sum_nxt[maxn][20], sum_pre[maxn][20], ans;
int main() {
  cin >> s + 1;
  n = strlen(s + 1);
  ans = (long long)n * n * n - (long long)n * n;
  for (int i = 1; i <= n; i++) app[s[i] -= 'a'] = true;
  for (int i = 0; i <= 25; i++)
    if (app[i]) mp[i] = c_cnt++;
  for (int i = 1; i <= n; i++) s[i] = mp[s[i]];
  for (int i = 1; i <= n; i++) {
    memcpy(pre_pos[i], pre_pos[i - 1], 30 * 4);
    pre_pos[i][s[i]] = i;
    vector<pair<int, int> > vec;
    for (int j = 0; j <= c_cnt - 1; j++)
      if (pre_pos[i][j]) vec.push_back(make_pair(pre_pos[i][j], j));
    sort(vec.begin(), vec.end(), greater<pair<int, int> >());
    for (pair<int, int> p : vec) pre_c[i][++pre_c[i][0]] = p.second;
  }
  for (int i = n; i; i--) {
    memcpy(nxt_pos[i], nxt_pos[i + 1], 30 * 4);
    nxt_pos[i][s[i]] = i;
    vector<pair<int, int> > vec;
    for (int j = 0; j <= c_cnt - 1; j++)
      if (nxt_pos[i][j]) vec.push_back(make_pair(nxt_pos[i][j], j));
    sort(vec.begin(), vec.end());
    for (pair<int, int> p : vec) nxt_c[i][++nxt_c[i][0]] = p.second;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= c_cnt - 1; j++) {
      if (!pre_pos[i][j]) pre_pos[i][j] = 1;
      if (!nxt_pos[i][j]) nxt_pos[i][j] = n;
    }
  for (int i = 1; i <= n; i++) l[i] = r[i] = i;
  f_nxt[n][0] = sum_nxt[n][0] = n;
  f_pre[1][0] = sum_pre[1][0] = 1;
  for (int i = 1; i <= c_cnt; i++) {
    for (int j = 1; j <= n; j++) {
      if (pre_c[j][0] >= i && j < n) {
        if (i == 1)
          f_nxt[j][0] = nxt_pos[j + 1][s[j]];
        else
          f_nxt[j][0] = max(f_nxt[j][0], nxt_pos[j + 1][pre_c[j][i]]);
        sum_nxt[j][0] = f_nxt[j][0];
      }
      if (nxt_c[j][0] >= i && j > 1) {
        if (i == 1)
          f_pre[j][0] = pre_pos[j - 1][s[j]];
        else
          f_pre[j][0] = min(f_pre[j][0], pre_pos[j - 1][nxt_c[j][i]]);
        sum_pre[j][0] = f_pre[j][0];
      }
    }
    for (int lvl = 1; lvl <= 16; lvl++)
      for (int j = 1; j <= n; j++) {
        if (pre_c[j][0] >= i) {
          if (f_nxt[j][lvl - 1] == -1)
            f_nxt[j][lvl] = -1;
          else {
            int hp = f_nxt[j][lvl - 1];
            if (pre_c[hp][0] > i &&
                pre_pos[hp][pre_c[hp][i + 1]] >= pre_pos[j][pre_c[j][i]])
              f_nxt[j][lvl] = -1;
            else
              f_nxt[j][lvl] = f_nxt[hp][lvl - 1],
              sum_nxt[j][lvl] = sum_nxt[j][lvl - 1] + sum_nxt[hp][lvl - 1];
          }
        }
        if (nxt_c[j][0] >= i) {
          if (f_pre[j][lvl - 1] == -1)
            f_pre[j][lvl] = -1;
          else {
            int hp = f_pre[j][lvl - 1];
            if (nxt_c[hp][0] > i &&
                nxt_pos[hp][nxt_c[hp][i + 1]] <= nxt_pos[j][nxt_c[j][i]])
              f_pre[j][lvl] = -1;
            else
              f_pre[j][lvl] = f_pre[hp][lvl - 1],
              sum_pre[j][lvl] = sum_pre[j][lvl - 1] + sum_pre[hp][lvl - 1];
          }
        }
      }
    if (i == c_cnt) {
      for (int j = 1; j <= n; j++)
        for (int k = 16; k >= 0; k--)
          if (1 << k < n - cnt[j]) {
            cnt[j] += 1 << k;
            ans = ans - sum_nxt[r[j]][k] + sum_pre[l[j]][k];
            l[j] = f_pre[l[j]][k];
            r[j] = f_nxt[r[j]][k];
          }
    } else {
      for (int j = 1; j <= n; j++)
        if (pre_c[r[j]][0] == i || pre_pos[r[j]][pre_c[r[j]][i + 1]] < l[j])
          for (int k = 16; k >= 0; k--)
            if (~f_pre[l[j]][k] && ~f_nxt[r[j]][k]) {
              cnt[j] += 1 << k;
              ans = ans - sum_nxt[r[j]][k] + sum_pre[l[j]][k];
              l[j] = f_pre[l[j]][k];
              r[j] = f_nxt[r[j]][k];
              if (pre_c[r[j]][0] > i &&
                  pre_pos[r[j]][pre_c[r[j]][i + 1]] >= l[j])
                break;
            }
    }
  }
  cout << ans << '\n';
  return 0;
}
