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;
char s[1000006];
int n, m;
long long f[26];
int main() {
  scanf("%d", &n);
  for (; n--;) {
    scanf("%s", s);
    m = strlen(s);
    vector<pair<int, int> > G;
    for (int i = 0, j; i < m; i = j) {
      for (j = i; j < m && s[i] == s[j]; j++)
        ;
      G.push_back(make_pair(s[i] - 'a', j - i));
    }
    if (G.size() == 1) {
      for (int i = (0), LIM = (25); i <= LIM; i++)
        if (i ^ G[0].first) f[i] = min(f[i], 1ll);
      f[G[0].first] += (f[G[0].first] + 1ll) * G[0].second;
    } else {
      for (int i = (0), LIM = (25); i <= LIM; i++) f[i] = min(f[i], 1ll);
      if (G[0].first == G.back().first)
        f[G[0].first] += G[0].second + G.back().second;
      else {
        f[G[0].first] += G[0].second;
        f[G.back().first] += G.back().second;
      }
      for (int i = (0), LIM = (G.size() - 1); i <= LIM; i++)
        f[G[i].first] = max(f[G[i].first], G[i].second * 1ll);
    }
  }
  long long ans = 0;
  for (int i = (0), LIM = (25); i <= LIM; i++) ans = max(ans, f[i]);
  printf("%d\n", ans);
}
