9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
long long int dp[maxn], sum[30], cnt[30];
int main() {
  int n;
  while (~scanf("%d", &n) && n) {
    for (int i = 0; i < 30; i++) sum[i] = cnt[i] = 0;
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      for (int i = 0; i < str.size(); i++) {
        str[i] -= 'a';
        if (i == 0 || str[i] != str[i - 1])
          dp[i] = 1;
        else
          dp[i] = dp[i - 1] + 1;
      }
      long long int num[30];
      memset(num, 0, sizeof(num));
      for (int i = 0; i < str.size(); i++) {
        num[str[i]] = max(dp[i], num[str[i]]);
      }
      for (int i = 0; i < 30; i++) {
        if (num[i] != 0) {
          sum[i] += num[i] * (sum[i] + 1);
          cnt[i]++;
        }
      }
    }
    long long int res = 1;
    for (int i = 0; i < 26; i++)
      if (sum[i] > res && cnt[i] != 1) res = sum[i];
    printf("%I64\n", res);
  }
  return 0;
}
