#K71822. Construct Target Word

    ID: 33617 Type: Default 1000ms 256MiB

Construct Target Word

Construct Target Word

You are given an integer n and a list of n words. Your task is to determine whether a given target string can be constructed by concatenating one or more words from the list. Words can be reused as many times as needed.

For example, if n = 3, words = ["app", "le", "pie"] and target = "applepie", then the answer is "YES" because "applepie" can be constructed as "app" + "le" + "pie".

Output "YES" if the target is constructible; otherwise, output "NO".

inputFormat

The input is given via standard input with the following format:

  • The first line contains a single integer n — the number of words.
  • The second line contains n space-separated strings representing the list of words.
  • The third line contains the target string.

All tokens are separated by whitespace.

outputFormat

Output a single line containing "YES" if the target string can be constructed by concatenating the given words; otherwise, output "NO".

## sample
3
app le pie
applepie
YES