using System;
using System.IO;
using System.Text;

namespace Gušter
{
	internal class Program
	{
		public static string Reverse(string s)
		{
			char[] charArray = s.ToCharArray();
			Array.Reverse(charArray);
			return new string(charArray);
		}

		static void Guster(string str, ref int k, char c, char[] chars, int[] ponavljanja)
        {
			int r = 0;
			int i = str.IndexOf(c), j = str.IndexOf(c, i + 1), iF = str.IndexOf(c), jF = str.Length;
			string[] strings = new string[1];
			strings[0] = str;
			while(true)
            {
				if ((j - i) % 2 == 1)
				{
					r++;
					Array.Resize(ref strings, strings.Length + 1);
					if (i + 1 < strings[strings.Length - 2].Length)
					{
						strings[strings.Length - 1] = strings[strings.Length - 2].Substring(i + 1);
						strings[strings.Length - 2] = strings[strings.Length - 2].Substring(0, i + 1);
					}
					else break;
					if (strings.Length - 2 % 2 == 1) Reverse(strings[strings.Length - 2]);
					jF = i;
					i = j;
					j = str.IndexOf(c, i + 1);
				}
                else
                {
					j = str.IndexOf(c, j + 1);
                }
			Provera:
                if (j == -1)
                {
					i = str.IndexOf(c, i + 1);
					if (i == -1) break;
					j = str.IndexOf(c, i + 1);
					goto Provera;
				}
			}
			if (strings.Length - 1 % 2 == 1) Reverse(strings[strings.Length - 1]);
			if (string.IsNullOrEmpty(strings[strings.Length - 1])) Array.Resize(ref strings, strings.Length - 1);
			int n = strings.Length;
            if (strings.Length > 1)
            {
				for (int x = 0; x < n; x++)
				{
					if (ponavljanja[x] > 1)
					{
						i = strings[0].IndexOf(chars[x]);
						j = strings[1].IndexOf(chars[x]);
						for (int y = 2; y < strings.Length; y++)
						{
							if(i!=-1 && j != -1)
                            {
								if (y % 2 == 0 && strings[y - 1].Length - i == strings[y].Length - j)
								{
									r++;
									i = strings[y - 1].IndexOf(chars[x], i + 1);
									j = strings[y].IndexOf(chars[x], j + 1);
									if (i == -1 || j == -1) break;
								}
								else if (y % 2 == 1 && i == j)
								{
									r++;
									i = strings[y - 1].IndexOf(chars[x], i + 1);
									j = strings[y].IndexOf(chars[x], j + 1);
									if (i == -1 || j == -1) break;
								}
								else
								{
									if (j < strings[y].Length - 1) j = strings[y].IndexOf(chars[x], j + 1);
									Provera:
									if (j == -1)
									{
										i = str.IndexOf(c, i + 1);
										if (i == -1) break;
										j = str.IndexOf(c, i + 1);
										goto Provera;
									}
								}
                            }
                            else
                            {
								i = strings[y - 1].IndexOf(chars[x]);
								j = strings[y].IndexOf(chars[x]);
							}
						}
					}
				}
			}
			int rr1 = 0, rr2 = 0;
            if (iF > 1 && r>0)
            {
				for (i = 0; i < chars.Length; i++)
				{
					if (ponavljanja[i] > 1)
					{
						int[] ponavaljanja_copy = new int[ponavljanja.Length];
						Array.Copy(ponavljanja, 0, ponavaljanja_copy, 0, ponavaljanja_copy.Length);
						ponavaljanja_copy[new string(chars).IndexOf(c)] = 1;
						Guster(str.Substring(0, iF), ref rr1, chars[i], chars, ponavaljanja_copy);
					}
				}
			}
			if (str.Length - jF - 1 > 1 && r > 0)
			{
				for (i = 0; i < chars.Length; i++)
				{
					if (ponavljanja[i] > 1)
					{
						int[] ponavaljanja_copy = new int[ponavljanja.Length];
						Array.Copy(ponavljanja, 0, ponavaljanja_copy, 0, ponavaljanja_copy.Length);
						ponavaljanja_copy[new string(chars).IndexOf(c)] = 1;
						Guster(str.Substring(jF, str.Length - jF - 1), ref rr2, chars[i], chars, ponavaljanja_copy);
					}
				}
			}
			r += rr1 + rr2;
			if (k < r) k = r;
        }

		static void Main(string[] args)
		{
			Console.SetIn(new StreamReader(Console.OpenStandardInput(), Encoding.UTF8, false, 24016));
			string str = Console.ReadLine();
			char[] chars = new char[0];
			int[] ponavljanja = new int[0];
			int k = 0;
			for(int i = 0; i < str.Length; i++)
            {
				bool b = false;
				for(int j=0; j < chars.Length; j++)
                {
                    if (str[i] == chars[j])
                    {
						b = true;
						ponavljanja[j]++;
						break;
                    }
                }
				if (!b)
                {
					Array.Resize(ref chars, chars.Length + 1);
					chars[chars.Length - 1] = str[i];
					Array.Resize(ref ponavljanja, chars.Length);
					ponavljanja[ponavljanja.Length - 1] = 1;
				}
            }
			for (int i = 0; i < chars.Length; i++)
			{
				if (ponavljanja[i] > 1)
				{
					Guster(str, ref k, chars[i], chars, ponavljanja);
				}
			}
			Console.Write(k);
		}
	}
}