Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.

Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.

Input

The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are n lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.

Output

Print a single integer — the maximum possible total length of words in Andrew's article.

Examples

Input

4
abb
cacc
aaa
bbb

Output

9

Input

5
a
a
bcbcb
cdecdecdecdecdecde
aaaa

Output

6

Note

In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.

In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.

对于这个题,我们的做法是把26个字母任取两个进行枚举,看在字符串中那些最多

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std;
string str[105];
int main()
{
int n;
cin>>n;
for(int t=0;t<n;t++)
{
cin>>str[t];
}
int sum;
int maxn=0;
for(int i='a';i<='z';i++)
{
for(int j=i;j<='z';j++)
{ sum=0;
for(int k=0;k<n;k++)
{
int len=str[k].length();
int m;
for( m=0;m<len;m++)
{
if(str[k][m]!=i&&str[k][m]!=j)
{
break;
}
}
if(m==len)
{
sum+=len;
}
}
maxn=max(maxn,sum);
}
} cout<<maxn<<endl;
return 0;
}

CodeForces - 593A -2Char(思维+暴力枚举)的更多相关文章

  1. CodeForces - 1244D (思维+暴力)

    题意 https://vjudge.net/problem/CodeForces-1244D 有一棵树,有3种颜色,第i个节点染成第j种颜色的代价是c(i,j),现在要你求出一种染色方案,使得总代价最 ...

  2. Codeforces 626E Simple Skewness(暴力枚举+二分)

    E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...

  3. codeforces Restore Cube(暴力枚举)

    /* 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 问是否可以还原出一个立方体的坐标,注意这一句话: The numbers in the i-th output ...

  4. codeforces 700C Break Up 暴力枚举边+边双缩点(有重边)

    题意:n个点,m条无向边,每个边有权值,给你 s 和 t,问你至多删除两条边,让s,t不连通,问方案的权值和最小为多少,并且输出删的边 分析:n<=1000,m是30000  s,t有4种情况( ...

  5. Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

    You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...

  6. CodeForces 496D Tennis Game (暴力枚举)

    题意:进行若干场比赛,每次比赛两人对决,赢的人得到1分,输的人不得分,先得到t分的人获胜,开始下场比赛,某个人率先赢下s场比赛时, 游戏结束.现在给出n次对决的记录,问可能的s和t有多少种,并按s递增 ...

  7. CodeForces 593A 2Char

    暴力. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...

  8. Codeforces 327A-Flipping Game(暴力枚举)

    A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. CodeForces - 1230C(思维/暴力)

    题意 https://vjudge.net/problem/CodeForces-1230C 给了你总共有21张多米诺骨牌,每张牌有两个面,然后给你一个无向图,保证没有环和一个顶点多条边的情况存在.现 ...

随机推荐

  1. Android Studio Build APK没有报错,但是Generate signed apk报错

    有时候 ,我们在调试APK,直接Build是可以正常生成,没有报错,但是当我们将自己的签名文件加上去,就会报错.一般情况下,我们可以在build.gradle中的android{}里面添加一个东西 l ...

  2. springboot整合mybatis+generator

    源码地址:springboot-integration 如果你觉得解决了你使用的需求,欢迎fork|star.

  3. 关于handler和异步任务

    handler使用流程概要 首先在主线程新建一个handler实例,重写onhandlemessage(Message msg) 方法,对传过来的message进行处理 然后在子线程中完成操作,操作完 ...

  4. solr的copyFeild用法(改变各个feild的权重,修改打分结果)-注意!

    copyField的dest字段all本身有分析器处理:假设为mmseg4j name,title,description三个字段都复制到all字段上:其中title和description都是mms ...

  5. 使用Post进行Http通信

    --------------siwuxie095                             有道翻译官网:http://fanyi.youdao.com/     找到官网页面下方的 有 ...

  6. spark 1.5的hivecontext的问题

    spark升级到1.5,里面的hive版本升级到1.2.1版本,我写了如下的代码 object SQLApp extends App{ val sparkconf = new SparkConf(). ...

  7. map集合的应用

    分析以下需求,并用代码实现: (1)利用键盘录入,输入一个字符串 (2)统计该字符串中各个字符的数量例如 用户输入字符串"If~you-want~to~change-your_fate_I_ ...

  8. 带有通配符的字符串匹配算法-C/C++

    日前某君给我出了这样一道题目:两个字符串,一个是普通字符串,另一个含有*和?通配符,*代表零个到多个任意字符,?代表一个任意字符,通配符可能多次出现.写一个算法,比较两个字符串是否相等. 我花了四个小 ...

  9. Spring学习大纲

    1.BeanFactory 和 FactoryBean? 2.Spring IOC 的理解,其初始化过程? 3.BeanFactory 和 ApplicationContext? 4.Spring B ...

  10. [raspberry pi3] 安装ffmpeg

    买了个pi3,pi相对于通常的嵌入式系统的最大好处是里面夹带了gcc编译器,有很多东西都不需要交叉编译了. arm和pc的性能还是不能比的,io的瓶颈还是很明显的, 想要编的快点还是要在pc上交叉编译 ...