House Hunting
Ravi recently landed an exciting role at OpenAI and is looking for a new house. Luckily, he has found a street with all the amenities he needs, such as supermarkets, restaurants, and more! Now, he needs to pick the perfect place to live.
The street has houses numbered from to
, and Ravi can live at any integer house number along the street. Each utility that matters to him is also located at an integer house number. Ravi and one or more utilities can potentially share the same house number (they will live on different floors).
If Ravi chooses to live at house number , and a utility is located at house number
, he incurs an inconvenience equal to
, the distance between them. For example, if a utility is at house number
:
- If Ravi lives at house
, he gets inconvenience
- If Ravi lives at house
, he gets inconvenience
- If Ravi lives at house
, he gets inconvenience
Ravi wants to choose a house that minimises his total inconvenience across all utilities. Can you help him?
Input
The first line contains an integer
, the number of utilities on Ravi's street.
The second line contains integers
, where
is the house number of the
th utility on Ravi's street. These numbers can be repeated.
Output
Output the house number Ravi should live at to minimise his total inconvenience across all utilities. If multiple ideal locations exist, output the one with the smallest house number.
Example
Input 1
4
2 6 8 8
Output 1
6
If Ravi lives at house #6, his total inconvenience is as follows:
for the first utility.
for the second utility.
for the third utility.
for the fourth utility.
This is a total inconvenience of , which is the lowest out of any houses he could have chosen.

Input 2
3
4 7 5
Output 2
5
Input 3
2
1 1000000000
Output 3
1
Comments