6072: 特殊任务

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述


特工智能海狸在ABBYY的一个秘密研究部门工作。他在那里工作了很长时间,对自己的工作很满意,因为这让他可以在最好的餐厅吃饭,并在那里订购最昂贵和最具异国情调的木材类型。
内容特工有一个重要的任务:获得英国科学家对英语的最新研究。这些开发被编码并存储在一个大保险箱中。海狸的牙齿足够结实,因此当局保证,到达该地点后,海狸打开保险箱不会有任何问题。
他完成了白杨树枝,离开了这项重要的任务。当然,海狸到达该地点没有任何问题,但唉。他不能用他强壮的大牙齿打开保险箱。此时,智能海狸接到总部的电话,得知没有必要用牙齿打开保险箱,因为可靠的消息来源已发送以下信息:保险箱代码由数字组成,没有前导零。还有一个特殊的提示,可以用来打开保险箱。提示是具有以下结构的字符串 s:
如果 si = “?”,则安全代码中第 i 位的数字可以是任何值(介于 0 到 9 之间,包括 0 到 9);
如果 si 是一个数字(介于 0 到 9 之间,包括 0 到 9),则表示在代码中的位置 i 上有数字 SI;
如果字符串包含从“A”到“J”的字母,则具有相同字母的所有位置必须包含相同的数字,并且具有不同字母的位置必须包含不同的数字。
安全代码的长度与提示的长度一致。
例如,提示“?JGJ9“有这样的匹配安全代码变体:”51919“、”55959“、”12329“、”93539“等,并且有错误的变体,如:”56669“、”00111“、”03539“和”13666”。
收到这些信息后,当局改变了计划,要求特工安静而温和地工作,不要试图通过机械手段打开保险箱,并尝试使用给定的提示找到密码。
在一所特工学校,聪明的海狸是他排中最快找到这种保险箱的密码的人,但现在他不是那种状态:岁月会付出代价......帮助他确定保险箱代码的可能变体的数量,与给定的提示相匹配。收到这些信息后,知道自己输入代码的速度,聪明的海狸将能够确定他是否有时间在他最喜欢的电视频道上观看今晚的节目“海狸在路上”,或者他应该工作一个不眠之夜......

Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
  • if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
  • if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
  • if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
  • The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s − the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
  • 1≤|s|≤5.
The input limits for scoring 100 points are (subproblems A1+A2):
  • 1≤|s|≤105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100

输入格式

第一行包含字符串 s − 安全代码的提示。字符串 s 由以下字符组成:?、0-9、A-J。保证字符串 s 的第一个字符不等于字符 0。
得分 30 分的输入限制为(子问题 A1):
1≤|s|≤5.
得分 100 分的输入限制为(子问题 A1+A2):
1≤|s|≤10^5。
这里|s|表示字符串 s 的长度。

输出格式

打印与给定提示匹配的代码数。
例子
输入
AJ
输出
81
输入
1?AA
输出
100

输入样例 复制

AJ

输出样例 复制

81