#K86402. Median Finder
Median Finder
Median Finder
You are given an integer n representing the number of elements in a list, a placeholder string name, and a list of n integers. Your task is to calculate the median of the list. The median is defined as follows:
If the list contains an odd number of elements, the median is the middle element after sorting the list in non-decreasing order. If the list contains an even number of elements, the median is the integer average of the two middle elements (i.e. \( \text{median} = \frac{a_{\frac{n}{2}} + a_{\frac{n}{2}+1}}{2} \) using zero-indexing with appropriate adjustment, implemented using integer division).
Note that the name parameter is provided as a placeholder and does not affect the computation.
inputFormat
The input is given from standard input (stdin) in the following format:
Line 1: An integer n, the number of elements in the list. Line 2: A string (name), which is not used in the computation. Line 3: n space-separated integers representing the list.
outputFormat
Output a single integer to standard output (stdout) representing the median of the list. If n is odd, output the middle element of the sorted list. If n is even, output the integer average (using floor division) of the two middle elements.## sample
5
Charlie
4 1 3 5 2
3