304773: CF910C. Minimum Sum

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Minimum Sum

题意翻译

Petya 有一个长度为n的正整数序列 $a_{1},a_{2},...,a_{n}$。他的朋友Vasya 想要捉弄他,Vasya用一个字母替换了Petya 的号码中的所有数字。 他用小写字母‘a’到‘j’中的一个字母替换了所有数字 0,用另一个字母替换了所有 1,依次类推。对于不同的两个数字,Vasya 用‘a’到‘j’中不同的字母。 你的任务是还原 Petya 的序列。还原得到的数字应是没有前导零(数字开头没有零)的正整数。由于可能有多种方式实现,所以要求恢复后的序列总和最小。保证初始时序列中数字没有前导零。 输入格式: 第一行包含一个数字n。 之后的每一行包含一个由小写字母‘a’到‘j’构成非空字符串,每个字符串长度不超过六个字符。 输出格式: 恢复后的序列的和的最小值。保证有解。 Translated by Fowany

题目描述

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.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=1000 $ ) — 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.

输出格式


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.

输入输出样例

输入样例 #1

3
ab
de
aj

输出样例 #1

47

输入样例 #2

5
abcdef
ghij
bdef
accbd
g

输出样例 #2

136542

输入样例 #3

3
aa
jj
aa

输出样例 #3

44

说明

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] $ .

Input

题意翻译

Petya 有一个长度为n的正整数序列 $a_{1},a_{2},...,a_{n}$。他的朋友Vasya 想要捉弄他,Vasya用一个字母替换了Petya 的号码中的所有数字。 他用小写字母‘a’到‘j’中的一个字母替换了所有数字 0,用另一个字母替换了所有 1,依次类推。对于不同的两个数字,Vasya 用‘a’到‘j’中不同的字母。 你的任务是还原 Petya 的序列。还原得到的数字应是没有前导零(数字开头没有零)的正整数。由于可能有多种方式实现,所以要求恢复后的序列总和最小。保证初始时序列中数字没有前导零。 输入格式: 第一行包含一个数字n。 之后的每一行包含一个由小写字母‘a’到‘j’构成非空字符串,每个字符串长度不超过六个字符。 输出格式: 恢复后的序列的和的最小值。保证有解。 Translated by Fowany

加入题单

上一题 下一题 算法标签: