Problem: There is a string s of lowercase English letters. A cursor is positioned on one of the characters. The cursor can be moved with the following operation: choose a letter c and a direction (left or right). The cursor is then moved to the closest occurence of c in the chosen direction. If there is no letter c in that direction, the cursor stays in place. For example, if s = abaab with the cursor on the second character (a[b]aab), then:

  * moving to the closest letter a to the left places the cursor on the first character ([a]baab);
  * moving to the closest letter a to the right places the cursor the third character (ab[a]ab);
  * moving to the closest letter b to the right places the cursor on the fifth character (abaa[b]);
  * any other operation leaves the cursor in place.



Let dist(i, j) be the smallest number of operations needed to move the cursor from the i-th character to the j-th character. Compute \displaystyle ∑_{i = 1}^n ∑_{j = 1}^n dist(i, j).

Input

The only line contains a non-empty string s of at most 10^5 lowercase English letters.

Output

Print a single integer \displaystyle ∑_{i = 1}^n ∑_{j = 1}^n dist(i, j).

Examples

Input


abcde


Output


20


Input


abacaba


Output


58

Note

In the first sample case, dist(i, j) = 0 for any pair i = j, and 1 for all other pairs.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, bzmax = 19;
const int inf = (~0u >> 2);
int n;
char s[N];
int h[30];
int cnt[26][N];
int pre[N], suf[N];
int bzl[N][bzmax], bzr[N][bzmax];
bool have(int l, int r, int c) { return cnt[c][r] ^ cnt[c][l - 1]; }
int get_tpl(int p, int c) {
  if (!cnt[c][p]) return inf;
  if (have(pre[p], p, c)) return 0;
  int t = 0, x = p;
  for (int i = bzmax - 1; ~i; i--) {
    int q = bzl[x][i];
    if (!have(pre[q], p, c)) {
      x = q;
      t |= 1 << i;
    }
  }
  return t + 1;
}
int get_tpr(int p, int c) {
  if (cnt[c][n] == cnt[c][p]) return inf;
  if (have(p, suf[p], c)) return 0;
  int t = 0, x = p;
  for (int i = bzmax - 1; ~i; i--) {
    int q = bzr[x][i];
    if (!have(p, suf[q], c)) {
      x = q;
      t |= 1 << i;
    }
  }
  return t + 1;
}
int jump(int bz[][bzmax], int p, int step) {
  for (int i = 0; step; step >>= 1, i++) {
    if (step & 1) {
      p = bz[p][i];
    }
  }
  return p;
}
long long fl[N], fr[N];
int ipre[N], isuf[N];
long long eval(int l, int r, int lastl, int lastr) {
  if (suf[r] > n && !pre[l]) return 0;
  int tmin = inf, idc = -1, t, tl, tr;
  for (int c = 0; c < 26; c++) {
    if (!have(lastl, lastr, c) &&
        ((tl = get_tpl(l, c)) ^ (tr = get_tpr(r, c)))) {
      t = min(tl, tr);
      if (t < tmin) {
        tmin = t;
        idc = c;
      }
    }
  }
  if (idc == -1) return fl[l] + fr[r];
  int nl = jump(bzl, l, tmin);
  int nr = jump(bzr, r, tmin);
  if (!nl || nr > n) return fl[l] + fr[r];
  assert(nl && nr <= n);
  long long ret = fl[l] + fr[r] - fl[bzl[nl][0]] - fr[bzr[nr][0]];
  int sl = ((pre[bzl[nl][0]] < pre[ipre[nr]]) ? (bzl[nl][0]) : (ipre[nr]));
  int sr = ((suf[bzr[nr][0]] > suf[isuf[nl]]) ? (bzr[nr][0]) : (isuf[nl]));
  return ret + eval(sl, sr, pre[l], suf[r]);
}
long long ans = 0;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    cnt[(int)(s[i] -= 'a')][i]++;
  }
  for (int c = 0; c < 26; c++) {
    for (int i = 1; i <= n + 1; i++) {
      cnt[c][i] += cnt[c][i - 1];
    }
  }
  memset(h, 0, sizeof(h));
  for (int i = 1; i <= n; i++) {
    pre[i] = h[(int)s[i]];
    h[(int)s[i]] = i;
  }
  for (int i = 0; i < 26; i++) h[i] = n + 1;
  for (int i = n; i; i--) {
    suf[i] = h[(int)s[i]];
    h[(int)s[i]] = i;
  }
  pre[0] = 0, suf[n + 1] = n + 1;
  for (int i = 0; i < bzmax; i++) bzl[0][i] = 0, bzr[n + 1][i] = n + 1;
  for (int i = 1; i <= n; i++) {
    int &id = bzl[i][0], mi = inf;
    for (int j = pre[i]; j < i; j++) {
      if (pre[j] < mi) {
        mi = pre[j];
        id = j;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int &id = bzr[i][0], mx = -1;
    for (int j = i + 1; j <= suf[i]; j++) {
      if (suf[j] > mx) {
        mx = suf[j];
        id = j;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int &id = ipre[i], mi = inf;
    for (int j = i; j <= suf[i] && j <= n; j++) {
      if (pre[j] < mi) {
        mi = pre[j];
        id = j;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int &id = isuf[i], mx = -1;
    for (int j = max(pre[i], 1); j <= i; j++) {
      if (suf[j] > mx) {
        mx = suf[j];
        id = j;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    fl[i] = fl[bzl[i][0]] + max(0, pre[i] - 1);
    for (int j = 1; j < bzmax; j++) {
      bzl[i][j] = bzl[bzl[i][j - 1]][j - 1];
    }
  }
  for (int i = n; i; i--) {
    fr[i] = fr[bzr[i][0]] + max(0, n - suf[i]);
    for (int j = 1; j < bzmax; j++) {
      bzr[i][j] = bzr[bzr[i][j - 1]][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    long long tmp = eval(i, i, i, i) + n - 1;
    ans += tmp;
  }
  printf("%lld\n", ans);
  return 0;
}