Hide

Problem B
Permutations

In CMPSC 360 you learn about permutations, which are all the different ways to make a list in which the order of the arrangement of objects matters. So, 1234 is different from 2431 However, the more difficult problems are permutations with restrictions. We would like to make the full list of all possible ways that a bunch of numbers can be arranged given specific restrictions.

Input

The first line will only have one integer, which will be the number of rules that will be given (or the number of lines to follow). The subsequent lines of the input will consist of all the different rules. They will be in the form *n*, where n is the restricted integer and the * can be any integer 0-9.

Output

A list of all the different permutations of integers, where each permutation is listed in the order that the rules are provided. The integer on the first line should be the number of lines of output.

Note: Assume that the rules themselves will not contain a space or any unexpected character. The restricted number will always be an integer.

Sample Input 1 Sample Output 1
2
7*
*5
20
70
71
72
73
74
75
76
77
78
79
05
15
25
35
45
55
65
75
85
95

Sample Input 2 Sample Output 2
1
*3

10
03
13
23
33
43
53
63
73
83
93

Please log in to submit a solution to this problem

Log in