Antenna

Interview

Time limit1sMemory limit256 MB

Summary
Given positions of houses on a line, pick the house position that minimizes the total distance to all houses, choosing the smallest such position on ties.
Level

Medium4 of 10

Topics
Sorting, Math, Array, Greedy
Solved
No attempts yet

Problem

Several houses are located along a straight line in a village. The village decided to install a single antenna at one of the houses at a specific position. For efficiency, the antenna must be installed where the total distance from the antenna to every house is minimized. The antenna can only be installed at a position where a house is located, and logically, multiple houses can exist at the same position.

Given the positions of the houses, write a program that selects the position to install the antenna.

For example, suppose N=4N=4 and the positions are 1, 5, 7, and 9.

In this case, installing at position 5 minimizes the total distance from the antenna to every house to (4+0+2+4)=10(4+0+2+4)=10.

Input

The first line gives the number of houses NN as a natural number. (1≤N≤200,0001 \le N \le 200{,}000) The second line gives the positions of the NN houses, separated by spaces, as natural numbers between 1 and 100,000 inclusive.

Output

Print the position value at which to install the antenna on the first line. If multiple position values are possible for installing the antenna, print the smallest one.

Examples1

  1. Example 1

    Input
    4
    5 1 7 9
    
    Expected output
    5