#include <bits/stdc++.h>

using namespace std;

int main()
{
long long br=0, brt=0,brd=0,brd2 = 0 ,brn=0,k,ki,ki2;
string a;
cin >> a;
for(int i =0;i < a.length(); i++)
{
    brt=1;brd=1;brn=0;brd2 = 0;ki = 0;ki2=0;
            while(a[i] == a[i + 1])
        {
        brt++;
        i++;
        }
    for(int j = i + 1;j<a.length();j++){
        if(a[i] == a[j]){
            while(a[j] = a[j + 1])
            {
                brd++;
                a[j] = 'c';
                j++;

            }
            k = j - i - brd;
            if(k == min(k,min(brd,brt)))
            {
                brn+= k;
                i = j;
                j++;
                brt +=  brd + ki2;
                brd2 = 0;
            }
            else if(brt == min(k,min(brd,brt)))
            {
                br += brd;
                j = a.length();
                brn = 0;
            }
            else
            {
                brd2 += brd;
                ki2 += brd;
            }

        }
        if(a[j] == 'c')
            ki++;

        }

    br += brd2 + brn;

}
cout << br;
return 0;
}