For her final CS project, Mafuyu needs to build a tree with
After buying the required nodes, Mafuyu needs to go home and actually build the tree by repeatedly melding two connectors from two different nodes into a single edge connecting the two nodes. The final product should not have any leftover connectors that are not melded.
Given these conditions, please find the minimum total cost required for Mafuyu to build a tree with
Constraints
Subtask 1 [15%]
Subtask 2 [20%]
Subtask 3 [20%]
Subtask 4 [20%]
Subtask 5 [25%]
No additional constraints.
Input Specification
The first line contains
The next line contains
Output Specification
Output the minimum total cost (in yen) required for Mafuyu to build a tree with
Sample Input
4 3
1 3 4
Sample Output
7
Explanation
Mafuyu can buy
Comments