#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using PII = pair<char, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// BEGIN CUT
ll modpow(ll x, ll y, ll m) {
    ll a = 1, p = x;
    while (y > 0) {
        if (y % 2 == 0) {
            p = (p * p) % m;
            y /= 2;
        } else {
            a = (a * p) % m;
            y--;
        }
    }
    return a;
}
// END CUT

int main() {
    string S;
    cin >> S;
    char prv = S[0];
    int len = 1;
    vector<PII> vec;
    for (int i = 1; i < S.size(); i++) {
        if (prv != S[i]) {
            vec.emplace_back(prv, len);
            len = 1;
        } else {
            len++;
        }
        prv = S[i];
    }
    vec.emplace_back(prv, len);
    ll ans = 0;
    stack<PII> st;
    for (int i = vec.size() - 1; i >= 0; i--) {
        ll len = vec[i].second;
        if (vec[i].second >= 2) {
            while (!st.empty()) {
                PII p = st.top();
                st.pop();
                if (p.first != vec[i].first)
                    ans += p.second;
                len += p.second;
            }
        }
        st.emplace(vec[i].first, len);
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
//#define ll long long
#define int long long
//#define ull unsigned long long
//#define PI pair<int,int>
//#define PII pair<int,PI>
//#define PI pair<ll,int>
//#define endl "\n"
using namespace std;
const int maxm=2e6+5;
//const int mod=1e9+7;



signed main(){
    ios::sync_with_stdio(0);
    string s;cin>>s;
    int n=s.size();
    int ans=0;
    map<char,int>mark;
    for(int i=n-1;i>=0;i--){
        mark[s[i]]++;
        if(i>n-3)continue;
        if(s[i]==s[i+1]&&s[i]!=s[i+2]){
            ans+=(n-1)-i+1-mark[s[i]];
            mark.clear();
            mark[s[i]]=(n-1)-i+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*


*/
/*


*/



