#P2298. Hide and Seek
Hide and Seek
Hide and Seek
mzc has n male servants who have gathered together to play hide and seek. mzc stands at the origin (position 0) and, using his superb searching skills, he can find exactly one servant in each round – specifically, the one closest to him. In case of a tie (i.e. when two servants are equally distant from 0), he will choose the one with the smaller coordinate (thus preferring the negative value).
Your task is to help mzc determine which servant he will find first based on their hiding positions.
Note on tie-breaking: If two positions have the same absolute value, the position with the lower numerical value is chosen.
inputFormat
The input consists of two lines:
- The first line contains an integer n (1 \(\leq n \leq 10^5\)) — the number of servants.
- The second line contains n space-separated integers which represent the positions at which the servants are hiding on a number line.
outputFormat
Output a single integer — the coordinate of the servant mzc finds (i.e. the one closest to position 0). In case of a tie, output the smaller coordinate.
sample
5
-2 4 1 -3 10
1
</p>