"Kronecker's Knumbers" is a small company that makes plastic digits for signs, the kind used on theater marquees and gas station price displays. The owner and sole employee, Klyde Kronecker, records how many of each digit he has used in an inventory book. Say he has just finished a sign carrying the telephone number "5553141". In one column he writes 5553141, and in the next he lists the digits he used: two 1s, one 3, one 4, and three 5s. Digits he did not use never appear. He writes this in condensed form as 21131435.
The other day Klyde filled an order for 31123314 and found that the inventory of this number is the number itself: three 1s, one 2, three 3s, and one 4. He calls such a number self-inventorying. He wants to know which numbers are self-inventorying, and which ones reach a self-inventorying number by repeating the inventory operation defined below.
Given a non-negative integer n, its inventory is the integer formed by concatenating c1d1c2d2⋯ckdk, where every ci is a positive integer, every di is a digit, and 0≤d1<d2<⋯<dk≤9. For each digit d that appears in n there is an i with d=di, and that d occurs exactly ci times in the decimal representation of n. For 5553141 we set c1=2, d1=1, c2=1, d2=3, and so on, giving 21131435. The inventory of 1000000000000 is 12011, twelve 0s and one 1.
n is self-inventorying if n equals its own inventory. It becomes self-inventorying after j steps if j (j≥1) is the smallest number for which the j-th iterated inventory of n is self-inventorying. The inventory of 21221314 is 31321314, the inventory of 31321314 is 31123314, and 31123314 is self-inventorying, so 21221314 becomes self-inventorying after 2 steps.
n enters an inventory loop of length k if k (k≥2) is the smallest number for which the j-th iterated inventory equals the (j+k)-th iterated inventory for some j≥0. The inventory of 314213241519 is 412223241519, and the inventory of 412223241519 is 314213241519 again, so 314213241519 enters an inventory loop of length 2, with j=0.
Write a program that reads a sequence of non-negative integers and, for each value, reports whether it is self-inventorying, becomes self-inventorying after j steps, enters an inventory loop of length k, or fits none of these after 15 applications of the inventory operation.
The input gives one non-negative integer per line. Each integer has at most 80 digits and no extra leading zeros. The last line holds the terminating value -1, which is not part of the data.
For each input value n, print exactly one of the four lines below. Echo n exactly as it appears in the input. j is a positive integer and k is an integer greater than 1.
n is self-inventorying
n becomes self-inventorying after j steps
n enters an inventory loop of length k
n can not be classified after 15 iterations
The inventory operation is applied at most 15 times, so only n0=n through n15 are examined. If none of the first three conditions shows up among those values, print the fourth line. The word steps is used even when j=1.