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'}.

Difficulty: interview

Starter code:

Solutions:
def main():
    n = int(input())
    a = [input() for i in range(n)]
    
    result = 0
    for i in range(26):
        for j in range(i + 1, 26):
            t = 0
            ci = chr(i + ord('a'))
            cj = chr(j + ord('a'))
            for s in a:
                if s.count(ci) + s.count(cj) == len(s):
                    t += len(s)
            result = max(result, t)
    
    print(result)
    
    
    
main()

# import sys
# sys.stdin = open("cf593a.in")

alphabet = 'abcdefghijklmnopqrstuvwxyz'

n = int(input())
words = [input().strip() for _ in range(n)]
words = [(word, set(word)) for word in words]
words = [(word, s) for word, s in words if len(s) <= 2]

best = 0
for c1 in alphabet:
	for c2 in alphabet:
		shere = set([c1, c2])
		best = max(best, sum(len(word) for word, s in words if not (s - shere)))

print(best)

N = int(input())
words = [input() for i in range(N)]

abc = 'abcdefghijklmnopqrstuvwxyz'
def countf(a, b):
    c = a + b
    s = 0
    for w in words:
        if w.strip(c) is '':
            s += len(w)

    return s

m = 0
for a in abc:
    for b in abc:
        if a == b:
            continue

        m = max(countf(a, b), m)

print(m)


from string import ascii_lowercase
n = int(input())
words = [input() for _ in range(n)]
words = [word for word in words if len(set(word)) <= 2]
best = -1
for i1 in range(25):
    for i2 in range(i1 + 1, 26):
        cs = {ascii_lowercase[i1], ascii_lowercase[i2]}
        cw = [word for word in words if set(word) <= cs]
        cl = sum(len(word) for word in cw)
        if cl > best:
            best = cl
print(best)


n = int(input())
s = []
for i in range(n):
    k = input()
    s.append(k)
maxans = -1
for i in range(26):
    for j in range(26):
        ans = 0
        for k in s:
            for p in range(len(k)):
                if k[p] != chr(ord('a') + i) and k[p] != chr(ord('a') + j):
                    break
            if k[p] == chr(ord('a') + i) or k[p] == chr(ord('a') + j):
                ans += len(k)
        if ans > maxans:
            maxans = ans
print(maxans)


n = int(input())
a = [input() for i in range(n)]
alp = 'qwertyuiopasdfghjklzxcvbnm'
ans = 0
for i in range(26):
  for j in range(i + 1, 26):
    c1, c2 = alp[i], alp[j]
    cur = 0
    for s in a:
      if set(s) in ({c1, c2}, {c1}, {c2}):
        cur += len(s)
    ans = max(ans, cur)
print(ans)


n = int(input())
letters = 'qwertyuiopasdfghjklzxcvbnm'
words=[]
for i in range (n):
    words += [input()]

maxL=0
for i in range (25):
    for j in range (i+1, 26):
        letter1 = letters[i]
        letter2 = letters[j]
        currentL=0
        for word in words:
            good=True
            for letter in word:
                if letter!=letter1 and letter!=letter2:
                    good=False
            if good:
                currentL += len(word)
        if currentL > maxL:
            maxL = currentL
print(maxL)


import string
n = int(input())
a = []
for i in range(n):
        a.append(input())
ans = 0
small = string.ascii_lowercase
for i in small:
        for j in small:
                tmp = 0
                for s in a:
                        cnt = 0
                        for c in s:
                                if c == i or c == j:
                                        cnt += 1
                        if cnt == len(s):
                                tmp += len(s)
                ans = max(ans, tmp)
print(ans)


n=int(input())
i=0
x=[]
while i<n:
	x.append(str(input()))
	i+=1
i=25
r=0
while i:
	j=i
	while j:
		j-=1
		t=0
		k=n
		while k:
			k-=1
			y=x[k]
			z=len(y)
			ok=1
			while z:
				z-=1
				if ord(y[z])-ord('a')!=i:
					if ord(y[z])-ord('a')!=j:ok=0
			if ok:t+=len(y)
		if r<t:r=t
	i-=1
print(r)


n = int(input())


inp = [input() for i in range(n)]

gets = []

for line in inp:
    dt = {}
    for c in line:
        if c == ' ':
            continue
        if c in dt:
            dt[c] += 1
        else:
            dt[c] = 1
    ans = -1
    if len(dt) > 2:
        continue
    gets.append(dt)

lets = 'abcdefghijklmnopqrstuvwxyz'

ans = -1
for c1 in lets:
    for c2 in lets:
        if c2 <= c1:
            continue
        cans = 0
        for l in gets:
            failed = False
            for ch in l:
                if ch not in (c1, c2):
                    failed = True
            if failed:
                continue
            cans += sum(l.values())
        if cans > ans:
            ans = cans

print(ans)


