Dynamic median

Given a sequence of words, print the median of all the words seen so far at every moment. Please recall that the median of a set of nn elements is the element that would be in the position (n+1)/2\lfloor (n + 1)/ 2 \rfloor if the set was ordered. For example, the median of five elements is the third smallest, and the median of six elements is also the third smallest.

Input

Input consists of a sequence of different lowercase words ended in “END”.

Output

For every word in the input, print the median of the words read so far. Suppose that the words are sorted with the usual alphabetical order.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:31:55.695Z

© Jutge.org, 2006–2026.
https://jutge.org