Problem F
The Triangle Game
In the triangle game, you start with six triangles numbered on each edge, as shown in the example figure. You can slide and rotate the triangles so they form a hexagon, but the hexagon is only legal if edges common to two triangles have the same number on them. You may not flip any triangle over. Two legal hexagons formed from the six triangles are illustrated below.
The score for a legal hexagon is the sum of the numbers on the outside six edges.
Your problem is to find the highest score that can be achieved with any six particular triangles.
![\includegraphics[height=2in]{tri.png}](/problems/trianglegame/file/statement/en/img-0001.png)
Example of six triangles numbered on edges.
![\includegraphics[height=2in]{hex.png}](/problems/trianglegame/file/statement/en/img-0002.png)
Two legal hexagons formed from the six triangles.
Input
The input file will contain one or more data sets. Each data set is a sequence of six lines, each containing three integers from 1 to 100 separated by spaces. Each line contains the numbers on the edges of a triangle in clockwise order. Data sets are separated by a line containing only an asterisk (*). The last data set is followed by a line containing only a dollar sign ($).
Output
For each input data set, output a line containing only the word “none” if there are no legal hexagons, or the highest score if there is at least one legal hexagon.
| Sample Input 1 | Sample Output 1 |
|---|---|
1 4 20 3 1 5 50 2 3 5 2 7 7 5 20 4 7 50 $ |
152 |
| Sample Input 2 | Sample Output 2 |
|---|---|
10 1 20 20 2 30 30 3 40 40 4 50 50 5 60 60 6 10 $ |
21 |
| Sample Input 3 | Sample Output 3 |
|---|---|
10 1 20 20 2 30 30 3 40 40 4 50 50 5 60 10 6 60 $ |
none |
