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: EASY

Solutions:
n = int(input())
a = []
for i in range(n):
	b = input()
	c = {}
	count = 0
	for j in b:
		if j in c:
			c[j] += 1
		else:
			c[j] = 1
			count += 1
		if count > 2:
			break
	if 1 <= count <= 2:
		a.append(c)
eng = 'abcdefghijklmnopqrstuvwxyz'
maxs = 0
for i in range(26):
	for j in range(i + 1, 26):
		sum = 0
		for k in a:
			if eng[i] in k and eng[j] in k:
				sum += k[eng[i]] + k[eng[j]]
			elif eng[i] in k and len(list(k.keys())) == 1:
				sum += k[eng[i]]
			elif eng[j] in k and len(list(k.keys())) == 1:
				sum += k[eng[j]]
		maxs = max(sum, maxs)
print(maxs)


from string import ascii_lowercase
n = int(input())
cs = {}
for c in ascii_lowercase:
	cs[c] = 0
for i in range(n):
	s = input()
	_cs = {}
	for c in s:
		if c in _cs:
			_cs[c] += 1
		else:
			_cs[c] = 1
	k = list(_cs.keys())
	if len(k) == 1:
		cs[k[0]] += _cs[k[0]]
	elif len(k) == 2:
		ns = ''.join(sorted(k))
		if ns not in cs:
			cs[ns] = 0
		cs[ns] += _cs[k[0]]
		cs[ns] += _cs[k[1]]
m = 0
for c0 in ascii_lowercase:
	for c1 in ascii_lowercase:
		if c0 == c1:
			continue
		current = 0
		current += cs[c0]
		current += cs[c1]
		ns = ''.join(sorted(c0 + c1))
		if ns in cs:
			current += cs[ns]
		m = max(m, current)
print(m)


n = int(input())
arr = [input() for i in range(n)]
d1 = dict()
d2 = dict()
for s in arr:
	x = tuple(sorted(set(s)))
	if len(x) == 1:
		if s[0] in d1:
			d1[s[0]] += len(s)
		else:
			d1[s[0]] = len(s)
	elif len(x) == 2:
		if x in d2:
			d2[x] += len(s)
		else:
			d2[x] = len(s)
a = 0
if d1:
	m = d1.values()
	if len(m) == 1:
		a = max(m)
	else:
		m = sorted(m)
		m = m[::-1]
		a = m[0] + m[1]
b = 0
for (k, v) in d2.items():
	c = v
	if k[0] in d1:
		c += d1[k[0]]
	if k[1] in d1:
		c += d1[k[1]]
	b = max(b, c)
print(max(a, b))


n = int(input())
w = [str(input()) for p in range(n)]
l = []
for x in w:
	y = [str(p) for p in x]
	if len(set(y)) <= 2:
		l.append(x)
c = ''.join(l)
d = []
for x in c:
	if x not in d:
		d.append(x)
r = 0
for x in d:
	for y in d:
		s = 0
		for z in l:
			b = [str(p) for p in z]
			if set([x, y]).issuperset(set(b)):
				s += len(z)
		if s > r:
			r = s
print(r)


letras = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
text = []
tamanhos = []
for i in range(n):
	aux = input()
	text.append(aux)
resp = 0
for i in range(26):
	for j in range(i + 1, 26):
		cont = 0
		for k in text:
			c = k.count(letras[i]) + k.count(letras[j])
			if c == len(k):
				cont += c
		if cont > resp:
			resp = cont
print(resp)


n = int(input())
d = dict()
for k in range(n):
	string = input()
	if len(string) == 1:
		if d.get(string[0]) is None:
			d[string[0]] = 1
		else:
			d[string[0]] += 1
	else:
		first = string[0]
		second = None
		count = 1
		flag = True
		for i in range(1, len(string)):
			if second is None and string[i] != first:
				second = string[i]
			if string[i] == first or string[i] == second:
				count += 1
			else:
				flag = False
				break
		if flag:
			if first == second or second is None:
				if d.get(first) is None:
					d[first] = count
				else:
					d[first] += count
			else:
				temp = [first, second]
				temp.sort()
				temp = ''.join(temp)
				if d.get(temp) is None:
					d[temp] = count
				else:
					d[temp] += count
maximum = 0
for i in range(26):
	for j in range(26):
		if j == i:
			first = chr(ord('a') + i)
			if (d[first] if d.get(first) is not None else 0) > maximum:
				maximum = d[first]
		else:
			first = chr(ord('a') + i)
			second = chr(ord('a') + j)
			temp1 = [first, second]
			temp1.sort()
			temp1 = ''.join(temp1)
			temp = (d[first] if d.get(first) is not None else 0) + (d[second] if d.get(second) is not None else 0) + (d[temp1] if d.get(temp1) is not None else 0)
			if temp > maximum:
				maximum = temp
print(maximum)


n = input()
d = dict()
empty = []
for i in range(int(n)):
	s = input()
	for c in s:
		if c in d:
			d[c] += 1
		else:
			d[c] = 1
	empty.append(s)
m = -1
for i in range(97, 123):
	for j in range(97, 123):
		ans = 0
		if j < i or d.get(chr(i), -1) == -1 or d.get(chr(j), -1) == -1:
			continue
		for k in range(len(empty)):
			flag = 0
			for c in empty[k]:
				if c != chr(i) and c != chr(j):
					flag = 1
					break
			if flag == 0:
				ans += len(empty[k])
		if m < ans:
			m = ans
print(m)


I = input
d = {}
S = 'abcdefghijklmnopqrstuvwxyz'
for i in S:
	for j in S:
		d[i + j] = 0
for _ in '1' * int(I()):
	s = I()
	t = set(s)
	for k in d:
		if set(k) >= t:
			d[k] += len(s)
print(max(d.values()))


data = [s for s in (input() for _ in range(int(input()))) if len(set(s)) <= 2]
print(max((sum((len(s) for s in data if set(s) <= {chr(i), chr(j)})) for i in range(ord('a'), ord('z') + 1) for j in range(i, ord('z') + 1))))


s = 'abcdefghijklmnopqrstuvwxyz'
lenth = 0
n = int(input())
l = []
for i in range(n):
	a = input()
	lenth += len(a)
	l.append(a)
maxes = [lenth for i in range(26 * 26)]
for l1 in s:
	for l2 in s:
		if l1 == l2:
			i = s.index(l1)
			maxes[i * 26 + i] = 0
			continue
		for i in range(n):
			bad = 0
			for let in l[i]:
				if let != l1 and let != l2:
					bad = 1
			if bad:
				maxes[26 * s.index(l1) + s.index(l2)] -= len(l[i])
print(max(maxes))


from collections import defaultdict
from itertools import combinations
n = int(input())
cs = set()
ss = []
for i in range(n):
	s = input()
	ss.append(s)
	for c in s:
		cs.add(c)
