#K70262. Concatenated String Formation

    ID: 33270 Type: Default 1000ms 256MiB

Concatenated String Formation

Concatenated String Formation

You are given an integer \(k\), a target string \(t\), an integer \(n\) representing the number of available strings, and a list of \(n\) strings \(s\). Your task is to determine whether it is possible to form the string \(t\) by concatenating exactly \(k\) strings selected from \(s\) (each string can be selected any number of times), such that the concatenation is exactly equal to \(t\>.

Note: Use each string in its entirety. Partial usage of a string is not allowed.

Formally, if you denote the chosen strings as \(s_{i_1}, s_{i_2}, \ldots, s_{i_k}\), then you must have:

\[ s_{i_1} + s_{i_2} + \cdots + s_{i_k} = t \]

where + denotes string concatenation. If such a sequence exists, print YES; otherwise, print NO.

inputFormat

The input is read from standard input and has the following format:

  1. An integer \(k\), the number of strings to concatenate.
  2. A string \(t\), the target string.
  3. An integer \(n\), the number of available strings.
  4. \(n\) lines follow, each containing one string from the list \(s\).

It is guaranteed that all strings contain only visible characters and there are no extra spaces.

outputFormat

Output a single line to standard output: YES if it is possible to form the target string \(t\) by concatenating exactly \(k\) strings from \(s\); otherwise, output NO.

## sample
2
abcd
3
ab
cd
abc
YES

</p>