This page is still under construction.

Parts of this page are still being built. What you see may change.

Uniting Departments

Time limit1sMemory limit256 MB

Summary
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 SiS_i 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 N−1N - 1 times until a single department remains. One operation goes like this.

  1. Choose one department a among the remaining departments.
  2. Choose one department b, different from a, among the remaining departments.
  3. Merge department a and department b. SaS_a becomes Sa+SbS_a + S_b, and department b disappears.
  4. Append the merged pair (a,b)(a, b) 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 Sa×SbS_a \times S_b, 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. (1≤N≤1000001 \le N \le 100000)

The second line contains N natural numbers S1,S2,…,SNS_1, S_2, \dots, S_N, 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 (1,2)(1, 2) and the pair (2,1)(2, 1) count as different cases.

Examples3

  1. Example 1

    Input
    2
    2 3
    
    Expected output
    6
    2
    
  2. Example 2

    Input
    1
    7
    
    Expected output
    0
    1
    
  3. Example 3

    Input
    3
    1 2 3
    
    Expected output
    11
    12