#C14366. Find Median Height

    ID: 44007 Type: Default 1000ms 256MiB

Find Median Height

Find Median Height

You are given a list of integers representing the heights of individuals. Your task is to calculate the median height.

The median is defined as follows:

  • If the number of elements, \(n\), is odd, the median is the middle element once the list is sorted.
  • If \(n\) is even, the median is the average of the two middle elements, i.e., \(\frac{a_{n/2} + a_{n/2+1}}{2}\), when the list is sorted (1-indexed).

If the list is empty (i.e. \(n = 0\)), output the error message: "The list of heights cannot be empty".

inputFormat

The input is read from standard input (stdin). The first line contains an integer \(n\) representing the number of heights. The second line contains \(n\) space-separated integers denoting the heights.

For example:

5
5 2 9 3 8

outputFormat

Print the median height to standard output (stdout). If the median is an integer, output it without a decimal point; if it is a fractional number, print the floating-point result. In case the input list is empty (i.e. \(n = 0\)), print the error message exactly as "The list of heights cannot be empty".

## sample
5
5 2 9 3 8
5