eolymp
bolt
Try our new interface for solving problems
Problems

Median of numbers

Median of numbers

In the set of distinct numbers, the median is an element \textbf{m} such that the number of elements greater than \textbf{m} is equal to the number of elements smaller than \textbf{m}. For example, in a set \{\textbf{1}, \textbf{4}, \textbf{2}, \textbf{5}, \textbf{7}\} the median is 4 because two elements (\textbf{5} and \textbf{7}) are greater than \textbf{4} and \textbf{2} elements (\textbf{1} and \textbf{2}) smaller than \textbf{4}. The set \{\textbf{1}, \textbf{5}, \textbf{8}, \textbf{3}\} has no median because no element from it satisfies the definition above. \InputFile In one line \textbf{n} (\textbf{n} ≤ \textbf{1000}) different positive integers are given, each of them is not greater than \textbf{1000}. \OutputFile Print the median of given numbers. If the median does not exist, print \textbf{-1}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1 4 2 5 7
Output example #1
4