#C327. Median Word Finder

    ID: 46678 Type: Default 1000ms 256MiB

Median Word Finder

Median Word Finder

You are given a list of n words. Your task is to sort the words lexicographically and then output the median word.

Let \(n\) be the number of words. If the sorted list is \(S\), then the answer is the element at index \(\lfloor (n-1)/2 \rfloor\). This means that if the number of words is even, you should output the word immediately preceding the middle.

For example, if \(n = 5\) and the sorted words are [apple, banana, cherry, date, elderberry], then the median word is cherry. Similarly, for \(n = 4\) and the sorted words [grape, kiwi, melon, orange], the median word is grape (since index \(\lfloor (4-1)/2 \rfloor = 1\) in 0-indexed order, but note that after sorting "grape" comes first in lexicographical order between kiwi, melon, and orange, so be careful with ordering).

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains an integer \(n\) which is the number of words.
  2. The second line contains \(n\) space-separated words.

outputFormat

Output the median word (after sorting lexicographically) to stdout.

Note: For an even number of words, output the word immediately preceding the middle element in the sorted list.

## sample
5
apple banana cherry date elderberry
cherry

</p>