#include <bits/stdc++.h>
constexpr int sigma = 26;
using ll = long long;
std::vector<int> vec[35];
int pre[100005], nxt[100005], cur_l[100005], cur_r[100005];
int left[25][100005], right[25][100005], ext[100005], app[35];
ll sum_l[25][100005], sum_r[25][100005], ans;
char str[100005];
int main() {
  scanf("%s", str);
  int n = strlen(str);
  for (int i = 0; i < n; i++) {
    vec[str[i] - 'a'].push_back(i);
    cur_l[i] = cur_r[i] = i;
  }
  for (int c = 0; c < sigma; c++) {
    for (int i = 0; i < vec[c].size(); i++) {
      pre[vec[c][i]] = i ? vec[c][i - 1] : 0;
      nxt[vec[c][i]] = i + 1 == vec[c].size() ? n - 1 : vec[c][i + 1];
    }
  }
  for (int lim = 1; lim <= sigma; lim++) {
    std::multiset<int> se_l, se_r;
    for (int l = 0, r = 0, cur = 0; l < n; l++) {
      while (r < n && cur + !app[str[r] - 'a'] <= lim) {
        se_l.insert(pre[r]);
        se_r.insert(nxt[r]);
        right[0][r] = *--se_r.end();
        cur += !app[str[r++] - 'a']++;
      }
      ext[l] = r;
      left[0][l] = *se_l.begin();
      sum_l[0][l] = l;
      sum_r[0][l] = n - l - 1;
      cur -= !--app[str[l] - 'a'];
      se_l.erase(se_l.find(pre[l]));
      se_r.erase(se_r.find(nxt[l]));
    }
    for (int i = 1; i < 20; i++) {
      for (int j = 0; j < n; j++) {
        left[i][j] = left[i - 1][left[i - 1][j]];
        right[i][j] = right[i - 1][right[i - 1][j]];
        sum_l[i][j] = sum_l[i - 1][j] + sum_l[i - 1][left[i - 1][j]];
        sum_r[i][j] = sum_r[i - 1][j] + sum_r[i - 1][right[i - 1][j]];
      }
    }
    for (int i = 0; i < n; i++) {
      auto jump = [&](int t) {
        ans += sum_r[t][cur_r[i]] + sum_l[t][cur_l[i]];
        cur_l[i] = left[t][cur_l[i]];
        cur_r[i] = right[t][cur_r[i]];
      };
      for (int j = 19; j >= 0; j--) {
        if (right[j][cur_r[i]] < ext[left[j][cur_l[i]]]) jump(j);
      }
      if (cur_r[i] < ext[cur_l[i]]) jump(0);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

### Prompt

Generate a Cpp solution to the following 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.

### Response

```cpp
#include <bits/stdc++.h>
constexpr int sigma = 26;
using ll = long long;
std::vector<int> vec[35];
int pre[100005], nxt[100005], cur_l[100005], cur_r[100005];
int left[25][100005], right[25][100005], ext[100005], app[35];
ll sum_l[25][100005], sum_r[25][100005], ans;
char str[100005];
int main() {
  scanf("%s", str);
  int n = strlen(str);
  for (int i = 0; i < n; i++) {
    vec[str[i] - 'a'].push_back(i);
    cur_l[i] = cur_r[i] = i;
  }
  for (int c = 0; c < sigma; c++) {
    for (int i = 0; i < vec[c].size(); i++) {
      pre[vec[c][i]] = i ? vec[c][i - 1] : 0;
      nxt[vec[c][i]] = i + 1 == vec[c].size() ? n - 1 : vec[c][i + 1];
    }
  }
  for (int lim = 1; lim <= sigma; lim++) {
    std::multiset<int> se_l, se_r;
    for (int l = 0, r = 0, cur = 0; l < n; l++) {
      while (r < n && cur + !app[str[r] - 'a'] <= lim) {
        se_l.insert(pre[r]);
        se_r.insert(nxt[r]);
        right[0][r] = *--se_r.end();
        cur += !app[str[r++] - 'a']++;
      }
      ext[l] = r;
      left[0][l] = *se_l.begin();
      sum_l[0][l] = l;
      sum_r[0][l] = n - l - 1;
      cur -= !--app[str[l] - 'a'];
      se_l.erase(se_l.find(pre[l]));
      se_r.erase(se_r.find(nxt[l]));
    }
    for (int i = 1; i < 20; i++) {
      for (int j = 0; j < n; j++) {
        left[i][j] = left[i - 1][left[i - 1][j]];
        right[i][j] = right[i - 1][right[i - 1][j]];
        sum_l[i][j] = sum_l[i - 1][j] + sum_l[i - 1][left[i - 1][j]];
        sum_r[i][j] = sum_r[i - 1][j] + sum_r[i - 1][right[i - 1][j]];
      }
    }
    for (int i = 0; i < n; i++) {
      auto jump = [&](int t) {
        ans += sum_r[t][cur_r[i]] + sum_l[t][cur_l[i]];
        cur_l[i] = left[t][cur_l[i]];
        cur_r[i] = right[t][cur_r[i]];
      };
      for (int j = 19; j >= 0; j--) {
        if (right[j][cur_r[i]] < ext[left[j][cur_l[i]]]) jump(j);
      }
      if (cur_r[i] < ext[cur_l[i]]) jump(0);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

```