#C4165. Sum of Good String Lengths
Sum of Good String Lengths
Sum of Good String Lengths
You are given a list of words and a string chars that represents a collection of characters. A word is considered good if it can be formed using the characters from chars, where each character in chars can be used at most once. Your task is to compute the sum of the lengths of all good strings in the list.
Mathematically, a word w is good if for every character c in w, $$\text{count}_{w}(c) \le \text{count}_{chars}(c)$$ where \(\text{count}_{w}(c)\) and \(\text{count}_{chars}(c)\) denote the number of occurrences of \(c\) in w and chars respectively.
Input/Output Format: The input is read from standard input (stdin) and the result is produced on standard output (stdout).
inputFormat
The first line contains an integer n representing the number of words. The second line contains n strings separated by spaces representing the words. The third line contains a string chars that stores the available characters.
outputFormat
Output a single integer representing the sum of the lengths of all good strings. A string is good if it can be formed using the characters from chars (each character can only be used once).
## sample4
cat bt hat tree
atach
6
</p>