using System;
using System.Linq;
using System.Security.Cryptography;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void menjanje(ref string s, ref int br)
        {
            int c = 2;
            if (s[0] == s[s.Length - 1])
            {
                string b = "";
                for (int i = 0; i < s.Length - 1; i++)
                {
                    b += s[i];
                }
                s = b;
                br++;
            }
            for (int i = c; i < s.Length - 1; i = c)
            {
                brisanje(ref s);
                string a = s[0].ToString();
                int k = br;
                for (int j = 0; j < i; j++)
                {
                    s += "a";
                }
                for (int j = 0; j < s.Length - i; j++)
                {
                    if (s[j] == s[j + i])
                    {
                        j += i;
                        br += i - 1;
                    }
                    a += s[j];
                }
                if (k == br)
                {
                    c++;
                }
                s = a;
            }
        }
        static void brisanje(ref string s)
        {
            string a = s[0].ToString();
            for (int i = 1; i < s.Length; i++)
            {
                if (s[i] != s[i - 1])
                {
                    a += s[i].ToString();
                }
            }
            s = a;
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int br = 0;
            menjanje(ref s, ref br);
            Console.WriteLine(br);
        }
    }
}