#K51627. Count Valid Words

    ID: 29130 Type: Default 1000ms 256MiB

Count Valid Words

Count Valid Words

You are given a list of words and a string of characters. Your task is to determine the number of words that can be completely formed using the characters given. Each character in the characters string can be used at most once per word.

Formally, for each word \(w\) in the list, check if for every character \(c\) that appears in \(w\), the number of occurrences of \(c\) in \(w\) does not exceed the number of occurrences of \(c\) in the provided characters string.

Example: For words = ["hello", "world", "students"] and characters = "welldonerhstu", only "hello" and "world" can be formed, so the output is 2.

inputFormat

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

n
word1
word2
...
wordn
chars

Here, the first line contains an integer \(n\) (the number of words). The next \(n\) lines each contain a word. The last line contains the string of available characters, chars.

outputFormat

Output a single integer to stdout – the count of words that can be formed using the available characters.

## sample
3
hello
world
students
welldonerhstu
2