Problem
Many students live in a hostel. Hostel — it's a big world of fun and opportunities, but it has its downsides.
There is only one shower in the hostel, and of course, there are more people who want to take a shower in the morning. Therefore, every morning there is a queue of five people in front of the dorm shower.
As soon as the shower opens, the first person in line enters the shower. After some time, when the first one comes out of the shower, the next one enters the shower. This process continues until everyone in the queue has taken a shower.
Shower — it’s not a fast business, so while waiting, students communicate. At each moment of time, students communicate in pairs: (2i - 1)-th person in the queue (currently) communicates with (2i)-m.
Let's consider this process in more detail. Let's denote the people by numbers from 1 to 5. Let the queue initially look like 23154 (person 2 is at the head of the queue). Then before opening the soul 2 communicates with 3, 1 communicates with 5, 4 does not communicate with anyone. Then 2 goes into the shower. While 2 is showering, 3 and 1 are chatting, and 5 and 4 are chatting. Then 3 enters the shower. While 3 is showering, 1 and 5 are talking, 4 is not talking to anyone. Then 1 enters the shower, and while he takes a shower, 5 and 4 communicate. Then 5 goes into the shower and then 4 goes into the shower.
It is known that if students i and j communicate, then student i's joy increases by g
i, j, and student j's joy increases by g
j, i. You need to find such an initial order of students in the queue that the total joy of all students in the end is maximum. It is worth noting that some students can communicate several times. In the example above, students 1 and 5 are chatting while they wait for the shower to open and also while 3 takes a shower.
Input:
The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line denotes g
i, j (0 ≤ g
i, j ≤ 10
5). It is guaranteed that g
i, j = 0 for all i.
Consider the students numbered from 1 to 5.
Output:
Print a single integer — the maximum possible total joy of students.
Examples:
Input |
Output |
0 0 0 0 9
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
7 0 0 0 0
| 32 |
0 43 21 18 2
3 0 21 11 65
5 2 0 1 4
54 62 12 0 99
87 64 81 33 0
| 620 |