
/*
jednoduche zjisteni poctu vyhovujicich zapisu
*/

#include <stdio.h>
#include <string.h>

#define MAX_DIGITS  40
#define ZERO  '0'

int numlen;
char number [MAX_DIGITS];
	/* given code and its length are stored here */

int cnt [MAX_DIGITS];
	/* cnt[i] tells how many possibilities are there to split first
	   'i' characters of the code to valid digits;
	   reused for every possible radix
	*/


int read_number (void)
{
	if ( scanf ("%s", number) < 1 )  return 0;
	if ( number[0] == '#' )  return 0;
	return numlen = strlen (number);
}


int one_radix (int r)
{
	int i, j;
	int n;
	n = numlen;

	/* radix cannot begin with zero */
	if ( number[n-r] == ZERO )
		return 0;

	/* a little piece of dynamic programming */
	cnt[0] = 1;
	for ( i = 1;  i <= n - r;  ++i )
	{
		cnt[i] = 0;
		for ( j = (i - r < 0) ? 0 : (i - r);  j < i;  ++j )
		{
			/* now check whether characters between indices
			   `i' (incl) and `j' (excl) form a valid digit
			   of the given radix
			*/

			/* cannot begin with zero unless it is a single character */
			if ( j+1 < i && number[j] == ZERO )  continue;

			/* the first digit cannot be zero if any other follow */
			if ( j == 0 && n-r > 1 && number[j] == ZERO )  continue;

			/* digit must be less than radix */
			if ( j + r == i )
				if ( strncmp (number + j, number + n-r, r) >= 0 )
					continue;

			/* it is ok, add the number of possible splits */
			cnt[i] += cnt[j];
		}
	}

	return cnt[n-r];
}


int main (void)
{
	int r, c;

	while ( read_number() > 0 )
	{
		c = 0;
		for ( r = 1;  r < numlen;  ++r )
			c += one_radix (r);
		if ( c )
			printf ("The code %s can represent "
					"%d numbers.\n", number, c);
		else
			printf ("The code %s is invalid.\n", number);
	}
	return 0;
}

