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 long long N = 1e5 + 5, M = 26;
long long n, m, pre, suf, f[N][M], ans;
char s[N];
signed main() {
  scanf("%lld", &m);
  for (long long i = 1; i <= m; i++) {
    scanf("%s", s + 1), n = strlen(s + 1), pre = suf = 1;
    for (long long j = 2; j <= n; j++) {
      if (s[j] == s[1])
        pre++;
      else
        break;
    }
    for (long long j = n - 1; j >= 1; j--) {
      if (s[j] == s[n])
        suf++;
      else
        break;
    }
    for (long long j = 0; j < 26; j++) f[i][j] = (f[i - 1][j] > 0);
    for (long long j = 1; j <= n; j++) {
      long long k = j;
      while (k + 1 <= n && s[k + 1] == s[j]) k++;
      f[i][s[j] - 'a'] = max(f[i][s[j] - 'a'], k - j + 1), j = k;
    }
    if (pre == n)
      f[i][s[1] - 'a'] = (f[i - 1][s[1] - 'a'] + 1) * n + f[i - 1][s[1] - 'a'];
    else {
      f[i][s[1] - 'a'] =
          max(f[i][s[1] - 'a'], pre + (f[i - 1][s[1] - 'a'] > 0));
      f[i][s[n] - 'a'] =
          max(f[i][s[n] - 'a'], suf + (f[i - 1][s[n] - 'a'] > 0));
      if (s[1] == s[n] && f[i - 1][s[1] - 'a'])
        f[i][s[1] - 'a'] = max(f[i][s[1] - 'a'], pre + suf + 1);
    }
  }
  for (long long j = 0; j < 26; j++) ans = max(ans, f[m][j]);
  printf("%lld\n", ans);
  return 0;
}
