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 Max = 1e5 + 10, Sig = 30, LOG = 17;
int n, last[Sig], prv[Max], nxt[Max], lst[Sig][Max], L[Sig][Max], R[Sig][Max],
    cnt[Max], ll[Max], rr[Max], lll[Max][LOG], rrr[Max][LOG];
long long lsum[Max][LOG], rsum[Max][LOG];
vector<int> vec;
inline bool OK(int l, int r, int c) {
  return (l != 1 || r != n) && l > lst[c + 1][r];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string A;
  cin >> A;
  n = A.size();
  A = '.' + A;
  for (int i = 0; i < 26; i++) last[i] = 0;
  for (int i = 1; i <= n; i++)
    prv[i] = max(last[A[i] - 'a'], 1), last[A[i] - 'a'] = i;
  for (int i = 0; i < 26; i++) last[i] = n + 1;
  for (int i = n; i >= 1; i--)
    nxt[i] = min(last[A[i] - 'a'], n), last[A[i] - 'a'] = i;
  for (int i = 0; i < 26; i++) last[i] = 0;
  for (int i = 1; i <= n; i++) {
    last[A[i] - 'a'] = i;
    vec.clear();
    for (int c = 0; c < 26; c++)
      if (last[c] >= 1) vec.push_back(last[c]);
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    lst[0][i] = n + 1;
    for (int c = 0; c < vec.size(); c++) lst[c + 1][i] = vec[c];
    R[0][i] = i;
    for (int c = 0; c < 26; c++)
      R[c + 1][i] = max(R[c][i], c < vec.size() ? nxt[vec[c]] : i);
  }
  for (int i = 0; i < 26; i++) last[i] = n + 1;
  for (int i = n; i >= 1; i--) {
    last[A[i] - 'a'] = i;
    vec.clear();
    for (int c = 0; c < 26; c++)
      if (last[c] <= n) vec.push_back(last[c]);
    sort(vec.begin(), vec.end());
    L[0][i] = i;
    for (int c = 0; c < 26; c++)
      L[c + 1][i] = min(L[c][i], c < vec.size() ? prv[vec[c]] : i);
  }
  long long ANS = 0;
  for (int i = 1; i <= n; i++) ll[i] = rr[i] = i;
  for (int c = 1; c <= 26; c++) {
    for (int i = 1; i <= n; i++)
      lsum[i][0] = lll[i][0] = L[c][i], rsum[i][0] = rrr[i][0] = R[c][i];
    for (int lg = 1; lg < LOG; lg++)
      for (int i = 1; i <= n; i++)
        lsum[i][lg] = lsum[i][lg - 1] + lsum[lll[i][lg - 1]][lg - 1],
        lll[i][lg] = lll[lll[i][lg - 1]][lg - 1],
        rsum[i][lg] = rsum[i][lg - 1] + rsum[rrr[i][lg - 1]][lg - 1],
        rrr[i][lg] = rrr[rrr[i][lg - 1]][lg - 1];
    for (int i = 1; i <= n; i++)
      if (OK(ll[i], rr[i], c)) {
        int tl = ll[i], tr = rr[i];
        for (int lg = LOG; lg--;)
          if (OK(lll[tl][lg], rrr[tr][lg], c))
            cnt[i] += 1 << lg, ANS += lsum[tl][lg] - rsum[tr][lg],
                tl = lll[tl][lg], tr = rrr[tr][lg];
        cnt[i]++, ANS += lsum[tl][0] - rsum[tr][0], tl = lll[tl][0],
                                                    tr = rrr[tr][0];
        ll[i] = tl, rr[i] = tr;
      }
  }
  for (int i = 1; i <= n; i++) ANS += 1ll * (cnt[i] + 1) * (n - 1);
  cout << ANS << '\n';
}