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 ch[100005];
long long a[27], b[27];
int main() {
  long long n, l, x, y;
  bool fl;
  cin >> n;
  while (n--) {
    scanf("%s", ch);
    fl = 0;
    l = strlen(ch);
    for (int i = 0; i <= l - 1; ++i) ch[i] -= 97;
    for (int i = 1; i <= l - 1; ++i)
      if (ch[i] != ch[0]) fl = 1;
    if (!fl) {
      x = ch[0];
      if (a[x] <= 1000000000) a[x] = a[x] + (a[x] + 1) * l;
      for (int j = 0; j <= 25; ++j)
        if (j != x) {
          if (a[j] > 0) a[j] = 1;
        }
    } else {
      int ox = 0, oy = 0, L = 0, R = l - 1;
      while (ch[L] == ch[0]) ++ox, ++L;
      while (ch[R] == ch[l - 1]) ++oy, --R;
      x = ch[0], y = ch[l - 1];
      if (x == y) {
        if (a[x] > 0)
          a[x] = 1 + ox + oy;
        else
          a[x] = max(ox, oy);
      } else {
        if (a[x] > 0) a[x] = 1;
        a[x] += ox;
        if (a[y] > 0) a[y] = 1;
        a[y] += oy;
      }
      long long cnt = 1;
      memset(b, 0, 216);
      for (int i = 1; i <= l - 1; ++i) {
        if (ch[i] == ch[i - 1])
          ++cnt;
        else
          b[ch[i - 1]] = max(b[ch[i - 1]], cnt), cnt = 1;
      }
      b[ch[l - 1]] = max(b[ch[l - 1]], cnt);
      for (int i = 0; i <= 25; ++i)
        if (i != x && i != y) {
          if (a[i] > 0) a[i] = 1;
        }
      for (int i = 0; i <= 25; ++i) a[i] = max(a[i], b[i]);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= 25; ++i) ans = max(ans, a[i]);
  cout << ans << endl;
  return 0;
}