ans = 0
if len(cs) == 1:
	for s in ss:
		ans += len(s)
	if ans <= 1000:
		print(ans)
	else:
		print(0)
else:
	m = 0
	for c in cs:
		ans = 0
		for s in ss:
			if set(s) != set(c):
				continue
			for c in s:
				ans += 1
		if ans > m and ans <= 1000:
			m = ans
	for (c1, c2) in combinations(cs, 2):
		ans = 0
		for s in ss:
			if len(set(s) | set([c1, c2])) >= 3:
				continue
			for c in s:
				ans += 1
		if ans > m and ans <= 1000:
			m = ans
	print(m)


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())
strings = []
for i in range(n):
	strings.append(input())
data = [[] for i in range(n)]
for i in range(n):
	data[i].append(len(strings[i]))
	data[i].append('')
	for j in range(len(strings[i])):
		if strings[i][j] not in data[i][1]:
			data[i][1] += strings[i][j]
			data[i][1] = ''.join(sorted(data[i][1]))
alph = 'abcdefghijklmnopqrstuvwxyz'
max_summ = 0
for i in range(len(alph) - 1):
	for j in range(i + 1, len(alph)):
		summ = 0
		for c in range(n):
			if data[c][1] == alph[i] or data[c][1] == alph[j] or data[c][1] == alph[i] + alph[j]:
				summ += data[c][0]
		if summ > max_summ:
			max_summ = summ
print(max_summ)


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(xs):
	counts = [collections.Counter(s) for s in xs if len(set(s)) <= 2]
	all_letters = set(it.chain.from_iterable(counts))
	if len(all_letters) <= 1:
		return sum((sum(d.values()) for d in counts))
	maxval = 0
	for (a, b) in it.combinations(all_letters, 2):
		maxlocal = sum((d[a] + d[b] for d in counts if all((l in (a, b) for l in d))))
		maxval = max(maxval, maxlocal)
	return maxval

def print_stderr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def main():
	n = int(input())
	xs = [input().strip() for _ in range(n)]
	result = solve(xs)
	print(result)
main()


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(range(26), 2):
		result = max(result, d[a, b])
	print(result)
try:
	while True:
		main()
except EOFError:
	pass


words = [input() for _ in range(int(input()))]
alphabet = 'abcdefghijklmnopqrstuvwxyz'
Max = 0
for c in alphabet:
	for cc in alphabet:
		s = 0
		for w in words:
			if set([i for i in w]) <= {c, cc}:
				s += len(w)
		Max = max(Max, s)
print(Max)


from itertools import combinations
n = int(input())
a = [input() for _ in range(n)]
ans = 0
for (c, d) in combinations('abcdefghijklmnopqrstuvwxyz', 2):
	t = 0
	for s in a:
		if len(s) == s.count(c) + s.count(d):
			t += len(s)
	ans = max(ans, t)
print(ans)


from collections import Counter
from itertools import combinations

def main():
	n = int(input())
	single = Counter()
	double = Counter()
	for w in range(n):
		word = input()
		letters = set(word)
		if len(letters) == 1:
			single[word[0]] += len(word)
		elif len(letters) == 2:
			(m1, m2) = (min(letters), max(letters))
			double[m1, m2] += len(word)
	res = 0
	if single:
		res = max(single.values())
	for (a, b) in combinations(single.items(), 2):
		c = a[1] + b[1]
		if c > res:
			res = c
	for ((a, b), v) in double.items():
		c = v + single[a] + single[b]
		if c > res:
			res = c
	print(res)
main()


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())
a = {}
for i in range(n):
	s = input()
	A = ''
	B = ''
	f = 0
	for j in s:
		if A == '' or A == j:
			A = j
		elif B == '' or B == j:
			B = j
		else:
			f = 1
	if f != 1:
		c = A + B if A < B else B + A
		if c in a:
			a[c] += len(s)
		else:
			a[c] = len(s)
maxi = 0
for i in a:
	for j in a:
		if i in j and i != j:
			a[j] += a[i]
			maxi = max(maxi, a[j])
		if len(j) == len(i) == 1 and i != j:
			maxi = max(maxi, a[i] + a[j])
		maxi = max(maxi, a[i])
print(maxi)


alpha = [[0] * 26 for _ in range(26)]
for _ in range(int(input())):
	s = input()
	st = set(s)
	if len(st) == 1:
		m = ord(st.pop()) - ord('a')
		for i in range(26):
			alpha[m][i] += len(s)
			alpha[i][m] += len(s)
		alpha[m][m] -= len(s)
	elif len(st) == 2:
		m = ord(st.pop()) - ord('a')
		n = ord(st.pop()) - ord('a')
		alpha[m][n] += len(s)
		alpha[n][m] += len(s)
print(max([max(alpha[i]) for i in range(26)]))


n = int(input())
a = []
d = {}
ans = -1
for i in range(n):
	se = set()
	s = input()
	kol = 0
	for i in range(len(s)):
		if s[i] not in se:
			kol += 1
			se.add(s[i])
	if kol <= 2:
		a.append(s)
for i in range(ord('a'), ord('z') + 1):
	s = 0
	for j in a:
		s += j.count(chr(i))
	ans = max(ans, s)
for i in range(ord('a'), ord('z') + 1):
	for j in range(i + 1, ord('z') + 1):
		s = 0
		for k in a:
			k1 = k.count(chr(i))
			k2 = k.count(chr(j))
			if k1 + k2 == len(k):
				s += k1 + k2
		ans = max(ans, s)
print(ans)


z = int(input())
matrix = []
for i in range(26):
	matrix += [[0] * 26]
for i in range(z):
	x = input()
	y = list(set(x))
	lenght = len(y)
	if lenght > 2:
		continue
	elif lenght == 1:
		matrix[ord(y[0]) - 97][ord(y[0]) - 97] += len(x)
	else:
		matrix[ord(y[0]) - 97][ord(y[1]) - 97] += len(x)
		matrix[ord(y[1]) - 97][ord(y[0]) - 97] += len(x)
ans = 0
for i in range(26):
	for j in range(26):
		if i != j:
			ans = max(ans, matrix[i][i] + matrix[j][j] + matrix[i][j])
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)


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)


def main():
	l = ([], [])
	for _ in range(int(input())):
		w = [0] * 26
		s = input()
		for c in s:
			w[ord(c) - 97] += 1
		i = w.count(0)
		if i > 23:
			l[25 - i].append(w)
	(l2, l) = (l[1], [sum(_) for _ in zip([0] * 26, *l[0])])
	print(max((sum((w[i] + w[j] for w in l2 if w[i] and w[j])) + l[i] + l[j] for i in range(1, 26) for j in range(i))))
main()


