#K13376. Longest Word in Dictionary through Deleting

    ID: 23899 Type: Default 1000ms 256MiB

Longest Word in Dictionary through Deleting

Longest Word in Dictionary through Deleting

Given a string \(s\) and a list of words, your task is to find the longest word in the list that can be derived from \(s\) by deleting some characters without changing the order of the remaining characters. If there are multiple words of the same maximum length, return the one that is lexicographically smallest. If no word can be formed, output an empty string.

Note: The solution must read input from standard input (stdin) and write the result to standard output (stdout).

inputFormat

The input consists of three lines:

  • The first line contains an integer \(n\), representing the number of words.
  • The second line contains \(n\) words separated by spaces.
  • The third line contains the string \(s\).

outputFormat

Output a single line containing the longest word that can be formed. If no such word exists, output an empty string.

## sample
4
ale apple monkey plea
abpcplea
apple

</p>