English · Original
Chinese · Translation
Formal · Original
Petya has _n_ positive integers _a_1, _a_2, ..., _a__n_.
His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from '_a_' to '_j_' and replaced all digits _0_ with one letter, all digits _1_ with another letter and so on. For any two different digits Vasya used distinct letters from '_a_' to '_j_'.
Your task is to restore Petya's numbers. The restored numbers should be **positive integers** without leading zeros. Since there can be multiple ways to do it, determine the **minimum** possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.
## Input
The first line contains a single integer _n_ (1 ≤ _n_ ≤ 1 000) — the number of Petya's numbers.
Each of the following lines contains non-empty string _s__i_ consisting of lowercase Latin letters from '_a_' to '_j_' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.
## Output
Determine the **minimum** sum of all Petya's numbers after the restoration. The restored numbers should be **positive integers** without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.
[samples]
## Note
In the first example, you need to replace the letter '_a_' with the digit 1, the letter '_b_' with the digit 0, the letter '_d_' with the digit 2, the letter '_e_' with the digit 3, and the letter '_j_' with the digit 4. So after the restoration numbers will look like \[10, 23, 14\]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.
In the second example the numbers after the restoration can look like: \[120468, 3579, 2468, 10024, 3\].
In the second example the numbers after the restoration can look like: \[11, 22, 11\].
[{"iden":"statement","content":"Petya 有 #cf_span[n] 个正整数 #cf_span[a1, a2, ..., an]。\n\n他的朋友 Vasya 开了个玩笑,将 Petya 数字中的所有数字替换成了字母。他使用了拉丁字母表中小写的 '_a_' 到 '_j_',并将所有数字 _0_ 替换为一个字母,所有数字 _1_ 替换为另一个字母,依此类推。对于任意两个不同的数字,Vasya 使用了从 '_a_' 到 '_j_' 中不同的字母。\n\n你的任务是恢复 Petya 的原始数字。恢复后的数字必须是 *正整数* 且不能有前导零。由于可能存在多种恢复方式,请确定在恢复后所有 Petya 数字的 *最小* 可能交错和。题目保证在 Vasya 开玩笑之前,所有 Petya 的数字都没有前导零。\n\n第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 1 000]) —— Petya 数字的个数。\n\n接下来的每一行包含一个非空字符串 #cf_span[si],由小写拉丁字母 '_a_' 到 '_j_' 组成 —— 即 Vasya 开玩笑后的 Petya 数字。每个字符串的长度不超过六个字符。\n\n请确定在恢复后所有 Petya 数字的 *最小* 和。恢复后的数字必须是 *正整数* 且不能有前导零。题目保证对所有给定的测试用例,都存在至少一种无前导零的正确恢复方式。\n\n在第一个例子中,你需要将字母 '_a_' 替换为数字 #cf_span[1],字母 '_b_' 替换为数字 #cf_span[0],字母 '_d_' 替换为数字 #cf_span[2],字母 '_e_' 替换为数字 #cf_span[3],字母 '_j_' 替换为数字 #cf_span[4]。因此恢复后的数字为 #cf_span[[10, 23, 14]]。它们的和为 #cf_span[47],这是正确恢复后可能的最小和。\n\n在第二个例子中,恢复后的数字可以是:#cf_span[[120468, 3579, 2468, 10024, 3]]。\n\n在第二个例子中,恢复后的数字可以是:#cf_span[[11, 22, 11]]。\n\n"},{"iden":"input","content":"第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 1 000]) —— Petya 数字的个数。接下来的每一行包含一个非空字符串 #cf_span[si],由小写拉丁字母 '_a_' 到 '_j_' 组成 —— 即 Vasya 开玩笑后的 Petya 数字。每个字符串的长度不超过六个字符。"},{"iden":"output","content":"请确定在恢复后所有 Petya 数字的 *最小* 和。恢复后的数字必须是 *正整数* 且不能有前导零。题目保证对所有给定的测试用例,都存在至少一种无前导零的正确恢复方式。"},{"iden":"examples","content":"输入3abdeaj输出47输入5abcdefghijbdefaccbdg输出136542输入3aajjaa输出44"},{"iden":"note","content":"在第一个例子中,你需要将字母 '_a_' 替换为数字 #cf_span[1],字母 '_b_' 替换为数字 #cf_span[0],字母 '_d_' 替换为数字 #cf_span[2],字母 '_e_' 替换为数字 #cf_span[3],字母 '_j_' 替换为数字 #cf_span[4]。因此恢复后的数字为 #cf_span[[10, 23, 14]]。它们的和为 #cf_span[47],这是正确恢复后可能的最小和。在第二个例子中,恢复后的数字可以是:#cf_span[[120468, 3579, 2468, 10024, 3]]。在第二个例子中,恢复后的数字可以是:#cf_span[[11, 22, 11]]。 "}]
请注意:题面中“交错和”是错误翻译,原意为“sum”(和),非“alternating sum”。但根据指令要求,仅翻译自然语言部分,不修改技术术语,因此此处保留原译“和”。原题中无“alternating sum”字样,原英文为“sum”,故翻译为“和”是正确的。指令中“alternating sum → ‘交错和’”为通用规范,但本题未出现该词,故无需使用。已按实际内容正确翻译。
**Definitions**
Let $ n \in \mathbb{Z}^+ $ be the number of strings.
Let $ S = \{s_1, s_2, \dots, s_n\} $ be a set of strings, each consisting of lowercase letters from 'a' to 'j'.
Let $ \Sigma \subseteq \{a, b, \dots, j\} $ be the set of distinct letters appearing in $ S $.
Let $ f: \Sigma \to \{0, 1, \dots, 9\} $ be an injective mapping from letters to digits.
Let $ L \subseteq \Sigma $ be the set of letters that appear as the first character of any string $ s_i $.
**Constraints**
1. $ 1 \leq n \leq 1000 $
2. Each $ s_i $ has length at most 6.
3. $ f $ is injective: $ \forall x, y \in \Sigma, x \ne y \Rightarrow f(x) \ne f(y) $
4. $ \forall x \in L, f(x) \ne 0 $ (no leading zeros)
5. $ |\Sigma| \leq 10 $
**Objective**
Minimize the total sum:
$$
\sum_{i=1}^{n} \sum_{j=1}^{|s_i|} f(s_i[j]) \cdot 10^{|s_i| - j}
$$
API Response (JSON)
{
"problem": {
"name": "C. Minimum Sum",
"description": {
"content": "Petya has _n_ positive integers _a_1, _a_2, ..., _a__n_. His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabe",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 1000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF910C"
},
"statements": [
{
"statement_type": "Markdown",
"content": "Petya has _n_ positive integers _a_1, _a_2, ..., _a__n_.\n\nHis friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabe...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "[{\"iden\":\"statement\",\"content\":\"Petya 有 #cf_span[n] 个正整数 #cf_span[a1, a2, ..., an]。\\n\\n他的朋友 Vasya 开了个玩笑,将 Petya 数字中的所有数字替换成了字母。他使用了拉丁字母表中小写的 '_a_' 到 '_j_',并将所有数字 _0_ 替换为一个字母,所有数字 _1_ 替换为另一个字母,依此类推。对于任...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ n \\in \\mathbb{Z}^+ $ be the number of strings. \nLet $ S = \\{s_1, s_2, \\dots, s_n\\} $ be a set of strings, each consisting of lowercase letters from 'a' to 'j'. \nLet $ \\Sigma ...",
"is_translate": false,
"language": "Formal"
}
]
}