#K85812. Median Age Calculation
Median Age Calculation
Median Age Calculation
You are given a list of ages. Your task is to compute the median age from this list.
If the list is empty, output \(-1\). If there is exactly one element in the list, return that element in floating point format. For more than one element, first sort the list. If the number of elements is odd, the median is the middle element. If even, the median is defined as:
\[ \text{median} = \frac{a_{\frac{n}{2}} + a_{\frac{n}{2}+1}}{2} \]
where the list (after sorting) is \(a_1, a_2, \ldots, a_n\).
Input is given via standard input and output via standard output.
inputFormat
The first line contains a single integer \(n\) denoting the number of ages. If \(n > 0\), the second line contains \(n\) space-separated integers representing the ages.
outputFormat
Output the median age as a floating point number. If the list is empty (i.e., \(n = 0\)), output \(-1\).
## sample0
-1