#include char buf[100]; int may[50][50]; int n, r; long long total; long long choices_to[100]; int valid(char *nbr, int ln, char *rdx, int lr, int fst) { int i; if (*nbr == '0') return (ln == 1) && !fst; if (ln > lr) return 0; if (ln < lr) return 1; for (i = 0; i < ln; i++) if (nbr[i] > rdx[i]) return 0; else if (nbr[i] < rdx[i]) return 1; return 0; } long long comp(int radix) { int i, j; if (buf[radix] == '0') return 0; for (i = 0; i < radix; i++) for (j = i; j < radix; j++) may[i][j] = valid (buf + i, j - i + 1, buf + radix, n - radix, (i == 0) && ! (radix == 1)); choices_to[0] = 1; for (i = 1; i <= radix; i++) { choices_to[i] = 0; for (j = 0; j < i; j++) if (may[j][i - 1]) choices_to[i] += choices_to[j]; } return choices_to[radix]; } int main(void) { while (1) { scanf ("%s", buf); if (*buf == '#') return 0; total = 0; n = strlen (buf); for (r = 1; r < n; r++) total += comp(r); if (!total) printf("The code %s is invalid.\n", buf); else printf ("The code %s can represent %lld numbers.\n", buf, total); } }