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 maxn = 1e5 + 5;
char s[maxn];
int pre_pos[maxn][30], nxt_pos[maxn][30], pre_c[maxn][30], nxt_c[maxn][30],
    mp[30], c_cnt;
bool app[30];
int n, f_nxt[maxn][20], f_pre[maxn][20], l[maxn], r[maxn], cnt[maxn];
long long sum_nxt[maxn][20], sum_pre[maxn][20], ans;
int main() {
  cin >> s + 1;
  n = strlen(s + 1);
  ans = (long long)n * n * n - (long long)n * n;
  for (int i = 1; i <= n; i++) app[s[i] -= 'a'] = true;
  for (int i = 0; i <= 25; i++)
    if (app[i]) mp[i] = c_cnt++;
  for (int i = 1; i <= n; i++) s[i] = mp[s[i]];
  for (int i = 1; i <= n; i++) {
    memcpy(pre_pos[i], pre_pos[i - 1], 30 * 4);
    pre_pos[i][s[i]] = i;
    vector<pair<int, int> > vec;
    for (int j = 0; j <= c_cnt - 1; j++)
      if (pre_pos[i][j]) vec.push_back(make_pair(pre_pos[i][j], j));
    sort(vec.begin(), vec.end(), greater<pair<int, int> >());
    for (pair<int, int> p : vec) pre_c[i][++pre_c[i][0]] = p.second;
  }
  for (int i = n; i; i--) {
    memcpy(nxt_pos[i], nxt_pos[i + 1], 30 * 4);
    nxt_pos[i][s[i]] = i;
    vector<pair<int, int> > vec;
    for (int j = 0; j <= c_cnt - 1; j++)
      if (nxt_pos[i][j]) vec.push_back(make_pair(nxt_pos[i][j], j));
    sort(vec.begin(), vec.end());
    for (pair<int, int> p : vec) nxt_c[i][++nxt_c[i][0]] = p.second;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= c_cnt - 1; j++) {
      if (!pre_pos[i][j]) pre_pos[i][j] = 1;
      if (!nxt_pos[i][j]) nxt_pos[i][j] = n;
    }
  for (int i = 1; i <= n; i++) l[i] = r[i] = i;
  f_nxt[n][0] = sum_nxt[n][0] = n;
  f_pre[1][0] = sum_pre[1][0] = 1;
  for (int i = 1; i <= c_cnt; i++) {
    for (int j = 1; j <= n; j++) {
      if (pre_c[j][0] >= i && j < n) {
        if (i == 1)
          f_nxt[j][0] = nxt_pos[j + 1][s[j]];
        else
          f_nxt[j][0] = max(f_nxt[j][0], nxt_pos[j + 1][pre_c[j][i]]);
        sum_nxt[j][0] = f_nxt[j][0];
      }
      if (nxt_c[j][0] >= i && j > 1) {
        if (i == 1)
          f_pre[j][0] = pre_pos[j - 1][s[j]];
        else
          f_pre[j][0] = min(f_pre[j][0], pre_pos[j - 1][nxt_c[j][i]]);
        sum_pre[j][0] = f_pre[j][0];
      }
    }
    for (int lvl = 1; lvl <= 16; lvl++)
      for (int j = 1; j <= n; j++) {
        if (pre_c[j][0] >= i) {
          if (f_nxt[j][lvl - 1] == -1)
            f_nxt[j][lvl] = -1;
          else {
            int hp = f_nxt[j][lvl - 1];
            if (pre_c[hp][0] > i &&
                pre_pos[hp][pre_c[hp][i + 1]] >= pre_pos[j][pre_c[j][i]])
              f_nxt[j][lvl] = -1;
            else
              f_nxt[j][lvl] = f_nxt[hp][lvl - 1],
              sum_nxt[j][lvl] = sum_nxt[j][lvl - 1] + sum_nxt[hp][lvl - 1];
          }
        }
        if (nxt_c[j][0] >= i) {
          if (f_pre[j][lvl - 1] == -1)
            f_pre[j][lvl] = -1;
          else {
            int hp = f_pre[j][lvl - 1];
            if (nxt_c[hp][0] > i &&
                nxt_pos[hp][nxt_c[hp][i + 1]] <= nxt_pos[j][nxt_c[j][i]])
              f_pre[j][lvl] = -1;
            else
              f_pre[j][lvl] = f_pre[hp][lvl - 1],
              sum_pre[j][lvl] = sum_pre[j][lvl - 1] + sum_pre[hp][lvl - 1];
          }
        }
      }
    if (i == c_cnt) {
      for (int j = 1; j <= n; j++)
        for (int k = 16; k >= 0; k--)
          if (1 << k < n - cnt[j]) {
            cnt[j] += 1 << k;
            ans = ans - sum_nxt[r[j]][k] + sum_pre[l[j]][k];
            l[j] = f_pre[l[j]][k];
            r[j] = f_nxt[r[j]][k];
          }
    } else {
      for (int j = 1; j <= n; j++)
        if (pre_c[r[j]][0] == i || pre_pos[r[j]][pre_c[r[j]][i + 1]] < l[j])
          for (int k = 16; k >= 0; k--)
            if (~f_pre[l[j]][k] && ~f_nxt[r[j]][k]) {
              cnt[j] += 1 << k;
              ans = ans - sum_nxt[r[j]][k] + sum_pre[l[j]][k];
              l[j] = f_pre[l[j]][k];
              r[j] = f_nxt[r[j]][k];
              if (pre_c[r[j]][0] > i &&
                  pre_pos[r[j]][pre_c[r[j]][i + 1]] >= l[j])
                break;
            }
    }
  }
  cout << ans << '\n';
  return 0;
}