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;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
int bsr(unsigned int x) {
  if (x == 0) return -1;
  return 31 ^ __builtin_clz(x);
}
struct SparseTable {
  using D = int;
  VV<D> d;
  int lg;
  SparseTable() {}
  SparseTable(const vector<D>& v) {
    int N = v.size();
    assert(N > 0);
    lg = bsr(N) + 1;
    d.resize(lg);
    d[0] = v;
    for (int t = 1; t < lg; t++) {
      int len = 1 << t;
      d[t].resize(N - len + 1);
      for (int i = 0; i < (int)(N - len + 1); i++) {
        d[t][i] = d[t - 1][i] | d[t - 1][i + len / 2];
      }
    }
  }
  D query(int l, int r) const {
    if (l >= r) return 0;
    int u = bsr(r - l);
    return d[u][l] | d[u][r - (1 << u)];
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  V<int> s;
  int Z = 0;
  {
    string t;
    cin >> t;
    for (char c : t) s.push_back(c - 'a');
    V<int> cs = s;
    sort(cs.begin(), cs.end());
    cs.erase(unique(cs.begin(), cs.end()), cs.end());
    Z = cs.size();
    for (int i = 0; i < (int)(s.size()); i++)
      s[i] = lower_bound(cs.begin(), cs.end(), s[i]) - cs.begin();
  }
  int N = s.size();
  V<int> s_bit(N);
  for (int i = 0; i < (int)(N); i++) s_bit[i] = 1 << s[i];
  SparseTable ST(s_bit);
  auto MASK = [&](int l, int r) {
    r++;
    return ST.query(l, r);
  };
  VV<int> pre(N, V<int>(Z, 0)), nxt(N, V<int>(Z, N - 1));
  for (int i = 1; i <= (int)(N - 1); i++) {
    pre[i] = pre[i - 1];
    pre[i][s[i - 1]] = i - 1;
  }
  for (int i = N - 2; i >= 0; i--) {
    nxt[i] = nxt[i + 1];
    nxt[i][s[i + 1]] = i + 1;
  }
  V<int> L(N), R(N);
  for (int i = 0; i < (int)(N); i++) {
    L[i] = pre[i][s[i]];
    pre[i][s[i]] = i;
    R[i] = nxt[i][s[i]];
    nxt[i][s[i]] = i;
    sort(nxt[i].begin(), nxt[i].end());
    sort(pre[i].begin(), pre[i].end(), greater<int>());
  }
  V<ll> num(N), segL(N), segR(N);
  V<ll> segLsum(N), segRsum(N);
  for (int i = 0; i < (int)(N); i++) {
    segL[i] = segR[i] = i;
  }
  const int LOGN = 17;
  VV<int> jumpL(LOGN, V<int>(N, 1e9)), jumpR(LOGN, V<int>(N, -1e9));
  VV<ll> Lsum(LOGN, V<ll>(N)), Rsum(LOGN, V<ll>(N));
  for (int t = 1; t <= (int)(Z); t++) {
    true;
    true;
    for (int i = 0; i < (int)(N); i++) {
      {
        int newone = nxt[i][t - 1];
        if (newone != N) {
          jumpL[0][i] = min(jumpL[0][i], L[newone]);
        }
        Lsum[0][i] = i;
      }
      {
        int newone = pre[i][t - 1];
        if (newone != -1) {
          jumpR[0][i] = max(jumpR[0][i], R[newone]);
        }
        Rsum[0][i] = i;
      }
    }
    for (int k = 1; k <= (int)(LOGN - 1); k++) {
      for (int i = 0; i < (int)(N); i++) {
        jumpL[k][i] = jumpL[k - 1][jumpL[k - 1][i]];
        jumpR[k][i] = jumpR[k - 1][jumpR[k - 1][i]];
        Lsum[k][i] = Lsum[k - 1][i] + Lsum[k - 1][jumpL[k - 1][i]];
        Rsum[k][i] = Rsum[k - 1][i] + Rsum[k - 1][jumpR[k - 1][i]];
      }
    }
    for (int i = 0; i < (int)(N); i++) {
      int mask_now = MASK(segL[i], segR[i]);
      if (__builtin_popcount(mask_now) != t) continue;
      for (int k = LOGN - 1; k >= 0; k--) {
        int nL = jumpL[k][segL[i]], nR = jumpR[k][segR[i]];
        if (MASK(nL, nR) == mask_now) {
          num[i] += 1 << k;
          segLsum[i] += Lsum[k][segL[i]];
          segRsum[i] += Rsum[k][segR[i]];
          segL[i] = nL, segR[i] = nR;
        }
      }
      segLsum[i] += Lsum[0][segL[i]];
      segL[i] = jumpL[0][segL[i]];
      segRsum[i] += Rsum[0][segR[i]];
      segR[i] = jumpR[0][segR[i]];
      num[i]++;
    }
  }
  true;
  ll ans = 0;
  for (int i = 0; i < (int)(N); i++) {
    ll ans_i = num[i] * N - (segRsum[i] + num[i] - segLsum[i]);
    ans += ans_i;
  }
  cout << ans << endl;
}