| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 79 | 12 | 6 | 8.955% |
Elisabeth the Efficient, a famous magician, was called by Emmanuel the Empowered, the mighty lord of the East Embarkmentlands, to enhance the magical protection of his enchanted fortress.
After arriving at the site and studying the structure of the fortress and the existing spells that protect its integrity, Elisabeth found out the following properties of the spell to design:
For instance, if $s=$ABC and
$$\begin{equation*} d = \left(\begin{array}{ccc} 1 & -1 & 2 \\ - & 2 & -3 \\ - & - & 1 \end{array}\right) \end{equation*}$$
then a spell A has strength 1, ABC has strength 2, and AC has strength 4.
However, the problem appeared to be too difficult to Elisabeth, because she has only little experience of working with computers. Can you help her to find the strongest spell?
The first line of the input file contains the string $s,ドル that will not be empty and may contain only big Latin letters or symbols !, ?, @, *. All symbols will be pairwise different. Its length $n = |s|$ will thus not exceed 30.
The following $n$ lines contain the description of the matrix $d$. The $i$-th of these lines (1ドル \le i \le n$) contains $n + 1 - i$ integer numbers $d_{i,i},ドル $d_{i,i+1},ドル $\ldots,ドル $d_{i,n},ドル separated by single whitespace symbols. These numbers do not exceed 10ドル^6$ by the absolute values.
Output the length of the strongest spell in the first line. In the second line, output the spell itself. If there are multiple equally strongest spells, output any of them.
ABC 1 -1 2 2 -3 1
2 AC
@ -1
0
ABDFHORSU!? 1 -1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 -1 1 1 1 1 1 -1 1 1 1 1 -1 1 1 1 -1 1 1 -1 1 -1 -1
9 FUSRODAH!