#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
string s;
ll ans;
char prv;
int prvLoc;
int cnt[26];

int main(){
    cin >> s;
    n = (int)s.size();
    prvLoc = n;
    for(int i=n-1; i>=0; i--){
        if(i < n-1 && s[i] == s[i+1] && (i == n-2 || s[i+1] != s[i+2])){
            if(s[i] == prv){ /// 이전과 같은 문자
                ans += accumulate(cnt, cnt+26, 0) - cnt[s[i]-'a'];
            }
            else{
                ans += accumulate(cnt, cnt+26, 0) - cnt[s[i]-'a'];
                ans += n - prvLoc;
            }
            prv = s[i];
            fill(cnt, cnt+26, 0);
            prvLoc = i;
        }
        else cnt[s[i]-'a']++;
    }
    printf("%lld", ans);
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
//char __buf[1<<20],*__p1,*__p2;
//#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++)
int read() {
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
//const int maxn = 2e5+10;
//const int mod = ;
//struct Edge{int to,next;}a[maxn];int h[maxn],cnt;
//void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
//vector<int>G[maxn];
//void add(int x,int y) {G[x].push_back(y),G[y].push_back(x);}
int n,ans=1ll<<60;
signed main() {
	n=read();
	for(int b=1,cb=0;b<=n;b<<=1,++cb) {
		ans=min(ans,n/b+cb+n%b);
	}
	cout<<ans<<'\n';
	return 0;
}