#include <iostream>
#include <vector>
#include <string>

struct Group
{
	size_t b, e, l;
	char digit;

	Group(size_t b, size_t e, char digit)
		: b(b), e(e), digit(digit)
	{

	}
};

int main()
{
	std::string s;
	size_t size;
	std::cin >> s;	

	int promene = 0;
		
	char lastDigit = s[0];
	std::vector<Group> groups;
	groups.reserve(s.size() / 3);
	groups.emplace_back(0, 0, lastDigit);
	for (size_t i = 0; i < s.size(); ++i)
	{
		if (s[i] != lastDigit)
		{
			groups.back().e = i;
			groups.back().l = groups.back().e - groups.back().b;
			groups.emplace_back(i, 0, s[i]);			
			lastDigit = s[i];
		}
	}
	groups.back().e = s.size();
	groups.back().l = groups.back().e - groups.back().b;

	for (int i = 0; i < groups.size(); ++i)
	{
		int j = i + 1;
		for (; j < groups.size() && groups[i].digit != groups[j].digit; ++j);

		if (j == groups.size())
			continue;
		
		auto& g1 = groups[i];
		auto& g2 = groups[j];		

		if (g1.l < g2.l)
			if (g1.l < g2.b - g1.e)
			{
				if (i > 0 && groups[i - 1].l > groups[i + 1].l)
				{					
					promene += g1.l;
					if (groups[i - 1].digit == groups[i + 1].digit)
					{
						groups[i + 1].b = groups[i - 1].b;
						groups[i + 1].l = groups[i + 1].e - groups[i + 1].b;
						groups.erase(groups.begin() + i - 1, groups.begin() + i + 1);
					}
					else
						groups.erase(groups.begin() + i);					
				}
				else
				{					
					promene += g1.l;
					if (i > 0 && groups[i - 1].digit == groups[i + 1].digit)
					{
						groups[i + 1].b = groups[i - 1].b;
						groups[i + 1].l = groups[i + 1].e - groups[i + 1].b;
						groups.erase(groups.begin() + i - 1, groups.begin() + i + 1);						
					}
					else
						groups.erase(groups.begin() + i);
				}					
			}
			else
			{				
				promene += g2.b - g1.e;
				groups.erase(groups.begin() + i + 1, groups.begin() + j);
			}
		else
			if (g2.l < g2.b - g1.e)			
				if (j < groups.size() - 1 && groups[j - 1].l < groups[j + 1].l)
				{					
					promene += g2.l;
					if (groups[j - 1].digit == groups[j + 1].digit)
					{
						groups[j + 1].b = groups[j - 1].b;
						groups[j + 1].l = groups[j + 1].e - groups[j + 1].b;
						groups.erase(groups.begin() + j - 1, groups.begin() + j + 1);						
					}
					else
						groups.erase(groups.begin() + j);
				}
				else
				{					
					promene += g2.l;

					if (j < groups.size() - 1 && groups[j - 1].digit == groups[j + 1].digit)
					{
						groups[j + 1].b = groups[j - 1].b;
						groups[j + 1].l = groups[j + 1].e - groups[j + 1].b;
						groups.erase(groups.begin() + j - 1, groups.begin() + j + 1);						
					}
					else
						groups.erase(groups.begin() + j);
				}
			else
			{				
				promene += g2.b - g1.e;
				g2.b = g1.b;
				g2.l = g2.e - g2.b;				
				groups.erase(groups.begin() + i, groups.begin() + j);
			}		
	}
	
	std::cout << promene;

	return 0;
}