#C7290. Find the Median of a List

    ID: 51145 Type: Default 1000ms 256MiB

Find the Median of a List

Find the Median of a List

Given a list of numbers, compute the median. The median is defined as follows: if the list has an odd number of elements, the median is the middle element in the sorted order; if the list has an even number of elements, the median is computed as (\frac{a+b}{2}), where (a) and (b) are the two middle numbers after sorting. If the list is empty, output None.

inputFormat

The input is read from standard input (stdin). The first line contains a non-negative integer (n) indicating the number of elements in the list. The second line contains (n) space-separated numbers (which can be integers or floats). If (n = 0), the second line may be empty.

outputFormat

Output the median of the list to standard output (stdout). If the median is a whole number, output it as an integer; otherwise, output it as a float. If the list is empty, output None.## sample

3
1 3 2
2