n = int(input())
dict = {}
for _ in range(n):
	s = input()
	k = ''.join(sorted(set(s)))
	if len(set(s)) <= 2:
		dict[k] = dict.get(k, 0) + len(s)
print(max((dict.get(chr(i) + chr(j), 0) + dict.get(chr(i), 0) + dict.get(chr(j), 0) for i in range(97, 123) for j in range(97, 123) if i < j)))


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)


import operator
n = int(input())
dict2 = {}
for i in range(0, n):
	s = input()
	s1 = ''.join(set(s))
	count = len(s1)
	if count == 2:
		if s1 in dict2.keys():
			dict2[s1] += len(s)
		elif s1[::-1] in dict2.keys():
			dict2[s1[::-1]] += len(s)
		else:
			dict2[s1] = len(s)
			for a in dict2.keys():
				if a in s1 and s1 != a:
					dict2[s1] += dict2[a]
	if count == 1:
		for a in dict2.keys():
			if s1 in a and s1 != a:
				dict2[a] += len(s)
		if s1 in dict2.keys():
			dict2[s1] += len(s)
		else:
			dict2[s1] = len(s)
dict2['0'] = 0
maxsum = 0
count2 = 2
for (key, value) in sorted(dict2.items(), key=operator.itemgetter(1), reverse=True):
	if len(key) == 1:
		maxsum += value
		count2 -= 1
	if count2 == 0:
		break
a = max(maxsum, max(dict2.values()))
ans = str(a)
print(str(ans))


n = int(input())
N = []
d = {}
c = 0
M = {}
for i in range(n):
	s = input()
	p = set(s)
	if len(p) > 2:
		continue
	else:
		N.append(len(s))
		d.update({c: p})
		c += 1
		if len(p) == 1:
			if s[0] not in M.keys():
				M.update({s[0]: len(s)})
			else:
				M[s[0]] += len(s)
best = 0
done = []
for i in d:
	if d[i] not in done:
		p = d[i]
		c_sum = 0
		for j in d:
			if d[j].issubset(p) == True:
				c_sum += N[j]
		done.append(d[i])
		best = max(c_sum, best)
best_single = 0
for i in M:
	for j in M:
		if i != j:
			best_single = max(best_single, M[i] + M[j])
print(max(best, best_single))


import collections
import itertools
import string

def chars(word):
	return tuple(sorted(set(word)))
N = int(input())
cnt = collections.Counter()
for _ in range(N):
	word = input()
	cnt[chars(word)] += len(word)
res = 0
for (a, b) in itertools.product(string.ascii_lowercase, string.ascii_lowercase):
	r = cnt[tuple(a)]
	if a != b:
		r += cnt[tuple(b)] + cnt[a, b]
	res = max(res, r)
print(res)


import itertools
nr_lines = int(input())
lengths = []
mapping = {}
solo_maps = {}
result = 0
for i in range(nr_lines):
	raw = input()
	input_length = len(raw)
	distinct_letters = ''.join(set(raw))
	if len(distinct_letters) > 2:
		continue
	distinct_letters = ''.join(sorted(distinct_letters))
	index = len(lengths)
	lengths.append(input_length)
	if len(distinct_letters) == 1:
		entry = solo_maps.setdefault(distinct_letters, [])
		entry.append(index)
	else:
		entry = mapping.setdefault(distinct_letters, [])
		entry.append(index)
results = {}
for (chars, indices) in mapping.items():
	extra_one = solo_maps.get(chars[0], [])
	extra_two = solo_maps.get(chars[1], [])
	all_indices = list(set(extra_one + extra_two + indices))
	results[chars] = all_indices
for (char, indices) in solo_maps.items():
	results[char] = indices
combos = itertools.combinations(solo_maps.keys(), 2)
for x in combos:
	extra_one = solo_maps.get(x[0], [])
	extra_two = solo_maps.get(x[1], [])
	all_indices = list(set(extra_one + extra_two))
	results[x] = all_indices
for indices in results.values():
	bert = sum([lengths[x] for x in indices])
	result = max(bert, result)
print(result)


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())
a = {}
for i in range(ord('a'), ord('z') + 1):
	a[chr(i)] = 0
b = {}
for i in range(ord('a'), ord('z')):
	for j in range(i + 1, ord('z') + 1):
		b[chr(i), chr(j)] = 0
for _ in range(N):
	x = input()
	p = set(x)
	if len(p) == 1:
		a[x[0]] += len(x)
	elif len(p) == 2:
		p = sorted(p)
		b[p[0], p[1]] += len(x)
x = sorted(b, key=lambda x: b[x], reverse=True)
maxa = 0
for i in range(len(x)):
	t = b[x[i]] + a[x[i][0]] + a[x[i][1]]
	if t > maxa:
		maxa = t
print(maxa)


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)


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())
arr = []
for i in range(n):
	x = input()
	arr.append(x)
res = 0
for i in range(0, 26):
	for j in range(0, 26):
		r = 0
		for x in arr:
			for y in x:
				if ord(y) - ord('a') != i and ord(y) - ord('a') != j:
					break
			else:
				r += len(x)
		res = max(res, r)
print(res)


n = int(input())
l = []
ans = 0
for i in range(n):
	s = input()
	l.append(s)
x = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
	for j in range(i + 1, 26):
		c = 0
		for s in l:
			l1 = len(s)
			if s.count(x[i]) + s.count(x[j]) == l1:
				c += l1
		ans = max(ans, c)
c = 0
for s in l:
	l1 = len(s)
	if s.count('z') == l1:
		c += l1
ans = max(ans, c)
print(ans)


a = int(input())
ans = []
for i in range(a):
	s = input()
	ans.append(s)
gam = []
for i in range(26):
	for j in range(26):
		if 1 == 2:
			print('1')
		else:
			t = chr(97 + i) + chr(97 + j)
			gam.append(t)
maxa = 0
for i in range(len(gam)):
	cnt = 0
	if gam[i][1] == gam[i][0]:
		for j in range(len(ans)):
			if ans[j].count(gam[i][1]) == len(ans[j]):
				cnt += len(ans[j])
		maxa = max(maxa, cnt)
		cnt = 0
		continue
	for j in range(len(ans)):
		if ans[j].count(gam[i][0]) + ans[j].count(gam[i][1]) == len(ans[j]):
			cnt += len(ans[j])
	maxa = max(maxa, cnt)
print(maxa)


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)


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)


n = int(input())
w = []
for _ in range(n):
	s = input()
	if len(set(s)) <= 2:
		w.append(s)
d = set()
for s in w:
	d |= set(s)
d = list(d)
m = 0
for i in range(0, len(d)):
	for j in range(i, len(d)):
		total = 0
		s = set([d[i], d[j]])
		for x in w:
			if set(x) <= s:
				total += len(x)
		m = max(m, total)
print(m)


def f(c):
	if type(c) == int:
		return chr(c + 97)
	if type(c) == str:
		return ord(c) - 97

