atcoder#ABC268F. [ABC268F] Best Concatenation
[ABC268F] Best Concatenation
Score : points
Problem Statement
You are given strings consisting of digits from 1
through 9
and the character X
.
We will choose a permutation of to construct a string , where denotes a concatenation of strings.
Then, we will calculate the "score" of the string (where denotes the length of ). The score is calculated by the following steps, starting from the initial score :
- Add point to the score as many times as the number of integer pairs such that ,
X
, and1
. - Add points to the score as many times as the number of integer pairs such that ,
X
, and2
. - Add points to the score as many times as the number of integer pairs such that ,
X
, and3
. - Add points to the score as many times as the number of integer pairs such that ,
X
, and9
.
Find the maximum possible score of when can be chosen arbitrarily.
Constraints
- is an integer.
- is a string of length at least consisting of digits from
1
through9
and the characterX
. - The sum of lengths of is at most .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1X3
59
XXX
71
When , we have XXX1X359
.
Then, the score of is calculated as follows:
- there are integer pairs such that ,
X
, and1
; - there are integer pairs such that ,
X
, and3
; - there are integer pairs such that ,
X
, and5
; - there are integer pairs such that ,
X
, and9
.
Therefore, the score of is $1 \times 3 + 3 \times 4 + 5 \times 4 + 9 \times 4 = 71$, which is the maximum possible value.
10
X63X395XX
X2XX3X22X
13
3716XXX6
45X
X6XX
9238
281X92
1XX4X4XX6
54X9X711X1
3010