#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>

char frequent(std::string str)
{
	int count[128] = {};
	int max = 0;
	char result;
	for(int i = 0; i < str.size(); i++) 
	{
		count[str[i]]++;
		if (max < count[str[i]]) 
		{
			max = count[str[i]];
			result = str[i];
		}
	}
	return result;
}

int main()
{
	std::string original_input;
    std::string input;
    std::getline(std::cin, input);
	
	std::vector<std::string> mat;

	for(int i = 0; i < input.size()/2; i++)
	{
		std::string str(input.size(), ' ');
		mat.push_back(str);
	}

	char most_freq = frequent(input);
	int counter = 0;
	bool side = true;
	int x = input.size() / 2;
	int y = 0;
	for(int i = 0; i < input.size(); i++)
	{
		if(x >= mat[y].size())
		{
			for(int c = 0; c < input.size() / 2; c++)
			{
				mat[c] += " ";
			}
		}
		if(x < 0)
		{
			for(int c = 0; c < input.size() / 2; c++)
			{
				mat[c] = " " + mat[c];
			}
		}
		if(y == mat.size())
		{
			mat.push_back(std::string(mat[y-1].size(), ' '));
		}

		mat[y][x] = input[i];
		x += side ? 1 : -1;
		if(input[i] == most_freq) 
		{	
			if(i != input.size()-1)
			{
				int c = i+1;
				counter = 0;
				while(input[c] != most_freq)
				{
					counter++;
					c++;
				}
				if(counter == 0) 
				{
					y++;
					side = !side;
					x += side ? 1 : -1;
				}
				else if(counter % 2 == 0)
				{
					for(int k = i+1; k < c; k++)
					{
						mat[y][x] = input[k];
						if(k == i + counter / 2)
						{
							y++;
							side = !side;
						}
						else
						{
							x += side ? 1 : -1;
						}
					}
					i = c-1;
				}
			}
		}
	}
	int score = 0;
	for(int i = 0; i < mat[0].size(); i++)
	{
		char c = '\0';
		for(int j = 0; j < mat.size(); j++)
		{
			if(mat[j][i] != ' ' && c == '\0') 
			{
				c = mat[j][i];
				continue;
			}
			if(mat[j][i] == c) score++;
		}
	}
	printf("%d\n", score);
    return 0;
}