#include<bits/stdc++.h>
#define ll long long int
#define pll pair<ll,ll>
#define vpll vector< pll >
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define print(x) {cout<<x<<nl;continue;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define err1(a) {cout<<#a<<' '<<a<<nl;}
#define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;}

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll bpow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}
ll dp[26][200005];
int main()
{
	//fast
	string s;
	cin>>s;
	int n=s(s);
	s='#'+s;
	FOR(i,1,n)
	{
	    int x=s[i]-'a';
	    dp[x][i]++;
	}
	FOR(i,0,25)
	{
	    FOR(j,1,n)
	    {
	        dp[i][j]+=dp[i][j-1];
	    }
	}
    //FOR(i,0,25)FOR(j,1,n)cout<<dp[i][j]<<(j==n?nl:' ');
	vector<pair<char,int>> v;
	FORB(i,n,2)
	{
	    if(s[i]==s[i-1])
        {
            v.eb(s[i],i);
        }
	}
	if(s(v)==0)cut(0)
    char x='?';ll r=n;
    ll ans=0;
   // trav(it,v)cout<<it.f<<' '<<it.sc<<nl;
    trav(it,v)
    {
        if(it.f!=x)
        {
            int y=it.sc;
            ans+=(n-it.sc)-(dp[it.f-'a'][r]-dp[it.f-'a'][y]);
            r=y-1;
            x=it.f;
        }
        else
        {
            int y=it.sc;
            ans+=(r-y)-(dp[it.f-'a'][r]-dp[it.f-'a'][y]);

            r=y-1;
        }
        //err2(x,r)
        //err1(ans)
    }
    cut(ans)

}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

int main() {
    string s;
    cin >> s;
    ll n = s.size();
    vector<vector<ll>> rightcnt(n, vector<ll>(27, 0));
    // for (ll i = n - 1; i >= 0; i--) {
    //     for (ll c = 0; c < 27; c++) {
    //         if (i < n - 1) rightcnt[i][c] = rightcnt[i + 1][c];
    //         ll cur = s[i] - 'a';
    //         rightcnt[i][cur]++;
    //     }
    // }
    ll ans = 0;
    //print(n);
    for (ll i = n - 1; i >= 0; i--) {
        ll cur = s[i] - 'a';
        for (ll c = 0; c < 27; c++) {
            if (i + 1 < n) rightcnt[i][c] = rightcnt[i + 1][c];
            //  print(i, c, rightcnt[i][c]);
        }
        rightcnt[i][cur]++;
        if (i + 2 < n && s[i] == s[i + 1] && s[i] != s[i + 2]) {
            for (ll c = 0; c < 27; c++) {
                if (c == cur) {
                    rightcnt[i][c] = (n - i);
                } else {
                    ans += rightcnt[i][c];
                    rightcnt[i][c] = 0;
                }
            }
            s[i + 1] = s[i];
            s[i + 2] = s[i];
        }
    }
    print(ans);
}
