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 = 100005;
using ll = long long;
int n, lst[27], l[N], r[N], pre[N][27], nxt[N][27], f[N][27], g[N][27], curl[N],
    curr[N];
int flft[17][N], glft[17][N];
char ss[N];
int s[N];
ll fsum[17][N], gsum[17][N];
int main() {
  ios::sync_with_stdio(false);
  cin >> (ss + 1);
  n = strlen(ss + 1);
  for (int i = 1; i <= n; i++) s[i] = ss[i] - 'a';
  for (int i = 0; i < 26; i++) lst[i] = 1;
  for (int i = 1; i <= n; i++) {
    l[i] = lst[s[i]];
    lst[s[i]] = i;
    memcpy(pre[i], lst, sizeof(pre[i]));
    sort(pre[i], pre[i] + 26, greater<int>());
    pre[i][26] = 0;
  }
  for (int i = 0; i < 26; i++) lst[i] = n;
  for (int i = n; i > 0; --i) {
    r[i] = lst[s[i]];
    lst[s[i]] = i;
    memcpy(nxt[i], lst, sizeof(nxt[i]));
    sort(nxt[i], nxt[i] + 26);
    nxt[i][26] = n + 1;
  }
  for (int i = 1; i <= n; i++) {
    curl[i] = curr[i] = f[i][0] = g[i][0] = i;
    for (int j = 0; j < 26; j++) {
      f[i][j + 1] = min(f[i][j], l[nxt[i][j]]);
      g[i][j + 1] = max(g[i][j], r[pre[i][j]]);
    }
  }
  ll ans = 0;
  for (int t = 1; t <= 26; t++) {
    for (int i = 1; i <= n; i++)
      flft[0][i] = f[i][t], glft[0][i] = g[i][t], fsum[0][i] = gsum[0][i] = i;
    for (int i = 1; (1 << i) <= n; i++)
      for (int j = 1; j <= n; j++) {
        flft[i][j] = flft[i - 1][flft[i - 1][j]];
        glft[i][j] = glft[i - 1][glft[i - 1][j]];
        fsum[i][j] = fsum[i - 1][j] + fsum[i - 1][flft[i - 1][j]];
        gsum[i][j] = gsum[i - 1][j] + gsum[i - 1][glft[i - 1][j]];
      }
    for (int i = 1; i <= n; i++) {
      for (int j = 31 - __builtin_clz(n); j >= 0; --j) {
        int nxl = flft[j][curl[i]], nxr = glft[j][curr[i]];
        if (nxr < nxt[nxl][t]) {
          ans += ((n - 1ll) << j) + fsum[j][curl[i]] - gsum[j][curr[i]];
          curl[i] = nxl;
          curr[i] = nxr;
        }
      }
      if (curr[i] < nxt[curl[i]][t]) {
        ans += n - 1 + curl[i] - curr[i];
        curl[i] = f[curl[i]][t];
        curr[i] = g[curr[i]][t];
      }
    }
  }
  cout << ans << endl;
  return 0;
}