#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 10, Sig = 30, LOG = 17;
int n, last[Sig], prv[Max], nxt[Max], lst[Max][Sig], L[Max][Sig], R[Max][Sig],
    cnt[Max], ll[Max], rr[Max], lll[Max][LOG], rrr[Max][LOG];
long long lsum[Max][LOG], rsum[Max][LOG];
vector<int> vec;
inline bool OK(int l, int r, int c) {
  return (l != 1 || r != n) && l > lst[r][c + 1];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string A;
  cin >> A;
  n = A.size();
  A = '.' + A;
  for (int i = 0; i < 26; i++) last[i] = 0;
  for (int i = 1; i <= n; i++)
    prv[i] = max(last[A[i] - 'a'], 1), last[A[i] - 'a'] = i;
  for (int i = 0; i < 26; i++) last[i] = n + 1;
  for (int i = n; i >= 1; i--)
    nxt[i] = min(last[A[i] - 'a'], n), last[A[i] - 'a'] = i;
  for (int i = 0; i < 26; i++) last[i] = 0;
  for (int i = 1; i <= n; i++) {
    last[A[i] - 'a'] = i;
    vec.clear();
    for (int c = 0; c < 26; c++)
      if (last[c] >= 1) vec.push_back(last[c]);
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    lst[i][0] = n + 1;
    for (int c = 0; c < vec.size(); c++) lst[i][c + 1] = vec[c];
    R[i][0] = i;
    for (int c = 0; c < 26; c++)
      R[i][c + 1] = max(R[i][c], c < vec.size() ? nxt[vec[c]] : i);
  }
  for (int i = 0; i < 26; i++) last[i] = n + 1;
  for (int i = n; i >= 1; i--) {
    last[A[i] - 'a'] = i;
    vec.clear();
    for (int c = 0; c < 26; c++)
      if (last[c] <= n) vec.push_back(last[c]);
    sort(vec.begin(), vec.end());
    L[i][0] = i;
    for (int c = 0; c < 26; c++)
      L[i][c + 1] = min(L[i][c], c < vec.size() ? prv[vec[c]] : i);
  }
  long long ANS = 0;
  for (int i = 1; i <= n; i++) ll[i] = rr[i] = i;
  for (int c = 1; c <= 26; c++) {
    for (int i = 1; i <= n; i++)
      lsum[i][0] = lll[i][0] = L[i][c], rsum[i][0] = rrr[i][0] = R[i][c];
    for (int lg = 1; lg < LOG; lg++)
      for (int i = 1; i <= n; i++)
        lsum[i][lg] = lsum[i][lg - 1] + lsum[lll[i][lg - 1]][lg - 1],
        lll[i][lg] = lll[lll[i][lg - 1]][lg - 1],
        rsum[i][lg] = rsum[i][lg - 1] + rsum[rrr[i][lg - 1]][lg - 1],
        rrr[i][lg] = rrr[rrr[i][lg - 1]][lg - 1];
    for (int i = 1; i <= n; i++)
      if (OK(ll[i], rr[i], c)) {
        int tl = ll[i], tr = rr[i];
        for (int lg = LOG; lg--;)
          if (OK(lll[tl][lg], rrr[tr][lg], c))
            cnt[i] += 1 << lg, ANS += lsum[tl][lg] - rsum[tr][lg],
                tl = lll[tl][lg], tr = rrr[tr][lg];
        cnt[i]++, ANS += lsum[tl][0] - rsum[tr][0], tl = lll[tl][0],
                                                    tr = rrr[tr][0];
        ll[i] = tl, rr[i] = tr;
      }
  }
  for (int i = 1; i <= n; i++) ANS += 1ll * (cnt[i] + 1) * (n - 1);
  cout << ANS << '\n';
}
