Interesting Story solution codeforces
Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters ‘a‘, ‘b‘, ‘c‘, ‘d‘ and ‘e‘!
To compose a story, Stephen wrote out maximum number of words to make an interesting story.words consisting of the first lowercase letters of the Latin alphabet. He wants to select the
Let a story be a sequence of words that are not necessarily different. A story is called interesting if there exists a letter which occurs among all words of the story more times than all other letters together.
For example, the story consisting of three words “bac“, “aaada“, “e” is interesting (the letter ‘a‘ occurs times, all other letters occur times in total). But the story consisting of two words “aba“, “abcde” is not (no such letter that it occurs more than all other letters in total).
You are given a sequence of a‘, ‘b‘, ‘c‘, ‘d‘ and ‘e‘. Your task is to choose the maximum number of them to make an interesting story. If there’s no way to make a non-empty story, output .words consisting of letters ‘
The first line contains one integer( ) — the number of test cases. Then test cases follow.
The first line of each test case contains one integer a‘, ‘b‘, ‘c‘, ‘d‘ and ‘e‘ may occur in the words.( ) — the number of the words in the sequence. Then lines follow, each of them contains a word — a non-empty string consisting of lowercase letters of the Latin alphabet. The words in the sequence may be non-distinct (i. e. duplicates are allowed). Only the letters ‘
It is guaranteed that the sum ofover all test cases doesn’t exceed ; the sum of the lengths of all words over all test cases doesn’t exceed .
For each test case, output the maximum number of words that compose an interesting story. Print 0 if there’s no way to make a non-empty interesting story.
input Interesting Story solution codeforces
6 3 bac aaada e 3 aba abcde aba 2 baba baba 4 ab ab c bc 5 cbdca d a d e 3 b c ca
3 2 0 2 3 2
In the first test case of the example, all bac aaada e“.words can be used to make an interesting story. The interesting story is “
In the second test case of the example, the aba aba“. Stephen can’t use all three words at the same time.-st and the -rd words can be used to make an interesting story. The interesting story is “
In the third test case of the example, Stephen can’t make a non-empty interesting story. So the answer is.
In the fourth test case of the example, Stephen can use the c ca“.-rd and the -th words to make an interesting story. The interesting story is “