#K62507. Concatenated Word Finder

    ID: 31546 Type: Default 1000ms 256MiB

Concatenated Word Finder

Concatenated Word Finder

Given a list of words, the goal is to find the first word (in the given order) that can be formed by concatenating two non-empty words from the list. For each word (w), you need to check if there exists an index (i) ((1 \leq i < |w|)) such that when (w) is split into (w = prefix + suffix), both (prefix) and (suffix) are present in the list. If multiple such words exist, return the one that appears first in the input order. If no such word exists, output "No such word".

The problem can be formulated mathematically as follows:
Find the first (w) in the list such that (\exists, i) (with (1 \le i < |w|)) satisfying [ prefix = w[0:i] \quad \text{and} \quad suffix = w[i:|w|] ] with both (prefix) and (suffix) belonging to the set of input words.

inputFormat

The input is given via standard input (stdin) and consists of multiple lines. The first line contains an integer (N) representing the number of words. The following (N) lines each contain one word.

outputFormat

Output a single line to standard output (stdout) containing the first concatenated word found. If no such word exists, output "No such word".## sample

4
cat
dog
cats
dogcat
dogcat

</p>