#include "bits/stdc++.h"
#define puba push_back
#define mapa make_pair
#define ff first
#define ss second
#define bend(_x) (_x).begin(), (_x).end()
#define szof(_x) ((int) (_x).size())
#define TASK_NAME "strange"

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int MAXN = 2e5 + 5;

char s[MAXN];
map<pii, vector<pii>> mp;
map<int, int> mp2;

bool cmp(pii a, pii b) {
    if (a.ff != b.ff) {
        return a.ff < b.ff;
    }
    return a.ss > b.ss;
}

int main() {        
    freopen(TASK_NAME ".in", "r", stdin);
    freopen(TASK_NAME ".out", "w", stdout);

    scanf("%s", s);
    int n = strlen(s);

    vector <pii> v;

    int prev = 0;
    for (int i = 1; i <= n; ++i) {
        if (s[i] != s[i - 1]) {
            v.puba(mapa(i - prev, s[i - 1] - 'a'));
            prev = i;
        }
    }

    /*
    for (auto p: v) {
        cerr << p.ff << " " << p.ss << endl;
    }*/

    ll ans = 0;

    for (auto p: v) {
        mp2[p.ss] = max(mp2[p.ss], p.ff);
    }

    for (auto p: mp2) {
        ans += p.ss;
    }


    for (int i = 0; i < szof(v) - 1; ++i) {
        mp[mapa(v[i].ss, v[i + 1].ss)].puba(mapa(v[i].ff, v[i + 1].ff));
    }

    

    for (auto p: mp) {
        vector<pii> tmp = p.ss;
        sort(bend(tmp), cmp);
        pii prev = mapa(0, 0);
        //cerr << "new " << p.ff.ff << " " << p.ff.ss << endl;
        for (int i = szof(tmp) - 2; i >= 0; --i) {
            tmp[i].ss = max(tmp[i].ss, tmp[i + 1].ss);
        }
        for (auto el: tmp) {
            //cerr << el.ff << " " << el.ss << endl;
            ans += (ll) (el.ff - prev.ff) * el.ss;
            prev = el;
        }
    }


    cout << ans << endl;

    return 0;
}