Under construction

Still being built. Things may change

Cow College

Interview

Time limit2sMemory limit1024 MB

Summary
Pick the tuition that maximizes price times the number of cows willing to pay it. Print the best revenue and the smallest such tuition.
Level

Easy3 of 10

Topics
Sorting, Greedy
Solved
No attempts yet

Problem

Farmer John is planning to open a new university for cows. There are NN (1≤N≤1051 \le N \le 10^5) cows who could potentially attend. Each cow is willing to pay a maximum tuition of cic_i (1≤ci≤1061 \le c_i \le 10^6). Farmer John sets one tuition that all cows must pay to enroll. If the tuition is higher than what a cow is willing to pay, that cow does not attend. Farmer John wants to earn as much money as possible so he can pay his instructors a fair wage. Find the maximum amount of money he can make and the tuition he should charge.

Input

The first line contains NN. The second line contains NN integers c1,c2,…,cNc_1, c_2, \dots, c_N, where cic_i is the maximum tuition cow ii is willing to pay.

Output

Output the maximum amount of money Farmer John can make and the optimal tuition he should charge. If several solutions exist, output the one with the smallest optimal tuition. The numbers involved can be large, so you may need a 64-bit integer type.

Hint

If Farmer John charges 44, then 33 cows attend, so he makes 3⋅4=123 \cdot 4 = 12.

Examples1

  1. Example 1

    Input
    4
    1 6 4 6
    
    Expected output
    12 4