#C8542. Taco's Dish Preparation Problem

    ID: 52536 Type: Default 1000ms 256MiB

Taco's Dish Preparation Problem

Taco's Dish Preparation Problem

You are given a string of available ingredients and a list of dishes that need to be prepared. Each dish is represented by a string where each character denotes a required ingredient. You must determine whether it is possible to prepare all the dishes in the given order. For each dish, you can only use the ingredients available at that moment, and once an ingredient is used it is no longer available for subsequent dishes.

A dish can be prepared if and only if for each ingredient \(x\) required by the dish, the number of times \(x\) appears in the available ingredients is at least the number of times it is needed (i.e., \(\text{count}_{available}(x) \geq \text{count}_{dish}(x)\)). After preparing a dish, subtract the used ingredients from the available pool.

inputFormat

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

  1. The first line contains two space-separated integers \(n\) and \(m\), where \(n\) is the number of dishes and \(m\) is the length of the ingredient string.
  2. The second line contains a string of length \(m\) representing the available ingredients.
  3. The next \(n\) lines each contain a string representing a dish (the required ingredients for that dish).

outputFormat

Output a single line to standard output containing YES if all dishes can be prepared following the given rules, or NO otherwise.

## sample
3 6
aaabbc
a
bc
aa
YES

</p>