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;
char s[110000];
int bn, n, las[26], newl, newr, l[110000], r[110000], pre[110000][27],
    nex[110000][27], curl[110000], curr[110000], f[110000][27], g[110000][27],
    fk[18][110000], gk[18][110000];
long long ans, fs[18][110000], gs[18][110000];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) s[i] -= 'a';
  ans = 0;
  for (int i = 0; i <= 25; i++) las[i] = 1;
  for (int i = 1; i <= n; i++) {
    l[i] = las[s[i]];
    las[s[i]] = i;
    for (int j = 0; j <= 25; j++) pre[i][j] = las[j];
    sort(pre[i], pre[i] + 26, std::greater<int>());
    pre[i][26] = 0;
  }
  for (int i = 0; i <= 25; i++) las[i] = n;
  for (int i = n; i >= 1; i--) {
    r[i] = las[s[i]];
    las[s[i]] = i;
    for (int j = 0; j <= 25; j++) nex[i][j] = las[j];
    sort(nex[i], nex[i] + 26);
    nex[i][26] = n + 1;
  }
  for (int i = 1; i <= n; i++) {
    curl[i] = curr[i] = i;
    f[i][0] = g[i][0] = i;
    for (int j = 1; j <= 26; j++) {
      f[i][j] = min(f[i][j - 1], l[nex[i][j - 1]]);
      g[i][j] = max(g[i][j - 1], r[pre[i][j - 1]]);
    }
  }
  for (bn = 0; (1 << bn) < n; bn++)
    ;
  for (int t = 1; t <= 26; t++) {
    for (int i = 1; i <= n; i++) {
      fk[0][i] = f[i][t];
      fs[0][i] = i;
      gk[0][i] = g[i][t];
      gs[0][i] = i;
    }
    for (int j = 1; j <= bn; j++)
      for (int i = 1; i <= n; i++) {
        fk[j][i] = fk[j - 1][fk[j - 1][i]];
        gk[j][i] = gk[j - 1][gk[j - 1][i]];
        fs[j][i] = fs[j - 1][i] + fs[j - 1][fk[j - 1][i]];
        gs[j][i] = gs[j - 1][i] + gs[j - 1][gk[j - 1][i]];
      }
    for (int i = 1; i <= n; i++) {
      for (int j = bn; j >= 0; j--) {
        if (curr[i] >= nex[curl[i]][t]) break;
        int &newl = fk[j][curl[i]];
        int &newr = gk[j][curr[i]];
        if (newr < nex[newl][t]) {
          ans += ((n - 1ll) << j) + fs[j][curl[i]] - gs[j][curr[i]];
          curl[i] = newl;
          curr[i] = newr;
        }
      }
      if (curr[i] < nex[curl[i]][t]) {
        ans += n - 1 + curl[i] - curr[i];
        curl[i] = fk[0][curl[i]];
        curr[i] = gk[0][curr[i]];
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}