P17822 [COCI 2026/2027 #1] Kockice
Description
Mr. Malnar is playing a game with dice. The rules are simple. First, each player rolls any number of dice. Then, the player may choose to flip **at most $k$ dice** so that the sides opposite the ones currently facing up become visible, or choose not to flip any dice at all. It is well known that the numbers on any pair of opposite sides of a die **add up to $7$** (e.g., $2$ and $5$ are on opposite sides). Each player's score is the sum of the numbers showing on the dice after all flips have been made. The player with the highest score wins.
Mr. Malnar really wants to win, so he has decided to cheat. He secretly took a photo of the dice on the table and sent it to you, asking for help. The photo has dimensions $3\times n$. Since the dice are the same colour as the table, their outlines cannot be seen. Fortunately, the dots on the dice are clearly visible. Each dot is represented by an `o`, while each empty space is represented by a `-`. The six sides of a die are represented in the photo as shown below:
```text
--- o-- o-- o-o o-o o-o
-o- --- -o- --- -o- o-o
--- --o --o o-o o-o o-o
1 2 3 4 5 6
```
Quick! Mr. Malnar needs your help! What is the maximum score he can achieve?
Input Format
The first line contains two natural numbers, $n$ ($3\le n\le 1000$) and $k$ ($0\le k\le 1000$), representing the width of the photo and the maximum number of dice Mr. Malnar may flip.
Each of the next three lines contains a string of length $n$, consisting only of `-` and `o`, representing the photo you received. The photo will always display **at least one rolled die**.
The sides of the dice will appear only in the orientations shown in the statement, i.e., they **cannot be rotated**. The photo will always represent a **valid arrangement of dice** that could result from rolling them onto the table.
Output Format
In the first and only line, write one number - the maximum score Mr. Malnar can achieve.
Explanation/Hint
#### Clarification of the first example
Mr. Malnar rolled one die and it showed the number $4$. Since $k=1$, Mr. Malnar can flip over the one die. The number opposite of $4$ is $3$ (because $4+3=7$) so if he flips the die he will get a score of $3$. However, it is optimal to not flip the die because the sum is bigger when the dice shows $4$ than when the dice shows $3$.
#### Clarification of the second example
Mr. Malnar rolled two dice and got the numbers $5$ and $3$. He can flip up to four dice; however, there are only two dice on the table so he can either flip one die, flip both of them, or not flip any. If he doesn't flip any die, he will get a score of $5+3=8$. If he only flips the die showing $5$, its value will change to $2$ making his score $2+3=5$. If he only flips the die showing $3$, its value will change to $4$ making his score $4+5=9$. If he flips both dice, they will show the numbers $2$ and $4$ making his score $6$. Therefore, the maximum score he can achieve is $9$ - this can be achieved by flipping the die showing $3$.
#### Clarification of the third example
Mr. Malnar rolled four dice and got the value $3$, $6$, $1$ and $2$, in that order as seen on the photo. He can flip up to two of them. A maximum score is achieved if he flips the die showing $1$ (which turns into $6$) and the die showing $2$ (which turns into $5$). This changes his score from $3+6+1+2=12$ to $3+6+6+5=20$.
#### Scoring
| Subtask | Points | Constraints |
| --- | --- | --- |
| 1 | 9 | $n=3$ |
| 2 | 10 | All the dice show either $1$ or $3$. |
| 3 | 13 | $k=0$ |
| 4 | 18 | No additional constraints. |