#c22706. 国家铁路
国家铁路
National Railway
Problem Description
dls's competitive-programming kingdom can be represented as a grid with rows and columns. We denote by the cell in the -th row from the north and the -th column from the west. Recently the citizens of this kingdom hope the king will build a railway.
Building a railway happens in two stages:
- Choose 2 different cells from all the cells, and build a train station on each of them. The cost to build a station on cell is .
- Build a rail between these two cells. Suppose the chosen cells are and ; the cost is .
dls's wish is to build a railway at the minimum cost to benefit the citizens. Now please compute this minimum cost.
Input Format
The first line contains three integers (, ).
The next lines each contain integers, representing ().
Output Format
Output one integer, the minimum cost.
Sample Input 1
3 4 2
1 7 7 9
9 6 3 7
7 8 6 4
Sample Output 1
10
Sample Input 2
3 3 1000000000
1000000 1000000 1
1000000 1000000 1000000
1 1000000 1000000
Sample Output 2
1001000001