The official statement of a problem is always the one
in the PDF document. The HTML version of the statement
is also given to help you, but may contain some content
that is not well displayed. In case of doubt, always use the PDF.
Public test cases
Input
Ann Beth Carol Dave Ethan
Ethan overtakes Dave
Carol overtakes Beth
Carol overtakes Ann
Beth overtakes Ann
Dave overtakes Ethan
Output
Carol
Beth
Ann
Dave
Ethan
Input
Ann Beth Carol Dave Ethan
Ethan overtakes Dave
Carol overtakes Beth
Carol overtakes Ann
Beth overtakes Ann
Dave overtakes Ethan