Two Representative Natural Numbers

Interview

Time limit2sMemory limit256 MB

Summary
Given up to 5,000,000 integers from 1 to 10,000, output the median (smallest if tie) and the rounded mean as representatives.
Level

Easy3 of 10

Topics
Math, Sorting, Array
Solved
No attempts yet

Problem

Given several positive integers, choose representative positive integers by two different criteria.

Criterion 1 chooses a positive integer that minimizes the sum of absolute differences from all given numbers. For the numbers 4, 3, 2, 2, 10, 10, choosing 3 gives |4-3| + |3-3| + |2-3| + |2-3| + |10-3| + |10-3| = 17, and choosing 4 also gives 17. Since this is the minimum possible value, the representatives by criterion 1 are 3 and 4. If there is more than one representative, choose the smallest one.

Criterion 2 chooses a positive integer that minimizes the sum of squared differences from all given numbers. For the same numbers, choosing 5 gives (4-5)^2 + (3-5)^2 + (2-5)^2 + (2-5)^2 + (10-5)^2 + (10-5)^2 = 73, which is the minimum possible value.

For the given positive integers, find the representative positive integer for criterion 1 and for criterion 2. A representative does not have to be one of the input numbers.

Input

The first line contains the number of positive integers N. N is between 1 and 5,000,000, inclusive.

The second line contains N positive integers separated by spaces. Each integer is between 1 and 10,000, inclusive.

Output

Print two integers on the first line: the representative for criterion 1 and the representative for criterion 2, separated by a space.

If a criterion has two or more possible representatives, print the smallest one among them.

Examples1

  1. Example 1

    Input
    6
    4 3 2 2 10 10
    
    Expected output
    3 5