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 int maxN = 100000 + 233;
const long long maxA = 1000000000 + 233;
int n;
long long a[26];
int main() {
  scanf("%d", &n);
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; ++i) {
    static char s[maxN];
    scanf("%s", s);
    int m = strlen(s);
    for (int i = 0; i < m; ++i) s[i] -= 'a';
    int pre = 0, post = 0;
    while (pre < m && s[pre] == s[0]) ++pre;
    while (post < m && s[m - 1 - post] == s[post]) ++post;
    for (int c = 0; c < 26; ++c) {
      if (pre == m)
        if (s[0] == c)
          a[c] = std::min(maxA, (a[c] + 1) * m + a[c]);
        else
          a[c] = 1;
      else if (a[c])
        a[c] = 1 + (s[0] == c ? pre : 0) + (s[m - 1] == c ? post : 0);
    }
    for (int i = 0; i < m; ++i) {
      int j = i;
      for (; s[i] == s[j] && j < m; ++j)
        ;
      a[(int)s[i]] = std::max(a[(int)s[i]], (long long)j - i);
      i = j - 1;
    }
  }
  long long ans = 0;
  for (int c = 0; c < 26; ++c) ans = std::max(ans, a[c]);
  printf("%d\n", (int)ans);
  return 0;
}
