Uniting Departments
Time limit1sMemory limit256 MB
Merge departments pairwise at product-of-sizes cost and report the total cost and the number of ordered merge sequences modulo 1000000007.
- Level
Medium5 of 10
- Topics
- Math, Combinatorics
- Solved
- No attempts yet
Problem
You want to unite N departments into one. Number the departments 1 to N, and let be the size of department i. Merging many departments at once causes too much confusion, so you repeat the operation of merging two departments into one times until a single department remains. One operation goes like this.
- Choose one department a among the remaining departments.
- Choose one department b, different from a, among the remaining departments.
- Merge department a and department b. becomes , and department b disappears.
- Append the merged pair to the end of the list of pairs recorded so far.
Merging two departments costs something. The cost depends on the method, and you know a method whose cost is , so you use that one. Find the minimum total cost, and the number of distinct processes whose cost is the minimum. Two processes are distinct when comparing the recorded pairs one by one in order gives at least one differing pair.
Input
The first line contains N, the number of departments. ()
The second line contains N natural numbers , the sizes of the departments, separated by spaces. Each size is between 1 and 100.
Output
Print the minimum total cost on the first line.
Print the number of distinct processes whose cost is the minimum, modulo 1,000,000,007, on the second line.
Hint
The pair and the pair count as different cases.