308641: CF1551C. Interesting Story

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Interesting Story

题意翻译

给定 $n$ 个仅由 $\texttt{a,b,c,d,e}$ 组成的单词 ($n \le 2\times 10^5$),从其中选出尽可能多的单词,使得存在某个字母在这些单词中出现的次数比其他所有字母的出现次数之和还要多。输出最多能选的单词个数。若无法构造,输出 $0$ **多组数据**

题目描述

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 $ n $ words consisting of the first $ 5 $ lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an interesting story. 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 $ 5 $ times, all other letters occur $ 4 $ 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 $ n $ words consisting of letters '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 $ 0 $ .

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 5000 $ ) — the number of test cases. Then $ t $ test cases follow. The first line of each test case contains one integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the number of the words in the sequence. Then $ n $ 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 'a', 'b', 'c', 'd' and 'e' may occur in the words. It is guaranteed that the sum of $ n $ over all test cases doesn't exceed $ 2 \cdot 10^5 $ ; the sum of the lengths of all words over all test cases doesn't exceed $ 4 \cdot 10^5 $ .

输出格式


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.

输入输出样例

输入样例 #1

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

输出样例 #1

3
2
0
2
3
2

说明

In the first test case of the example, all $ 3 $ words can be used to make an interesting story. The interesting story is "bac aaada e". In the second test case of the example, the $ 1 $ -st and the $ 3 $ -rd words can be used to make an interesting story. The interesting story is "aba aba". Stephen can't use all three words at the same time. In the third test case of the example, Stephen can't make a non-empty interesting story. So the answer is $ 0 $ . In the fourth test case of the example, Stephen can use the $ 3 $ -rd and the $ 4 $ -th words to make an interesting story. The interesting story is "c bc".

Input

题意翻译

给定 $n$ 个仅由 $\texttt{a,b,c,d,e}$ 组成的单词 ($n \le 2\times 10^5$),从其中选出尽可能多的单词,使得存在某个字母在这些单词中出现的次数比其他所有字母的出现次数之和还要多。输出最多能选的单词个数。若无法构造,输出 $0$ **多组数据**

加入题单

算法标签: