QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#22804. Cowese

Estadísticas

It is a little known fact that the cows love word games. They have their own cow crossword puzzles, cow word-find grids, and all sorts of other cow word games.

The cows need some computer assistance, though, in order to design certain word games. They have lists of $N$ distinct words ($2 \le N \le 20{,}000$) no longer than 100 characters, all of which are lower-case and contain only the letters 'a'..'z'.

They need to find two words in the list that share the longest prefix (i.e., the first $C$ characters of the words match and $C$ is the longest length for all possible pairs of words). The input datasets are guaranteed to have at least one pair of words with a shared prefix.

If more than two word pairs share prefixes of the same maximal size, the cows want to see the pair whose first word is closest to the beginning of the supplied list and whose other maximal-prefix word is closest to the beginning of the list.

Input

  • Line $1$: One line with a single integer: $N$
  • Lines $2..N+1$: Each line contains a single word.

Output

Two lines, each with a single word.

Examples

Input 1

9
noon
is
lunch
for
most
noone
waits
until
two

Output 1

noon
noone

Problem credits: Dan Adkins, 2001

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.