// James Sexton
// Solution for 2007 World Finals Problem B: Containers.
import java.util.*;
import java.io.*;

public class containers
{
	public static void main(String[] args) throws IOException
	{
		// This array has an extra slot so we don't iterate off the end of it.
		int[] available = new int[27];
		int caseNum = 1;
		
		Scanner in = new Scanner(new File("containers.in"));
		String s = in.next();
		
		// Read till the end of input.
		while (!s.equals("end"))
		{
			int minStacks = 1;
			Arrays.fill(available, 0, 26, 1);
			
			// Go through the string
			for (int i = 0; i < s.length(); i++)
			{
				int index = s.charAt(i) - 'A';
				
				// Indicates which stack we can use for this letter.
				int stack = available[index];
				
				// Adjust our number of stacks, if necessary.
				minStacks = Math.max(minStacks, stack);
				
				// What we're doing here is that every letter that comes
				// after the one we've just placed would theoretically need
				// to go into a new stack. Thus, we add one to each of these
				// indexes to indicate that if we later read in one of these
				// letters, we won't be able to fit it in without a new stack.
				while (available[++index] == stack)
					available[index]++;
			}
			
			// Output the answer.
			System.out.format("Case %d: %d\n", caseNum, minStacks);
			caseNum++;
			s = in.next();
		}
	}
}
