## Problem

Consider a “word” as any sequence of capital letters A-Z (not limited to just “dictionary words”). For any word with at least two different letters, there are other words composed of the same letters but in a different order (for instance, “STATIONARILY”/“ANTIROYALIST”, which happen to both be dictionary words; for our purposes “AAIILNORSTTY” is also a “word” composed of the same letters as these two).

We can then assign a number to every word, based on where it falls in an alphabetically sorted list of all words made up of the same group of letters. One way to do this would be to generate the entire list of words and find the desired one, but this would be slow if the word is long.

Given a word, return its number. Your function should be able to accept any word $25$ letters or less in length (possibly with some letters repeated), and take no more than $500$ milliseconds to run. To compare, when the solution code runs the $27$ test cases in JS, it takes $101$ms.

For very large words, you’ll run into number precision issues in JS (if the word’s position is greater than $2^{53}$). For the JS tests with large positions, there’s some leeway ($.000000001\%$). If you feel like you’re getting it right for the smaller ranks, and only failing by rounding on the larger, submit a couple more times and see if it takes.

Python, Java and Haskell have arbitrary integer precision, so you must be precise in those languages (unless someone corrects me).

C# is using a long, which may not have the best precision, but the tests are locked so we can’t change it.

## Sample

Sample words, with their rank:

## Solution

$$w = w_1w_2\ldots w_n$$

1. $v_1 < w_1​$：那么很显然，无论$v_2v_3\ldots v_n​$是怎样的排列，都有$v < w​$，这样的$v​$的个数是

$$\sum_{a\in A \land a < w_1} permutations(B - \lbrace a\rbrace)$$

2. $v_1 = w_1$：那么问题就变成了求$w’ = w_2,w_3\ldots w_n$排第几的问题，递归求解

$$permutations(B) = \frac{n!}{\prod_{a\in A}\text{count}(w,a)}$$