#include <iostream>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <string>

using namespace std;

const int MaxN = 200009;
const int MaxT = 27;
const int INF = 0;

string s;
int d[MaxN];
int t[MaxN];
vector <pair <int, int> > q[MaxT][MaxT];
int m[MaxT];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    freopen("strange.in", "r", stdin);
    freopen("strange.out", "w", stdout);

    cin >> s;
    int n = s.size();
    int last = -1;
    //cout << "^ ";
    for (int i = 0; i < n; i++) {
        if (last != s[i]) d[i] = 1;
        else d[i] = d[i - 1] + 1;
        last = s[i];
        //cout << d[i] << " ";
    }
    last = -1;
    //cout << "\n% ";
    for (int i = n - 1; i >= 0; i--) {
        if (last != s[i]) t[i] = 1;
        else t[i] = t[i + 1] + 1;
        last = s[i];
        //cout << t[i] << " ";
    }
    //cout << endl;
    for (int i = 0; i < n; i++) m[s[i] - 'a'] = max(m[s[i] - 'a'], d[i]);
    for (int i = 1; i < n; i++) {
        if (s[i] != s[i - 1]) q[s[i - 1] - 'a'][s[i] - 'a'].push_back(make_pair(d[i - 1], t[i]));
    }
    for (int i = 0; i < MaxT; i++) {
        for (int j = 0; j < MaxT; j++) {
            sort(q[i][j].rbegin(), q[i][j].rend());
        }
    }
    long long S = 0;
    for (int i = 0; i < MaxT; i++) {
        for (int j = 0; j < MaxT; j++) {
            if (q[i][j].size() != 0) {
                int Max = q[i][j][0].second;
                S += (long long)q[i][j][0].first * q[i][j][0].second;
                //cout << (char)(i + 'a') << " " << (char)(j + 'a') << " begin " << S << endl;
                for (int k = 1; k < q[i][j].size(); k++) {
                    if (q[i][j][k].second > Max) {
                        S += ((long long)q[i][j][k].second - Max) * q[i][j][k].first;
                        Max = q[i][j][k].second;
                    }
                }
                //cout << (char)(i + 'a') << " " << (char)(j + 'a') << " " << S << endl;
            }
        }
    }
    for (int i = 0; i < MaxT; i++) {
        S += m[i];
        //if (m[i] != 0) cout << "$ " << m[i] << endl;
    }
    cout << S;

    return 0;
}
