#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define _roverload(_a1,_a2,_a3,name,...) name
    #define _rep(i,n) repi(i,0,n)
    #define repi(i,a,b) for(int i=int(a);i<int(b);++i)
    #define rep(...) _roverload(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
    #define _rrep(i,n) rrepi(i,0,n)
    #define rrepi(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);--i)
    #define rrep(...) _roverload(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    void print() {cout << '\n';}
    template<class T> void print(const vector<T> &v)
    {bool f=false; for(const auto &e: v){if(f)cout << ' '; cout << e; f=true;} cout << '\n';}
    template<class... T> void print(const T&... args)
    {bool f=false; for(const auto &e: {args...}){if(f)cout << ' '; cout << e; f=true;} cout << '\n';}
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    string s; cin >> s;
    int n = s.length();
    vi cnt(26);
    ll ans = 0;
    rrep(i,n){
        cnt[s[i]-'a']++;
        if(i>0 && s[i-1]==s[i]){
            rep(j,26){
                if(s[i]-'a' == j) continue;
                ans += cnt[j];
                cnt[j] = 0;
            }
            cnt[s[i]-'a'] = n-i;
        }
    }
    print(ans);

}
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include<map> 
#define ll                   long long
#define skip                 cin>>ws;
#define vll                  vector<ll> 
#define vi                   vector<int>
#define vb                   vector<bool>
#define vpll                 vector<pair<ll,ll>>
#define vpi                  vector<pair<int, int>>
#define vvll                 vector<vector<ll>>
#define vvi                  vector<vector<int>>
#define vvvll                vector<vector<vector<ll>>>
#define pll                  pair<ll,ll>
#define vs                   vector<string>
#define vvpll                vector<vector<pair<ll, ll>>>
#define vvpi                 vector<vector<pair<int, int>>>
#define pb                   push_back
#define pob                  pop_back()
#define MOD                  (ll)(1e9 + 7)
#define MOD2                 (ll)(998244353)
#define INF                  (ll)(1e18 + 5)
#define count1(n)            __builtin_popcountll(n)
#define test                 ll t; cin>>t; while(t--)
#define enter(a)             for(ll i=0;i<a.size();i++) cin>>a[i];
#define show(a)              for(ll e: a) cout<<e<<" "; cout<<"\n";

using namespace std;

ll mo(ll a){ return a%MOD;}

ll po(ll x, ll y, ll p)
{
    ll res = 1; x = x % p;   
    while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } 
    return res%p; 
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    skip
    cin>>s;
    skip

    ll n = s.size(), pre_in = -1, pre = -1, ans = 0;
    vvll cnt(n + 1, vll(26));
    cnt[n-1][s[n-1] - 'a']++;

    for(ll i=n-2;i>=0;i--)
    {
        for(ll j=0;j<26;j++)
        {
            cnt[i][j] = cnt[i + 1][j];
        }
        cnt[i][s[i] - 'a']++;

        if(s[i] == s[i + 1])
        {
            if(s[i] - 'a' == pre)
            {
                ans += max((pre_in - (i + 1) - 1), 0LL);
                ans -= max((cnt[i + 1][s[i] - 'a'] - cnt[pre_in][s[i] - 'a'] -1), 0LL);
            }
            else
            {
                ans += (max((n-1) - (i + 1), 0LL) - (cnt[i + 2][s[i] - 'a']
                 - ((pre_in!=-1)?cnt[pre_in][s[i] - 'a'] :0LL)));   
            }
            // cout<<ans<<"\n";

            pre = s[i] - 'a';
            pre_in = i;
        }

    }

    cout<<ans<<"\n";

    return 0;
}   