Little Mislav owns glasses of infinite volume, and each glass contains some water. Mislav wants to drink all the water, but he doesn't want to drink from more than glasses. What Mislav can do with the glasses is pour the total volume of water from one glass to another.
Unfortunately, it matters to Mislav what glass he picks, because not all glasses are equally distant to him. More precisely, the amount of effort it takes to pour water from glass labeled with to glass labeled is denoted with .
Help Mislav and find the order of pouring the water from one glass to another such that the sum of effort is minimal.
Input Specification
The first line of input contains integers , .
The following lines contains integers .
The row and column contains value . It will hold that each is equal to .
Output Specification
Output the minimal effort needed for Mislav to achieve his goal.
Scoring
In test cases worth points total, it will hold .
Sample Input 1
3 3
0 1 1
1 0 1
1 1 0
Sample Output 1
0
Explanation for Sample Output 1
Mislav doesn't need to pour water in order to drink from at most glasses.
Sample Input 2
3 2
0 1 1
1 0 1
1 1 0
Sample Output 2
1
Explanation for Sample Output 2
Mislav must pour the water from precisely one (doesn't matter which) glass into any other glass in order to be left with only two glasses with water.
Sample Input 3
5 2
0 5 4 3 2
7 0 4 4 4
3 3 0 1 2
4 3 1 0 5
4 5 5 5 0
Sample Output 3
5
Explanation for Sample Output 3
In order for Mislav to achieve the minimal solution of , he can pour water from glass to (effort ), then → (effort ), and finally, → (effort ). In total, amount of effort.
Comments