题目描述
Problem Description
I was told to memorize a certain positive integer in base 10. The number has $ N $ digits and does not start with a $ 0 $.
Since it's an important number, I wrote it down twice in my notebook.
However, I'm not good at writing.
When I later read my notebook, I couldn't remember what some of the digits originally were.
The uncertain characters, at most $ 26 $ in total, will be represented by uppercase alphabets from A to Z. These characters originally were one of the digits from $ 0 $ to $ 9 $.
The same alphabet may appear multiple times in the written strings. If the same alphabet appears multiple times, they all originally represented the same digit. There may be alphabets that appear in both the first and second strings, and in that case, they also originally represented the same digit. Different alphabets may originally represent the same digit.
For example, if the first string in my notebook was 1XYX, the number I was supposed to memorize could be $1101\ (X = 1, Y = 0)$, $1111\ (X = 1, Y = 1)$, $1848\ (X = 8, Y = 4)$, etc. On the other hand, $1132\ (Y = 3)$ is not possible because X would then represent both $ 1 $ and $ 2 $.
Given the two strings written in my notebook, create a program to determine how many different numbers I could have been told to memorize.
Input Format
The input is given from the standard input in the following format:
$ N $ $ s_1 $ $ s_2 $
- The first line contains the number of digits $N\ (1 ≦ N ≦ 18)$ of the integer I was told to memorize.
- The second line contains the string $ s_1 $, which is the first string I wrote in my notebook. $ s_1 $ is exactly $ N $ characters long and consists only of uppercase alphabets and digits.
- The third line contains the string $ s_2 $, which is the second string I wrote in my notebook. $ s_2 $ is exactly $ N $ characters long and consists only of uppercase alphabets and digits.
- For all inputs used in the grading, at least one integer can be considered as the number I was told to memorize. This means that no matter how you assign digits to the alphabets, it will never result in both $ s_1 $ and $ s_2 $ having a leading $ 0 $ or representing different numbers.
Output Format
Output the number of different integers that could be the number I was told to memorize. The output should be a single line with a newline at the end.
Note that the output may not fit into a 32-bit integer.
Sample Input and Output
Sample Input #1
4
1XYX
1Z48
Sample Output #1
1
Sample Input #2
3
XXX
YYY
Sample Output #2
9
Sample Input #3
6
PRBLMB
ARC027
Sample Output #3
90
Notes/Hints
Partial Points
This problem has partial points.
- If you correctly solve the dataset where $ N ≦ 6 $, you will be awarded $ 30 $ points.
- If you correctly solve the dataset without additional constraints, you will be awarded an additional $ 70 $ points.
Sample Explanation 1
The only number that could be the one I was told to memorize is $1848\ (X=8, Y=4, Z=8)$.
Sample Explanation 2
Keep in mind that you cannot use 0 as the leading digit.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分