ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

ICPC UrFU Contest Qualifier 2026

About     Problems     Submit solution     Judge status     Standings
Contest is over

C. Problems for the Enthusiasts

Time limit: 0.5 second
Memory limit: 256 MB
Three teammates take part in a well-known programming contest. They want to solve one problem as fast as possible. First, someone must read the problem. For each teammate, we know how much time they need to read it. Then someone must come up with a solution. For each teammate, we know how much time they need for this. But if this is not the person who read the problem, the reader needs extra time to explain the statement to them. The last step is writing the code. Again, for each teammate, we know how much time they need. But if the code is written by someone else, not by the person who came up with the solution, the author of the idea needs time to explain the solution to the one who writes the code.
Using all this information, find the minimum time in which the team can submit the problem. Assume that the judging system works instantly and no debugging is needed after the submission

Input

The first line contains 3 integers x1, x2, x3 (1 ≤ x1, x2, x3 ≤ 109) — the time each teammate needs to read the problem.
The second line contains 3 integers y1, y2, y3 (1 ≤ y1, y2, y3 ≤ 109) — the time each teammate needs to come up with the solution.
The third line contains 3 integers z1, z2, z3 (1 ≤ z1, z2, z3 ≤ 109) — the time each teammate needs to write the code.
The next 3 lines contain 3 integers each — matrix b (0 ≤ bij ≤ 109, 1 ≤ i, j ≤ 3). bij denotes the time needed for teammate i to explain the statement to teammate j. It is guaranteed that bii = 0 for all 1 ≤ i ≤ 3, and also bij > 0 for all 1 ≤ i, j ≤ 3, i ≠q j.
The next 3 lines contain 3 integers each — matrix c (0 ≤ cij ≤ 109, 1 ≤ i, j ≤ 3). cij denotes the time needed for teammate i to explain the solution to teammate j. It is guaranteed that cii = 0 for all 1 ≤ i ≤ 3, and also cij > 0 for all 1 ≤ i, j ≤ 3, i ≠q j.

Output

Print a single integer — the answer to the problem.

Sample

inputoutput
1 2 3
2 1 3
3 2 1
0 1 1
1 0 1
1 1 0
0 1 1
1 0 1
1 1 0
5
Problem Author: Yackov Malin
Problem Source: The 2026 ICPC UrFU Qualification