n=int(input())
t=[[0 for i in range(26)] for j in range(26)]
for i in range(n):
	s=input()
	g=[0 for j in range(26)]
	for j in s:
		g[ord(j)-ord('a')]+=1
	nb=0
	for j in g:
		if j>0:nb+=1
	if nb==1:
		l=0
		for j in range(26):
			if g[j]>0:l=j
		for j in range(26):
			if l!=j:
				t[l][j]+=len(s)
				t[j][l]+=len(s)
	elif nb==2:
		l1=-1
		l2=-1
		for j in range(26):
			if g[j]>0:
				if l1==-1:l1=j
				else:l2=j
		t[l1][l2]+=len(s)
		t[l2][l1]+=len(s)
nb=0
for i in range(26):
	for j in range(26):
		nb=max(t[i][j],nb)
print(nb)

import math
from decimal import *
import sys
from fractions import Fraction


n=int(input())

S=set()
M=dict()
ma=0
alf = "abcdefghijklmnopqrstuvwxyz"
for c in range(0,n):
    s=input()
    L=len(s)
    co=len(set(s))
    if co == 1:
        ch=s[0]
        for j in alf:
            if ch+j not in S:
                S.add(ch+j)
                M[ch+j] = L
            else:
                M[ch+j] += L
            if ch != j:
                if j+ch not in S:
                    S.add(j+ch)
                    M[j+ch] = L
                else:
                    M[j+ch] += L
    if co == 2:
        ch1 = s[0]
        for j in range(0,L):
            if s[j] != ch1:
                ch2 = s[j]
        if ch1+ch2 not in S:
            S.add(ch1+ch2)
            M[ch1+ch2] = L
        else:
            M[ch1+ch2] += L
        if ch2+ch1 not in S:
            S.add(ch2+ch1)
            M[ch2+ch1] = L
        else:
            M[ch2+ch1] += L
for i in alf:
    for j in alf:
        if i+j in S:
            if M[i+j]>ma:
                ma=M[i+j]
print(ma)
    
    


n=int(input())
word=[]
val=[]
alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for i in range(n):
    a=input()
    if len(set(a))>2:
        pass
    else:
        word.append(set(a))
        val.append(len(a))
m=0
for i in alpha:
    for j in alpha:
        s=0
        for k in range(len(word)):
            if word[k].issubset({i,j}):
                s+=val[k]
        m=max(m,s)
print(m)

n = int(input())
arr = ["."] * n
d = dict()
for i in range(n):
    arr[i] = input().strip()
    s = set()
    for j in range(len(arr[i])):
        s.add(arr[i][j])
    if len(s) <= 2:    
        try:
            d[arr[i]][0] += 1
        except:
            d[arr[i]] = [1, s]
#print(d)    
ans = 0
for i in range(97, 97+26):
    for j in range(97, 97+26):
        c = 0
        a, b = chr(i), chr(j)
        q = set([a, b])
        for k in list(d.keys()):
            if q >= d[k][1]:
                c += d[k][0] * len(k)
        ans = max(ans, c)
print(ans)
        


n = int(input())
words = [input() for _ in range(n)]

abc = list('qwertyuiopasdfghjklzxcvbnm')
ans = 0
for i in range(len(abc)):
    for j in range(i+1,len(abc)):
        preAns = 0
        for word in words:
            canAdd = True
            for char in word:
                if char != abc[i] and char != abc[j]:
                    canAdd = False
                    break
            if canAdd:
                preAns += len(word)
        ans = max(ans, preAns)
print(ans)


#!/usr/bin/env python3

from collections import defaultdict
from itertools   import combinations

def main():
    n = int(input())
    d = defaultdict(lambda: 0)
    for i in range(n):
        s = input()
        c1 = c2 = None
        for c in s:
            if c not in (c1, c2):
                if c1 is None:
                    c1 = c
                elif c2 is None:
                    c2 = c
                else:
                    break
        else:
            if c2 is not None:
                a = ord(c1) - 97
                b = ord(c2) - 97
                d[(min(a, b), max(a, b))] += len(s)
            else:
                a = ord(c1) - 97
                for j in range(26):
                    d[(min(a, j), max(a, j))] += len(s)
    result = 0
    for a, b in combinations(list(range(26)), 2):
        result = max(result, d[(a, b)])
    print(result)

try:
    while True:
        main()
except EOFError:
    pass


import string
n = int(input())
d = dict()
for i in range(n):
    word = input()
    chars = set(word)
    if len(chars) < 3:
        dc = ''.join(sorted(chars))
        d[dc] = d.get(dc, 0) + len(word)
best = 0
for c1 in string.ascii_lowercase:
    for c2 in string.ascii_lowercase:
        curscore = 0
        for dc in d:
            if set(dc) <= set(c1+c2):
                curscore += d[dc]
        if curscore > best:
            best = curscore
