#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
using namespace std;
const int N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 8e18;
const int LOG = 20;
const int sigma = 26;
long long pw(long long a, long long b, long long M = mod, long long ret = 1) {
  while (b) {
    ret = ret * (b & 1 ? a : 1) % M, a = a * a % M, b >>= 1;
  }
  return ret;
}
char s[N];
int n, L[N], R[N], last[sigma], PL[N][sigma + 5], PR[N][sigma + 5],
    f[N][sigma + 5], first[N][sigma + 5], psl[N], psr[N], dp[LOG][N],
    pd[LOG][N];
long long tot, Ans1[LOG][N], Ans2[LOG][N];
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    int ch = s[i] - 'a';
    L[i] = last[ch];
    last[ch] = i;
    for (int j = 0; j < sigma; j++) PL[i][j] = last[j];
    sort(PL[i], PL[i] + sigma, greater<int>());
    PL[i][sigma] = -1;
  }
  for (int i = 0; i < sigma; i++) last[i] = n - 1;
  for (int i = n - 1; ~i; i--) {
    int ch = s[i] - 'a';
    R[i] = last[ch];
    last[ch] = i;
    for (int j = 0; j < sigma; j++) PR[i][j] = last[j];
    sort(PR[i], PR[i] + sigma);
    PR[i][sigma] = n;
  }
  for (int i = 0; i < n; i++) {
    psl[i] = psr[i] = f[i][0] = first[i][0] = i;
    for (int j = 0; j < sigma; j++) {
      f[i][j + 1] = min(f[i][j], L[PR[i][j]]);
      first[i][j + 1] = max(first[i][j], R[PL[i][j]]);
    }
  }
  for (int T = 1; T <= sigma; T++) {
    for (int i = 0; i < n; i++) {
      dp[0][i] = f[i][T], pd[0][i] = first[i][T], Ans1[0][i] = Ans2[0][i] = i;
    }
    for (int i = 1; n >> i >= 1; i++) {
      for (int j = 0; j < n; j++) {
        dp[i][j] = dp[i - 1][dp[i - 1][j]], pd[i][j] = pd[i - 1][pd[i - 1][j]];
        Ans1[i][j] = Ans1[i - 1][j] + Ans1[i - 1][dp[i - 1][j]],
        Ans2[i][j] = Ans2[i - 1][j] + Ans2[i - 1][pd[i - 1][j]];
      }
    }
    for (int i = 0; i < n; i++) {
      int ok = 0;
      for (int j = 31; ~j; j--) {
        if (n >> j & 1) ok = 1;
        if (!ok) {
          continue;
        }
        int left = dp[j][psl[i]], right = pd[j][psr[i]];
        if (right < PR[left][T]) {
          tot += ((1ll * (n - 1)) << j) + Ans1[j][psl[i]] - Ans2[j][psr[i]];
          psl[i] = left, psr[i] = right;
        }
      }
      if (psr[i] < PR[psl[i]][T]) {
        tot += n + psl[i] - psr[i] - 1;
        psl[i] = f[psl[i]][T];
        psr[i] = first[psr[i]][T];
      }
    }
  }
  printf("%lld", tot);
  return 0;
}

### Prompt

Your challenge is to write 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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
using namespace std;
const int N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 8e18;
const int LOG = 20;
const int sigma = 26;
long long pw(long long a, long long b, long long M = mod, long long ret = 1) {
  while (b) {
    ret = ret * (b & 1 ? a : 1) % M, a = a * a % M, b >>= 1;
  }
  return ret;
}
char s[N];
int n, L[N], R[N], last[sigma], PL[N][sigma + 5], PR[N][sigma + 5],
    f[N][sigma + 5], first[N][sigma + 5], psl[N], psr[N], dp[LOG][N],
    pd[LOG][N];
long long tot, Ans1[LOG][N], Ans2[LOG][N];
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    int ch = s[i] - 'a';
    L[i] = last[ch];
    last[ch] = i;
    for (int j = 0; j < sigma; j++) PL[i][j] = last[j];
    sort(PL[i], PL[i] + sigma, greater<int>());
    PL[i][sigma] = -1;
  }
  for (int i = 0; i < sigma; i++) last[i] = n - 1;
  for (int i = n - 1; ~i; i--) {
    int ch = s[i] - 'a';
    R[i] = last[ch];
    last[ch] = i;
    for (int j = 0; j < sigma; j++) PR[i][j] = last[j];
    sort(PR[i], PR[i] + sigma);
    PR[i][sigma] = n;
  }
  for (int i = 0; i < n; i++) {
    psl[i] = psr[i] = f[i][0] = first[i][0] = i;
    for (int j = 0; j < sigma; j++) {
      f[i][j + 1] = min(f[i][j], L[PR[i][j]]);
      first[i][j + 1] = max(first[i][j], R[PL[i][j]]);
    }
  }
  for (int T = 1; T <= sigma; T++) {
    for (int i = 0; i < n; i++) {
      dp[0][i] = f[i][T], pd[0][i] = first[i][T], Ans1[0][i] = Ans2[0][i] = i;
    }
    for (int i = 1; n >> i >= 1; i++) {
      for (int j = 0; j < n; j++) {
        dp[i][j] = dp[i - 1][dp[i - 1][j]], pd[i][j] = pd[i - 1][pd[i - 1][j]];
        Ans1[i][j] = Ans1[i - 1][j] + Ans1[i - 1][dp[i - 1][j]],
        Ans2[i][j] = Ans2[i - 1][j] + Ans2[i - 1][pd[i - 1][j]];
      }
    }
    for (int i = 0; i < n; i++) {
      int ok = 0;
      for (int j = 31; ~j; j--) {
        if (n >> j & 1) ok = 1;
        if (!ok) {
          continue;
        }
        int left = dp[j][psl[i]], right = pd[j][psr[i]];
        if (right < PR[left][T]) {
          tot += ((1ll * (n - 1)) << j) + Ans1[j][psl[i]] - Ans2[j][psr[i]];
          psl[i] = left, psr[i] = right;
        }
      }
      if (psr[i] < PR[psl[i]][T]) {
        tot += n + psl[i] - psr[i] - 1;
        psl[i] = f[psl[i]][T];
        psr[i] = first[psr[i]][T];
      }
    }
  }
  printf("%lld", tot);
  return 0;
}

```