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>
const long long N = 2e5 + 7, mod = 1e9 + 7, mod2 = mod * mod;
typedef long long aN[N];
char s[N];
long long f[N][27];
void qmax(long long& a, long long b) {
  if (a < b) a = b;
}
long long readll() {
  long long x = 0, w = 1;
  int c = getchar();
  for (; c < '0' || c > '9'; c - '-' || (w = -w), c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + (c ^ 48), c = getchar())
    ;
  return x * w;
}
int readchar(int l = '0', int r = 'z') {
  int c = getchar();
  for (; c < l || c > r; c = getchar())
    ;
  return c;
}
int main() {
  long long n = readll();
  for (register long long i = 1; i <= 26; i++) f[0][i] = 0;
  for (register long long t = 1; t <= n; t++) {
    long long* now = f[t];
    const long long* lst = f[t - 1];
    scanf("%s", s + 1);
    long long m = strlen(s + 1), fn = 0, ln = 0, fc = s[1] - 96, lc = s[m] - 96;
    long long ls = 0;
    for (register long long i = 1; i <= m; i++)
      if (s[i + 1] != s[i]) {
        qmax(now[s[i] - 96], i - ls), fn = fn ?: i - ls, ln = i - ls, ls = i;
      }
    for (register long long i = 1; i <= 26; i++) qmax(now[i], !!lst[i]);
    if (lst[fc]) qmax(now[fc], 1 + fn);
    if (lst[lc]) qmax(now[lc], 1 + ln);
    if (fc == lc && lst[fc]) qmax(now[fc], fn + ln + 1);
    if (fn == m) qmax(now[fc], m * (lst[fc] + 1) + lst[fc]);
  }
  long long ans = 0;
  for (register long long i = 1; i <= 26; i++) ans = std::max(ans, f[n][i]);
  printf("%lld\n", ans);
  return 0;
}
