#include <bits/stdc++.h>
using namespace std;
char s[100010];
long long n, l[100010], r[100010], la[27], vl[100010], vr[100010],
    vf[100010][27], vg[100010][27], pr[100010][27], va, sf[100010][27],
    f[20][100010], g[20][100010], fs[20][100010], gs[20][100010];
signed main() {
  cin >> s;
  n = strlen(s);
  for (long long i = 0; i < n; i++) s[i] -= 'a';
  for (long long i = 0; i < n; i++) {
    l[i] = la[s[i]];
    la[s[i]] = i;
    memcpy(pr[i], la, sizeof(la));
    sort(pr[i], pr[i] + 26, greater<long long>());
    pr[i][26] = -1;
  }
  for (long long i = 0; i < 26; i++) la[i] = n - 1;
  for (long long i = n - 1; ~i; i--) {
    r[i] = la[s[i]];
    la[s[i]] = i;
    memcpy(sf[i], la, sizeof(la));
    sort(sf[i], sf[i] + 26);
    sf[i][26] = n;
  }
  for (long long i = 0; i < n; i++) {
    vl[i] = vr[i] = i;
    vf[i][0] = vg[i][0] = i;
    for (long long j = 0; j < 26; j++) {
      vf[i][j + 1] = min(vf[i][j], l[sf[i][j]]);
      vg[i][j + 1] = max(vg[i][j], r[pr[i][j]]);
    }
  }
  for (long long t = 1; t <= 26; t++) {
    for (long long i = 0; i < n; i++) {
      f[0][i] = vf[i][t];
      g[0][i] = vg[i][t];
      fs[0][i] = gs[0][i] = i;
    }
    for (long long i = 1; (1 << i) <= n; i++)
      for (long long j = 0; j < n; j++) {
        f[i][j] = f[i - 1][f[i - 1][j]];
        g[i][j] = g[i - 1][g[i - 1][j]];
        fs[i][j] = fs[i - 1][j] + fs[i - 1][f[i - 1][j]];
        gs[i][j] = gs[i - 1][j] + gs[i - 1][g[i - 1][j]];
      }
    for (long long i = 0; i < n; i++) {
      for (long long j = 31 - __builtin_clz(n); ~j; j--) {
        long long nl = f[j][vl[i]], nr = g[j][vr[i]];
        if (nr < sf[nl][t]) {
          va += ((n - 1ll) << j) + fs[j][vl[i]] - gs[j][vr[i]];
          vl[i] = nl;
          vr[i] = nr;
        }
      }
      if (vr[i] < sf[vl[i]][t]) {
        va += n - 1 + vl[i] - vr[i];
        vl[i] = vf[vl[i]][t];
        vr[i] = vg[vr[i]][t];
      }
    }
  }
  cout << va;
}
