#C2359. Find the Median of a List

    ID: 45666 Type: Default 1000ms 256MiB

Find the Median of a List

Find the Median of a List

Given a list of numbers, your task is to find its median.

The median of a sorted list is defined as follows:

  • If the number of elements is odd, the median is the middle element.
  • If the number of elements is even, the median is given by \(\frac{a + b}{2}\), where a and b are the two middle numbers.

You are required to implement a solution which reads input from standard input (stdin) and writes the result to standard output (stdout).

inputFormat

The first line contains an integer n (1 \(\leq n \leq 10^5\)), representing the number of elements in the list. The second line contains n space-separated numbers, which can be integers or decimals.

outputFormat

Output a single number — the median of the list. If the median is an integer, output it without a decimal point. Otherwise, output the floating point value.

## sample
5
3 1 7 5 9
5

</p>