def g(s):
	r = []
	for i in s:
		if i not in r:
			r.append(i)
			if len(r) > 2:
				return r
	return r
m = [[0] * 26 for i in range(26)]
n = int(input())
for i in range(n):
	s = input()
	a = g(s)
	if len(a) == 1:
		m[f(a[0])][f(a[0])] += len(s)
	elif len(a) == 2:
		m[f(a[0])][f(a[1])] += len(s)
		m[f(a[1])][f(a[0])] += len(s)
cnt = 0
for i in range(26):
	for j in range(26):
		if i == j:
			cnt = max(cnt, m[i][j])
		else:
			cnt = max(cnt, m[i][i] + m[i][j] + m[j][j])
print(cnt)


n = int(input())
ds = {}
while n > 0:
	n -= 1
	s = input()
	ss = set(s)
	if len(ss) < 3:
		el = ''
		for i in ss:
			el += i
		ds.update({el: ds.get(el, 0) + len(s)})
maxds = 0
maxds1 = 0
maxds2 = 0
for i in ds:
	if len(i) == 1:
		if maxds1 < ds[i]:
			maxds2 = maxds1
			maxds1 = ds[i]
		elif maxds2 < ds[i]:
			maxds2 = ds[i]
	if len(i) == 2:
		m = ds[i] + ds.get(i[0], 0) + ds.get(i[1], 0) + ds.get(i[1] + i[0], 0)
		if maxds < m:
			maxds = m
if maxds < maxds1 + maxds2:
	maxds = maxds1 + maxds2
print(maxds)


z = input
r = range
d = [s for s in (z() for _ in r(int(z()))) if len(set(s)) <= 2]
print(max((sum((len(s) for s in d if set(s) <= {chr(i), chr(j)})) for i in r(97, 123) for j in r(i, 123))))


import string

def count_letters(word, candidates):
	counter = 0
	li = list()
	for c in string.ascii_lowercase:
		if word.find(c) != -1:
			counter += 1
			li.append(c)
	if counter <= 2:
		for a in li:
			if a not in candidates:
				candidates.append(a)
	return counter
n = int(input())
v = list()
candidates = list()
for i in range(n):
	s = input()
	if count_letters(s, candidates) <= 2:
		v.append(s)
m = 0
for (i, c1) in enumerate(candidates):
	ci = 0
	for (j, c2) in enumerate(candidates):
		caux = 0
		if j <= i and len(candidates) > 1:
			continue
		for w in v:
			if w.count(c2) == len(w):
				caux += len(w)
			elif w.count(c1) + w.count(c2) == len(w):
				caux += len(w)
		m = max(m, caux + ci)
print(m)


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)


n = int(input())
words = []
for i in range(n):
	word = input()
	cnt_letters = len(set(word))
	if cnt_letters > 2:
		continue
	words.append(word.lower())
res = 0
for i in range(26):
	for j in range(i + 1, 26):
		tmp = 0
		for w in words:
			if chr(i + 97) in w and chr(j + 97) in w:
				tmp += len(w)
			if chr(i + 97) in w and len(set(w)) == 1:
				tmp += len(w)
			if chr(j + 97) in w and len(set(w)) == 1:
				tmp += len(w)
		res = max(res, tmp)
print(res)


from string import ascii_lowercase as lower
import re
n = int(input())
words = [input() for _ in range(n)]
cur_max = -1
for first in lower:
	for second in lower:
		if second >= first:
			break
		regex = '^[%s%s]+$' % (first, second)
		count = 0
		for word in words:
			if re.match(regex, word):
				count += len(word)
		cur_max = max(cur_max, count)
print(cur_max)


import sys
from sys import stdin, stdout
n = int(input())
words = []
for i in range(n):
	words.append(stdin.readline().rstrip().split())
counts = [[0 for i in range(30)] for j in range(30)]
for word in words:
	nbLetters = len(set(word[0]))
	letters = list(set(word[0]))
	if nbLetters <= 2:
		if nbLetters == 1:
			letter = ord(letters[0]) - ord('a')
			for i in range(30):
				counts[letter][i] += len(word[0])
		if nbLetters == 2:
			letter1 = ord(letters[0]) - ord('a')
			letter2 = ord(letters[1]) - ord('a')
			counts[letter1][letter2] += len(word[0])
vmax = 0
for i in range(26):
	for j in range(26):
		if not i == j:
			vmax = max(vmax, counts[i][j] + counts[j][i])
stdout.write(str(int(vmax)) + '\n')


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	dic = {}
	allstr = []
	for x in range(n):
		s = input()
		allstr.append(s)
	ans = 0
	for x in range(ord('a'), ord('z') + 1):
		for y in range(ord('a'), ord('z') + 1):
			cnt = 0
			if x == y:
				continue
			for s in allstr:
				if chr(x) in list(s) and chr(y) in list(s) and (len(set(list(s))) == 2):
					cnt += len(s)
				elif len(set(list(s))) == 1 and (chr(x) in list(s) or chr(y) in list(s)):
					cnt += len(s)
			ans = max(ans, cnt)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
one = dict()
two = dict()
for i in range(n):
	f = input()
	q = set()
	for j in f:
		if j not in q:
			q.add(j)
	if len(q) < 3:
		if len(q) == 1:
			if ''.join(sorted(list(q))) in one:
				one[''.join(sorted(list(q)))] += len(f)
			else:
				one[''.join(sorted(list(q)))] = len(f)
		elif ''.join(sorted(list(q))) in two:
			two[''.join(sorted(list(q)))] += len(f)
		else:
			two[''.join(sorted(list(q)))] = len(f)
ans = 0
for i in two:
	if i[0] in one:
		two[i] += one[i[0]]
	if i[1] in one:
		two[i] += one[i[1]]
	if ans < two[i]:
		ans = two[i]
for i in one:
	if one[i] > ans:
		ans = one[i]
	for j in one:
		if i != j and one[i] + one[j] > ans:
			ans = one[i] + one[j]
print(ans)


n = int(input())
a = []
b = []
for i in range(n):
	s = input()
	a.append(sorted(list(set(s))))
	b.append(len(s))
v = 0
for i in range(97, 97 + 25):
	for j in range(98, 97 + 26):
		u = 0
		for k in range(n):
			for c in a[k]:
				if ord(c) != i and ord(c) != j:
					break
			else:
				u += b[k]
		v = max(u, v)
print(v)


a = int(input())
b = []
e = 0
f = 0
for i in range(a):
	b.append(input())
for i in range(97, 123):
	c = chr(i)
	for j in range(97, 123):
		d = chr(j)
		f = 0
		for k in b:
			ture = True
			for g in k:
				if g not in [c, d]:
					ture = False
			if ture:
				f += len(k)
		if f > e:
			e = f
print(e)


