#C13306. Longest Subsequence Word

    ID: 42830 Type: Default 1000ms 256MiB

Longest Subsequence Word

Longest Subsequence Word

Given a string S and a list of words, your task is to find the longest word from the list such that it is a subsequence of S. A subsequence of S is defined as a sequence that can be derived from S by deleting some characters (or none) without changing the order of the remaining characters. Formally, a word W is a subsequence of S if there exists indices \(1 \leq i_1 < i_2 < \cdots < i_{|W|} \leq |S|\) such that \(W[j] = S[i_j]\) for all \(1 \leq j \leq |W|\).

If multiple words of the maximum length exist, choose the lexicographically largest one. If no word from the list can be formed as a subsequence of S, output an empty string.

inputFormat

The input is given in three parts via standard input (stdin):

  1. An integer n representing the number of words.
  2. A line with n space-separated words.
  3. A line containing the string S.

outputFormat

Output the longest word that is a subsequence of S according to the rules described. If no such word exists, output an empty string.

## sample
10
algorithm binary code data debug function loop program syntax variable
programming
program