#include <bits/stdc++.h>

using namespace std;

int main() {
    ifstream in("strange.in");
    ofstream out("strange.out");
    string s;
    in >> s;
    int n = s.length();
    
    vector<pair<char, int> > cnt;
    cnt.push_back({s[0], 1});
    for (int i = 1; i < n; i++) {
    	if (cnt.back().first == s[i]) cnt.back().second++;
    	else cnt.push_back({s[i], 1});
    }
    
    vector<int> one(26);
    for (int i = 0; i < cnt.size(); i++) {
    	int pos = cnt[i].first - 'a';
    	one[pos] = max(one[pos], cnt[i].second);
    }

    vector<pair<int, int> > two[26][26];
    for (int i = 1; i < cnt.size(); i++) {
    	two[cnt[i - 1].first - 'a'][cnt[i].first - 'a'].push_back({cnt[i - 1].second, cnt[i].second});
    }
    
    long long ans = 0;
    for (auto x: one) {
    	ans += x;
    }

    for (int i = 0; i < 26; i++) {
    	for (int j = 0; j < 26; j++) {
    		sort(two[i][j].begin(), two[i][j].end());
			reverse(two[i][j].begin(), two[i][j].end());    		
			if (two[i][j].size() == 0) continue;
			ans += two[i][j][0].first * 1ll * two[i][j][0].second;
			long long maxy = two[i][j][0].second;
			for (int k = 1; k < two[i][j].size(); k++) {
				if (two[i][j][k].second > maxy) {
					ans += (two[i][j][k].second - maxy) * two[i][j][k].first;
					maxy = two[i][j][k].second;
				}	
			}
    	}
    }
    out << ans;
    return 0;
}