from collections import defaultdict
d = defaultdict(int)
for _ in range(int(input())):
	w = input()
	s = ''.join(sorted(set(w)))
	if len(s) < 2:
		for ch in 'abcdefghijklmnopqrstuvwxyz':
			if ch != s:
				d[''.join(sorted(s + ch))] += len(w)
	elif len(s) < 3:
		d[s] += len(w)
print(max(d.values(), default=0))


n = int(input())
if n > 1:
	lettersFull = {}
	inps = []
	for i in range(n):
		inp = str(input())
		letters = {}
		for ch in inp:
			try:
				letters[ch] = letters[ch] + 1
			except:
				letters[ch] = 1
		if len(letters) <= 2:
			inps.append(inp)
			for ch in letters:
				try:
					lettersFull[ch] = letters[ch] + lettersFull[ch]
				except:
					lettersFull[ch] = letters[ch]
	listLetters = [ch for ch in lettersFull]
	sums = {}
	mx = 0
	for ch1 in listLetters:
		for ch2 in listLetters:
			fullCount = 0
			for inp in inps:
				tmpCount = 0
				for ch in inp:
					if ch == ch1 or ch == ch2:
						tmpCount = tmpCount + 1
					else:
						tmpCount = 0
						break
				fullCount = fullCount + tmpCount
			if fullCount > mx:
				mx = fullCount
	if mx == 0 and len(listLetters) == 1:
		for inp in inps:
			mx = mx + len(inp)
	print(mx)
else:
	inp = str(input())
	letters = {}
	for ch in inp:
		try:
			letters[ch] = letters[ch] + 1
		except:
			letters[ch] = 1
	if len(letters) <= 2:
		print(len(inp))
	else:
		print(0)


n = int(input())
i = 0
dict = {}
a1 = ''
a2 = ''
while i < n:
	a1 = ''
	s = input()
	if len(s) > 0:
		a1 = s[0]
	a2 = ''
	f = 0
	for l in s:
		if l != a1 and l != a2:
			if a2 == '':
				a2 = l
			else:
				f = 1
				break
	if f == 0:
		length = len(s)
		if a2 != '' and ord(a1) > ord(a2):
			s = a2 + a1
		else:
			s = a1 + a2
		if len(s) == 1:
			for l in range(ord('a'), ord('z') + 1):
				if ord(a1) < l:
					s = a1 + chr(l)
				else:
					s = chr(l) + a1
				if s in dict:
					dict[s] = length + dict[s]
				else:
					dict[s] = length
		elif s in dict:
			dict[s] = length + dict[s]
		else:
			dict[s] = length
	i = i + 1
for w in sorted(dict, key=dict.get, reverse=True):
	print(dict[w])
	break
if len(dict) == 0:
	print(0)


s = 'qwertyuiopasdfghjklzxcvbnm'
n = int(input())
lst = []
for i in range(n):
	ss = input()
	lst2 = list(set(list(ss)))
	if len(lst2) <= 2:
		lst.append(ss)
mmax = 0
for i in range(26):
	cnt = 0
	for j in lst:
		if j.count(chr(97 + i)) == len(j):
			cnt = cnt + len(j)
	mmax = max(cnt, mmax)
for i in range(26):
	for j in range(i, 26):
		cnt = 0
		for k in lst:
			if k.count(chr(97 + i)) + k.count(chr(97 + j)) == len(k):
				cnt = cnt + len(k)
		mmax = max(cnt, mmax)
print(mmax)


import string
alphabet = string.ascii_lowercase

class Breakdown:

	def __init__(self, word):
		self.word = word
		self.length = len(word)
		self.count = {ch: word.count(ch) for ch in alphabet}
n = int(input())
breakdowns = [Breakdown(input().strip()) for i in range(n)]
best = 0
for (i, a) in enumerate(alphabet):
	for j in range(i + 1, len(alphabet)):
		b = alphabet[j]
		count = 0
		for breakdown in breakdowns:
			if breakdown.count[a] + breakdown.count[b] == breakdown.length:
				count += breakdown.length
		best = max(best, count)
print(best)


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)


n = int(input())
li = [s for s in (input() for _ in range(n)) if len(set(s)) <= 2]
print(max((sum((len(s) for s in li if set(s) <= {chr(i), chr(j)})) for i in range(97, 123) for j in range(i, 123))))


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

def pick2(arr):
	if len(arr) == 1:
		yield arr[0]
		return
	for i in range(len(arr)):
		for j in range(i + 1, len(arr)):
			yield (arr[i], arr[j])

def buildVocabulary(words):
	D = set()
	for word in words:
		for l in word:
			D.add(l)
	return list(D)

def pick(w, D):
	for l in w:
		if l not in D:
			return False
	return True

def filterLegal(words, lettersPicked):
	D = set()
	for l in lettersPicked:
		D.add(l)
	for w in words:
		if pick(w, D):
			yield w
vocab = buildVocabulary(words)
score = 0
for lettersPicked in pick2(vocab):
	lscore = 0
	for w in filterLegal(words, lettersPicked):
		lscore += len(w)
	score = max(score, lscore)
print(score)


w = [c for c in (input() for _ in range(int(input()))) if len(set(c)) < 3]
b = 0
for i in range(97, 122):
	for j in range(i, 123):
		b = max(b, sum((len(c) for c in w if set(c) <= {chr(i), chr(j)})))
print(b)


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)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
en = lambda x: list(enumerate(x))
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = [ip() for _ in range(n)]
ans = 0
c = 0
for i in string.ascii_lowercase:
	for j in string.ascii_lowercase:
		if i == j:
			continue
		ans = 0
		base = set([i, j])
		for k in arr:
			x = set(k)
			if x <= base:
				ans += len(k)
		c = max(ans, c)
print(c)


def main():
	letters = set()
	for c in range(ord('a'), ord('z') + 1):
		letters.add(chr(c))
	n = int(input())
	r = 0
	g = []
	for i in range(n):
		o = list(input())
		x = set(o)
		if len(x) <= 2:
			g.append((x, len(o)))
	for a in range(ord('a'), ord('z') + 1):
		for b in range(ord('a'), ord('z') + 1):
			ret = 0
			for gg in g:
				if len(gg[0].difference(set([chr(a), chr(b)]))) == 0:
					ret += gg[1]
			r = max(ret, r)
	return r
print(main())


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())
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)


def mass(string):
	answer = []
	for i in range(len(string)):
		answer.append(string[i])
	return answer
