A word addition is an addition such as 905 + 125 = 1030 in which every digit has been replaced by a letter.
For example, replacing 9 with A, 0 with C, 5 with M, 1 with I, 2 with B, and 3 with P turns the equation above into:
ACM + IBM = ICPC
For 905 + 125 = 1030, there are 4 different ways to turn the letters back into digits.
| Method | A | B | C | I | M | P |
|---|---|---|---|---|---|---|
| Method 1 | 9 | 2 | 0 | 1 | 5 | 3 |
| Method 2 | 9 | 3 | 0 | 1 | 5 | 4 |
| Method 3 | 9 | 6 | 0 | 1 | 5 | 7 |
| Method 4 | 9 | 7 | 0 | 1 | 5 | 8 |
Given a word addition, write a program that counts how many digit assignments make the equation hold. The assignment must satisfy all of the following conditions.
The input consists of several test cases. Each test case is given as follows.
These N words represent the equation (word 1) + (word 2) + ... + (word N-1) = (word N); that is, the last word equals the sum of all the preceding words.
N satisfies 2 < N < 13, the length of each word is greater than 0 and less than 9, and the number of distinct letters that appear in one test case is greater than 0 and less than 11.
The last line of the input contains a single 0, which is not processed.
For each test case, print on its own line the number of digit assignments that make the word addition hold.