시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 1 0 0 0.000%

문제

Figure 1:Each of the 26 lowercase letters and its value

Letter games are popular at home and on television. In one version of the game, every letter has a value, and you collect letters to form one or more words giving the highest possible score. Unless you have 'a way with words', you will try all the words you know, sometimes looking up the spelling, and then compute the scores. Obviously, this can be done more accurately by computer.

Given the values in Figure 1, a list of English words, and the letters collected: find the highest scoring words or pairs of words that can be formed.

입력

The first line with a string of lowercase letters (from 'a' to 'z'): the letters collected. The string consists of at least 3 and at most 7 letters in arbitrary order.

From the second line, there is a 'dictionary' consists of at most 40,000 lines. At the end of this file is a line with a single period ('.'). Each of the other lines contains a string of at least 3 and at most 7 lowercase letters. The dictionary is sorted alphabetically and contains no duplicates.

출력

On the first line of output, your program should write the highest score (Subtask A), and on each of the following lines, all the words and/or word pairs from dictionary with this score (Subtask B). A letter must not occur more often in an output line than in the input line. Use the letter values given in Figure 1.

When a combination of two words can be formed with the given letters, the words should be printed on the same line separated by a space. Do not duplicate pairs; for example, 'rag prom' and 'prom rag' are the same pair, therefore only one of them should be written. A pair in an output line may consist of two identical words.

예제 입력 1

prmgroa
profile
program
prom
rag
ram
rom
.

예제 출력 1

24
program
prom rag