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 = 100005;
const int MAXC = 256;
char s[MAXN];
int f[MAXC], nf[MAXC];
int main() {
  int n, m, ans = 0;
  scanf("%d", &n);
  for (int i = 0, pre, suf; i < n; ++i) {
    scanf("%s", s);
    m = strlen(s);
    memset(nf, 0, sizeof(nf));
    for (int j = 0, cur = 0; j < m; ++j)
      cur = (j > 0 && s[j] == s[j - 1] ? cur + 1 : 1),
      nf[s[j]] = max(nf[s[j]], cur);
    for (char ch = 'a'; ch <= 'z'; ++ch)
      nf[ch] = max(nf[ch], f[ch] > 0 ? 1 : 0);
    pre = suf = 0;
    for (int j = 0; j < m; ++j, ++pre)
      if (s[j] != s[0]) break;
    for (int j = m - 1; j >= 0; --j, ++suf)
      if (s[j] != s[m - 1]) break;
    if (pre == m) nf[s[0]] = max(nf[s[0]], f[s[0]] * m + f[s[0]] + m);
    if (f[s[0]]) nf[s[0]] = max(nf[s[0]], 1 + pre + (s[0] == s[m - 1]) * suf);
    if (f[s[m - 1]])
      nf[s[m - 1]] = max(nf[s[m - 1]], 1 + suf + (s[0] == s[m - 1]) * pre);
    memcpy(f, nf, sizeof(f));
  }
  for (char ch = 'a'; ch <= 'z'; ++ch) ans = max(ans, f[ch]);
  printf("%d\n", ans);
  return 0;
}