n = int(input())
data = []
alp = ['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):
	data.append(input())
for i in range(n):
	data[i] = [list(set(mass(data[i]))), len(data[i])]
	if len(data[i][0]) == 1:
		data[i][0].append(data[i][0][0])
answer = []
for i in range(26):
	for j in range(i, 26):
		max2 = 0
		help = [alp[i], alp[j]]
		for k in range(len(data)):
			if len(data[k][0]) == 2 and data[k][0][0] in help and (data[k][0][1] in help):
				max2 += data[k][1]
		answer.append(max2)
print(max(answer))


a2 = [[0 for i in range(26)] for i in range(26)]
a1 = [0 for i in range(26)]
mx = 0
n = int(input())
s_l = set()
for i in range(n):
	string = input()
	for i in range(len(string)):
		s_l.add(string[i])
	if len(s_l) == 2:
		s_ll = list(s_l)
		a2[ord(s_ll[0]) - 97][ord(s_ll[1]) - 97] += len(string)
		a2[ord(s_ll[1]) - 97][ord(s_ll[0]) - 97] += len(string)
	elif len(s_l) == 1:
		s_ll = list(s_l)
		a1[ord(s_ll[0]) - 97] += len(string)
	s_l = set()
for i in range(26):
	for j in range(i + 1, 26):
		if a2[i][j] + a1[i] + a1[j] > mx:
			mx = a2[i][j] + a1[i] + a1[j]
print(mx)


n = int(input())
words = []
letters = []
letfreq = {}
res = []
for w in range(n):
	wo = input()
	if len(set(list(wo))) < 3:
		words.append(wo)
		for let in set(list(wo)):
			letters.append(let)
if len(words) == 0:
	print(0)
	exit()
if len(set(letters)) == 1:
	cnt = 0
	for bruhy in words:
		cnt += len(bruhy)
	print(cnt)
	exit()
for lt1 in set(letters):
	for lt2 in set(letters):
		loc = 0
		for o in words:
			if o.count(lt1) + o.count(lt2) == len(o):
				loc += len(o)
		res.append(loc)
print(max(res))


import itertools
n = int(input())
words = [input() for x in range(n)]
letterList = []
for i in words:
	for character in i:
		if character not in letterList:
			letterList.append(character)
maxLength = 0
if len(letterList) == 1:
	for word in words:
		maxLength += len(word)
	print(maxLength)
	exit()
allCombinations = itertools.combinations(letterList, 2)
for c in allCombinations:
	(a, b) = (list(c)[0], list(c)[1])
	length = 0
	for word in words:
		j = 0
		for character in word:
			j += 1
			if character != a and character != b:
				break
			if j == len(word):
				length += len(word)
	if length > maxLength:
		maxLength = length
print(maxLength)


n = int(input())
words = [input() for i in range(n)]
variants1 = {}
variants2 = {}
for word in words:
	word_set = frozenset(word)
	if len(word_set) == 1:
		if word_set not in variants1:
			variants1[word_set] = 0
		variants1[word_set] += len(word)
	elif len(word_set) == 2:
		if word_set not in variants2:
			variants2[word_set] = 0
		variants2[word_set] += len(word)
for variant1 in variants1:
	for variant2 in variants2:
		if variant1 < variant2:
			variants2[variant2] += variants1[variant1]
variants1_keys = list(variants1.keys())
l = len(variants1)
for i in range(l - 1):
	for j in range(i + 1, l):
		k = variants1_keys[i].union(variants1_keys[j])
		if k not in variants2:
			variants2[k] = variants1[variants1_keys[i]] + variants1[variants1_keys[j]]
max1 = max(variants1.values()) if variants1 else 0
max2 = max(variants2.values()) if variants2 else 0
print(max(max1, max2))


from string import ascii_lowercase
n = int(input())
hashed_words = {}
word_buffer = []
for i in range(n):
	data = [i for i in input().strip()]
	if len(set(data)) <= 2:
		if ''.join(set(data)) in hashed_words.keys():
			hashed_words[''.join(set(data))] += len(data)
		else:
			hashed_words[''.join(set(data))] = len(data)
if len(hashed_words) > 0:
	my_max = 0
	for i in ascii_lowercase:
		for j in ascii_lowercase:
			if i != j:
				current = 0
				if i in hashed_words:
					current += hashed_words[i]
				if j in hashed_words:
					current += hashed_words[j]
				if i + j in hashed_words:
					current += hashed_words[i + j]
				if j + i in hashed_words:
					current += hashed_words[j + i]
				if my_max < current:
					my_max = current
	print(my_max)
else:
	print(0)


import string

def main():
	buf = input()
	n = int(buf)
	w = []
	for i in range(n):
		buf = input()
		w.append(str(buf))
	char_count_list = []
	for (i, word) in enumerate(w):
		char_dict = {}
		for char in word:
			if char in char_dict:
				char_dict[char] += 1
			else:
				char_dict[char] = 1
		char_count_list.append(char_dict)
	max_char_length = 0
	for (i, c1) in enumerate(string.ascii_lowercase):
		for c2 in string.ascii_lowercase[i + 1:]:
			char_length = 0
			for char_dict in char_count_list:
				if len(char_dict) > 2:
					continue
				elif len(char_dict) == 2:
					if c1 in char_dict and c2 in char_dict:
						char_length += char_dict[c1] + char_dict[c2]
				elif len(char_dict) == 1:
					if c1 in char_dict:
						char_length += char_dict[c1]
					elif c2 in char_dict:
						char_length += char_dict[c2]
			if char_length > max_char_length:
				max_char_length = char_length
	print(max_char_length)
main()


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)


n = int(input())

def get_letts(s):
	chrs = set()
	for i in range(len(s)):
		chrs.add(s[i])
	return sorted(list(chrs))
words = [input() for i in range(n)]
chrs_comb = {}
for word in words:
	chrs = get_letts(word)
	if len(chrs) == 2:
		key = chrs[0] + chrs[1]
		if key not in chrs_comb:
			chrs_comb[key] = 0
		chrs_comb[key] += len(word)
	elif len(chrs) == 1:
		key = chrs[0]
		if key not in chrs_comb:
			chrs_comb[key] = 0
		chrs_comb[key] += len(word)
ans = 0
for comb in chrs_comb:
	if len(comb) == 2:
		ans_tmp = chrs_comb[comb]
		if comb[0] != comb[1]:
			if comb[0] in chrs_comb:
				ans_tmp += chrs_comb[comb[0]]
		if comb[1] in chrs_comb:
			ans_tmp += chrs_comb[comb[1]]
		ans = max(ans, ans_tmp)
	else:
		ans = max(ans, chrs_comb[comb[0]])
		for i in range(ord('a'), ord('z') + 1):
			if i != ord(comb[0]):
				if chr(i) in chrs_comb:
					ans = max(ans, chrs_comb[chr(i)] + chrs_comb[comb[0]])
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)


n = int(input())
a = []
for i in range(n):
	x = input()
	a.append(x)
res = 0
for i in range(26):
	for j in range(26):
		s = 0
		for x in a:
			for z in x:
				if ord(z) - ord('a') != i and ord(z) - ord('a') != j:
					break
			else:
				s += len(x)
		res = max(s, res)
