#P7435. [2017年杭电多校]Balala Power!
[2017年杭电多校]Balala Power!
Balala Power!
Problem Description
Mr. Tang has strings consisting of lowercase English letters. Assign the letters distinct digits from to , and interpret each string as an integer in base .
Choose one common assignment for all strings to maximize their sum. The resulting numbers must have no leading zeros, except that a number consisting of the single digit 0 is allowed. It is guaranteed that at least one letter does not appear at the beginning of any input string.
Output the maximum sum modulo . Maximize the actual integer sum before taking the modulus.
Input
The input contains multiple test cases, ending at EOF. There is no leading test case count.
For each case, the first line contains an integer , where .
Each of the next lines contains a nonempty lowercase string , with and for this case.
Output
For each case, output one line in the format Case #x: y, where is the case number starting from , and is the maximum sum modulo .
样例输入1
1
a
2
aa
bb
3
a
ba
abc
样例输出1
Case #1: 25
Case #2: 1323
Case #3: 18221
Source
2017 Multi-University Training Contest - Team 1