#include <bits/stdc++.h>

using namespace std;
const int MAXN = 200000;
char s[MAXN + 1];
int main() {
    freopen("strange.in", "r", stdin);
    freopen("strange.out", "w", stdout);

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


    char prevc = '0';
    int prevlen = -1;
    int i = 0;
    int j = i;
    while (j < n && s[j] == s[i]) {
        j++;
    }
    prevc = s[i];
    prevlen = j - i;
    i = j;
    int maxlen[26];
    for (int r = 0; r < 26; r++) {
        maxlen[r] = 0;
    }
    maxlen[prevc - 'a'] = prevlen;
    vector<pair<int, int> > a[26][26];
    while (i < n) {
        j = i;
        while (j < n && s[j] == s[i]) {
            j++;
        }
        a[prevc - 'a'][s[i] - 'a'].push_back(make_pair(prevlen, j - i));
        prevc = s[i];
        prevlen = j - i;
        if (prevlen > maxlen[prevc - 'a']) {
            maxlen[prevc - 'a'] = prevlen;
        }
        i = j;
    } 
    long long ans = 0;
    for (i = 0; i < 26; i++) {
        for (j = 0; j < 26; j++) {
            if (a[i][j].size() == 0) continue;

            sort(a[i][j].begin(), a[i][j].end());
            stack<pair<int, int> > mystack;
            for (int w = 0; w < (int) a[i][j].size(); w++) {
                while (mystack.size() > 0 && mystack.top().second < a[i][j][w].second) {
                    mystack.pop();
                }
                mystack.push(a[i][j][w]);
            }
            vector<pair<int, int> > cur;
            while (mystack.size() > 0) {
                cur.push_back(mystack.top());
                mystack.pop();
            }
            reverse(cur.begin(), cur.end());
            long long curans = 0;
            curans += (cur[0].second + 0LL) * (cur[0].first);
            for (int w = 1; w < (int) cur.size(); w++) {
                curans += (cur[w].first - cur[w-1].first) * (cur[w].second + 0LL);
            }
            ans += curans;
        }
    }
    for (i = 0; i < 26; i++) {
        ans += maxlen[i];
    }
    cout << ans << endl;
    return 0;
}               