print(res)


n = int(input())
hit = {1: [], 2: []}
for i in range(n):
	ni = input()
	setni = set(ni)
	lenni = len(setni)
	if 0 < lenni < 3:
		for k in range(len(hit[lenni])):
			if setni == set(hit[lenni][k]):
				hit[lenni][k] += list(ni)
				break
		else:
			hit[lenni].append(list(ni))
for h2 in range(len(hit[2])):
	for h1 in range(len(hit[1])):
		if len(set(hit[2][h2] + hit[1][h1])) < 3:
			hit[2][h2] += hit[1][h1]
len1 = [len(i) for i in hit[1]]
len2 = [len(i) for i in hit[2]]
max1 = sum(sorted(len1)[-2:])
max2 = max(len2 + [0])
print(max(max1, max2))


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]
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 d.keys():
			if q >= d[k][1]:
				c += d[k][0] * len(k)
		ans = max(ans, c)
print(ans)


import itertools
alphabet = 'abcdefghijklmnopqrstuvwxyz'
pairs = list(itertools.combinations(alphabet, 2))

def isValidForPair(wordSet, pair):
	hyp = False
	for i in range(len(pair)):
		hyp = hyp or pair[i] in wordSet
	return hyp and len(wordSet - set(pair)) is 0
(words, wordCount) = ([], int(input()))
for i in range(wordCount):
	word = input()
	words.append([len(word), set(word)])
articleLengths = [0] * len(pairs)
for i in range(len(pairs)):
	for j in range(len(words)):
		if isValidForPair(words[j][1], pairs[i]):
			articleLengths[i] += words[j][0]
print(max(articleLengths))


n = int(input())
w = [input() for _ in range(n)]
alpha = 'abcdefghijklmnopqrstuvwxyz'
m = 0
for l1 in alpha:
	for l2 in alpha:
		s = 0
		for x in w:
			if set(x) == set([l1, l2]) or set(x) == {l1} or set(x) == {l2}:
				s += len(x)
		m = max(m, s)
print(m)


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()


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)


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())
arr = dict()
for i in range(n):
	inp = input()
	s = set(inp)
	if len(s) < 3:
		arr[inp] = [arr.get(inp, [s, 0])[0], arr.get(inp, [s, 0])[1] + 1]
mx = 0
for i in range(97, 123):
	for j in range(i + 1, 123):
		cnt = 0
		for elem in arr:
			t = True
			for q in arr[elem][0]:
				if ord(q) not in [i, j]:
					t = False
					break
			if t:
				cnt += len(elem) * arr[elem][1]
		if mx < cnt:
			mx = cnt
print(mx)


result = 0
words = [input() for i in range(int(input()))]
words = [i for i in words if len(set(i)) <= 2]
for i in range(25):
	for j in range(i + 1, 26):
		result = max(result, sum((len(word) for word in words if set(word) <= {chr(97 + i), chr(97 + j)})))
print(result)


orda = ord('a')
counts = {}
for a in range(26):
	for b in range(a):
		counts[b, a] = 0

def process_word(word):
	letters = {}
	for ch in word:
		if ch in letters:
			letters[ch] += 1
		else:
			letters[ch] = 1
		if len(letters) > 2:
			return
	k = [ord(c) - orda for c in letters.keys()]
	if len(k) == 2:
		counts[min(k), max(k)] += sum(letters.values())
	else:
		for i in range(26):
			if i == k[0]:
				continue
			l = [k[0], i]
			counts[min(l), max(l)] += sum(letters.values())
n = int(input())
for i in range(n):
	process_word(input())
m = 0
for v in counts.values():
	m = max(m, v)
print(m)


n = int(input())
inp = []
for p in range(n):
	inp.append(input())
ans = 0
for i in range(0, 26):
	for j in range(i + 1, 26):
		curans = 0
		for o in range(n):
			fail = False
			for k in range(len(inp[o])):
				if inp[o][k] != chr(ord('a') + i) and inp[o][k] != chr(ord('a') + j):
					fail = True
					break
			if not fail:
				curans += len(inp[o])
		ans = max(ans, curans)
print(ans)


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())
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)


d = {}
for _ in range(int(input())):
	s = input()
	S = set(s)
	if len(S) <= 2:
		k = ''.join(sorted(S))
		if d.__contains__(k):
			d[k] += len(s)
		else:
			d[k] = len(s)
l = [[len(set(i)), set(i), d[i]] for i in d.keys()]
l1 = []
l = sorted(l, reverse=True)
for i in range(len(l)):
	if l[i][0] == 1:
		l1 = l[i:]
		del l[i:]
		break
if len(l) == 0 and len(l1) == 0:
	print(0)
elif len(l) != 0 and len(l1) != 0:
	for i in l:
		for j in l1:
			if len(i[1] | j[1]) == 2:
				i[2] += j[2]
	d = {}
	for i in l1:
		k = i[1].pop()
		if d.__contains__(k):
			d[k] += i[2]
		else:
			d[k] = i[2]
	if len(d) > 1:
		k = list(sorted(d.values(), reverse=True))
		print(max(k[0] + k[1], max((i[2] for i in l))))
	else:
		print(max(max(d.values()), max((i[2] for i in l))))
elif len(l) == 0 and len(l1) != 0:
	d = {}
	for i in l1:
		k = i[1].pop()
		if d.__contains__(k):
			d[k] += i[2]
		else:
			d[k] = i[2]
	if len(d) > 1:
		k = list(sorted(d.values(), reverse=True))
		print(k[0] + k[1])
	else:
		print(max(d.values()))
else:
	print(max((i[2] for i in l)))


w = [input() for _ in range(int(input()))]
w = [c for c in w if len(set(c)) <= 2]
b = -1
for i in range(25):
	for j in range(i + 1, 26):
		b = max(b, sum((len(c) for c in w if set(c) <= {chr(97 + i), chr(97 + j)})))
print(b)


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)


from collections import defaultdict, Counter
n = int(input())
data = [input() for i in range(n)]
m = 0
for a in range(ord('a'), ord('z') + 1):
	for b in range(ord('a'), ord('z') + 1):
		curr = 0
		for (i, x) in enumerate(data):
			c = Counter(x)
			if len(c.keys()) == 2 and chr(a) in c and (chr(b) in c) and (len(set(c.keys()) - set([chr(a), chr(b)])) == 0) or (len(c.keys()) == 1 and (chr(a) in c.keys() or chr(b) in c.keys())):
				curr += len(x)
		if curr > m:
			m = curr
print(m)


a = []
for i in range(int(input())):
	s = input()
	if len(set(s)) <= 2:
		a.append(s)
ans = 0
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
	for j in range(i + 1, 26):
		temp = 0
		for k in a:
			if k.count(alpha[i]) + k.count(alpha[j]) == len(k):
				temp += len(k)
		ans = max(ans, temp)