print(best)

n = int(input())
c = [[0] * 26 for i in range(26)]
for w in range(n):
    word = input()
    wset = list(set(word))
    wset[0] = ord(wset[0]) - ord('a')
    if len(wset) > 1:
        wset[1] = ord(wset[1]) - ord('a')
    if len(wset) == 2:
        c[wset[0]][wset[1]] += len(word)
        c[wset[1]][wset[0]] += len(word)
    if len(wset) == 1:
        for i in range(26):
            c[i][wset[0]] += len(word)
            c[wset[0]][i] += len(word)
            c[wset[0]][wset[0]] -= len(word)
print(max([max(c[i]) for i in range(26)]))    


n=int(input())
s=[input() for i in range(n)]
l=[(set(x),len(x)) for x in s if len(set(x))<3]
ans=0
n=len(l)
t=[""]+list("qwertyuiopasdfghjklzxcvbnm")
for i in range(27):
    for j in range(27):
        if i==j: continue    
        r=0
        for k in range(n):
            if len(l[k][0]|{t[i]}|{t[j]})<3: r+=l[k][1]
        if r>ans: ans=r
print(ans)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from itertools import combinations

n = int(input())
lines = [input() for i in range(0,n)]
ans = 0

for a,b in combinations([chr(i) for i in range(ord('a'),ord('z')+1)], 2):
    hoge = 0
    for l in lines:
        sets = set(l)
        if len(sets) > 2 or (a not in sets and b not in sets): continue
        if len(sets) == 2 and not (a in sets and b in sets): continue
        hoge += len(l)
    ans = max(ans, hoge)
print(ans)
        
            


N = int(input())
tbl = [[0]*26 for x in range(26)]
for n in range(N):
	word = input()
	chrs = [0]*26
	for c in word: chrs[ord(c)-97] += 1
	stuff = [(i, x) for i, x in enumerate(chrs) if x > 0]
	if len(stuff) == 1:
		for a in range(26):
			if a != stuff[0][0]:
				tbl[a][stuff[0][0]] += stuff[0][1]
				tbl[stuff[0][0]][a] += stuff[0][1]
	elif len(stuff) == 2:
		tbl[stuff[0][0]][stuff[1][0]] += stuff[0][1] + stuff[1][1]
		tbl[stuff[1][0]][stuff[0][0]] += stuff[0][1] + stuff[1][1]

ans = 0
for a in range(26):
	for b in range(26):
		ans = max(ans, tbl[a][b])

print(ans)


n = int(input()) 

data = [] 
for i in range(n): 
    data.append(input()) 

res = -1 
cur_res = 0 

for i in range(ord('a'), ord('z') + 1): 
    for j in range(i + 1, ord('z') + 1): 
        for k in range(n): 
            if data[k].count(chr(i)) + data[k].count(chr(j)) == len(data[k]): 
                cur_res += len(data[k]) 
        res = max(res, cur_res) 
        cur_res = 0 

print(res) 


# n = int(input())
# s = input().strip()
# a = [int(tmp) for tmp in input().split()]
n = int(input())
s = [[0] * 26 for i in range(26)]
for i in range(n):
    tmp = input().strip()
    lel = [0] * 26
    lens = len(tmp)
    for j in tmp:
        lel[ord(j) - ord('a')] = lens
    if lel.count(0) == 24:
        tmp = 0
        for j in range(26):
            if tmp == 0 and lel[j] != 0:
                tmp += 1
                a = j
            if tmp == 1 and lel[j] != 0:
                b = j
        s[a][b] += lens
        s[b][a] += lens
    if lel.count(0) == 25:
        for j in range(26):
            if lel[j] != 0:
                a = j
        for j in range(26):
            s[a][j] += lens
            if j != a:
                s[j][a] += lens
mx = 0
for i in range(26):
    for j in range(26):
        mx = max(mx, s[i][j])
print(mx)

words=[]
n=int(input().strip())
for i in range(n):
    words.append(input().strip())
    
let=[chr(i) for i in range(ord('a'),ord('z')+1)]
max_tot_len=0
for i in range(len(let)):
    for j in range(i+1,len(let)):
        a=let[i]
        b=let[j]
        tot_len=0
        for w in words:
            if all([c in [a,b] for c in w]):
                tot_len+=len(w)
        if tot_len>max_tot_len:
            max_tot_len=tot_len
print(max_tot_len)


def valid(w,a,b):
    for i in w:
        if i not in [a,b]:
            return False
    return True
n=int(input())
words=[]
for i in range(n):
    s=input()
    words.append(s)
maxi=0
for i in range(26):
    for j in range(26):
        a,b=chr(97+i),chr(97+j)
        cur=0
        for w in words:
            if valid(w,a,b):
                cur+=len(w)
        if cur>maxi:
            maxi=cur
            
print(maxi)