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(N, V<int>(LOGN, 1e9)), jumpR(N, V<int>(LOGN, -1e9));
  VV<ll> Lsum(N, V<ll>(LOGN)), Rsum(N, V<ll>(LOGN));
  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[i][0] = min(jumpL[i][0], L[newone]);
        }
        Lsum[i][0] = i;
      }
      {
        int newone = pre[i][t - 1];
        if (newone != -1) {
          jumpR[i][0] = max(jumpR[i][0], R[newone]);
        }
        Rsum[i][0] = i;
      }
    }
    for (int i = 0; i < (int)(N); i++) {
      for (int k = 1; k <= (int)(LOGN - 1); k++) {
        jumpL[i][k] = jumpL[jumpL[i][k - 1]][k - 1];
        Lsum[i][k] = Lsum[i][k - 1] + Lsum[jumpL[i][k - 1]][k - 1];
      }
    }
    for (int i = N - 1; i >= 0; i--) {
      for (int k = 1; k <= (int)(LOGN - 1); k++) {
        jumpR[i][k] = jumpR[jumpR[i][k - 1]][k - 1];
        Rsum[i][k] = Rsum[i][k - 1] + Rsum[jumpR[i][k - 1]][k - 1];
      }
    }
    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[segL[i]][k], nR = jumpR[segR[i]][k];
        if (MASK(nL, nR) == mask_now) {
          num[i] += 1 << k;
          segLsum[i] += Lsum[segL[i]][k];
          segRsum[i] += Rsum[segR[i]][k];
          segL[i] = nL, segR[i] = nR;
        }
      }
      segLsum[i] += Lsum[segL[i]][0];
      segL[i] = jumpL[segL[i]][0];
      segRsum[i] += Rsum[segR[i]][0];
      segR[i] = jumpR[segR[i]][0];
      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;
}