print(ans)


n = int(input())
str = []
for i in range(n):
	str.append(input())
(s1, ans) = (ord('a'), 0)
while s1 <= ord('z'):
	s2 = ord('a')
	while s2 <= ord('z'):
		tmp = 0
		if s1 == s2:
			s2 += 1
			continue
		for s in str:
			if s.count(chr(s1)) + s.count(chr(s2)) == len(s):
				tmp += len(s)
		ans = max(ans, tmp)
		s2 += 1
	s1 += 1
print(ans)


import itertools
N = int(input())
counter = itertools.repeat([0 for i in range(26)], 26)
words = [input() for i in range(N)]
words_bit = [0 for i in range(N)]
for i in range(N):
	for ch in words[i]:
		words_bit[i] |= 1 << ord(ch) - ord('a')
ans = 0
for i in range(26):
	for j in range(26):
		x = 1 << i | 1 << j
		sol = 0
		for k in range(N):
			if not words_bit[k] & ~x:
				sol += len(words[k])
		ans = ans if ans > sol else sol
print(ans)


__author__ = 'artyom'

def main():
	z = [[0] * 26 for _ in range(26)]
	for _ in range(read()):
		l = r = None
		a = read(0)
		for c in a:
			if l == None:
				l = c
			elif c != l:
				if r == None:
					r = c
					if l > r:
						(l, r) = (r, l)
				elif c != r:
					break
		else:
			z[ord(l) - 97][ord(r or l) - 97] += len(a)
	mx = 0
	for i in range(26):
		for j in range(i + 1, 26):
			s = z[i][i] + z[i][j] + z[j][j]
			if s > mx:
				mx = s
	return mx

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


arr = [0] * 256
matrix = [[0 for col in range(256)] for row in range(256)]

def check_number_of_char(str):
	global arr
	global matrix
	t = [0] * 256
	x = 0
	p = 0
	q = 0
	for i in range(0, len(str)):
		if t[ord(str[i])] == 0:
			x += 1
			if x == 1:
				p = ord(str[i])
			elif x == 2:
				q = ord(str[i])
		t[ord(str[i])] += 1
	if x == 1:
		arr[p] += t[p]
	elif x == 2:
		matrix[p][q] += t[p] + t[q]
	else:
		return

def max():
	global arr
	global matrix
	res = 0
	for i in range(0, 256):
		for j in range(i + 1, 256):
			t = arr[i] + arr[j] + matrix[i][j] + matrix[j][i]
			if t > res:
				res = t
	return res
n_of_words = int(input())
for i in range(0, n_of_words):
	check_number_of_char(input())
print(max())


import string
import itertools

def get_ans(s, c):
	(c1, c2) = c
	if c1 == c2:
		return 0
	sum_num = s.count(c1) + s.count(c2)
	if sum_num < len(s):
		return 0
	else:
		return len(s)

def num_symbols(data, p):
	return sum([get_ans(s, p) for s in data])
n = int(input())
pairs = itertools.product(string.ascii_lowercase, string.ascii_lowercase)
data = []
for i in range(n):
	s = input()
	data.append(s)
answers = [num_symbols(data, p) for p in pairs]
print(max(answers))


from sys import stdin
n = int(stdin.readline().strip())
s = []
for i in range(n):
	s1 = stdin.readline().strip()
	s.append(s1)
let = [chr(97 + i) for i in range(26)]
ans = 0
for i in range(26):
	for j in range(i, 26):
		aux = 0
		for k in range(n):
			x = s[k].count(let[i])
			y = 0
			if i != j:
				y = s[k].count(let[j])
			if x + y == len(s[k]):
				aux += y + x
		ans = max(ans, aux)
print(ans)


words = int(input())
(singles, doubles) = ({}, [])
for i in range(words):
	newEntry = input()
	newSet = set(newEntry)
	lenSet = len(newSet)
	foundit = False
	if lenSet == 1:
		if newEntry[0] not in singles.keys():
			singles.update({newEntry[0]: len(newEntry)})
		else:
			singles[newEntry[0]] += len(newEntry)
	elif lenSet == 2:
		if not doubles:
			doubles.append([len(newEntry), newSet])
		else:
			for d in doubles:
				if d[1] == newSet:
					d[0] += len(newEntry)
					foundit = True
					break
			if not foundit:
				doubles.append([len(newEntry), newSet])
one = 0
if doubles:
	for j in doubles:
		for k in singles.keys():
			j[0] += singles[k] if k in j[1] else 0
if singles:
	singlesort = sorted(singles.items(), reverse=True, key=lambda x: x[1])
	if len(singles) > 1:
		one += singlesort[0][1] + singlesort[1][1]
	else:
		one += singlesort[0][1]
doubles.sort(reverse=True)
print(doubles[0][0] if doubles and doubles[0][0] > one else one)


import itertools
import functools
N = int(input())
words = [input() for i in range(N)]
words_bit = [[functools.reduce(lambda x, y: x | y, [0] + [1 << ord(ch) - ord('a') for ch in words[i]])][0] for i in range(N)]
print(max([sum([len(words[k]) for k in range(N) if not words_bit[k] & ~(1 << i | 1 << j)]) for i in range(26) for j in range(26)]))


def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	gets = lambda : [str(x) for x in (f.readline() if mode == 'file' else input()).split()]
	[n] = get()
	p = {}
	for z in range(n):
		[g] = gets()
		temp = set(g)
		if len(temp) < 3:
			temp = list(temp)
			temp.sort()
			h = ''.join(temp)
			if h not in p:
				p[h] = 0
			p[h] += len(g)
	maxx = 0
	for i in p:
		t = p[i]
		if len(i) == 1:
			temp = 0
			for j in p:
				if j == i:
					continue
				if len(j) == 1:
					temp = max(temp, p[j])
			t += temp
		if len(i) == 2:
			if i[0] in p:
				t += p[i[0]]
			if i[1] in p:
				t += p[i[1]]
		maxx = max(maxx, t)
	print(maxx)
	if mode == 'file':
		f.close()
main()


a = {}
n = int(input())
for i in range(n):
	n = input()
	x = ''.join(sorted(set(n)))
	if len(x) < 3:
		if x in a:
			a[x] = a[x] + len(n)
		else:
			a[x] = len(n)
a = sorted(a.items(), key=lambda x: x[1], reverse=True)
sum = max = 0
for i in a:
	if len(i[0]) == 2:
		sum = i[1]
		for j in a:
			if len(j[0]) == 1 and j[0] in i[0]:
				sum = sum + j[1]
	else:
		sum = i[1]
		for j in a:
			if len(j[0]) == 1 and j[0] != i[0]:
				sum = sum + j[1]
				break
	if sum > max:
		max = sum
print(max)