#d2849. 国家铁路
国家铁路
National Railway
Problem Description
dls's competitive-programming kingdom can be represented as a grid of rows and columns, where denotes the cell in the -th row from the north and the -th column from the west. The citizens recently asked the king to build a railway.
Building the railway has two stages:
- Pick distinct cells from the whole grid and build a train station on each. Building a station on cell costs .
- Build a track between the two cells. If the chosen cells are and , the cost is .
dls wants to build a railway at minimum cost for his citizens. Find this minimum cost.
Input Format
The first line contains three integers (, ).
The following lines each contain integers, giving ().
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